From 6d6bf8a10eed05dec4228935321a757b93165044 Mon Sep 17 00:00:00 2001 From: allgandalf Date: Mon, 4 Aug 2025 14:13:15 +0530 Subject: [PATCH 1/4] remove usage of Onyx.connect for currentDate --- .../TestDrive/Modal/EmployeeTestDriveModal.tsx | 2 ++ src/libs/actions/IOU.ts | 11 ++--------- src/pages/Search/SearchPage.tsx | 2 ++ src/pages/Share/SubmitDetailsPage.tsx | 2 ++ .../ReportActionCompose/ReportActionCompose.tsx | 2 ++ src/pages/iou/request/IOURequestStartPage.tsx | 5 ++++- tests/actions/IOUTest.ts | 7 ++++++- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx b/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx index 15e5804363de..4efa21d96c8e 100644 --- a/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx +++ b/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx @@ -36,6 +36,7 @@ function EmployeeTestDriveModal() { const reportID = generateReportID(); const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true}); + const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true}); const route = useRoute>(); const [bossEmail, setBossEmail] = useState(route.params?.bossEmail ?? ''); const [formError, setFormError] = useState(); @@ -70,6 +71,7 @@ function EmployeeTestDriveModal() { newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN, report, parentReport, + currentDate, }); setMoneyRequestReceipt(transactionID, source, filename, true, CONST.TEST_RECEIPT.FILE_TYPE, false, true); diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c7b561ed9c8d..f53731ff806d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -261,6 +261,7 @@ type InitMoneyRequestParams = { newIouRequestType: IOURequestType | undefined; report: OnyxEntry; parentReport: OnyxEntry; + currentDate: string | undefined; }; type MoneyRequestInformation = { @@ -808,14 +809,6 @@ Onyx.connect({ }, }); -let currentDate: OnyxEntry = ''; -Onyx.connect({ - key: ONYXKEYS.CURRENT_DATE, - callback: (value) => { - currentDate = value; - }, -}); - let quickAction: OnyxEntry = {}; Onyx.connect({ key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, @@ -900,7 +893,7 @@ function getReportPreviewAction(chatReportID: string | undefined, iouReportID: s * @param report the report to attach the transaction to * @param parentReport the parent report to attach the transaction to */ -function initMoneyRequest({reportID, policy, isFromGlobalCreate, currentIouRequestType, newIouRequestType, report, parentReport}: InitMoneyRequestParams) { +function initMoneyRequest({reportID, policy, isFromGlobalCreate, currentIouRequestType, newIouRequestType, report, parentReport, currentDate = ''}: InitMoneyRequestParams) { // Generate a brand new transactionID // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 // eslint-disable-next-line deprecation/deprecation diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index c27751b89c09..56ad1c740e54 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -72,6 +72,7 @@ function SearchPage({route}: SearchPageProps) { const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const isMobileSelectionModeEnabled = useMobileSelectionMode(); const [lastPaymentMethods] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {canBeMissing: true}); + const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true}); const newReportID = generateReportID(); const [newReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${newReportID}`, {canBeMissing: true}); const [newParentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${newReport?.parentReportID}`, {canBeMissing: true}); @@ -400,6 +401,7 @@ function SearchPage({route}: SearchPageProps) { newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN, report: newReport, parentReport: newParentReport, + currentDate, }); const newReceiptFiles: ReceiptFile[] = []; diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index 7e2940ecfcb2..213102178b21 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -52,6 +52,7 @@ function SubmitDetailsPage({ const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getIOURequestPolicyID(transaction, report)}`, {canBeMissing: false}); const [lastLocationPermissionPrompt] = useOnyx(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, {canBeMissing: false}); const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: (val) => val?.reports}); + const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true}); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const [startLocationPermissionFlow, setStartLocationPermissionFlow] = useState(false); @@ -85,6 +86,7 @@ function SubmitDetailsPage({ newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN, report, parentReport, + currentDate, }); }, [reportOrAccountID, policy, report, parentReport]); diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx index 72404c18fa8d..b8ee80eeb1b5 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx @@ -149,6 +149,7 @@ function ReportActionCompose({ const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const personalDetails = usePersonalDetails(); const [blockedFromConcierge] = useOnyx(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE, {canBeMissing: true}); + const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true}); const [shouldShowComposeInput = true] = useOnyx(ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, {canBeMissing: true}); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: true}); const [newParentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true}); @@ -500,6 +501,7 @@ function ReportActionCompose({ newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN, report, parentReport: newParentReport, + currentDate, }); files.forEach((file, index) => { diff --git a/src/pages/iou/request/IOURequestStartPage.tsx b/src/pages/iou/request/IOURequestStartPage.tsx index 5f1a50257ac2..1d7f4a8fbb71 100644 --- a/src/pages/iou/request/IOURequestStartPage.tsx +++ b/src/pages/iou/request/IOURequestStartPage.tsx @@ -69,6 +69,7 @@ function IOURequestStartPage({ canBeMissing: true, }); const [isMultiScanEnabled, setIsMultiScanEnabled] = useState((optimisticTransactions ?? []).length > 1); + const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true}); const tabTitles = { [CONST.IOU.TYPE.REQUEST]: translate('iou.createExpense'), @@ -129,6 +130,7 @@ function IOURequestStartPage({ newIouRequestType: transaction?.iouRequestType, report, parentReport, + currentDate, }); // eslint-disable-next-line }, []); @@ -148,9 +150,10 @@ function IOURequestStartPage({ newIouRequestType: newIOUType, report, parentReport, + currentDate, }); }, - [policy, reportID, isFromGlobalCreate, transaction, report, parentReport], + [policy, reportID, isFromGlobalCreate, transaction, report, parentReport, currentDate], ); // Clear out the temporary expense if the reportID in the URL has changed from the transaction's reportID. diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 331acef345d5..d2a760e01675 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -5798,9 +5798,11 @@ describe('actions/IOU', () => { merchant: '(none)', splitPayerAccountIDs: [3], }; + + const currentDate = '2025-04-01'; beforeEach(async () => { await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`, null); - await Onyx.merge(`${ONYXKEYS.CURRENT_DATE}`, '2025-04-01'); + await Onyx.merge(`${ONYXKEYS.CURRENT_DATE}`, currentDate); await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${fakeReport.reportID}`, fakeReport); await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy); await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${fakePersonalPolicy.id}`, fakePersonalPolicy); @@ -5817,6 +5819,7 @@ describe('actions/IOU', () => { newIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL, report: fakeReport, parentReport: fakeParentReport, + currentDate, }); }) .then(async () => { @@ -5835,6 +5838,7 @@ describe('actions/IOU', () => { newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN, report: fakeReport, parentReport: fakeParentReport, + currentDate, }); }) .then(async () => { @@ -5853,6 +5857,7 @@ describe('actions/IOU', () => { newIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL, report: fakeReport, parentReport: fakeParentReport, + currentDate, }); }) .then(async () => { From 5bb956186261eeb1d3ecfdba0f67a86a552e32f3 Mon Sep 17 00:00:00 2001 From: allgandalf Date: Mon, 4 Aug 2025 14:37:46 +0530 Subject: [PATCH 2/4] fix max warning --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 04d22167ebab..16cba5d633e3 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand", "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", - "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=320 --cache --cache-location=node_modules/.cache/eslint", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=319 --cache --cache-location=node_modules/.cache/eslint", "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh", "lint-watch": "npx eslint-watch --watch --changed", "shellcheck": "./scripts/shellCheck.sh", From 6026a666133723e6256775d989c2f835b8f5f580 Mon Sep 17 00:00:00 2001 From: allgandalf Date: Wed, 13 Aug 2025 11:59:35 +0530 Subject: [PATCH 3/4] add dependency --- src/pages/Share/SubmitDetailsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index bb724d09a0a6..1d808b7c3559 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -92,7 +92,7 @@ function SubmitDetailsPage({ parentReport, currentDate, }); - }, [reportOrAccountID, policy, report, parentReport]); + }, [reportOrAccountID, policy, report, parentReport, currentDate]); const selectedParticipants = unknownUserDetails ? [unknownUserDetails] : getMoneyRequestParticipantsFromReport(report); const participants = selectedParticipants.map((participant) => From 666ba30cb3b7cc820b5400be6cea172f5cd31000 Mon Sep 17 00:00:00 2001 From: allgandalf Date: Thu, 14 Aug 2025 13:46:03 +0530 Subject: [PATCH 4/4] fix prettier --- src/libs/actions/IOU.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 10d53c42885e..9cf67e979e2b 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -906,7 +906,17 @@ function getReportPreviewAction(chatReportID: string | undefined, iouReportID: s * @param report the report to attach the transaction to * @param parentReport the parent report to attach the transaction to */ -function initMoneyRequest({reportID, policy, isFromGlobalCreate, currentIouRequestType, newIouRequestType, report, parentReport, currentDate = '', lastSelectedDistanceRates}: InitMoneyRequestParams) { +function initMoneyRequest({ + reportID, + policy, + isFromGlobalCreate, + currentIouRequestType, + newIouRequestType, + report, + parentReport, + currentDate = '', + lastSelectedDistanceRates, +}: InitMoneyRequestParams) { // Generate a brand new transactionID // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 // eslint-disable-next-line deprecation/deprecation