Skip to content
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

Fix/30884: Fix dependency cycle #35127

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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,
Expand Down Expand Up @@ -3741,4 +3768,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 @@ -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(() => {
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
Loading