diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index 19ee17bba3b4..1aebfd83c450 100644 --- a/src/components/ReportActionItem/MoneyReportView.tsx +++ b/src/components/ReportActionItem/MoneyReportView.tsx @@ -25,6 +25,7 @@ import * as reportActions from '@src/libs/actions/Report'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Policy, PolicyReportField, Report} from '@src/types/onyx'; +import type {PendingAction} from '@src/types/onyx/OnyxCommon'; type MoneyReportViewProps = { /** The report currently being looked at */ @@ -41,9 +42,11 @@ type MoneyReportViewProps = { /** Flag to show, hide the thread divider line */ shouldHideThreadDividerLine: boolean; + + pendingAction?: PendingAction; }; -function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTotal = true, shouldHideThreadDividerLine}: MoneyReportViewProps) { +function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTotal = true, shouldHideThreadDividerLine, pendingAction}: MoneyReportViewProps) { const theme = useTheme(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -118,7 +121,8 @@ function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTo return ( transaction?.pendingFields?.[fieldPath] ?? pendingAction; + // Need to return undefined when we have pendingAction to avoid the duplicate pending action + const getPendingFieldAction = (fieldPath: TransactionPendingFieldsKey) => (pendingAction ? undefined : transaction?.pendingFields?.[fieldPath]); const getErrorForField = useCallback( (field: ViolationField, data?: OnyxTypes.TransactionViolation['data'], policyHasDependentTags = false, tagValue?: string) => { @@ -472,10 +473,12 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals {shouldShowAnimatedBackground && } <> {shouldShowReceiptAudit && ( - + + + )} {(hasReceipt || errors) && ( )} {shouldShowReceiptEmptyState && ( - - Navigation.navigate( - ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute( - CONST.IOU.ACTION.EDIT, - iouType, - transaction?.transactionID ?? '-1', - report?.reportID ?? '-1', - Navigation.getReportRHPActiveRoute(), - ), - ) - } - /> + + + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute( + CONST.IOU.ACTION.EDIT, + iouType, + transaction?.transactionID ?? '-1', + report?.reportID ?? '-1', + Navigation.getReportRHPActiveRoute(), + ), + ) + } + /> + )} {!shouldShowReceiptEmptyState && !hasReceipt && } {shouldShowAuditMessage && } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c422313a1946..6c5aa5394b28 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7639,10 +7639,26 @@ function detachReceipt(transactionID: string) { { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, - value: newTransaction, + value: { + ...newTransaction, + pendingFields: { + receipt: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + }, + }, }, ]; + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, + value: { + pendingFields: { + receipt: null, + }, + }, + }, + ]; const failureData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -7650,13 +7666,16 @@ function detachReceipt(transactionID: string) { value: { ...(transaction ?? null), errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.receiptDeleteFailureError'), + pendingFields: { + receipt: null, + }, }, }, ]; const parameters: DetachReceiptParams = {transactionID}; - API.write(WRITE_COMMANDS.DETACH_RECEIPT, parameters, {optimisticData, failureData}); + API.write(WRITE_COMMANDS.DETACH_RECEIPT, parameters, {optimisticData, successData, failureData}); } function replaceReceipt(transactionID: string, file: File, source: string) { @@ -7674,9 +7693,25 @@ function replaceReceipt(transactionID: string, file: File, source: string) { value: { receipt: receiptOptimistic, filename: file.name, + pendingFields: { + receipt: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, + value: { + pendingFields: { + receipt: null, + }, }, }, ]; + const failureData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -7685,6 +7720,9 @@ function replaceReceipt(transactionID: string, file: File, source: string) { receipt: !isEmptyObject(oldReceipt) ? oldReceipt : null, filename: transaction?.filename, errors: getReceiptError(receiptOptimistic, file.name), + pendingFields: { + receipt: null, + }, }, }, ]; @@ -7694,7 +7732,7 @@ function replaceReceipt(transactionID: string, file: File, source: string) { receipt: file, }; - API.write(WRITE_COMMANDS.REPLACE_RECEIPT, parameters, {optimisticData, failureData}); + API.write(WRITE_COMMANDS.REPLACE_RECEIPT, parameters, {optimisticData, successData, failureData}); } /** diff --git a/src/pages/home/report/ReportActionItemContentCreated.tsx b/src/pages/home/report/ReportActionItemContentCreated.tsx index ad40df3d5213..69e27701edd8 100644 --- a/src/pages/home/report/ReportActionItemContentCreated.tsx +++ b/src/pages/home/report/ReportActionItemContentCreated.tsx @@ -106,15 +106,17 @@ function ReportActionItemContentCreated({contextValue, parentReportAction, trans } return ( - - - - {renderThreadDivider} - - + + + + + {renderThreadDivider} + + + ); } @@ -157,6 +159,7 @@ function ReportActionItemContentCreated({contextValue, parentReportAction, trans report={report} policy={policy} isCombinedReport + pendingAction={action.pendingAction} shouldShowTotal={transaction ? transactionCurrency !== report.currency : false} shouldHideThreadDividerLine={shouldHideThreadDividerLine} /> @@ -174,6 +177,7 @@ function ReportActionItemContentCreated({contextValue, parentReportAction, trans )}