From 2f327ae10e2911ebacdcfbafc63e094f85b03bb6 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Mon, 23 Sep 2024 21:29:00 +0700 Subject: [PATCH 1/6] update hold request optimisticdata --- src/ROUTES.ts | 10 +++-- src/components/PromotedActionsBar.tsx | 5 ++- src/libs/ReportUtils.ts | 8 ++-- src/libs/actions/IOU.ts | 58 ++++++++++++++++++++++++++- src/pages/ReportDetailsPage.tsx | 15 ++++++- src/pages/iou/HoldReasonPage.tsx | 6 ++- 6 files changed, 89 insertions(+), 13 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 146d35611a72..beda5d175f3f 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -382,9 +382,13 @@ const ROUTES = { }, }, MONEY_REQUEST_HOLD_REASON: { - route: ':type/edit/reason/:transactionID?', - getRoute: (type: ValueOf, transactionID: string, reportID: string, backTo: string) => - `${type}/edit/reason/${transactionID}?backTo=${backTo}&reportID=${reportID}` as const, + route: ':type/edit/reason/:transactionID?/:hash?', + getRoute: (type: ValueOf, transactionID: string, reportID: string, backTo: string, hash?: number) => { + const route = hash + ? (`${type}/edit/reason/${transactionID}/${hash}/?backTo=${backTo}&reportID=${reportID}` as const) + : (`${type}/edit/reason/${transactionID}/?backTo=${backTo}&reportID=${reportID}` as const); + return route; + }, }, MONEY_REQUEST_CREATE: { route: ':action/:iouType/start/:transactionID/:reportID', diff --git a/src/components/PromotedActionsBar.tsx b/src/components/PromotedActionsBar.tsx index c374259f0447..68b0faee6cda 100644 --- a/src/components/PromotedActionsBar.tsx +++ b/src/components/PromotedActionsBar.tsx @@ -35,6 +35,7 @@ type PromotedActionsType = Record P reportID?: string; isDelegateAccessRestricted: boolean; setIsNoDelegateAccessMenuVisible: (isVisible: boolean) => void; + currentSearchHash?: number; }) => PromotedAction; }; @@ -76,7 +77,7 @@ const PromotedActions = { } }, }), - hold: ({isTextHold, reportAction, reportID, isDelegateAccessRestricted, setIsNoDelegateAccessMenuVisible}) => ({ + hold: ({isTextHold, reportAction, reportID, isDelegateAccessRestricted, setIsNoDelegateAccessMenuVisible, currentSearchHash}) => ({ key: CONST.PROMOTED_ACTIONS.HOLD, icon: Expensicons.Stopwatch, text: Localize.translateLocal(`iou.${isTextHold ? 'hold' : 'unhold'}`), @@ -97,7 +98,7 @@ const PromotedActions = { return; } - ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.SEARCH_REPORT.getRoute(targetedReportID)); + ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.SEARCH_REPORT.getRoute(targetedReportID), currentSearchHash); }, }), } satisfies PromotedActionsType; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8746490ecd30..90b27fdc1bb6 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3121,7 +3121,7 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry) return {canHoldRequest, canUnholdRequest}; } -const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, backTo?: string): void => { +const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, backTo?: string, hash?: number): void => { if (!ReportActionsUtils.isMoneyRequestAction(reportAction)) { return; } @@ -3138,11 +3138,13 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, bac const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null; if (isOnHold) { - IOU.unholdRequest(transactionID, reportAction.childReportID ?? ''); + IOU.unholdRequest(transactionID, reportAction.childReportID ?? '', hash); } else { const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', backTo || activeRoute)); + Navigation.navigate( + ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', backTo || activeRoute, hash), + ); } }; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 38e5d0a3ab9d..a4c5dc249788 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7843,7 +7843,7 @@ function adjustRemainingSplitShares(transaction: NonNullable ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, reportActions ?? [], isOffline), @@ -569,6 +571,7 @@ function ReportDetailsPage({policies, report}: ReportDetailsPageProps) { reportID: transactionThreadReportID ? report.reportID : moneyRequestAction?.childReportID ?? '-1', isDelegateAccessRestricted, setIsNoDelegateAccessMenuVisible, + currentSearchHash, }), ); } @@ -580,7 +583,17 @@ function ReportDetailsPage({policies, report}: ReportDetailsPageProps) { result.push(PromotedActions.share(report)); return result; - }, [report, moneyRequestAction, canJoin, isExpenseReport, shouldShowHoldAction, canHoldUnholdReportAction.canHoldRequest, transactionThreadReportID, isDelegateAccessRestricted]); + }, [ + report, + moneyRequestAction, + currentSearchHash, + canJoin, + isExpenseReport, + shouldShowHoldAction, + canHoldUnholdReportAction.canHoldRequest, + transactionThreadReportID, + isDelegateAccessRestricted, + ]); const nameSectionExpenseIOU = ( diff --git a/src/pages/iou/HoldReasonPage.tsx b/src/pages/iou/HoldReasonPage.tsx index 82f29acf7d10..218ca0aa6a9b 100644 --- a/src/pages/iou/HoldReasonPage.tsx +++ b/src/pages/iou/HoldReasonPage.tsx @@ -24,6 +24,8 @@ type HoldReasonPageRouteParams = { /** Link to previous page */ backTo: Route; + + hash?: number }; type HoldReasonPageProps = { @@ -34,7 +36,7 @@ type HoldReasonPageProps = { function HoldReasonPage({route}: HoldReasonPageProps) { const {translate} = useLocalize(); - const {transactionID, reportID, backTo} = route.params; + const {transactionID, reportID, backTo, hash} = route.params; const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID || -1}`); @@ -51,7 +53,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) { return; } - IOU.putOnHold(transactionID, values.comment, reportID); + IOU.putOnHold(transactionID, values.comment, reportID, hash); Navigation.navigate(backTo); }; From 8187b2b7ec2850c43f736f71a6b8957e5aa51a23 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Mon, 23 Sep 2024 21:48:40 +0700 Subject: [PATCH 2/6] minor fix --- src/libs/ReportUtils.ts | 2 +- src/pages/iou/HoldReasonPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 90b27fdc1bb6..f523aadd4f73 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3141,8 +3141,8 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, bac IOU.unholdRequest(transactionID, reportAction.childReportID ?? '', hash); } else { const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing Navigation.navigate( + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', backTo || activeRoute, hash), ); } diff --git a/src/pages/iou/HoldReasonPage.tsx b/src/pages/iou/HoldReasonPage.tsx index 218ca0aa6a9b..896b18b9f724 100644 --- a/src/pages/iou/HoldReasonPage.tsx +++ b/src/pages/iou/HoldReasonPage.tsx @@ -25,7 +25,7 @@ type HoldReasonPageRouteParams = { /** Link to previous page */ backTo: Route; - hash?: number + hash?: number; }; type HoldReasonPageProps = { From 45979f08da44288f4f69bec5d38657a00c0d0e32 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Tue, 24 Sep 2024 20:37:46 +0700 Subject: [PATCH 3/6] update variable and add comment --- src/ROUTES.ts | 8 ++++---- src/libs/ReportUtils.ts | 6 +++--- src/libs/actions/IOU.ts | 18 ++++++++++-------- src/pages/iou/HoldReasonPage.tsx | 6 +++--- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index beda5d175f3f..08d171639d91 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -382,10 +382,10 @@ const ROUTES = { }, }, MONEY_REQUEST_HOLD_REASON: { - route: ':type/edit/reason/:transactionID?/:hash?', - getRoute: (type: ValueOf, transactionID: string, reportID: string, backTo: string, hash?: number) => { - const route = hash - ? (`${type}/edit/reason/${transactionID}/${hash}/?backTo=${backTo}&reportID=${reportID}` as const) + route: ':type/edit/reason/:transactionID?/:searchHash?', + getRoute: (type: ValueOf, transactionID: string, reportID: string, backTo: string, searchHash?: number) => { + const route = searchHash + ? (`${type}/edit/reason/${transactionID}/${searchHash}/?backTo=${backTo}&reportID=${reportID}` as const) : (`${type}/edit/reason/${transactionID}/?backTo=${backTo}&reportID=${reportID}` as const); return route; }, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f523aadd4f73..f4419b701ec6 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3121,7 +3121,7 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry) return {canHoldRequest, canUnholdRequest}; } -const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, backTo?: string, hash?: number): void => { +const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, backTo?: string, searchHash?: number): void => { if (!ReportActionsUtils.isMoneyRequestAction(reportAction)) { return; } @@ -3138,12 +3138,12 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry, bac const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null; if (isOnHold) { - IOU.unholdRequest(transactionID, reportAction.childReportID ?? '', hash); + IOU.unholdRequest(transactionID, reportAction.childReportID ?? '', searchHash); } else { const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); Navigation.navigate( // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', backTo || activeRoute, hash), + ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, transactionID, reportAction.childReportID ?? '', backTo || activeRoute, searchHash), ); } }; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index a4c5dc249788..dca8b01ea458 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7843,7 +7843,7 @@ function adjustRemainingSplitShares(transaction: NonNullable Date: Tue, 24 Sep 2024 20:55:42 +0700 Subject: [PATCH 4/6] Update src/libs/actions/IOU.ts Co-authored-by: Joel Davies --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index dca8b01ea458..4ccc3cc97091 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -8001,7 +8001,7 @@ function unholdRequest(transactionID: string, reportID: string, searchHash?: num }, ]; - // If we are holding from the search page, we optimistically update the snapshot data that search uses so that it is kept in sync + // If we are unholding from the search page, we optimistically update the snapshot data that search uses so that it is kept in sync if (searchHash) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, From 5674d03908e2edd6ca36f358046e851958af7d3a Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Wed, 25 Sep 2024 22:02:30 +0700 Subject: [PATCH 5/6] ts check --- src/libs/actions/IOU.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 7f1f77fcccaf..ce6b26978719 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -64,6 +64,7 @@ import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type ReportAction from '@src/types/onyx/ReportAction'; import type {OnyxData} from '@src/types/onyx/Request'; +import {SearchTransaction} from '@src/types/onyx/SearchResults'; import type {Comment, Receipt, ReceiptSource, Routes, SplitShares, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import * as CachedPDFPaths from './CachedPDFPaths'; @@ -7904,7 +7905,7 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea canUnhold: true, }, }, - }, + } as Record>>, }); failureData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -7916,7 +7917,7 @@ function putOnHold(transactionID: string, comment: string, reportID: string, sea canUnhold: false, }, }, - }, + } as Record>>, }); } @@ -8005,7 +8006,7 @@ function unholdRequest(transactionID: string, reportID: string, searchHash?: num canUnhold: false, }, }, - }, + } as Record>>, }); failureData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -8017,7 +8018,7 @@ function unholdRequest(transactionID: string, reportID: string, searchHash?: num canUnhold: true, }, }, - }, + } as Record>>, }); } From a8bb04171341526aa5c7e64347403cbcbd59ab43 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Wed, 25 Sep 2024 23:05:13 +0700 Subject: [PATCH 6/6] import type --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index ce6b26978719..382b207a4517 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -64,7 +64,7 @@ import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type ReportAction from '@src/types/onyx/ReportAction'; import type {OnyxData} from '@src/types/onyx/Request'; -import {SearchTransaction} from '@src/types/onyx/SearchResults'; +import type {SearchTransaction} from '@src/types/onyx/SearchResults'; import type {Comment, Receipt, ReceiptSource, Routes, SplitShares, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import * as CachedPDFPaths from './CachedPDFPaths';