-
Notifications
You must be signed in to change notification settings - Fork 4k
refactor: move per diem expense navigation into the UI #99525
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
00e3504
5f3a448
40b8a79
ac78106
1dfb8a0
9c9ef7a
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 |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ import cleanupAndNavigateAfterExpenseCreate from '@libs/Navigation/helpers/clean | |
| import dismissModalAndOpenReportInInboxTab from '@libs/Navigation/helpers/dismissModalAndOpenReportInInboxTab'; | ||
| import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; | ||
| import navigateAfterExpenseCreate from '@libs/Navigation/helpers/navigateAfterExpenseCreate'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import {rand64, roundToTwoDecimalPlaces} from '@libs/NumberUtils'; | ||
| import {isTrackOnboardingChoice} from '@libs/OnboardingUtils'; | ||
| import {getNewAccountIDsAndLogins} from '@libs/PersonalDetailsUtils'; | ||
|
|
@@ -61,7 +62,7 @@ import { | |
| import {resolveChatTargetForSubmitCleanup} from '@pages/iou/request/step/resolveChatTarget'; | ||
|
|
||
| import {isOneToTwoTransactionTransition} from '@userActions/IOU/PendingNewTransactions'; | ||
| import {getPerDiemExpensePolicyID, submitPerDiemExpenseForSelfDM, submitPerDiemExpense as submitPerDiemExpenseIOUActions} from '@userActions/IOU/PerDiem'; | ||
| import {getPerDiemExpensePolicyID, hasCompletePerDiemCustomUnit, submitPerDiemExpenseForSelfDM, submitPerDiemExpense as submitPerDiemExpenseIOUActions} from '@userActions/IOU/PerDiem'; | ||
| import {getReceiverType, sendInvoice} from '@userActions/IOU/SendInvoice'; | ||
| import {sendMoneyElsewhere, sendMoneyWithWallet} from '@userActions/IOU/SendMoney'; | ||
| import {createDistanceRequest as createDistanceRequestIOUActions, resolveOptimisticSplitChatReportID, splitBill, splitBillAndOpenReport, startSplitBill} from '@userActions/IOU/Split'; | ||
|
|
@@ -606,33 +607,41 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { | |
| return; | ||
| } | ||
| if (isTrackExpense) { | ||
| const optimisticChatReportID = selfDMReport?.reportID ?? generateReportID(); | ||
| submitPerDiemExpenseForSelfDM({ | ||
| dateFnsLocale, | ||
| getCurrencyDecimals, | ||
| selfDMReport, | ||
| policy, | ||
| transactionParams: { | ||
| currency: transaction.currency, | ||
| created: transaction.created, | ||
| comment: trimmedComment, | ||
| category: transaction.category, | ||
| tag: transaction.tag, | ||
| customUnit: transaction.comment?.customUnit, | ||
| billable: transaction.billable, | ||
| reimbursable: transaction.reimbursable, | ||
| attendees: transaction.comment?.attendees, | ||
| isFromGlobalCreate: getIsFromGlobalCreate(transaction), | ||
| }, | ||
| currentUserAccountIDParam: currentUserPersonalDetails.accountID, | ||
| currentUserEmailParam: currentUserPersonalDetails.login ?? '', | ||
| quickAction, | ||
| optimisticChatReportID, | ||
| delegateAccountID, | ||
| isTrackIntentUser, | ||
| }); | ||
| if (shouldHandleNavigation) { | ||
| dismissModalAndOpenReportInInboxTab(optimisticChatReportID, false, false); | ||
| // Mirror the action's bail: a submit it would no-op must not clean up or dismiss. | ||
| if (!isEmptyObject(policy) && hasCompletePerDiemCustomUnit(transaction.comment?.customUnit)) { | ||
|
TaduJR marked this conversation as resolved.
|
||
| const optimisticChatReportID = selfDMReport?.reportID ?? generateReportID(); | ||
| submitPerDiemExpenseForSelfDM({ | ||
| dateFnsLocale, | ||
| getCurrencyDecimals, | ||
| selfDMReport, | ||
| policy, | ||
| transactionParams: { | ||
| currency: transaction.currency, | ||
| created: transaction.created, | ||
| comment: trimmedComment, | ||
| category: transaction.category, | ||
| tag: transaction.tag, | ||
| customUnit: transaction.comment?.customUnit, | ||
| billable: transaction.billable, | ||
| reimbursable: transaction.reimbursable, | ||
| attendees: transaction.comment?.attendees, | ||
| isFromGlobalCreate: getIsFromGlobalCreate(transaction), | ||
| }, | ||
| currentUserAccountIDParam: currentUserPersonalDetails.accountID, | ||
| currentUserEmailParam: currentUserPersonalDetails.login ?? '', | ||
| quickAction, | ||
| optimisticChatReportID, | ||
| delegateAccountID, | ||
| isTrackIntentUser, | ||
| }); | ||
| if (shouldHandleNavigation) { | ||
| cleanupAfterExpenseCreate({draftTransactionIDs: [CONST.IOU.OPTIMISTIC_TRANSACTION_ID], shouldWaitForUpcomingTransition: true}); | ||
| dismissModalAndOpenReportInInboxTab(optimisticChatReportID, false, false); | ||
| } else { | ||
| cleanupAfterExpenseCreate({draftTransactionIDs: [CONST.IOU.OPTIMISTIC_TRANSACTION_ID]}); | ||
| } | ||
| } else { | ||
| Log.alert('[useExpenseSubmission] Skipped per diem self-DM submit: missing policy or incomplete custom unit'); | ||
|
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. We should do something on the UI otherwise the user is stuck in the same place with no idea that something is happening. Can we surface that some error has happened?
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. If a per diem is missing its subrate (or the amount isn't valid), the confirm screen already blocks the submit and shows the error right there, either "There must be at least one subrate" or "Please enter a valid quantity". I checked it browser. With the subrate removed, tapping Create expense doesn't go through and the error shows. So the user gets feedback, not a silent dead end. The guard we added only kicks in for a deeper broken state, where the destination or date info is missing even though the earlier steps always fill it in. You can't reach that by clicking through the flow. I could only trigger it by manually corrupting the saved draft. And even then it behaved well. It blocked the submit and kept the draft intact, nothing lost. It just logs instead of showing a second error. So the reachable cases already show a message, and the guard is a safety net for a state a user can't actually create. If you'd still like extra coverage, we could add a simple "Something went wrong, please try again" whenever a per diem submit gets skipped. Otherwise I'd lean on the check that's already there. WDYT?
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. that's fine then, we can leave it as is |
||
| } | ||
| } else { | ||
| const isExpenseReport = isMoneyRequestReportReportUtils(report); | ||
|
|
@@ -647,6 +656,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { | |
| existingChatReport, | ||
| ); | ||
| const activeReportID = isExpenseReport ? report?.reportID : chatReportID; | ||
| const notifyReportID = isExpenseReport && Navigation.getTopmostReportId() === report?.reportID ? report?.reportID : chatReportID; | ||
|
|
||
| const perDiemParticipantParams = { | ||
| payeeEmail: currentUserPersonalDetails.login, | ||
|
|
@@ -690,6 +700,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { | |
| betas, | ||
| personalDetails, | ||
| optimisticChatReportID, | ||
| notifyReportID, | ||
| formatPhoneNumber, | ||
| delegateAccountID, | ||
| isTrackIntentUser, | ||
|
|
@@ -698,6 +709,9 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { | |
| // When backToReport exists we are creating the expense from chat, not the expense report, so no pending transaction registration needed. | ||
| const isOneToTwoTransition = !backToReport && isOneToTwoTransactionTransition(isMoneyRequestReport, reportTransactions); | ||
|
|
||
| if (result) { | ||
| cleanupAfterExpenseCreate({draftTransactionIDs: [CONST.IOU.OPTIMISTIC_TRANSACTION_ID], shouldWaitForUpcomingTransition: shouldHandleNavigation}); | ||
| } | ||
| if (result && targetReportID) { | ||
| navigateAfterExpenseCreate({ | ||
| activeReportID: targetReportID, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.