-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Jules iou show paid preview #3404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fb8df7f
8d5d4d8
1881cd4
592e86f
3227a82
25c8e19
ec0070a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import withLocalize, {withLocalizePropTypes} from './withLocalize'; | |
| import {fetchIOUReportByID} from '../libs/actions/Report'; | ||
| import themeColors from '../styles/themes/default'; | ||
| import Icon from './Icon'; | ||
| import CONST from '../CONST'; | ||
| import {Checkmark} from './Icon/Expensicons'; | ||
|
|
||
| const propTypes = { | ||
|
|
@@ -82,6 +83,14 @@ const ReportActionItemIOUPreview = ({ | |
| onPayButtonPressed, | ||
| translate, | ||
| }) => { | ||
| // Usually the parent determines whether the IOU Preview is displayed. But as the iouReport total cannot be known | ||
| // until it is stored locally, we need to make this check within the Component after retrieving it. This allows us | ||
| // to handle the loading UI from within this Component instead of needing to declare it within each parent, which | ||
| // would duplicate and complicate the logic | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tbh, I don't really follow what logic would be complicated by this. It seems like the logic is already kind of weird and confusing and this comment doesn't explain much about why it was set up that way. e.g. this component perhaps should not be responsible for fetching the iou at all... this comment made me look into how we are doing it and... I think it's a pretty bad practice to be making an API call like this when the component renders... (instead of e.g. using a lifecycle method) Not sure if anything needs to be done right now and I won't block on it (since the issue seems important to address), but feels like a code smell to me.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, when making these changes it became apparent that the parent should perhaps be handling the loading state. Also, only one use of the comp has any requirement for displaying the preview now, so it might be possible to further simplify the I didn't want this to turn into a large refactor and risk longer delays, so I've created an issue to refactor this component that I'll make external. |
||
| if (iouReport.total === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const sessionEmail = lodashGet(session, 'email', null); | ||
| const managerEmail = iouReport.managerEmail || ''; | ||
| const ownerEmail = iouReport.ownerEmail || ''; | ||
|
|
@@ -131,7 +140,9 @@ const ReportActionItemIOUPreview = ({ | |
| ? translate('iou.owes', {manager: managerName, owner: ownerName}) | ||
| : translate('iou.paid', {manager: managerName, owner: ownerName})} | ||
| </Text> | ||
| {(isCurrentUserManager && !shouldHidePayButton && ( | ||
| {(isCurrentUserManager | ||
| && !shouldHidePayButton | ||
| && iouReport.stateNum === CONST.REPORT.STATE_NUM.PROCESSING && ( | ||
| <TouchableOpacity | ||
| style={[styles.buttonSmall, styles.buttonSuccess, styles.mt4]} | ||
| onPress={onPayButtonPressed} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why this is not needed anymore, wouldn't this mean that we would show the preview for a paid IOU? I thought we did not want that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, is it because of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah exactly. That logic had to move to within the Preview, as once the
iouReportis paid we cannot guarantee it will be stored locally -- and the iouReport will be null