From 4c7a5623c8eb99c5fe2c095053a2fa114434fb34 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 25 Jan 2024 11:59:54 +0700 Subject: [PATCH 1/3] fix dependency cycle --- src/libs/IOUUtils.ts | 30 +------------------ src/libs/actions/IOU.js | 28 +++++++++++++++++ .../step/IOURequestStepConfirmation.js | 2 +- .../step/IOURequestStepParticipants.js | 2 +- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/libs/IOUUtils.ts b/src/libs/IOUUtils.ts index 11dd0f5badda..c0fb4c6195b1 100644 --- a/src/libs/IOUUtils.ts +++ b/src/libs/IOUUtils.ts @@ -3,9 +3,7 @@ import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {Report, Transaction} from '@src/types/onyx'; -import * as IOU from './actions/IOU'; import * as CurrencyUtils from './CurrencyUtils'; -import * as FileUtils from './fileDownload/FileUtils'; import Navigation from './Navigation/Navigation'; import * as TransactionUtils from './TransactionUtils'; @@ -24,32 +22,6 @@ function navigateToStartMoneyRequestStep(requestType: ValueOf void; -// eslint-disable-next-line rulesdir/no-negated-variables -function navigateToStartStepIfScanFileCannotBeRead( - receiptFilename: string, - receiptPath: string, - onSuccess: SuccessCallback, - requestType: ValueOf, - iouType: ValueOf, - transactionID: string, - reportID: string, -) { - if (!receiptFilename || !receiptPath) { - return; - } - - const onFailure = () => { - IOU.setMoneyRequestReceipt(transactionID, '', '', true); - if (requestType === CONST.IOU.REQUEST_TYPE.MANUAL) { - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams())); - return; - } - navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID); - }; - FileUtils.readFileAsync(receiptPath, receiptFilename, onSuccess, onFailure); -} - /** * Calculates the amount per user given a list of participants * @@ -127,4 +99,4 @@ function isValidMoneyRequestType(iouType: string): boolean { return moneyRequestType.includes(iouType); } -export {calculateAmount, updateIOUOwnerAndTotal, isIOUReportPendingCurrencyConversion, isValidMoneyRequestType, navigateToStartMoneyRequestStep, navigateToStartStepIfScanFileCannotBeRead}; +export {calculateAmount, updateIOUOwnerAndTotal, isIOUReportPendingCurrencyConversion, isValidMoneyRequestType, navigateToStartMoneyRequestStep}; diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index d258b5419103..20247e6af883 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -26,6 +26,7 @@ import ViolationsUtils from '@libs/Violations/ViolationsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import * as FileUtils from '../fileDownload/FileUtils'; import * as Policy from './Policy'; import * as Report from './Report'; @@ -3683,6 +3684,32 @@ function getIOUReportID(iou, route) { return lodashGet(route, 'params.reportID') || lodashGet(iou, 'participants.0.reportID', ''); } +/** + * @param {String} receiptFilename + * @param {String} receiptPath + * @param {Function} onSuccess + * @param {String} requestType + * @param {String} iouType + * @param {String} transactionID + * @param {String} reportID + */ +// eslint-disable-next-line rulesdir/no-negated-variables +function navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, onSuccess, requestType, iouType, transactionID, reportID) { + if (!receiptFilename || !receiptPath) { + return; + } + + const onFailure = () => { + setMoneyRequestReceipt(transactionID, '', '', true); + if (requestType === CONST.IOU.REQUEST_TYPE.MANUAL) { + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams())); + return; + } + IOUUtils.navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID); + }; + FileUtils.readFileAsync(receiptPath, receiptFilename, onSuccess, onFailure); +} + export { setMoneyRequestParticipants, createDistanceRequest, @@ -3741,4 +3768,5 @@ export { detachReceipt, getIOUReportID, editMoneyRequest, + navigateToStartStepIfScanFileCannotBeRead, }; diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 9df2564ae38d..6028a735d132 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -144,7 +144,7 @@ function IOURequestStepConfirmation({ setReceiptFile(receipt); }; - IOUUtils.navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, onSuccess, requestType, iouType, transactionID, reportID); + IOU.navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, onSuccess, requestType, iouType, transactionID, reportID); }, [receiptPath, receiptFilename, requestType, iouType, transactionID, reportID]); useEffect(() => { diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.js b/src/pages/iou/request/step/IOURequestStepParticipants.js index 730441035d08..1726c9fcbc60 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.js +++ b/src/pages/iou/request/step/IOURequestStepParticipants.js @@ -47,7 +47,7 @@ function IOURequestStepParticipants({ // This is because until the request is saved, the receipt file is only stored in the browsers memory as a blob:// and if the browser is refreshed, then // the image ceases to exist. The best way for the user to recover from this is to start over from the start of the request process. useEffect(() => { - IOUUtils.navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, () => {}, iouRequestType, iouType, transactionID, reportID); + IOU.navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, () => {}, iouRequestType, iouType, transactionID, reportID); }, [receiptPath, receiptFilename, iouRequestType, iouType, transactionID, reportID]); const addParticipant = useCallback( From c1592c9efb76f57308d2b1b0db3a12fbd0cbb19e Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 25 Jan 2024 12:42:40 +0700 Subject: [PATCH 2/3] fix dependency cycle --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 20247e6af883..01e19444da81 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -26,7 +26,7 @@ import ViolationsUtils from '@libs/Violations/ViolationsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import * as FileUtils from '../fileDownload/FileUtils'; +import * as FileUtils from '@libs/fileDownload/FileUtils'; import * as Policy from './Policy'; import * as Report from './Report'; From 490dba377626a3f991d9fdb5b2c036f44a56e506 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 25 Jan 2024 13:01:04 +0700 Subject: [PATCH 3/3] fix dependency cycle --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 01e19444da81..fb2676ec5b86 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -10,6 +10,7 @@ import * as API from '@libs/API'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import DateUtils from '@libs/DateUtils'; import * as ErrorUtils from '@libs/ErrorUtils'; +import * as FileUtils from '@libs/fileDownload/FileUtils'; import * as IOUUtils from '@libs/IOUUtils'; import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; import * as Localize from '@libs/Localize'; @@ -26,7 +27,6 @@ import ViolationsUtils from '@libs/Violations/ViolationsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import * as FileUtils from '@libs/fileDownload/FileUtils'; import * as Policy from './Policy'; import * as Report from './Report';