From c8ed1eb89889dba1bb4cab78a3be6c4f3aa04feb Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Fri, 17 Jan 2025 10:56:13 +0700 Subject: [PATCH 1/4] reset request flow --- .../iou/request/step/IOURequestStepConfirmation.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 3c24f317c812..e7350dfd2006 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -152,6 +152,16 @@ function IOURequestStepConfirmation({ IOU.setMoneyRequestBillable(transactionID, defaultBillable); }, [transactionID, defaultBillable]); + useEffect(() => { + if (transaction?.transactionID) return; + IOU.startMoneyRequest( + CONST.IOU.TYPE.CREATE, + // When starting to create an expense from the global FAB, there is not an existing report yet. A random optimistic reportID is generated and used + // for all of the routes in the creation flow. + ReportUtils.generateReportID(), + ); + }, []); + useEffect(() => { if (!transaction?.category) { return; From 790d041c1c74f7441833c33f767a47d8f2074bf4 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Fri, 17 Jan 2025 22:07:50 +0700 Subject: [PATCH 2/4] update new lint rule --- .../step/IOURequestStepConfirmation.tsx | 105 ++++++++++-------- 1 file changed, 61 insertions(+), 44 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index e7350dfd2006..eb0c3c869bce 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -16,17 +16,34 @@ import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import DateUtils from '@libs/DateUtils'; -import * as DeviceCapabilities from '@libs/DeviceCapabilities'; -import * as FileUtils from '@libs/fileDownload/FileUtils'; +import {canUseTouchScreen} from '@libs/DeviceCapabilities'; +import {isLocalFile as isLocalFileFunc} from '@libs/fileDownload/FileUtils'; import getCurrentPosition from '@libs/getCurrentPosition'; -import * as IOUUtils from '@libs/IOUUtils'; +import {isMovingTransactionFromTrackExpense as isMovingTransactionFromTrackExpenseFunc, navigateToStartMoneyRequestStep, shouldUseTransactionDraft} from '@libs/IOUUtils'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; -import * as OptionsListUtils from '@libs/OptionsListUtils'; -import * as ReportUtils from '@libs/ReportUtils'; +import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils'; +import {generateReportID, getBankAccountRoute} from '@libs/ReportUtils'; import playSound, {SOUNDS} from '@libs/Sound'; -import * as TransactionUtils from '@libs/TransactionUtils'; -import * as IOU from '@userActions/IOU'; +import {getDefaultTaxCode, getRateID, getRequestType, getValidWaypoints} from '@libs/TransactionUtils'; +import { + createDistanceRequest as createDistanceRequestFunc, + getIOURequestPolicyID, + GpsPoint, + navigateToStartStepIfScanFileCannotBeRead, + requestMoney as requestMoneyFunc, + sendInvoice, + sendMoneyElsewhere, + sendMoneyWithWallet, + setMoneyRequestBillable, + setMoneyRequestCategory, + splitBillAndOpenReport as splitBillAndOpenReportFunc, + splitBill as splitBillFunc, + startMoneyRequest, + startSplitBill as startSplitBillFunc, + trackExpense as trackExpenseFunc, + updateLastLocationPermissionPrompt, +} from '@userActions/IOU'; import {openDraftWorkspaceRequest} from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -55,11 +72,11 @@ function IOURequestStepConfirmation({ const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const personalDetails = usePersonalDetails(); - const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`); - const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${IOU.getIOURequestPolicyID(transaction, reportReal)}`); - const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${IOU.getIOURequestPolicyID(transaction, reportReal)}`); - const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`); - const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${IOU.getIOURequestPolicyID(transaction, reportReal)}`); + const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${getIOURequestPolicyID(transaction, reportDraft)}`); + const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getIOURequestPolicyID(transaction, reportReal)}`); + const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${getIOURequestPolicyID(transaction, reportReal)}`); + const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${getIOURequestPolicyID(transaction, reportDraft)}`); + const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getIOURequestPolicyID(transaction, reportReal)}`); const report = reportReal ?? reportDraft; const policy = policyReal ?? policyDraft; @@ -74,7 +91,7 @@ function IOURequestStepConfirmation({ const [selectedParticipantList, setSelectedParticipantList] = useState([]); const [receiptFile, setReceiptFile] = useState>(); - const requestType = TransactionUtils.getRequestType(transaction); + const requestType = getRequestType(transaction); const isDistanceRequest = requestType === CONST.IOU.REQUEST_TYPE.DISTANCE; const isPerDiemRequest = requestType === CONST.IOU.REQUEST_TYPE.PER_DIEM; const [lastLocationPermissionPrompt] = useOnyx(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT); @@ -82,13 +99,13 @@ function IOURequestStepConfirmation({ const receiptFilename = transaction?.filename; const receiptPath = transaction?.receipt?.source; const receiptType = transaction?.receipt?.type; - const customUnitRateID = TransactionUtils.getRateID(transaction) ?? ''; - const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction); + const customUnitRateID = getRateID(transaction) ?? ''; + const defaultTaxCode = getDefaultTaxCode(policy, transaction); const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? ''; const transactionTaxAmount = transaction?.taxAmount ?? 0; const isSharingTrackExpense = action === CONST.IOU.ACTION.SHARE; const isCategorizingTrackExpense = action === CONST.IOU.ACTION.CATEGORIZE; - const isMovingTransactionFromTrackExpense = IOUUtils.isMovingTransactionFromTrackExpense(action); + const isMovingTransactionFromTrackExpense = isMovingTransactionFromTrackExpenseFunc(action); const payeePersonalDetails = useMemo(() => { if (personalDetails?.[transaction?.splitPayerAccountIDs?.at(0) ?? -1]) { return personalDetails?.[transaction?.splitPayerAccountIDs?.at(0) ?? -1]; @@ -127,14 +144,14 @@ function IOURequestStepConfirmation({ if (participant.isSender && iouType === CONST.IOU.TYPE.INVOICE) { return participant; } - return participant.accountID ? OptionsListUtils.getParticipantsOption(participant, personalDetails) : OptionsListUtils.getReportOption(participant); + return participant.accountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant); }) ?? [], [transaction?.participants, personalDetails, iouType], ); const isPolicyExpenseChat = useMemo(() => participants?.some((participant) => participant.isPolicyExpenseChat), [participants]); const formHasBeenSubmitted = useRef(false); - useFetchRoute(transaction, transaction?.comment?.waypoints, action, IOUUtils.shouldUseTransactionDraft(action) ? CONST.TRANSACTION.STATE.DRAFT : CONST.TRANSACTION.STATE.CURRENT); + useFetchRoute(transaction, transaction?.comment?.waypoints, action, shouldUseTransactionDraft(action) ? CONST.TRANSACTION.STATE.DRAFT : CONST.TRANSACTION.STATE.CURRENT); useEffect(() => { const policyExpenseChat = participants?.find((participant) => participant.isPolicyExpenseChat); @@ -149,16 +166,16 @@ function IOURequestStepConfirmation({ const defaultBillable = !!policy?.defaultBillable; useEffect(() => { - IOU.setMoneyRequestBillable(transactionID, defaultBillable); + setMoneyRequestBillable(transactionID, defaultBillable); }, [transactionID, defaultBillable]); useEffect(() => { if (transaction?.transactionID) return; - IOU.startMoneyRequest( + startMoneyRequest( CONST.IOU.TYPE.CREATE, // When starting to create an expense from the global FAB, there is not an existing report yet. A random optimistic reportID is generated and used // for all of the routes in the creation flow. - ReportUtils.generateReportID(), + generateReportID(), ); }, []); @@ -167,7 +184,7 @@ function IOURequestStepConfirmation({ return; } if (policyCategories?.[transaction.category] && !policyCategories[transaction.category].enabled) { - IOU.setMoneyRequestCategory(transactionID, '', policy?.id); + setMoneyRequestCategory(transactionID, '', policy?.id); } }, [policy?.id, policyCategories, transaction?.category, transactionID]); @@ -178,7 +195,7 @@ function IOURequestStepConfirmation({ if (requestType !== CONST.IOU.REQUEST_TYPE.DISTANCE || !!transaction?.category) { return; } - IOU.setMoneyRequestCategory(transactionID, defaultCategory, policy?.id); + setMoneyRequestCategory(transactionID, defaultCategory, policy?.id); // Prevent resetting to default when unselect category // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [transactionID, requestType, defaultCategory, policy?.id]); @@ -201,7 +218,7 @@ function IOURequestStepConfirmation({ Navigation.goBack(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, transaction?.reportID || reportID, undefined, action)); return; } - IOUUtils.navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID, action); + navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID, action); }, [action, isPerDiemRequest, transaction?.participantsAutoAssigned, transaction?.reportID, participantsAutoAssignedFromRoute, requestType, iouType, transactionID, reportID]); const navigateToAddReceipt = useCallback(() => { @@ -214,7 +231,7 @@ function IOURequestStepConfirmation({ // skip this in case user is moving the transaction as the receipt path will be valid in that case useEffect(() => { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const isLocalFile = FileUtils.isLocalFile(receiptPath); + const isLocalFile = isLocalFileFunc(receiptPath); if (!isLocalFile) { setReceiptFile(transaction?.receipt); @@ -227,11 +244,11 @@ function IOURequestStepConfirmation({ setReceiptFile(receipt); }; - IOU.navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, onSuccess, requestType, iouType, transactionID, reportID, receiptType); + navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, onSuccess, requestType, iouType, transactionID, reportID, receiptType); }, [receiptType, receiptPath, receiptFilename, requestType, iouType, transactionID, reportID, action, transaction?.receipt]); const requestMoney = useCallback( - (selectedParticipants: Participant[], trimmedComment: string, receiptObj?: Receipt, gpsPoints?: IOU.GpsPoint) => { + (selectedParticipants: Participant[], trimmedComment: string, receiptObj?: Receipt, gpsPoints?: GpsPoint) => { if (!transaction) { return; } @@ -240,7 +257,7 @@ function IOURequestStepConfirmation({ if (!participant) { return; } - IOU.requestMoney({ + requestMoneyFunc({ report, participantParams: { payeeEmail: currentUserPersonalDetails.login, @@ -277,7 +294,7 @@ function IOURequestStepConfirmation({ ); const trackExpense = useCallback( - (selectedParticipants: Participant[], trimmedComment: string, receiptObj?: OnyxEntry, gpsPoints?: IOU.GpsPoint) => { + (selectedParticipants: Participant[], trimmedComment: string, receiptObj?: OnyxEntry, gpsPoints?: GpsPoint) => { if (!report || !transaction) { return; } @@ -285,7 +302,7 @@ function IOURequestStepConfirmation({ if (!participant) { return; } - IOU.trackExpense( + trackExpenseFunc( report, transaction.amount, transaction.currency, @@ -306,7 +323,7 @@ function IOURequestStepConfirmation({ policyTags, policyCategories, gpsPoints, - Object.keys(transaction?.comment?.waypoints ?? {}).length ? TransactionUtils.getValidWaypoints(transaction.comment?.waypoints, true) : undefined, + Object.keys(transaction?.comment?.waypoints ?? {}).length ? getValidWaypoints(transaction.comment?.waypoints, true) : undefined, action, transaction.actionableWhisperReportActionID, transaction.linkedTrackedExpenseReportAction, @@ -335,7 +352,7 @@ function IOURequestStepConfirmation({ if (!transaction) { return; } - IOU.createDistanceRequest({ + createDistanceRequestFunc({ report, participants: selectedParticipants, currentUserLogin: currentUserPersonalDetails.login, @@ -359,7 +376,7 @@ function IOURequestStepConfirmation({ taxAmount: transactionTaxAmount, customUnitRateID, splitShares: transaction.splitShares, - validWaypoints: TransactionUtils.getValidWaypoints(transaction.comment?.waypoints, true), + validWaypoints: getValidWaypoints(transaction.comment?.waypoints, true), billable: transaction.billable, }, }); @@ -404,7 +421,7 @@ function IOURequestStepConfirmation({ // If we have a receipt let's start the split expense by creating only the action, the transaction, and the group DM if needed if (iouType === CONST.IOU.TYPE.SPLIT && receiptFile) { if (currentUserPersonalDetails.login && !!transaction) { - IOU.startSplitBill({ + startSplitBillFunc({ participants: selectedParticipants, currentUserLogin: currentUserPersonalDetails.login, currentUserAccountID: currentUserPersonalDetails.accountID, @@ -426,7 +443,7 @@ function IOURequestStepConfirmation({ // Since the user is already viewing the report, we don't need to navigate them to the report if (iouType === CONST.IOU.TYPE.SPLIT && !transaction?.isFromGlobalCreate) { if (currentUserPersonalDetails.login && !!transaction) { - IOU.splitBill({ + splitBillFunc({ participants: splitParticipants, currentUserLogin: currentUserPersonalDetails.login, currentUserAccountID: currentUserPersonalDetails.accountID, @@ -452,7 +469,7 @@ function IOURequestStepConfirmation({ // If the split expense is created from the global create menu, we also navigate the user to the group report if (iouType === CONST.IOU.TYPE.SPLIT) { if (currentUserPersonalDetails.login && !!transaction) { - IOU.splitBillAndOpenReport({ + splitBillAndOpenReportFunc({ participants: splitParticipants, currentUserLogin: currentUserPersonalDetails.login, currentUserAccountID: currentUserPersonalDetails.accountID, @@ -475,7 +492,7 @@ function IOURequestStepConfirmation({ } if (iouType === CONST.IOU.TYPE.INVOICE) { - IOU.sendInvoice(currentUserPersonalDetails.accountID, transaction, report, receiptFile, policy, policyTags, policyCategories); + sendInvoice(currentUserPersonalDetails.accountID, transaction, report, receiptFile, policy, policyTags, policyCategories); return; } @@ -579,13 +596,13 @@ function IOURequestStepConfirmation({ if (paymentMethod === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { setIsConfirmed(true); - IOU.sendMoneyElsewhere(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); + sendMoneyElsewhere(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); return; } if (paymentMethod === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { setIsConfirmed(true); - IOU.sendMoneyWithWallet(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); + sendMoneyWithWallet(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant); } }, [transaction?.amount, transaction?.comment, transaction?.currency, participants, currentUserPersonalDetails.accountID, report], @@ -593,7 +610,7 @@ function IOURequestStepConfirmation({ const setBillable = useCallback( (billable: boolean) => { - IOU.setMoneyRequestBillable(transactionID, billable); + setMoneyRequestBillable(transactionID, billable); }, [transactionID], ); @@ -626,7 +643,7 @@ function IOURequestStepConfirmation({ return ( @@ -652,7 +669,7 @@ function IOURequestStepConfirmation({ resetPermissionFlow={() => setStartLocationPermissionFlow(false)} onGrant={() => createTransaction(selectedParticipantList, true)} onDeny={() => { - IOU.updateLastLocationPermissionPrompt(); + updateLastLocationPermissionPrompt(); createTransaction(selectedParticipantList, false); }} /> @@ -674,8 +691,8 @@ function IOURequestStepConfirmation({ iouType={iouType} reportID={reportID} isPolicyExpenseChat={isPolicyExpenseChat} - policyID={IOU.getIOURequestPolicyID(transaction, report)} - bankAccountRoute={ReportUtils.getBankAccountRoute(report)} + policyID={getIOURequestPolicyID(transaction, report)} + bankAccountRoute={getBankAccountRoute(report)} iouMerchant={transaction?.merchant} iouCreated={transaction?.created} isDistanceRequest={isDistanceRequest} From a7ff3403f9e0caa2833c445fabbc4f5069f0788d Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Fri, 17 Jan 2025 22:35:38 +0700 Subject: [PATCH 3/4] adjust style --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 745315e97f3d..bafe9e211986 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -23,7 +23,7 @@ import {isMovingTransactionFromTrackExpense as isMovingTransactionFromTrackExpen import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils'; -import {getBankAccountRoute} from '@libs/ReportUtils'; +import {getBankAccountRoute, generateReportID} from '@libs/ReportUtils'; import playSound, {SOUNDS} from '@libs/Sound'; import {getDefaultTaxCode, getRateID, getRequestType, getValidWaypoints} from '@libs/TransactionUtils'; import type {GpsPoint} from '@userActions/IOU'; @@ -39,6 +39,7 @@ import { setMoneyRequestCategory, splitBill, splitBillAndOpenReport, + startMoneyRequest, startSplitBill, submitPerDiemExpense as submitPerDiemExpenseIOUActions, trackExpense as trackExpenseIOUActions, @@ -171,13 +172,16 @@ function IOURequestStepConfirmation({ }, [transactionID, defaultBillable]); useEffect(() => { - if (transaction?.transactionID) return; + if (transaction?.transactionID) { + return; + } startMoneyRequest( CONST.IOU.TYPE.CREATE, // When starting to create an expense from the global FAB, there is not an existing report yet. A random optimistic reportID is generated and used // for all of the routes in the creation flow. generateReportID(), ); + // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- we don't want this effect to run again }, []); useEffect(() => { From 263d29105fbd4d2c98d4e69515d40e3d12b3db0f Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Fri, 17 Jan 2025 22:41:26 +0700 Subject: [PATCH 4/4] prettier --- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index bafe9e211986..287f2feb5eca 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -23,7 +23,7 @@ import {isMovingTransactionFromTrackExpense as isMovingTransactionFromTrackExpen import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils'; -import {getBankAccountRoute, generateReportID} from '@libs/ReportUtils'; +import {generateReportID, getBankAccountRoute} from '@libs/ReportUtils'; import playSound, {SOUNDS} from '@libs/Sound'; import {getDefaultTaxCode, getRateID, getRequestType, getValidWaypoints} from '@libs/TransactionUtils'; import type {GpsPoint} from '@userActions/IOU';