diff --git a/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx b/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx index 56bcd7f51148..2322dd99b9b9 100644 --- a/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx +++ b/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx @@ -49,7 +49,6 @@ function EmployeeTestDriveModal() { const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const personalPolicy = usePersonalPolicy(); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true}); - const [draftTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {canBeMissing: true}); const hasOnlyPersonalPolicies = useMemo(() => hasOnlyPersonalPoliciesUtil(allPolicies), [allPolicies]); const onBossEmailChange = useCallback((value: string) => { @@ -86,7 +85,6 @@ function EmployeeTestDriveModal() { currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies, - draftTransactions, }); setMoneyRequestReceipt(transactionID, source, filename, true, CONST.TEST_RECEIPT.FILE_TYPE, false, true); diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 5262fca15145..67af9e80cdfd 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -286,7 +286,6 @@ type InitMoneyRequestParams = { lastSelectedDistanceRates?: OnyxEntry; currentUserPersonalDetails: CurrentUserPersonalDetails; hasOnlyPersonalPolicies: boolean; - draftTransactions: OnyxCollection; }; type MoneyRequestInformation = { @@ -1096,7 +1095,6 @@ function initMoneyRequest({ lastSelectedDistanceRates, currentUserPersonalDetails, hasOnlyPersonalPolicies, - draftTransactions, }: InitMoneyRequestParams) { // Generate a brand new transactionID const newTransactionID = CONST.IOU.OPTIMISTIC_TRANSACTION_ID; @@ -1107,7 +1105,7 @@ function initMoneyRequest({ const created = currentDate || format(new Date(), 'yyyy-MM-dd'); // We remove draft transactions created during multi scanning if there are some - removeDraftTransactions(true, draftTransactions); + removeDraftTransactions(true); // in case we have to re-init money request, but the IOU request type is the same with the old draft transaction, // we should keep most of the existing data by using the ONYX MERGE operation diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index a323b94dac88..b99936696b08 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -124,7 +124,6 @@ function SearchPage({route}: SearchPageProps) { const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true}); const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true}); const [personalPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${personalPolicyID}`, {canBeMissing: true}); - const [draftTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {canBeMissing: true}); const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true}); const [integrationsExportTemplates] = useOnyx(ONYXKEYS.NVP_INTEGRATION_SERVER_EXPORT_TEMPLATES, {canBeMissing: true}); @@ -1039,7 +1038,6 @@ function SearchPage({route}: SearchPageProps) { currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies, - draftTransactions, }); const newReceiptFiles: ReceiptFile[] = []; diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index 385ee063caf8..37198a5b38dc 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -86,7 +86,6 @@ function SubmitDetailsPage({ const fileName = shouldUsePreValidatedFile ? getFileName(validFilesToUpload?.uri ?? CONST.ATTACHMENT_IMAGE_DEFAULT_NAME) : getFileName(currentAttachment?.content ?? ''); const fileType = shouldUsePreValidatedFile ? (validFilesToUpload?.type ?? CONST.RECEIPT_ALLOWED_FILE_TYPES.JPEG) : (currentAttachment?.mimeType ?? ''); const [hasOnlyPersonalPolicies = false] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true, selector: hasOnlyPersonalPoliciesUtil}); - const [draftTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {canBeMissing: true}); useEffect(() => { if (!errorTitle || !errorMessage) { @@ -108,10 +107,7 @@ function SubmitDetailsPage({ currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies, - draftTransactions, }); - // The draftTransactions can be changed if users update the expense, so we don't want to re-init the money request - // eslint-disable-next-line react-hooks/exhaustive-deps }, [reportOrAccountID, policy, personalPolicy, report, parentReport, currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies]); const selectedParticipants = unknownUserDetails ? [unknownUserDetails] : getMoneyRequestParticipantsFromReport(report, currentUserPersonalDetails.accountID); diff --git a/src/pages/inbox/report/ReportActionCompose/useAttachmentUploadValidation.ts b/src/pages/inbox/report/ReportActionCompose/useAttachmentUploadValidation.ts index d55863fda5d0..8004a4674ec6 100644 --- a/src/pages/inbox/report/ReportActionCompose/useAttachmentUploadValidation.ts +++ b/src/pages/inbox/report/ReportActionCompose/useAttachmentUploadValidation.ts @@ -55,7 +55,6 @@ function useAttachmentUploadValidation({ const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy?.id}`, {canBeMissing: true}); const personalPolicy = usePersonalPolicy(); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true}); - const [draftTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {canBeMissing: true}); const hasOnlyPersonalPolicies = useMemo(() => hasOnlyPersonalPoliciesUtil(allPolicies), [allPolicies]); const reportAttachmentsContext = useContext(AttachmentModalContext); @@ -102,7 +101,6 @@ function useAttachmentUploadValidation({ currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies, - draftTransactions, }); for (const [index, file] of files.entries()) { diff --git a/src/pages/iou/request/DistanceRequestStartPage.tsx b/src/pages/iou/request/DistanceRequestStartPage.tsx index 6aaf719ada45..e2bd8a4a32ea 100644 --- a/src/pages/iou/request/DistanceRequestStartPage.tsx +++ b/src/pages/iou/request/DistanceRequestStartPage.tsx @@ -58,7 +58,6 @@ function DistanceRequestStartPage({ const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE, {canBeMissing: true}); const isLoadingSelectedTab = isLoadingOnyxValue(selectedTabResult); const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${getNonEmptyStringOnyxID(route?.params.transactionID)}`, {canBeMissing: true}); - const [draftTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {canBeMissing: true}); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false}); const [lastSelectedDistanceRates] = useOnyx(ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES, {canBeMissing: true}); const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true}); @@ -121,7 +120,6 @@ function DistanceRequestStartPage({ lastSelectedDistanceRates, currentUserPersonalDetails, hasOnlyPersonalPolicies, - draftTransactions, }); }, [ @@ -136,7 +134,6 @@ function DistanceRequestStartPage({ lastSelectedDistanceRates, currentUserPersonalDetails, hasOnlyPersonalPolicies, - draftTransactions, ], ); diff --git a/src/pages/iou/request/IOURequestStartPage.tsx b/src/pages/iou/request/IOURequestStartPage.tsx index 424f95fbddab..b0e1fb87c109 100644 --- a/src/pages/iou/request/IOURequestStartPage.tsx +++ b/src/pages/iou/request/IOURequestStartPage.tsx @@ -90,7 +90,6 @@ function IOURequestStartPage({ selector: transactionDraftValuesSelector, canBeMissing: true, }); - const [draftTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {canBeMissing: true}); const [isMultiScanEnabled, setIsMultiScanEnabled] = useState((optimisticTransactions ?? []).length > 1); const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true}); const {isOffline} = useNetwork(); @@ -197,7 +196,6 @@ function IOURequestStartPage({ lastSelectedDistanceRates, currentUserPersonalDetails, hasOnlyPersonalPolicies, - draftTransactions, }); }, [ @@ -213,7 +211,6 @@ function IOURequestStartPage({ lastSelectedDistanceRates, currentUserPersonalDetails, hasOnlyPersonalPolicies, - draftTransactions, ], ); diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 041a69635323..37db6c9566c2 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -8091,7 +8091,6 @@ describe('actions/IOU', () => { currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies: false, - draftTransactions: undefined, }); }) .then(async () => { @@ -8114,7 +8113,6 @@ describe('actions/IOU', () => { currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies: false, - draftTransactions: undefined, }); }) .then(async () => { @@ -8138,7 +8136,6 @@ describe('actions/IOU', () => { currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies: false, - draftTransactions: undefined, }); }) .then(async () => { @@ -8148,134 +8145,6 @@ describe('actions/IOU', () => { }); }); }); - - it('should remove non-optimistic draft transactions when draftTransactions is provided', async () => { - const otherDraftTransactionID = '123456'; - const otherDraftTransaction: Transaction = { - ...createRandomTransaction(1), - transactionID: otherDraftTransactionID, - }; - - // Set up an additional draft transaction - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${otherDraftTransactionID}`, otherDraftTransaction); - - const draftTransactions = { - [`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${otherDraftTransactionID}`]: otherDraftTransaction, - }; - - await waitForBatchedUpdates() - .then(() => { - initMoneyRequest({ - reportID: fakeReport.reportID, - policy: fakePolicy, - personalPolicy: fakePersonalPolicy, - isFromGlobalCreate: true, - newIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL, - report: fakeReport, - parentReport: fakeParentReport, - currentDate, - currentUserPersonalDetails, - hasOnlyPersonalPolicies: false, - draftTransactions, - }); - }) - .then(async () => { - // The other draft transaction should be removed (Onyx returns undefined for removed keys) - expect(await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${otherDraftTransactionID}`)).toBeUndefined(); - // The optimistic transaction should be created - expect(await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`)).toStrictEqual(transactionResult); - }); - }); - - it('should preserve optimistic transaction in draftTransactions while removing others', async () => { - const otherDraftTransactionID = '789012'; - const otherDraftTransaction: Transaction = { - ...createRandomTransaction(2), - transactionID: otherDraftTransactionID, - }; - const existingOptimisticTransaction: Transaction = { - ...createRandomTransaction(3), - transactionID: CONST.IOU.OPTIMISTIC_TRANSACTION_ID, - }; - - // Set up both draft transactions - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${otherDraftTransactionID}`, otherDraftTransaction); - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`, existingOptimisticTransaction); - - const draftTransactions = { - [`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${otherDraftTransactionID}`]: otherDraftTransaction, - [`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`]: existingOptimisticTransaction, - }; - - await waitForBatchedUpdates() - .then(() => { - initMoneyRequest({ - reportID: fakeReport.reportID, - policy: fakePolicy, - personalPolicy: fakePersonalPolicy, - isFromGlobalCreate: true, - newIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL, - report: fakeReport, - parentReport: fakeParentReport, - currentDate, - currentUserPersonalDetails, - hasOnlyPersonalPolicies: false, - draftTransactions, - }); - }) - .then(async () => { - // The other draft transaction should be removed (Onyx returns undefined for removed keys) - expect(await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${otherDraftTransactionID}`)).toBeUndefined(); - // The optimistic transaction should be updated with the new transaction result (not removed) - expect(await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`)).toStrictEqual(transactionResult); - }); - }); - - it('should remove multiple draft transactions when draftTransactions contains several entries', async () => { - const draftTransactionID1 = '111111'; - const draftTransactionID2 = '222222'; - const draftTransaction1: Transaction = { - ...createRandomTransaction(4), - transactionID: draftTransactionID1, - }; - const draftTransaction2: Transaction = { - ...createRandomTransaction(5), - transactionID: draftTransactionID2, - }; - - // Set up multiple draft transactions - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${draftTransactionID1}`, draftTransaction1); - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${draftTransactionID2}`, draftTransaction2); - - const draftTransactions = { - [`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${draftTransactionID1}`]: draftTransaction1, - [`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${draftTransactionID2}`]: draftTransaction2, - }; - - await waitForBatchedUpdates() - .then(() => { - initMoneyRequest({ - reportID: fakeReport.reportID, - policy: fakePolicy, - personalPolicy: fakePersonalPolicy, - isFromGlobalCreate: true, - newIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL, - report: fakeReport, - parentReport: fakeParentReport, - currentDate, - currentUserPersonalDetails, - hasOnlyPersonalPolicies: false, - draftTransactions, - }); - }) - .then(async () => { - // Both draft transactions should be removed (Onyx returns undefined for removed keys) - expect(await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${draftTransactionID1}`)).toBeUndefined(); - expect(await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${draftTransactionID2}`)).toBeUndefined(); - // The optimistic transaction should be created - expect(await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`)).toStrictEqual(transactionResult); - }); - }); }); describe('updateMoneyRequestAmountAndCurrency', () => {