Skip to content

Commit

Permalink
Merge pull request #35127 from DylanDylann/fix/30884-warning-dependen…
Browse files Browse the repository at this point in the history
…cy-cycle

Fix/30884: Fix dependency cycle
  • Loading branch information
cristipaval authored Jan 26, 2024
2 parents 9dc595a + 490dba3 commit 01ae927
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
30 changes: 1 addition & 29 deletions src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -24,32 +22,6 @@ function navigateToStartMoneyRequestStep(requestType: ValueOf<typeof CONST.IOU.R
}
}

type SuccessCallback = (file?: File) => void;
// eslint-disable-next-line rulesdir/no-negated-variables
function navigateToStartStepIfScanFileCannotBeRead(
receiptFilename: string,
receiptPath: string,
onSuccess: SuccessCallback,
requestType: ValueOf<typeof CONST.IOU.REQUEST_TYPE>,
iouType: ValueOf<typeof CONST.IOU.TYPE>,
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
*
Expand Down Expand Up @@ -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};
28 changes: 28 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -3719,6 +3720,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,
Expand Down Expand Up @@ -3778,4 +3805,5 @@ export {
detachReceipt,
getIOUReportID,
editMoneyRequest,
navigateToStartStepIfScanFileCannotBeRead,
};
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 01ae927

Please sign in to comment.