Repository navigation
Add retry button and logic #99902
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
Add retry button and logic #99902
Changes from all commits
c3a6979
f3738be
096c7fe
fee2262
25a2515
533c76a
1895eda
69bf7c8
f9367e2
629ba4e
4bf4a6d
463e657
668eeed
ff62592
be7fc2c
80e62b2
5f8e9b9
ffe4f42
2e458ff
05ee28b
c67acc7
0ad227b
e088ac4
8674792
ee6b5d8
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 |
|---|---|---|
|
|
@@ -37,8 +37,12 @@ import {getBrokenConnectionUrlToFixPersonalCard} from '@libs/CardUtils'; | |
| import {hasHoverSupport} from '@libs/DeviceCapabilities'; | ||
| import {getMicroSecondOnyxErrorObject, getMicroSecondOnyxErrorWithTranslationKey, isReceiptError} from '@libs/ErrorUtils'; | ||
| import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; | ||
| import Log from '@libs/Log'; | ||
| import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute'; | ||
| import {isTrackOnboardingChoice} from '@libs/OnboardingUtils'; | ||
| import {isGroupPolicyByType} from '@libs/PolicyUtils'; | ||
| import retryReceiptUpload, {canBuildRetryPayload} from '@libs/ReceiptUploadRetryHandler'; | ||
| import type {ReceiptRetryContext} from '@libs/ReceiptUploadRetryHandler/types'; | ||
| import {getThumbnailAndImageURIs} from '@libs/ReceiptUtils'; | ||
| import {getOriginalMessage, isMoneyRequestAction, wasActionTakenByCurrentUser} from '@libs/ReportActionsUtils'; | ||
| import {isMarkAsCashActionForTransaction} from '@libs/ReportPrimaryActionUtils'; | ||
|
|
@@ -70,15 +74,15 @@ import variables from '@styles/variables'; | |
|
|
||
| import {clearAllRelatedReportActionErrors} from '@userActions/ClearReportActionErrors'; | ||
| import {cleanUpMoneyRequest} from '@userActions/IOU/DeleteMoneyRequest'; | ||
| import {replaceReceipt} from '@userActions/IOU/Receipt'; | ||
| import {clearReceiptUploadError, replaceReceipt} from '@userActions/IOU/Receipt'; | ||
| import {addAttachmentWithComment, navigateToConciergeChatAndDeleteReport, setDeleteTransactionNavigateBackUrl} from '@userActions/Report'; | ||
| import {clearError, getLastModifiedExpense, revert} from '@userActions/Transaction'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES'; | ||
| import type * as OnyxTypes from '@src/types/onyx'; | ||
| import type {TransactionPendingFieldsKey} from '@src/types/onyx/Transaction'; | ||
| import type {ReceiptError, TransactionPendingFieldsKey} from '@src/types/onyx/Transaction'; | ||
| import type {FileObject} from '@src/types/utils/Attachment'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
|
|
||
|
|
@@ -137,8 +141,8 @@ function MoneyRequestReceiptView({ | |
| hasParentPendingAction = false, | ||
| }: MoneyRequestReceiptViewProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate, dateFnsLocale} = useLocalize(); | ||
| const {isBetaEnabledOrUnknown} = usePermissions(); | ||
| const {translate, dateFnsLocale, formatPhoneNumber} = useLocalize(); | ||
| const {isBetaEnabled, isBetaEnabledOrUnknown} = usePermissions(); | ||
| const isVendorMatchingBetaEnabled = isBetaEnabledOrUnknown(CONST.BETAS.VENDOR_MATCHING); | ||
| const {convertToDisplayString, getCurrencyDecimals} = useCurrencyListActions(); | ||
| const {environmentURL} = useEnvironment(); | ||
|
|
@@ -418,6 +422,44 @@ function MoneyRequestReceiptView({ | |
|
|
||
| const {showConfirmModal} = useConfirmModal(); | ||
|
|
||
| const retryableReceiptError = Object.values(errors ?? {}).find((error): error is ReceiptError => isReceiptError(error)); | ||
| const receiptRetryContext: ReceiptRetryContext | undefined = retryableReceiptError | ||
| ? { | ||
| receiptError: retryableReceiptError, | ||
| transaction, | ||
| iouReport: moneyRequestReport, | ||
| iouActionID: parentReportAction?.reportActionID, | ||
| transactionThreadReportID: report?.reportID, | ||
| policyParams: {policy, policyCategories, policyTagList}, | ||
| isVendorMatchingBetaEnabled, | ||
| rules, | ||
| conciergeReportID, | ||
| isSelfTourViewed: !!isSelfTourViewed, | ||
| isASAPSubmitBetaEnabled: isBetaEnabled(CONST.BETAS.ASAP_SUBMIT), | ||
| isTrackIntentUser: isTrackOnboardingChoice(introSelected?.choice), | ||
| delegateAccountID, | ||
| formatPhoneNumber, | ||
| getCurrencyDecimals, | ||
| } | ||
| : undefined; | ||
|
|
||
| const canRetryUpload = !!receiptRetryContext && canBuildRetryPayload(receiptRetryContext); | ||
|
|
||
| const retryReceiptUploadAndClearError = () => { | ||
| if (!receiptRetryContext) { | ||
| return; | ||
| } | ||
|
|
||
| retryReceiptUpload(receiptRetryContext, () => | ||
| clearReceiptUploadError({ | ||
|
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. Could we consider clearing the receipt error only after
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. Good point. Now the error is cleared only after If the retry fails on the server, |
||
| transactionID: transaction?.transactionID, | ||
| reportID: parentReportAction?.reportID ?? report?.reportID, | ||
| reportActionID: parentReportAction?.reportActionID, | ||
| reportIDWithCreationError: report?.reportID, | ||
| }), | ||
| ).catch((error: unknown) => Log.alert('[ReceiptRetry] Retry failed unexpectedly', {error})); | ||
| }; | ||
|
|
||
| const transactionAndReportActionErrors = useMemo( | ||
| () => ({ | ||
| ...transaction?.errors, | ||
|
|
@@ -662,6 +704,7 @@ function MoneyRequestReceiptView({ | |
| }); | ||
| }} | ||
| dismissError={dismissReceiptError} | ||
| onRetryReceiptUpload={canRetryUpload ? retryReceiptUploadAndClearError : undefined} | ||
| style={[shouldShowAuditMessage ? styles.mt3 : styles.mv3, !showReceiptErrorWithEmptyState && styles.flex1]} | ||
| contentContainerStyle={styles.flex1} | ||
| > | ||
|
|
||
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 did not want to change the props declaration, do let me know if we should rather make changes uptree.