diff --git a/package.json b/package.json index 50c20769cba3..883075e6ba52 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=260 --cache --cache-location=node_modules/.cache/eslint", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=259 --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", 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 10ca2a167595..9cf67e979e2b 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -262,6 +262,7 @@ type InitMoneyRequestParams = { newIouRequestType: IOURequestType | undefined; report: OnyxEntry; parentReport: OnyxEntry; + currentDate: string | undefined; lastSelectedDistanceRates?: OnyxEntry; }; @@ -821,14 +822,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, @@ -913,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, 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 diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index 8e5b069ee90a..2c4aba5ac3a9 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -74,6 +74,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}); @@ -544,6 +545,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 5792da27cc4c..712b62493b0b 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -51,6 +51,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); @@ -76,8 +77,9 @@ function SubmitDetailsPage({ newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN, report, parentReport, + currentDate, }); - }, [reportOrAccountID, policy, report, parentReport]); + }, [reportOrAccountID, policy, report, parentReport, currentDate]); const selectedParticipants = unknownUserDetails ? [unknownUserDetails] : getMoneyRequestParticipantsFromReport(report); const participants = selectedParticipants.map((participant) => diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx index ae2895467544..53049408caab 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx @@ -141,6 +141,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}); @@ -492,6 +493,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 f9107cde8c8b..8b171d2a7c81 100644 --- a/src/pages/iou/request/IOURequestStartPage.tsx +++ b/src/pages/iou/request/IOURequestStartPage.tsx @@ -70,6 +70,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'), @@ -130,6 +131,7 @@ function IOURequestStartPage({ newIouRequestType: transaction?.iouRequestType, report, parentReport, + currentDate, lastSelectedDistanceRates, }); // eslint-disable-next-line @@ -150,10 +152,11 @@ function IOURequestStartPage({ newIouRequestType: newIOUType, report, parentReport, + currentDate, lastSelectedDistanceRates, }); }, - [transaction?.iouRequestType, reportID, policy, isFromGlobalCreate, report, parentReport, lastSelectedDistanceRates], + [transaction?.iouRequestType, reportID, policy, isFromGlobalCreate, report, parentReport, currentDate, lastSelectedDistanceRates], ); // 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 e97e49faf7ef..a4c2a36bbcaa 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -5817,9 +5817,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); @@ -5836,6 +5838,7 @@ describe('actions/IOU', () => { newIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL, report: fakeReport, parentReport: fakeParentReport, + currentDate, }); }) .then(async () => { @@ -5854,6 +5857,7 @@ describe('actions/IOU', () => { newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN, report: fakeReport, parentReport: fakeParentReport, + currentDate, }); }) .then(async () => { @@ -5872,6 +5876,7 @@ describe('actions/IOU', () => { newIouRequestType: CONST.IOU.REQUEST_TYPE.MANUAL, report: fakeReport, parentReport: fakeParentReport, + currentDate, }); }) .then(async () => {