-
Notifications
You must be signed in to change notification settings - Fork 4k
Add a Time sensitive to-do for employees with missing deposit accounts
#96623
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
base: main
Are you sure you want to change the base?
Changes from all commits
7ba2855
250d7b5
1fd7535
1545cb5
edbc5d1
89c755a
a63cee5
fe3b338
f735cd7
165d3ac
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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /** | ||
| * Identifies queued payments that require the current user to add a personal bank account. | ||
| */ | ||
| import useOnyx from '@hooks/useOnyx'; | ||
|
|
||
| import hasCreditBankAccount from '@libs/actions/ReimbursementAccount/hasCreditBankAccount'; | ||
| import {isNewerReportAction, isReimbursementQueuedAction} from '@libs/ReportActionsUtils'; | ||
| import {getMissingPaymentMethodForQueuedPayment} from '@libs/ReportUtils'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Report, ReportAction, ReportActions} from '@src/types/onyx'; | ||
| import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; | ||
|
|
||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
|
|
||
| import {accountIDSelector} from '@selectors/Session'; | ||
| import {tierNameSelector} from '@selectors/UserWallet'; | ||
|
|
||
| type ReimbursementQueuedAction = ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_QUEUED>; | ||
|
|
||
| function getLatestReimbursementQueuedAction(reportID: string, allReportActions: OnyxCollection<ReportActions>): ReimbursementQueuedAction | undefined { | ||
| let latestAction: ReimbursementQueuedAction | undefined; | ||
| const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; | ||
|
sharabai marked this conversation as resolved.
|
||
|
|
||
| for (const action of Object.values(reportActions ?? {})) { | ||
| if (isReimbursementQueuedAction(action) && (!latestAction || isNewerReportAction(action, latestAction))) { | ||
| latestAction = action; | ||
| } | ||
| } | ||
|
|
||
| return latestAction; | ||
| } | ||
|
|
||
| function useTimeSensitiveAddBankAccount() { | ||
| const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector}); | ||
| const waitingReportIDsSelector = (allReports: OnyxCollection<Report>): string[] => | ||
|
sharabai marked this conversation as resolved.
|
||
| Object.values(allReports ?? {}) | ||
| .filter((report): report is Report => !!report?.reportID && report.isWaitingOnBankAccount === true && report.ownerAccountID === accountID) | ||
|
Comment on lines
+38
to
+39
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. should we add
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. @grgia Great question! As far as I can tell, we don't need it. Our selector already requires |
||
| .map((report) => report.reportID); | ||
|
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. Can we use reduce to decrease the number of operations?
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. Good suggestion, thanks! In this case, though, |
||
| const [waitingReportIDs] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: waitingReportIDsSelector}); | ||
| const [bankAccountList, bankAccountListMetadata] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); | ||
| const [userWalletTierName] = useOnyx(ONYXKEYS.USER_WALLET, {selector: tierNameSelector}); | ||
| const canShowAddBankAccount = accountID !== undefined && !isLoadingOnyxValue(bankAccountListMetadata) && !hasCreditBankAccount(bankAccountList); | ||
|
|
||
| const shouldShowAddBankAccountSelector = (allReportActions: OnyxCollection<ReportActions>): boolean => { | ||
|
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. Let's move this to the selectors folder for consistency
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. @ZhenjaHorbach Hmm, I had a look before replying, and I'm not sure we have a consistent convention here:
So moving selectors into With that in mind, I'd rather keep this one next to the hook, especially since it isn't just projecting a single Onyx value. It would need When you mentioned consistency, did you have something more specific in mind? Happy to move it if I'm missing the pattern you're pointing out. |
||
| if (!canShowAddBankAccount) { | ||
| return false; | ||
| } | ||
|
|
||
| return (waitingReportIDs ?? []).some((reportID) => { | ||
| const queuedAction = getLatestReimbursementQueuedAction(reportID, allReportActions); | ||
|
sharabai marked this conversation as resolved.
|
||
| return !!queuedAction && getMissingPaymentMethodForQueuedPayment(userWalletTierName, queuedAction, bankAccountList) === CONST.MISSING_PAYMENT_METHODS.BANK_ACCOUNT; | ||
| }); | ||
| }; | ||
| const [shouldShowAddBankAccount = false] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {selector: shouldShowAddBankAccountSelector}); | ||
|
|
||
| return {shouldShowAddBankAccount}; | ||
| } | ||
|
|
||
| export default useTimeSensitiveAddBankAccount; | ||
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.
what is this
@contextUh oh!
There was an error while loading. Please reload this page.
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.
Not sure why
@contextis used to provide context for the strings 🤔, but that's the convention I've seen in this file. There are lots of examples that do the same thing.