From 2867f5e561d39826f0c31191c47fa2aef8fec10d Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 31 May 2024 09:22:39 +0200 Subject: [PATCH 01/46] update to Onyx 2.0.43 --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4860078733f9..c91ac86e35b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -102,7 +102,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "2.0.41", + "react-native-onyx": "2.0.43", "react-native-pager-view": "6.2.3", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", @@ -31466,9 +31466,9 @@ } }, "node_modules/react-native-onyx": { - "version": "2.0.41", - "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.41.tgz", - "integrity": "sha512-33r0sVBq7MV/GZwRneRt81uxgW8x3YG75VNJvThycB/dkCnGCfbxoVkZADVH3ET3jzfFXy9wnS06sZnZp78zMQ==", + "version": "2.0.43", + "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.43.tgz", + "integrity": "sha512-V6YLDfxAxP1wbVN0TAmHiTe+jfOjDevxYc0XHq3fSchpUNGDNG03sKN6OmsJM1rXRPODCOPyHrTUFjrwr+m7tg==", "dependencies": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", diff --git a/package.json b/package.json index f98162df327a..5b0141ea15b9 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "2.0.41", + "react-native-onyx": "2.0.43", "react-native-pager-view": "6.2.3", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", From cb0711e535c67cb3a49ca9a90aa9850fcb8741f5 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 31 May 2024 10:53:12 +0200 Subject: [PATCH 02/46] fix: report related null chnages --- src/libs/ReportActionsUtils.ts | 30 ++++---- src/libs/ReportUtils.ts | 132 ++++++++++++++++----------------- tests/unit/ReportUtilsTest.ts | 42 +++++------ 3 files changed, 98 insertions(+), 106 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 50c21ff28fe1..25550a1e52c0 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -419,9 +419,9 @@ function extractLinksFromMessageHtml(reportAction: OnyxEntry): str * @param reportActions - all actions * @param actionIndex - index of the action */ -function findPreviousAction(reportActions: ReportAction[] | null, actionIndex: number): OnyxEntry { +function findPreviousAction(reportActions: ReportAction[] | undefined, actionIndex: number): OnyxEntry { if (!reportActions) { - return null; + return undefined; } for (let i = actionIndex + 1; i < reportActions.length; i++) { @@ -432,7 +432,7 @@ function findPreviousAction(reportActions: ReportAction[] | null, actionIndex: n } } - return null; + return undefined; } /** @@ -441,7 +441,7 @@ function findPreviousAction(reportActions: ReportAction[] | null, actionIndex: n * * @param actionIndex - index of the comment item in state to check */ -function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] | null, actionIndex: number): boolean { +function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] | undefined, actionIndex: number): boolean { const previousAction = findPreviousAction(reportActions, actionIndex); const currentAction = reportActions?.[actionIndex]; @@ -643,7 +643,7 @@ function getLastVisibleAction(reportID: string, actionsToMerge: OnyxCollection shouldReportActionBeVisibleAsLastAction(action)); const sortedReportActions = getSortedReportActions(visibleReportActions, true); if (sortedReportActions.length === 0) { - return null; + return undefined; } return sortedReportActions[0]; } @@ -717,12 +717,12 @@ function getSortedReportActionsForDisplay(reportActions: OnyxEntry): OnyxEntry { // If closed report action is not present, return early if (!Object.values(reportActions ?? {}).some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED)) { - return null; + return undefined; } const filteredReportActions = filterOutDeprecatedReportActions(reportActions); const sortedReportActions = getSortedReportActions(filteredReportActions); - return lodashFindLast(sortedReportActions, (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED) ?? null; + return lodashFindLast(sortedReportActions, (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED); } /** @@ -744,16 +744,16 @@ function getFirstVisibleReportActionID(sortedReportActions: ReportAction[] = [], /** * @returns The latest report action in the `onyxData` or `null` if one couldn't be found */ -function getLatestReportActionFromOnyxData(onyxData: OnyxUpdate[] | null): OnyxEntry { +function getLatestReportActionFromOnyxData(onyxData: OnyxUpdate[] | undefined): OnyxEntry { const reportActionUpdate = onyxData?.find((onyxUpdate) => onyxUpdate.key.startsWith(ONYXKEYS.COLLECTION.REPORT_ACTIONS)); if (!reportActionUpdate) { - return null; + return undefined; } const reportActions = Object.values((reportActionUpdate.value as ReportActions) ?? {}); const sortedReportActions = getSortedReportActions(reportActions); - return sortedReportActions.at(-1) ?? null; + return sortedReportActions.at(-1); } /** @@ -767,8 +767,8 @@ function getLinkedTransactionID(reportActionOrID: string | OnyxEntry { - return ( - Object.values(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`] ?? {}).find( - (reportAction) => reportAction && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && reportAction.originalMessage.linkedReportID === iouReportID, - ) ?? null + return Object.values(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`] ?? {}).find( + (reportAction) => reportAction && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && reportAction.originalMessage.linkedReportID === iouReportID, ); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5f9f6d0aea2f..31661f6bc186 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -514,7 +514,7 @@ let currentUserPersonalDetails: OnyxEntry; Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, callback: (value) => { - currentUserPersonalDetails = value?.[currentUserAccountID ?? -1] ?? null; + currentUserPersonalDetails = value?.[currentUserAccountID ?? -1] ?? undefined; allPersonalDetails = value ?? {}; allPersonalDetailLogins = Object.values(allPersonalDetails).map((personalDetail) => personalDetail?.login ?? ''); }, @@ -605,13 +605,13 @@ function getChatType(report: OnyxEntry | Participant | EmptyObject): Val */ function getReport(reportID: string | undefined): OnyxEntry { if (!allReports && !allReportsDraft) { - return null; + return undefined; } const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; const draftReport = allReportsDraft?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportID}`]; - return report ?? draftReport ?? null; + return report ?? draftReport; } /** @@ -650,7 +650,7 @@ function getRootParentReport(report: OnyxEntry | undefined | EmptyObject const parentReport = getReport(report?.parentReportID); // Runs recursion to iterate a parent report - return getRootParentReport(!isEmptyObject(parentReport) ? parentReport : null); + return getRootParentReport(!isEmptyObject(parentReport) ? parentReport : undefined); } /** @@ -674,7 +674,7 @@ function getPolicyType(report: OnyxEntry, policies: OnyxCollection | undefined | EmptyObject, returnEmptyIfNotFound = false, policy: OnyxEntry | undefined = undefined): string { +function getPolicyName(report: OnyxEntry | undefined | EmptyObject, returnEmptyIfNotFound = false, policy: OnyxEntry = undefined): string { const noPolicyFound = returnEmptyIfNotFound ? '' : Localize.translateLocal('workspace.common.unavailable'); if (isEmptyObject(report)) { return noPolicyFound; @@ -1014,7 +1014,7 @@ function isWorkspaceTaskReport(report: OnyxEntry): boolean { if (!isTaskReport(report)) { return false; } - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`]; return isPolicyExpenseChat(parentReport); } @@ -1204,10 +1204,10 @@ function findLastAccessedReport( return sortedReports[0]; } - return adminReport ?? sortedReports.find((report) => !isConciergeChatReport(report)) ?? null; + return adminReport ?? sortedReports.find((report) => !isConciergeChatReport(report)); } - return adminReport ?? sortedReports.at(-1) ?? null; + return adminReport ?? sortedReports.at(-1); } /** @@ -1363,7 +1363,7 @@ function isChildReport(report: OnyxEntry): boolean { function isExpenseRequest(report: OnyxEntry): boolean { if (isThread(report)) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`]; return isExpenseReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction); } return false; @@ -1376,7 +1376,7 @@ function isExpenseRequest(report: OnyxEntry): boolean { function isIOURequest(report: OnyxEntry): boolean { if (isThread(report)) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`]; return isIOUReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction); } return false; @@ -1398,7 +1398,7 @@ function isTrackExpenseReport(report: OnyxEntry): boolean { * Checks if a report is an IOU or expense request. */ function isMoneyRequest(reportOrID: OnyxEntry | string): boolean { - const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; + const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? undefined : reportOrID; return isIOURequest(report) || isExpenseRequest(report); } @@ -1406,7 +1406,7 @@ function isMoneyRequest(reportOrID: OnyxEntry | string): boolean { * Checks if a report is an IOU or expense report. */ function isMoneyRequestReport(reportOrID: OnyxEntry | EmptyObject | string): boolean { - const report = typeof reportOrID === 'object' ? reportOrID : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null; + const report = typeof reportOrID === 'object' ? reportOrID : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? undefined; return isIOUReport(report) || isExpenseReport(report); } @@ -1615,7 +1615,7 @@ function getReportRecipientAccountIDs(report: OnyxEntry, currentLoginAcc // In 1:1 chat threads, the participants will be the same as parent report. If a report is specifically a 1:1 chat thread then we will // get parent report and use its participants array. if (isThread(report) && !(isTaskReport(report) || isMoneyRequestReport(report))) { - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`]; if (isOneOnOneChat(parentReport)) { finalReport = parentReport; } @@ -1779,7 +1779,7 @@ function getIconsForParticipants(participants: number[], personalDetails: OnyxEn /** * Given a report, return the associated workspace icon. */ -function getWorkspaceIcon(report: OnyxEntry, policy: OnyxEntry = null): Icon { +function getWorkspaceIcon(report: OnyxEntry, policy?: OnyxEntry): Icon { const workspaceName = getPolicyName(report, false, policy); const policyExpenseChatAvatarSource = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL @@ -1925,7 +1925,7 @@ function getIcons( defaultIcon: AvatarSource | null = null, defaultName = '', defaultAccountID = -1, - policy: OnyxEntry = null, + policy: OnyxEntry = undefined, ): Icon[] { if (isEmptyObject(report)) { const fallbackIcon: Icon = { @@ -2321,7 +2321,7 @@ function hasNonReimbursableTransactions(iouReportID: string | undefined): boolea return transactions.filter((transaction) => transaction.reimbursable === false).length > 0; } -function getMoneyRequestSpendBreakdown(report: OnyxEntry, allReportsDict: OnyxCollection = null): SpendBreakdown { +function getMoneyRequestSpendBreakdown(report: OnyxEntry, allReportsDict?: OnyxCollection): SpendBreakdown { const allAvailableReports = allReportsDict ?? allReports; let moneyRequestReport; if (isMoneyRequestReport(report) || isInvoiceReport(report)) { @@ -2822,7 +2822,7 @@ function getReportPreviewMessage( iouReportAction: OnyxEntry | EmptyObject = {}, shouldConsiderScanningReceiptOrPendingRoute = false, isPreviewMessageForParentChatReport = false, - policy: OnyxEntry = null, + policy: OnyxEntry = undefined, isForListPreview = false, originalReportAction: OnyxEntry | EmptyObject = iouReportAction, ): string { @@ -3153,7 +3153,7 @@ function getInvoicesChatName(report: OnyxEntry): string { /** * Get the title for a report. */ -function getReportName(report: OnyxEntry, policy: OnyxEntry = null): string { +function getReportName(report: OnyxEntry, policy?: OnyxEntry): string { let formattedName: string | undefined; const parentReportAction = ReportActionsUtils.getParentReportAction(report); if (isChatThread(report)) { @@ -3169,7 +3169,7 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu return Localize.translateLocal('parentReportAction.deletedMessage'); } - const isAttachment = ReportActionsUtils.isReportActionAttachment(!isEmptyObject(parentReportAction) ? parentReportAction : null); + const isAttachment = ReportActionsUtils.isReportActionAttachment(!isEmptyObject(parentReportAction) ? parentReportAction : undefined); const parentReportActionMessage = getReportActionMessage(parentReportAction, report?.parentReportID).replace(/(\r\n|\n|\r)/gm, ' '); if (isAttachment && parentReportActionMessage) { return `[${Localize.translateLocal('common.attachment')}]`; @@ -3859,12 +3859,12 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num const report = getReport(iouReportID); if (type === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { - return getIOUSubmittedMessage(!isEmptyObject(report) ? report : null); + return getIOUSubmittedMessage(!isEmptyObject(report) ? report : undefined); } const amount = type === CONST.IOU.REPORT_ACTION_TYPE.PAY - ? CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(!isEmptyObject(report) ? report : null).totalDisplaySpend, currency) + ? CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(!isEmptyObject(report) ? report : undefined).totalDisplaySpend, currency) : CurrencyUtils.convertToDisplayString(total, currency); let paymentMethodMessage; @@ -4126,7 +4126,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, * @param [comment] - User comment for the IOU. * @param [transaction] - optimistic first transaction of preview */ -function buildOptimisticReportPreview(chatReport: OnyxEntry, iouReport: Report, comment = '', transaction: OnyxEntry = null, childReportID?: string): ReportAction { +function buildOptimisticReportPreview(chatReport: OnyxEntry, iouReport: Report, comment = '', transaction: OnyxEntry = undefined, childReportID?: string): ReportAction { const hasReceipt = TransactionUtils.hasReceipt(transaction); const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction); const message = getReportPreviewMessage(iouReport); @@ -4289,7 +4289,7 @@ function updateReportPreview( reportPreviewAction: ReportPreviewAction, isPayRequest = false, comment = '', - transaction: OnyxEntry = null, + transaction: OnyxEntry = undefined, ): ReportPreviewAction { const hasReceipt = TransactionUtils.hasReceipt(transaction); const recentReceiptTransactions = reportPreviewAction?.childRecentReceiptTransactionIDs ?? {}; @@ -5037,7 +5037,7 @@ function isUnread(report: OnyxEntry): boolean { return lastReadTime < lastVisibleActionCreated || lastReadTime < lastMentionedTime; } -function isIOUOwnedByCurrentUser(report: OnyxEntry, allReportsDict: OnyxCollection = null): boolean { +function isIOUOwnedByCurrentUser(report: OnyxEntry, allReportsDict?: OnyxCollection): boolean { const allAvailableReports = allReportsDict ?? allReports; if (!report || !allAvailableReports) { return false; @@ -5101,7 +5101,7 @@ function canAccessReport(report: OnyxEntry, policies: OnyxCollection, currentReportId: string): boolean { const currentReport = getReport(currentReportId); - const parentReport = getParentReport(!isEmptyObject(currentReport) ? currentReport : null); + const parentReport = getParentReport(!isEmptyObject(currentReport) ? currentReport : undefined); const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.reportID}`] ?? {}; const isChildReportHasComment = Object.values(reportActions ?? {})?.some((reportAction) => (reportAction?.childVisibleActionCount ?? 0) > 0); return parentReport?.reportID !== report?.reportID && !isChildReportHasComment; @@ -5283,65 +5283,59 @@ function shouldReportBeInOptionList({ */ function getChatByParticipants(newParticipantList: number[], reports: OnyxCollection = allReports): OnyxEntry { const sortedNewParticipantList = newParticipantList.sort(); - return ( - Object.values(reports ?? {}).find((report) => { - const participantAccountIDs = Object.keys(report?.participants ?? {}); - - // If the report has been deleted, or there are no participants (like an empty #admins room) then skip it - if ( - participantAccountIDs.length === 0 || - isChatThread(report) || - isTaskReport(report) || - isMoneyRequestReport(report) || - isChatRoom(report) || - isPolicyExpenseChat(report) || - isGroupChat(report) - ) { - return false; - } + return Object.values(reports ?? {}).find((report) => { + const participantAccountIDs = Object.keys(report?.participants ?? {}); + + // If the report has been deleted, or there are no participants (like an empty #admins room) then skip it + if ( + participantAccountIDs.length === 0 || + isChatThread(report) || + isTaskReport(report) || + isMoneyRequestReport(report) || + isChatRoom(report) || + isPolicyExpenseChat(report) || + isGroupChat(report) + ) { + return false; + } - const sortedParticipantsAccountIDs = participantAccountIDs.map(Number).sort(); + const sortedParticipantsAccountIDs = participantAccountIDs.map(Number).sort(); - // Only return the chat if it has all the participants - return lodashIsEqual(sortedNewParticipantList, sortedParticipantsAccountIDs); - }) ?? null - ); + // Only return the chat if it has all the participants + return lodashIsEqual(sortedNewParticipantList, sortedParticipantsAccountIDs); + }); } /** * Attempts to find an invoice chat report in onyx with the provided policyID and receiverID. */ function getInvoiceChatByParticipants(policyID: string, receiverID: string | number, reports: OnyxCollection = allReports): OnyxEntry { - return ( - Object.values(reports ?? {}).find((report) => { - if (!report || !isInvoiceRoom(report)) { - return false; - } + return Object.values(reports ?? {}).find((report) => { + if (!report || !isInvoiceRoom(report)) { + return false; + } - const isSameReceiver = - report.invoiceReceiver && - (('accountID' in report.invoiceReceiver && report.invoiceReceiver.accountID === receiverID) || - ('policyID' in report.invoiceReceiver && report.invoiceReceiver.policyID === receiverID)); + const isSameReceiver = + report.invoiceReceiver && + (('accountID' in report.invoiceReceiver && report.invoiceReceiver.accountID === receiverID) || + ('policyID' in report.invoiceReceiver && report.invoiceReceiver.policyID === receiverID)); - return report.policyID === policyID && isSameReceiver; - }) ?? null - ); + return report.policyID === policyID && isSameReceiver; + }); } /** * Attempts to find a policy expense report in onyx that is owned by ownerAccountID in a given policy */ function getPolicyExpenseChat(ownerAccountID: number, policyID: string): OnyxEntry { - return ( - Object.values(allReports ?? {}).find((report: OnyxEntry) => { - // If the report has been deleted, then skip it - if (!report) { - return false; - } + return Object.values(allReports ?? {}).find((report: OnyxEntry) => { + // If the report has been deleted, then skip it + if (!report) { + return false; + } - return report.policyID === policyID && isPolicyExpenseChat(report) && report.ownerAccountID === ownerAccountID; - }) ?? null - ); + return report.policyID === policyID && isPolicyExpenseChat(report) && report.ownerAccountID === ownerAccountID; + }); } function getAllPolicyReports(policyID: string): Array> { @@ -6119,7 +6113,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry, return Localize.translateLocal(translationKey, {amount: formattedAmount, payer: ''}); } - const transactionDetails = getTransactionDetails(!isEmptyObject(transaction) ? transaction : null); + const transactionDetails = getTransactionDetails(!isEmptyObject(transaction) ? transaction : undefined); const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency); const isRequestSettled = isSettled(originalMessage.IOUReportID); const isApproved = isReportApproved(iouReport); @@ -6582,7 +6576,7 @@ function hasMissingPaymentMethod(userWallet: OnyxEntry, iouReportID: * - we have one, but it's waiting on the payee adding a bank account * - we have one, but we can't add more transactions to it due to: report is approved or settled, or report is processing and policy isn't on Instant submit reporting frequency */ -function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxEntry | undefined | null, chatReport: OnyxEntry | null): boolean { +function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxEntry | undefined, chatReport: OnyxEntry): boolean { return !existingIOUReport || hasIOUWaitingOnCurrentUserBankAccount(chatReport) || !canAddOrDeleteTransactions(existingIOUReport); } diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 81d8bd8357f0..326e020464e0 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -267,7 +267,7 @@ describe('ReportUtils', () => { describe('requiresAttentionFromCurrentUser', () => { it('returns false when there is no report', () => { - expect(ReportUtils.requiresAttentionFromCurrentUser(null)).toBe(false); + expect(ReportUtils.requiresAttentionFromCurrentUser(undefined)).toBe(false); }); it('returns false when the matched IOU report does not have an owner accountID', () => { const report = { @@ -358,7 +358,7 @@ describe('ReportUtils', () => { describe('return empty iou options if', () => { it('participants array contains excluded expensify iou emails', () => { const allEmpty = CONST.EXPENSIFY_ACCOUNT_IDS.every((accountID) => { - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(null, null, [currentUserAccountID, accountID]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(undefined, undefined, [currentUserAccountID, accountID]); return moneyRequestOptions.length === 0; }); expect(allEmpty).toBe(true); @@ -369,7 +369,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); @@ -379,7 +379,7 @@ describe('ReportUtils', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, isOwnPolicyExpenseChat: false, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); @@ -389,7 +389,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.IOU, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); @@ -400,7 +400,7 @@ describe('ReportUtils', () => { stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.APPROVED, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); @@ -410,7 +410,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.EXPENSE, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); @@ -424,7 +424,7 @@ describe('ReportUtils', () => { parentReportID: '100', type: CONST.REPORT.TYPE.EXPENSE, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(0); }); }); @@ -468,7 +468,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), chatType, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); return moneyRequestOptions.length === 1 && moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT); }); expect(onlyHaveSplitOption).toBe(true); @@ -479,7 +479,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, ...participantsAccountIDs]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); }); @@ -489,7 +489,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, ...participantsAccountIDs]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); }); @@ -500,7 +500,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.CHAT, participantsAccountIDs: [currentUserAccountID, ...participantsAccountIDs], }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs.map(Number)]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, ...participantsAccountIDs.map(Number)]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); }); @@ -514,7 +514,7 @@ describe('ReportUtils', () => { stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -526,7 +526,7 @@ describe('ReportUtils', () => { stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -544,7 +544,7 @@ describe('ReportUtils', () => { parentReportID: '102', type: CONST.REPORT.TYPE.EXPENSE, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(2); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); @@ -587,7 +587,7 @@ describe('ReportUtils', () => { stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -599,7 +599,7 @@ describe('ReportUtils', () => { stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -646,7 +646,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.CHAT, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, participantsAccountIDs[0]]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(3); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); @@ -659,7 +659,7 @@ describe('ReportUtils', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, isOwnPolicyExpenseChat: true, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, null, [currentUserAccountID, ...participantsAccountIDs]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, ...participantsAccountIDs]); expect(moneyRequestOptions.length).toBe(3); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); @@ -693,14 +693,14 @@ describe('ReportUtils', () => { {reportID: '4', lastReadTime: '2023-07-07 07:15:44.030', type: CONST.REPORT.TYPE.IOU}, {lastReadTime: '2023-07-09 07:15:44.030'} as Report, {reportID: '6'}, - null, + undefined, ]; const sortedReports: Array> = [ {reportID: '3', lastReadTime: '2023-07-06 07:15:44.030'}, {reportID: '4', lastReadTime: '2023-07-07 07:15:44.030', type: CONST.REPORT.TYPE.IOU}, {reportID: '1', lastReadTime: '2023-07-08 07:15:44.030'}, ]; - expect(ReportUtils.sortReportsByLastRead(reports, null)).toEqual(sortedReports); + expect(ReportUtils.sortReportsByLastRead(reports, undefined)).toEqual(sortedReports); }); }); From 1fde4640514648828be891ec53a677822d027ba3 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 31 May 2024 11:25:24 +0200 Subject: [PATCH 03/46] migrate more tests --- src/types/utils/CollectionDataSet.ts | 6 +- tests/actions/IOUTest.ts | 274 ++++++++---------- tests/actions/SessionTest.ts | 4 +- .../perf-test/ReportActionsList.perf-test.tsx | 2 +- tests/unit/MigrationTest.ts | 10 +- 5 files changed, 136 insertions(+), 160 deletions(-) diff --git a/src/types/utils/CollectionDataSet.ts b/src/types/utils/CollectionDataSet.ts index b8065cee8f84..1fe1b52f0a03 100644 --- a/src/types/utils/CollectionDataSet.ts +++ b/src/types/utils/CollectionDataSet.ts @@ -1,12 +1,12 @@ -import type {OnyxEntry} from 'react-native-onyx'; +import type {OnyxInput} from 'react-native-onyx'; import type {OnyxCollectionKey, OnyxCollectionValuesMapping} from '@src/ONYXKEYS'; /** Helps with typing a collection item update inside Onyx.multiSet call */ -type CollectionDataSet = Record<`${TCollectionKey}${string}`, OnyxEntry>; +type CollectionDataSet = Record<`${TCollectionKey}${string}`, OnyxInput>; const toCollectionDataSet = ( collectionKey: TCollectionKey, - collection: Array>, + collection: Array>, idSelector: (collectionValue: OnyxCollectionValuesMapping[TCollectionKey]) => string, ) => { const collectionDataSet = collection.reduce>((result, collectionValue) => { diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 4640167c2c60..510e05028f22 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -313,11 +313,10 @@ describe('actions/IOU', () => { callback: (allIOUReportActions) => { Onyx.disconnect(connectionID); - iouCreatedAction = Object.values(allIOUReportActions ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) ?? null; - iouAction = - Object.values(allIOUReportActions ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, - ) ?? null; + iouCreatedAction = Object.values(allIOUReportActions ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); + iouAction = Object.values(allIOUReportActions ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, + ); // The CREATED action should not be created after the IOU action expect(Date.parse(iouCreatedAction?.created ?? '')).toBeLessThan(Date.parse(iouAction?.created ?? '')); @@ -492,8 +491,8 @@ describe('actions/IOU', () => { expect(Object.values(allReports ?? {}).find((report) => report?.reportID === chatReportID)).toBeTruthy(); expect(Object.values(allReports ?? {}).find((report) => report?.reportID === iouReportID)).toBeTruthy(); - chatReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.CHAT) ?? null; - iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU) ?? null; + chatReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.CHAT); + iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); // The total on the iou report should be updated expect(iouReport?.total).toBe(11000); @@ -513,11 +512,10 @@ describe('actions/IOU', () => { Onyx.disconnect(connectionID); expect(Object.values(reportActionsForIOUReport ?? {}).length).toBe(3); - newIOUAction = - Object.values(reportActionsForIOUReport ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => - reportAction?.reportActionID !== createdAction.reportActionID && reportAction?.reportActionID !== iouAction?.reportActionID, - ) ?? null; + newIOUAction = Object.values(reportActionsForIOUReport ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => + reportAction?.reportActionID !== createdAction.reportActionID && reportAction?.reportActionID !== iouAction?.reportActionID, + ); // The IOUReportID should be correct expect(iouAction.originalMessage.IOUReportID).toBe(iouReportID); @@ -551,7 +549,7 @@ describe('actions/IOU', () => { // There should be two transactions expect(Object.values(allTransactions ?? {}).length).toBe(2); - newTransaction = Object.values(allTransactions ?? {}).find((transaction) => transaction?.transactionID !== existingTransaction.transactionID) ?? null; + newTransaction = Object.values(allTransactions ?? {}).find((transaction) => transaction?.transactionID !== existingTransaction.transactionID); expect(newTransaction?.reportID).toBe(iouReportID); expect(newTransaction?.amount).toBe(amount); @@ -733,7 +731,7 @@ describe('actions/IOU', () => { callback: (reportActionsForIOUReport) => { Onyx.disconnect(connectionID); expect(Object.values(reportActionsForIOUReport ?? {}).length).toBe(2); - iouAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + iouAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(iouAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); resolve(); }, @@ -749,10 +747,9 @@ describe('actions/IOU', () => { callback: (reportActionsForTransactionThread) => { Onyx.disconnect(connectionID); expect(Object.values(reportActionsForTransactionThread ?? {}).length).toBe(3); - transactionThreadAction = - Object.values(reportActionsForTransactionThread?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReport?.reportID}`] ?? {}).find( - (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, - ) ?? null; + transactionThreadAction = Object.values( + reportActionsForTransactionThread?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReport?.reportID}`] ?? {}, + ).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); expect(transactionThreadAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); resolve(); }, @@ -794,7 +791,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: false, callback: (reportActionsForReport) => { Onyx.disconnect(connectionID); - iouAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + iouAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(iouAction).toBeFalsy(); resolve(); }, @@ -811,7 +808,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: false, callback: (reportActionsForReport) => { Onyx.disconnect(connectionID); - iouAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + iouAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(iouAction).toBeFalsy(); resolve(); }, @@ -1096,54 +1093,50 @@ describe('actions/IOU', () => { expect(Object.values(allReports ?? {}).length).toBe(10); // 1. The chat report with Rory + Carlos - carlosChatReport = Object.values(allReports ?? {}).find((report) => report?.reportID === carlosChatReport?.reportID) ?? null; + carlosChatReport = Object.values(allReports ?? {}).find((report) => report?.reportID === carlosChatReport?.reportID); expect(isEmptyObject(carlosChatReport)).toBe(false); expect(carlosChatReport?.pendingFields).toBeFalsy(); // 2. The IOU report with Rory + Carlos (new) - carlosIOUReport = - Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU && report.managerID === CARLOS_ACCOUNT_ID) ?? null; + carlosIOUReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU && report.managerID === CARLOS_ACCOUNT_ID); expect(isEmptyObject(carlosIOUReport)).toBe(false); expect(carlosIOUReport?.total).toBe(amount / 4); // 3. The chat report with Rory + Jules - julesChatReport = Object.values(allReports ?? {}).find((report) => report?.reportID === julesChatReport?.reportID) ?? null; + julesChatReport = Object.values(allReports ?? {}).find((report) => report?.reportID === julesChatReport?.reportID); expect(isEmptyObject(julesChatReport)).toBe(false); expect(julesChatReport?.pendingFields).toBeFalsy(); // 4. The IOU report with Rory + Jules - julesIOUReport = Object.values(allReports ?? {}).find((report) => report?.reportID === julesIOUReport?.reportID) ?? null; + julesIOUReport = Object.values(allReports ?? {}).find((report) => report?.reportID === julesIOUReport?.reportID); expect(isEmptyObject(julesIOUReport)).toBe(false); expect(julesChatReport?.pendingFields).toBeFalsy(); expect(julesIOUReport?.total).toBe((julesExistingTransaction?.amount ?? 0) + amount / 4); // 5. The chat report with Rory + Vit (new) - vitChatReport = - Object.values(allReports ?? {}).find( - (report) => - report?.type === CONST.REPORT.TYPE.CHAT && - isEqual(report.participants, {[RORY_ACCOUNT_ID]: RORY_PARTICIPANT, [VIT_ACCOUNT_ID]: VIT_PARTICIPANT}), - ) ?? null; + vitChatReport = Object.values(allReports ?? {}).find( + (report) => + report?.type === CONST.REPORT.TYPE.CHAT && isEqual(report.participants, {[RORY_ACCOUNT_ID]: RORY_PARTICIPANT, [VIT_ACCOUNT_ID]: VIT_PARTICIPANT}), + ); expect(isEmptyObject(vitChatReport)).toBe(false); expect(vitChatReport?.pendingFields).toStrictEqual({createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}); // 6. The IOU report with Rory + Vit (new) - vitIOUReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU && report.managerID === VIT_ACCOUNT_ID) ?? null; + vitIOUReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU && report.managerID === VIT_ACCOUNT_ID); expect(isEmptyObject(vitIOUReport)).toBe(false); expect(vitIOUReport?.total).toBe(amount / 4); // 7. The group chat with everyone - groupChat = - Object.values(allReports ?? {}).find( - (report) => - report?.type === CONST.REPORT.TYPE.CHAT && - isEqual(report.participants, { - [CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT, - [JULES_ACCOUNT_ID]: JULES_PARTICIPANT, - [VIT_ACCOUNT_ID]: VIT_PARTICIPANT, - [RORY_ACCOUNT_ID]: RORY_PARTICIPANT, - }), - ) ?? null; + groupChat = Object.values(allReports ?? {}).find( + (report) => + report?.type === CONST.REPORT.TYPE.CHAT && + isEqual(report.participants, { + [CARLOS_ACCOUNT_ID]: CARLOS_PARTICIPANT, + [JULES_ACCOUNT_ID]: JULES_PARTICIPANT, + [VIT_ACCOUNT_ID]: VIT_PARTICIPANT, + [RORY_ACCOUNT_ID]: RORY_PARTICIPANT, + }), + ); expect(isEmptyObject(groupChat)).toBe(false); expect(groupChat?.pendingFields).toStrictEqual({createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}); @@ -1183,14 +1176,12 @@ describe('actions/IOU', () => { // Carlos DM should have two reportActions – the existing CREATED action and a pending IOU action expect(Object.values(carlosReportActions ?? {}).length).toBe(2); - carlosIOUCreatedAction = - Object.values(carlosReportActions ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, - ) ?? null; - carlosIOUAction = - Object.values(carlosReportActions ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, - ) ?? null; + carlosIOUCreatedAction = Object.values(carlosReportActions ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, + ); + carlosIOUAction = Object.values(carlosReportActions ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, + ); expect(carlosIOUAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); expect(carlosIOUAction?.originalMessage.IOUReportID).toBe(carlosIOUReport?.reportID); expect(carlosIOUAction?.originalMessage.amount).toBe(amount / 4); @@ -1201,15 +1192,13 @@ describe('actions/IOU', () => { // Jules DM should have three reportActions, the existing CREATED action, the existing IOU action, and a new pending IOU action expect(Object.values(julesReportActions ?? {}).length).toBe(3); expect(julesReportActions?.[julesCreatedAction.reportActionID]).toStrictEqual(julesCreatedAction); - julesIOUCreatedAction = - Object.values(julesReportActions ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, - ) ?? null; - julesIOUAction = - Object.values(julesReportActions ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => - reportAction.reportActionID !== julesCreatedAction.reportActionID && reportAction.reportActionID !== julesExistingIOUAction.reportActionID, - ) ?? null; + julesIOUCreatedAction = Object.values(julesReportActions ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, + ); + julesIOUAction = Object.values(julesReportActions ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => + reportAction.reportActionID !== julesCreatedAction.reportActionID && reportAction.reportActionID !== julesExistingIOUAction.reportActionID, + ); expect(julesIOUAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); expect(julesIOUAction?.originalMessage.IOUReportID).toBe(julesIOUReport?.reportID); expect(julesIOUAction?.originalMessage.amount).toBe(amount / 4); @@ -1219,14 +1208,12 @@ describe('actions/IOU', () => { // Vit DM should have two reportActions – a pending CREATED action and a pending IOU action expect(Object.values(vitReportActions ?? {}).length).toBe(2); - vitCreatedAction = - Object.values(vitReportActions ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, - ) ?? null; - vitIOUAction = - Object.values(vitReportActions ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, - ) ?? null; + vitCreatedAction = Object.values(vitReportActions ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, + ); + vitIOUAction = Object.values(vitReportActions ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, + ); expect(vitCreatedAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); expect(vitIOUAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); expect(vitIOUAction?.originalMessage.IOUReportID).toBe(vitIOUReport?.reportID); @@ -1237,12 +1224,10 @@ describe('actions/IOU', () => { // Group chat should have two reportActions – a pending CREATED action and a pending IOU action w/ type SPLIT expect(Object.values(groupReportActions ?? {}).length).toBe(2); - groupCreatedAction = - Object.values(groupReportActions ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) ?? null; - groupIOUAction = - Object.values(groupReportActions ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, - ) ?? null; + groupCreatedAction = Object.values(groupReportActions ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); + groupIOUAction = Object.values(groupReportActions ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, + ); expect(groupCreatedAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); expect(groupIOUAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); expect(groupIOUAction?.originalMessage).not.toHaveProperty('IOUReportID'); @@ -1271,19 +1256,16 @@ describe('actions/IOU', () => { expect(Object.values(allTransactions ?? {}).length).toBe(5); expect(allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${julesExistingTransaction?.transactionID}`]).toBeTruthy(); - carlosTransaction = - Object.values(allTransactions ?? {}).find( - (transaction) => transaction?.transactionID === (carlosIOUAction?.originalMessage as IOUMessage)?.IOUTransactionID, - ) ?? null; - julesTransaction = - Object.values(allTransactions ?? {}).find( - (transaction) => transaction?.transactionID === (julesIOUAction?.originalMessage as IOUMessage)?.IOUTransactionID, - ) ?? null; - vitTransaction = - Object.values(allTransactions ?? {}).find( - (transaction) => transaction?.transactionID === (vitIOUAction?.originalMessage as IOUMessage)?.IOUTransactionID, - ) ?? null; - groupTransaction = Object.values(allTransactions ?? {}).find((transaction) => transaction?.reportID === CONST.REPORT.SPLIT_REPORTID) ?? null; + carlosTransaction = Object.values(allTransactions ?? {}).find( + (transaction) => transaction?.transactionID === (carlosIOUAction?.originalMessage as IOUMessage)?.IOUTransactionID, + ); + julesTransaction = Object.values(allTransactions ?? {}).find( + (transaction) => transaction?.transactionID === (julesIOUAction?.originalMessage as IOUMessage)?.IOUTransactionID, + ); + vitTransaction = Object.values(allTransactions ?? {}).find( + (transaction) => transaction?.transactionID === (vitIOUAction?.originalMessage as IOUMessage)?.IOUTransactionID, + ); + groupTransaction = Object.values(allTransactions ?? {}).find((transaction) => transaction?.reportID === CONST.REPORT.SPLIT_REPORTID); expect(carlosTransaction?.reportID).toBe(carlosIOUReport?.reportID); expect(julesTransaction?.reportID).toBe(julesIOUReport?.reportID); @@ -1423,7 +1405,7 @@ describe('actions/IOU', () => { expect(chatReport).toHaveProperty('reportID'); expect(chatReport).toHaveProperty('iouReportID'); - iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU) ?? null; + iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); expect(iouReport).toBeTruthy(); expect(iouReport).toHaveProperty('reportID'); expect(iouReport).toHaveProperty('chatReportID'); @@ -1450,8 +1432,7 @@ describe('actions/IOU', () => { const reportActionsForIOUReport = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.iouReportID}`]; - createIOUAction = - Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(createIOUAction).toBeTruthy(); expect((createIOUAction?.originalMessage as IOUMessage)?.IOUReportID).toBe(iouReport?.reportID); @@ -1469,7 +1450,7 @@ describe('actions/IOU', () => { callback: (allTransactions) => { Onyx.disconnect(connectionID); expect(Object.values(allTransactions ?? {}).length).toBe(1); - transaction = Object.values(allTransactions ?? {}).find((t) => t) ?? null; + transaction = Object.values(allTransactions ?? {}).find((t) => t); expect(transaction).toBeTruthy(); expect(transaction?.amount).toBe(amount); expect(transaction?.reportID).toBe(iouReport?.reportID); @@ -1497,8 +1478,8 @@ describe('actions/IOU', () => { expect(Object.values(allReports ?? {}).length).toBe(3); - chatReport = Object.values(allReports ?? {}).find((r) => r?.type === CONST.REPORT.TYPE.CHAT) ?? null; - iouReport = Object.values(allReports ?? {}).find((r) => r?.type === CONST.REPORT.TYPE.IOU) ?? null; + chatReport = Object.values(allReports ?? {}).find((r) => r?.type === CONST.REPORT.TYPE.CHAT); + iouReport = Object.values(allReports ?? {}).find((r) => r?.type === CONST.REPORT.TYPE.IOU); expect(chatReport?.iouReportID).toBeFalsy(); @@ -1522,11 +1503,10 @@ describe('actions/IOU', () => { const reportActionsForIOUReport = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`]; expect(Object.values(reportActionsForIOUReport ?? {}).length).toBe(3); - payIOUAction = - Object.values(reportActionsForIOUReport ?? {}).find( - (reportAction) => - reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && reportAction?.originalMessage?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY, - ) ?? null; + payIOUAction = Object.values(reportActionsForIOUReport ?? {}).find( + (reportAction) => + reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && reportAction?.originalMessage?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY, + ); expect(payIOUAction).toBeTruthy(); expect(payIOUAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); @@ -1547,8 +1527,8 @@ describe('actions/IOU', () => { expect(Object.values(allReports ?? {}).length).toBe(3); - chatReport = Object.values(allReports ?? {}).find((r) => r?.type === CONST.REPORT.TYPE.CHAT) ?? null; - iouReport = Object.values(allReports ?? {}).find((r) => r?.type === CONST.REPORT.TYPE.IOU) ?? null; + chatReport = Object.values(allReports ?? {}).find((r) => r?.type === CONST.REPORT.TYPE.CHAT); + iouReport = Object.values(allReports ?? {}).find((r) => r?.type === CONST.REPORT.TYPE.IOU); expect(chatReport?.iouReportID).toBeFalsy(); @@ -1572,11 +1552,9 @@ describe('actions/IOU', () => { const reportActionsForIOUReport = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`]; expect(Object.values(reportActionsForIOUReport ?? {}).length).toBe(3); - payIOUAction = - Object.values(reportActionsForIOUReport ?? {}).find( - (reportAction) => - reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && reportAction.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY, - ) ?? null; + payIOUAction = Object.values(reportActionsForIOUReport ?? {}).find( + (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && reportAction.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY, + ); expect(payIOUAction).toBeTruthy(); resolve(); @@ -1598,9 +1576,9 @@ describe('actions/IOU', () => { it('updates the IOU request and IOU report when offline', () => { let thread: OptimisticChatReport; - let iouReport: OnyxEntry = null; - let iouAction: OnyxEntry = null; - let transaction: OnyxEntry = null; + let iouReport: OnyxEntry; + let iouAction: OnyxEntry; + let transaction: OnyxEntry; mockFetch?.pause?.(); IOU.requestMoney({reportID: ''}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment, {}); @@ -1617,7 +1595,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU) ?? null; + iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); resolve(); }, @@ -1648,7 +1626,7 @@ describe('actions/IOU', () => { callback: (allTransactions) => { Onyx.disconnect(connectionID); - transaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)) ?? null; + transaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); resolve(); }, }); @@ -1799,7 +1777,7 @@ describe('actions/IOU', () => { callback: (allTransactions) => { Onyx.disconnect(connectionID); - transaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)) ?? null; + transaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); resolve(); }, }); @@ -1926,7 +1904,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT) ?? null; + chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); resolve(); }, @@ -1947,7 +1925,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); resolve(); }, @@ -2039,7 +2017,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT) ?? null; + chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); resolve(); }, @@ -2060,7 +2038,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); resolve(); }, @@ -2153,13 +2131,13 @@ describe('actions/IOU', () => { expect(Object.values(allReports ?? {}).length).toBe(3); // Then one of them should be a chat report with relevant properties - chatReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.CHAT) ?? null; + chatReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.CHAT); expect(chatReport).toBeTruthy(); expect(chatReport).toHaveProperty('reportID'); expect(chatReport).toHaveProperty('iouReportID'); // Then one of them should be an IOU report with relevant properties - iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU) ?? null; + iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); expect(iouReport).toBeTruthy(); expect(iouReport).toHaveProperty('reportID'); expect(iouReport).toHaveProperty('chatReportID'); @@ -2187,10 +2165,9 @@ describe('actions/IOU', () => { // Then we should find an IOU action with specific properties const reportActionsForIOUReport = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.iouReportID}`]; - createIOUAction = - Object.values(reportActionsForIOUReport ?? {}).find( - (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, - ) ?? null; + createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find( + (reportAction): reportAction is ReportActionBase & OriginalMessageIOU => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU, + ); expect(createIOUAction).toBeTruthy(); expect(createIOUAction?.originalMessage.IOUReportID).toBe(iouReport?.reportID); @@ -2207,7 +2184,7 @@ describe('actions/IOU', () => { }); // Then we should find a specific transaction with relevant properties - transaction = Object.values(allTransactions ?? {}).find((t) => t) ?? null; + transaction = Object.values(allTransactions ?? {}).find((t) => t); expect(transaction).toBeTruthy(); expect(transaction?.amount).toBe(amount); expect(transaction?.reportID).toBe(iouReport?.reportID); @@ -2238,7 +2215,7 @@ describe('actions/IOU', () => { }); }); - createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); // Then the IOU Action should be truthy for offline support. expect(createIOUAction).toBeTruthy(); @@ -2272,7 +2249,7 @@ describe('actions/IOU', () => { }); }); - createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(createIOUAction).toBeFalsy(); // Then we recheck the transaction from the transactions collection @@ -2387,7 +2364,7 @@ describe('actions/IOU', () => { await waitForBatchedUpdates(); - iouReport = Object.values(allReports ?? {}).find((report) => ReportUtils.isIOUReport(report)) ?? null; + iouReport = Object.values(allReports ?? {}).find((report) => ReportUtils.isIOUReport(report)); expect(iouReport).toBeTruthy(); expect(iouReport).toHaveProperty('reportID'); expect(iouReport).toHaveProperty('chatReportID'); @@ -2406,7 +2383,7 @@ describe('actions/IOU', () => { }); }); // Then expect that the IOU report still exists - iouReport = Object.values(allReports ?? {}).find((report) => ReportUtils.isIOUReport(report)) ?? null; + iouReport = Object.values(allReports ?? {}).find((report) => ReportUtils.isIOUReport(report)); expect(iouReport).toBeTruthy(); expect(iouReport).toHaveProperty('reportID'); expect(iouReport).toHaveProperty('chatReportID'); @@ -2451,7 +2428,7 @@ describe('actions/IOU', () => { }); }); const reportActionsForIOUReport = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.iouReportID}`]; - createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(createIOUAction?.childReportID).toBe(thread.reportID); await waitForBatchedUpdates(); @@ -2533,7 +2510,7 @@ describe('actions/IOU', () => { }); }); const reportActionsForIOUReport = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.iouReportID}`]; - createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(createIOUAction?.childReportID).toBe(thread.reportID); await waitForBatchedUpdates(); @@ -2569,7 +2546,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: false, callback: (reportActionsForReport) => { Onyx.disconnect(connectionID); - createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); resolve(); }, }); @@ -2718,7 +2695,7 @@ describe('actions/IOU', () => { }); const reportActionsForIOUReport = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.iouReportID}`]; - createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(createIOUAction?.childReportID).toBe(thread.reportID); await waitForBatchedUpdates(); @@ -2738,7 +2715,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: false, callback: (reportActionsForReport) => { Onyx.disconnect(connectionID); - createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); resolve(); }, }); @@ -2808,7 +2785,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: false, callback: (reportActionsForReport) => { Onyx.disconnect(connectionID); - createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(createIOUAction?.message?.[0]?.isDeletedParentAction).toBeTruthy(); resolve(); }, @@ -2826,7 +2803,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: false, callback: (reportActionsForReport) => { Onyx.disconnect(connectionID); - createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(createIOUAction?.message?.[0]?.isDeletedParentAction).toBeTruthy(); resolve(); }, @@ -2949,7 +2926,7 @@ describe('actions/IOU', () => { }); const reportActionsForIOUReport = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.iouReportID}`]; - createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) ?? null; + createIOUAction = Object.values(reportActionsForIOUReport ?? {}).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(createIOUAction?.childReportID).toBe(thread.reportID); await waitForBatchedUpdates(); @@ -2976,7 +2953,7 @@ describe('actions/IOU', () => { await waitForBatchedUpdates(); - iouReport = Object.values(allReports ?? {}).find((report) => ReportUtils.isIOUReport(report)) ?? null; + iouReport = Object.values(allReports ?? {}).find((report) => ReportUtils.isIOUReport(report)); expect(iouReport).toBeTruthy(); expect(iouReport).toHaveProperty('reportID'); expect(iouReport).toHaveProperty('chatReportID'); @@ -2994,7 +2971,7 @@ describe('actions/IOU', () => { }); }); - iouReport = Object.values(allReports ?? {}).find((report) => ReportUtils.isIOUReport(report)) ?? null; + iouReport = Object.values(allReports ?? {}).find((report) => ReportUtils.isIOUReport(report)); expect(iouReport).toBeTruthy(); expect(iouReport).toHaveProperty('reportID'); expect(iouReport).toHaveProperty('chatReportID'); @@ -3038,7 +3015,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT) ?? null; + chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); resolve(); }, @@ -3070,7 +3047,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE); Onyx.merge(`report_${expenseReport?.reportID}`, { statusNum: 0, stateNum: 0, @@ -3088,7 +3065,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE); // Verify report is a draft expect(expenseReport?.stateNum).toBe(0); @@ -3112,8 +3089,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE) ?? null; - + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE); // Report was submitted correctly expect(expenseReport?.stateNum).toBe(1); expect(expenseReport?.statusNum).toBe(1); @@ -3142,7 +3118,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT) ?? null; + chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); resolve(); }, @@ -3174,7 +3150,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE); Onyx.merge(`report_${expenseReport?.reportID}`, { statusNum: 0, stateNum: 0, @@ -3192,7 +3168,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE); // Verify report is a draft expect(expenseReport?.stateNum).toBe(0); @@ -3216,7 +3192,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE); // Report is closed since the default policy settings is Submit and Close expect(expenseReport?.stateNum).toBe(2); @@ -3246,7 +3222,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT) ?? null; + chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); resolve(); }, @@ -3278,7 +3254,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE); Onyx.merge(`report_${expenseReport?.reportID}`, { statusNum: 0, stateNum: 0, @@ -3296,7 +3272,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE); // Verify report is a draft expect(expenseReport?.stateNum).toBe(0); @@ -3321,7 +3297,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE) ?? null; + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE); // Report was submitted with some fail expect(expenseReport?.stateNum).toBe(0); diff --git a/tests/actions/SessionTest.ts b/tests/actions/SessionTest.ts index f4c4d186ff50..62d6a54b20b5 100644 --- a/tests/actions/SessionTest.ts +++ b/tests/actions/SessionTest.ts @@ -35,13 +35,13 @@ describe('Session', () => { const TEST_INITIAL_AUTH_TOKEN = 'initialAuthToken'; const TEST_REFRESHED_AUTH_TOKEN = 'refreshedAuthToken'; - let credentials: OnyxEntry = null; + let credentials: OnyxEntry; Onyx.connect({ key: ONYXKEYS.CREDENTIALS, callback: (val) => (credentials = val), }); - let session: OnyxEntry = null; + let session: OnyxEntry; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (val) => (session = val), diff --git a/tests/perf-test/ReportActionsList.perf-test.tsx b/tests/perf-test/ReportActionsList.perf-test.tsx index 7d45e3e4b45d..ff284fdd7584 100644 --- a/tests/perf-test/ReportActionsList.perf-test.tsx +++ b/tests/perf-test/ReportActionsList.perf-test.tsx @@ -95,7 +95,7 @@ function ReportActionsListWrapper() { { it('Should move individual draft to a draft collection of report', () => { const setQueries: ReportActionsDraftCollectionDataSet = {}; - setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_1`] = 'a' as unknown as OnyxEntry; - setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_2`] = 'b' as unknown as OnyxEntry; + setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_1`] = 'a' as unknown as OnyxInput; + setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_2`] = 'b' as unknown as OnyxInput; setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}2`] = {3: 'c'}; - setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}2_4`] = 'd' as unknown as OnyxEntry; + setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}2_4`] = 'd' as unknown as OnyxInput; return Onyx.multiSet(setQueries) .then(KeyReportActionsDraftByReportActionID) @@ -320,7 +320,7 @@ describe('Migrations', () => { it("Shouldn't move empty individual draft to a draft collection of report", () => { const setQueries: ReportActionsDraftCollectionDataSet = {}; - setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_1`] = '' as unknown as OnyxEntry; + setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_1`] = '' as unknown as OnyxInput; setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1`] = {}; return Onyx.multiSet(setQueries) From 903b8419c4f96231a7ddd93cd5217251722e5717 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 31 May 2024 11:35:33 +0200 Subject: [PATCH 04/46] migrate more components --- src/components/MoneyRequestConfirmationList.tsx | 12 ++++++------ src/libs/DistanceRequestUtils.ts | 10 +++++----- .../substeps/CompanyOwnersListUBO.tsx | 2 +- src/pages/ReportDetailsPage.tsx | 4 ++-- src/pages/iou/SplitBillDetailsPage.tsx | 2 +- .../iou/request/step/IOURequestStepDescription.tsx | 2 +- src/pages/settings/Report/ReportSettingsPage.tsx | 4 ++-- .../settings/Wallet/Card/BaseGetPhysicalCard.tsx | 2 +- src/pages/settings/Wallet/ExpensifyCardPage.tsx | 6 +++--- src/pages/tasks/NewTaskPage.tsx | 2 +- src/pages/tasks/TaskAssigneeSelectorModal.tsx | 8 ++++---- src/pages/workspace/AccessOrNotFoundWrapper.tsx | 2 +- src/pages/workspace/WorkspaceNewRoomPage.tsx | 1 - 13 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index b18a98b13304..77da57c58d9c 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -186,7 +186,7 @@ const getTaxAmount = (transaction: OnyxEntry, policy: Ony }; function MoneyRequestConfirmationList({ - transaction = null, + transaction, onSendMoney, onConfirm, iouType = CONST.IOU.TYPE.SUBMIT, @@ -697,7 +697,7 @@ function MoneyRequestConfirmationList({ if (selectedParticipants.length === 0) { return; } - if (!isEditingSplitBill && isMerchantRequired && (isMerchantEmpty || (shouldDisplayFieldError && TransactionUtils.isMerchantMissing(transaction ?? null)))) { + if (!isEditingSplitBill && isMerchantRequired && (isMerchantEmpty || (shouldDisplayFieldError && TransactionUtils.isMerchantMissing(transaction)))) { setFormError('iou.error.invalidMerchant'); return; } @@ -727,7 +727,7 @@ function MoneyRequestConfirmationList({ return; } - if (isEditingSplitBill && TransactionUtils.areRequiredFieldsEmpty(transaction ?? null)) { + if (isEditingSplitBill && TransactionUtils.areRequiredFieldsEmpty(transaction)) { setDidConfirmSplit(true); setFormError('iou.error.genericSmartscanFailureMessage'); return; @@ -849,8 +849,8 @@ function MoneyRequestConfirmationList({ style={[styles.moneyRequestMenuItem, styles.mt2]} titleStyle={styles.moneyRequestConfirmationAmount} disabled={didConfirm} - brickRoadIndicator={shouldDisplayFieldError && TransactionUtils.isAmountMissing(transaction ?? null) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} - errorText={shouldDisplayFieldError && TransactionUtils.isAmountMissing(transaction ?? null) ? translate('common.error.enterAmount') : ''} + brickRoadIndicator={shouldDisplayFieldError && TransactionUtils.isAmountMissing(transaction) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} + errorText={shouldDisplayFieldError && TransactionUtils.isAmountMissing(transaction) ? translate('common.error.enterAmount') : ''} /> ), shouldShow: shouldShowSmartScanFields, @@ -1084,7 +1084,7 @@ function MoneyRequestConfirmationList({ isThumbnail, fileExtension, isLocalFile, - } = receiptPath && receiptFilename ? ReceiptUtils.getThumbnailAndImageURIs(transaction ?? null, receiptPath, receiptFilename) : ({} as ReceiptUtils.ThumbnailAndImageURI); + } = receiptPath && receiptFilename ? ReceiptUtils.getThumbnailAndImageURIs(transaction, receiptPath, receiptFilename) : ({} as ReceiptUtils.ThumbnailAndImageURI); const resolvedThumbnail = isLocalFile ? receiptThumbnail : tryResolveUrlFromApiRoot(receiptThumbnail ?? ''); const resolvedReceiptImage = isLocalFile ? receiptImage : tryResolveUrlFromApiRoot(receiptImage ?? ''); diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index 9cb48534214e..42b869c84d21 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -48,14 +48,14 @@ const METERS_TO_MILES = 0.000621371; // There are approximately 0.000621371 mile * @returns [currency] - The currency associated with the rate. * @returns [unit] - The unit of measurement for the distance. */ -function getDefaultMileageRate(policy: OnyxEntry | EmptyObject): MileageRate | null { +function getDefaultMileageRate(policy: OnyxEntry | EmptyObject): MileageRate | undefined { if (!policy?.customUnits) { - return null; + return; } const distanceUnit = Object.values(policy.customUnits).find((unit) => unit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE); if (!distanceUnit?.rates) { - return null; + return; } const distanceRate = Object.values(distanceUnit.rates).find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE) ?? Object.values(distanceUnit.rates)[0]; @@ -253,8 +253,8 @@ function convertToDistanceInMeters(distance: number, unit: Unit): number { * Returns custom unit rate ID for the distance transaction */ function getCustomUnitRateID(reportID: string) { - const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? null; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; + const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`]; const policy = PolicyUtils.getPolicy(report?.policyID ?? parentReport?.policyID ?? ''); let customUnitRateID: string = CONST.CUSTOM_UNITS.FAKE_P2P_ID; diff --git a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/CompanyOwnersListUBO.tsx b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/CompanyOwnersListUBO.tsx index 542d3d0cf6d0..af92d2626ec0 100644 --- a/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/CompanyOwnersListUBO.tsx +++ b/src/pages/ReimbursementAccount/BeneficialOwnerInfo/substeps/CompanyOwnersListUBO.tsx @@ -74,7 +74,7 @@ function CompanyOwnersListUBO({ const {isOffline} = useNetwork(); const isLoading = reimbursementAccount?.isLoading ?? false; - const requestorData = getSubstepValues(REQUESTOR_PERSONAL_INFO_KEYS, null, reimbursementAccount); + const requestorData = getSubstepValues(REQUESTOR_PERSONAL_INFO_KEYS, undefined, reimbursementAccount); const error = ErrorUtils.getLatestErrorMessage(reimbursementAccount); const extraBeneficialOwners = diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index b7c9ab910947..7436092ffbe3 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -69,7 +69,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD const route = useRoute(); const [isLastMemberLeavingGroupModalVisible, setIsLastMemberLeavingGroupModalVisible] = useState(false); const policy = useMemo(() => policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? ''}`], [policies, report?.policyID]); - const isPolicyAdmin = useMemo(() => PolicyUtils.isPolicyAdmin(policy ?? null), [policy]); + const isPolicyAdmin = useMemo(() => PolicyUtils.isPolicyAdmin(policy), [policy]); const isPolicyEmployee = useMemo(() => PolicyUtils.isPolicyEmployee(report?.policyID ?? '', policies), [report?.policyID, policies]); const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(report), [report]); const shouldUseFullTitle = useMemo(() => ReportUtils.shouldUseFullTitleToDisplay(report), [report]); @@ -201,7 +201,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD }); } - if (isGroupChat || (isChatRoom && ReportUtils.canLeaveChat(report, policy ?? null))) { + if (isGroupChat || (isChatRoom && ReportUtils.canLeaveChat(report, policy))) { items.push({ key: CONST.REPORT_DETAILS_MENU_ITEM.LEAVE_ROOM, translationKey: 'common.leave', diff --git a/src/pages/iou/SplitBillDetailsPage.tsx b/src/pages/iou/SplitBillDetailsPage.tsx index 7d0b9bb15b07..e3fef3450fb0 100644 --- a/src/pages/iou/SplitBillDetailsPage.tsx +++ b/src/pages/iou/SplitBillDetailsPage.tsx @@ -108,7 +108,7 @@ function SplitBillDetailsPage({personalDetails, report, route, reportActions, tr )} {!!participants.length && ( Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID) ?? null, [policies, report?.policyID]); + const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); const shouldDisableRename = useMemo(() => ReportUtils.shouldDisableRename(report, linkedWorkspace), [report, linkedWorkspace]); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); @@ -130,7 +130,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) { ))} - {linkedWorkspace !== null && ( + {linkedWorkspace != null && ( cardsToShow?.filter((card) => card?.nameValuePairs?.isVirtual), [cardsToShow]); const physicalCards = useMemo(() => cardsToShow?.filter((card) => !card?.nameValuePairs?.isVirtual), [cardsToShow]); - const [cardsDetails, setCardsDetails] = useState>({}); + const [cardsDetails, setCardsDetails] = useState>({}); const [isCardDetailsLoading, setIsCardDetailsLoading] = useState>({}); const [cardsDetailsErrors, setCardsDetailsErrors] = useState>({}); @@ -116,7 +116,7 @@ function ExpensifyCardPage({ // eslint-disable-next-line rulesdir/no-thenable-actions-in-views Card.revealVirtualCardDetails(revealedCardID) .then((value) => { - setCardsDetails((prevState: Record) => ({...prevState, [revealedCardID]: value as TCardDetails})); + setCardsDetails((prevState: Record) => ({...prevState, [revealedCardID]: value as TCardDetails})); setCardsDetailsErrors((prevState) => ({ ...prevState, [revealedCardID]: '', @@ -140,7 +140,7 @@ function ExpensifyCardPage({ const goToGetPhysicalCardFlow = () => { let updatedDraftValues = draftValues; if (!draftValues) { - updatedDraftValues = GetPhysicalCardUtils.getUpdatedDraftValues(null, privatePersonalDetails, loginList); + updatedDraftValues = GetPhysicalCardUtils.getUpdatedDraftValues(undefined, privatePersonalDetails, loginList); // Form draft data needs to be initialized with the private personal details // If no draft data exists FormActions.setDraftValues(ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM, updatedDraftValues); diff --git a/src/pages/tasks/NewTaskPage.tsx b/src/pages/tasks/NewTaskPage.tsx index d038e8260418..5eb55b68417c 100644 --- a/src/pages/tasks/NewTaskPage.tsx +++ b/src/pages/tasks/NewTaskPage.tsx @@ -79,7 +79,7 @@ function NewTaskPage({task, reports, personalDetails}: NewTaskPageProps) { // If we have a share destination, we want to set the parent report and // the share destination data if (task?.shareDestination) { - setParentReport(reports?.[`report_${task.shareDestination}`] ?? null); + setParentReport(reports?.[`report_${task.shareDestination}`]); const displayDetails = TaskActions.getShareDestination(task.shareDestination, reports, personalDetails); setShareDestination(displayDetails); } diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index b049cacfa0b6..75b1370adfb3 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -103,14 +103,14 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro const report: OnyxEntry = useMemo(() => { if (!route.params?.reportID) { - return null; + return; } if (report && !ReportUtils.isTaskReport(report)) { Navigation.isNavigationReady().then(() => { Navigation.dismissModal(report.reportID); }); } - return reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`] ?? null; + return reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`]; }, [reports, route]); const sections = useMemo(() => { @@ -172,7 +172,7 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro option?.login ?? '', option?.accountID ?? -1, report.reportID, - null, // passing null as report because for editing task the report will be task details report page not the actual report where task was created + undefined, // passing null as report because for editing task the report will be task details report page not the actual report where task was created OptionsListUtils.isCurrentUser({...option, accountID: option?.accountID ?? -1, login: option?.login ?? ''}), ); @@ -186,7 +186,7 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro option?.login ?? '', option.accountID, task?.shareDestination ?? '', - null, // passing null as report is null in this condition + undefined, // passing null as report is null in this condition OptionsListUtils.isCurrentUser({...option, accountID: option?.accountID ?? -1, login: option?.login ?? undefined}), ); Navigation.goBack(ROUTES.NEW_TASK); diff --git a/src/pages/workspace/AccessOrNotFoundWrapper.tsx b/src/pages/workspace/AccessOrNotFoundWrapper.tsx index a9d971d4c0f1..5e5c4b6f8299 100644 --- a/src/pages/workspace/AccessOrNotFoundWrapper.tsx +++ b/src/pages/workspace/AccessOrNotFoundWrapper.tsx @@ -115,7 +115,7 @@ function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps const isPageAccessible = accessVariants.reduce((acc, variant) => { const accessFunction = ACCESS_VARIANTS[variant]; - return acc && accessFunction(policy, report, allPolicies ?? null, iouType); + return acc && accessFunction(policy, report, allPolicies, iouType); }, true); const isPolicyNotAccessible = isEmptyObject(policy) || (Object.keys(policy).length === 1 && !isEmptyObject(policy.errors)) || !policy?.id; diff --git a/src/pages/workspace/WorkspaceNewRoomPage.tsx b/src/pages/workspace/WorkspaceNewRoomPage.tsx index 382c1dde6d47..bf8b68db7327 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.tsx +++ b/src/pages/workspace/WorkspaceNewRoomPage.tsx @@ -358,6 +358,5 @@ export default withOnyx Date: Fri, 31 May 2024 11:44:05 +0200 Subject: [PATCH 05/46] migrate more components --- src/components/MoneyRequestConfirmationList.tsx | 2 +- src/pages/home/ReportScreen.tsx | 8 ++++---- src/pages/home/report/ReportActionsView.tsx | 2 +- src/pages/home/report/SystemChatReportFooterMessage.tsx | 3 +-- .../home/report/withReportAndReportActionOrNotFound.tsx | 8 ++++---- src/pages/iou/request/step/IOURequestStepCategory.tsx | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 77da57c58d9c..0edc42fb989d 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -131,7 +131,7 @@ type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps & selectedParticipants: Participant[]; /** Payee of the expense with login */ - payeePersonalDetails?: OnyxEntry; + payeePersonalDetails?: OnyxEntry | null; /** Should the list be read only, and not editable? */ isReadOnly?: boolean; diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 80f1efcb00aa..797197fbe1f5 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -104,7 +104,7 @@ function isEmpty(report: OnyxTypes.Report): boolean { function getParentReportAction(parentReportActions: OnyxEntry, parentReportActionID: string | undefined): OnyxEntry { if (!parentReportActions || !parentReportActionID) { - return null; + return; } return parentReportActions[parentReportActionID ?? '0']; } @@ -293,12 +293,12 @@ function ReportScreen({ const lastReportAction: OnyxEntry = useMemo( () => reportActions.length - ? [...reportActions, parentReportAction].find((action) => ReportUtils.canEditReportAction(action) && !ReportActionsUtils.isMoneyRequestAction(action)) ?? null - : null, + ? [...reportActions, parentReportAction].find((action) => ReportUtils.canEditReportAction(action) && !ReportActionsUtils.isMoneyRequestAction(action)) + : undefined, [reportActions, parentReportAction], ); const isSingleTransactionView = ReportUtils.isMoneyRequest(report) || ReportUtils.isTrackExpenseReport(report); - const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`] ?? null; + const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; const isTopMostReportId = currentReportID === reportIDFromRoute; const didSubscribeToReportLeavingEvents = useRef(false); diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 5e18378ff949..d3eaf9136164 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -164,7 +164,7 @@ function ReportActionsView({ const parentReportActionForTransactionThread = useMemo( () => isEmptyObject(transactionThreadReportActions) - ? null + ? undefined : (allReportActions.find((action) => action.reportActionID === transactionThreadReport?.parentReportActionID) as OnyxEntry), [allReportActions, transactionThreadReportActions, transactionThreadReport?.parentReportActionID], ); diff --git a/src/pages/home/report/SystemChatReportFooterMessage.tsx b/src/pages/home/report/SystemChatReportFooterMessage.tsx index c9ccac8f5c18..1a5729dcb63a 100644 --- a/src/pages/home/report/SystemChatReportFooterMessage.tsx +++ b/src/pages/home/report/SystemChatReportFooterMessage.tsx @@ -36,7 +36,7 @@ function SystemChatReportFooterMessage({choice, policies, activePolicyID}: Syste const adminChatReport = useMemo(() => { const adminPolicy = activePolicyID - ? PolicyUtils.getPolicy(activePolicyID ?? '') + ? PolicyUtils.getPolicy(activePolicyID) : Object.values(policies ?? {}).find((policy) => PolicyUtils.shouldShowPolicy(policy, false) && policy?.role === CONST.POLICY.ROLE.ADMIN && policy?.chatReportIDAdmins); return ReportUtils.getReport(String(adminPolicy?.chatReportIDAdmins)); @@ -86,6 +86,5 @@ export default withOnyx `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : 0}`, - selector: (parentReportActions: OnyxEntry, props: WithOnyxInstanceState): OnyxEntry => { + selector: (parentReportActions: OnyxEntry, props?: WithOnyxState): OnyxEntry => { const parentReportActionID = props?.report?.parentReportActionID; if (!parentReportActionID) { - return null; + return; } - return parentReportActions?.[parentReportActionID] ?? null; + return parentReportActions?.[parentReportActionID]; }, canEvict: false, }, diff --git a/src/pages/iou/request/step/IOURequestStepCategory.tsx b/src/pages/iou/request/step/IOURequestStepCategory.tsx index a38380904851..119b0fd0cc00 100644 --- a/src/pages/iou/request/step/IOURequestStepCategory.tsx +++ b/src/pages/iou/request/step/IOURequestStepCategory.tsx @@ -81,7 +81,7 @@ function IOURequestStepCategory({ const transactionCategory = ReportUtils.getTransactionDetails(isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction : transaction)?.category; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const reportAction = reportActions?.[report?.parentReportActionID || reportActionID] ?? null; + const reportAction = reportActions?.[report?.parentReportActionID || reportActionID]; const shouldShowCategory = (ReportUtils.isReportInGroupPolicy(report) || ReportUtils.isGroupPolicy(policy?.type ?? '')) && From e35b74842a2dbf94c116b56d3dc821714015227c Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 31 May 2024 11:51:29 +0200 Subject: [PATCH 06/46] migrate more files --- .../shouldShowPushNotification.ts | 2 +- src/libs/OptionsListUtils.ts | 26 +++++++++---------- src/libs/TransactionUtils.ts | 2 +- src/libs/actions/User.ts | 2 +- .../KeyReportActionsDraftByReportActionID.ts | 2 +- .../RemoveEmptyReportActionsDrafts.ts | 2 +- .../TransactionBackupsToCollection.ts | 2 +- src/pages/EditReportFieldPage.tsx | 2 +- src/pages/home/HeaderView.tsx | 3 +-- .../BaseReportActionContextMenu.tsx | 4 +-- .../PopoverReportActionContextMenu.tsx | 4 +-- .../ComposerWithSuggestions.tsx | 2 +- src/pages/home/report/ReportActionItem.tsx | 2 +- .../iou/request/step/IOURequestStepDate.tsx | 2 +- src/pages/tasks/NewTaskPage.tsx | 2 +- 15 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index fd6029857ded..8dbc28f035a6 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -24,7 +24,7 @@ export default function shouldShowPushNotification(pushPayload: PushPayload): bo return true; } - const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData(data.onyxData ?? null); + const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData(data.onyxData); const shouldShow = Report.shouldShowReportActionNotification(String(data.reportID), reportAction, true); Log.info(`[PushNotification] ${shouldShow ? 'Showing' : 'Not showing'} notification`); return shouldShow; diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index f321c10c686e..dca681d1552e 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -372,7 +372,7 @@ function getPersonalDetailsForAccountIDs(accountIDs: number[] | undefined, perso if (!cleanAccountID) { return; } - let personalDetail: OnyxEntry = personalDetails[accountID]; + let personalDetail: OnyxEntry = personalDetails[accountID] ?? undefined; if (!personalDetail) { personalDetail = {} as PersonalDetails; } @@ -526,12 +526,12 @@ function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry< {}, ); const parentReportAction: OnyxEntry = - !report?.parentReportID || !report?.parentReportActionID ? null : allReportActions?.[report.parentReportID ?? '']?.[report.parentReportActionID ?? ''] ?? null; + !report?.parentReportID || !report?.parentReportActionID ? undefined : allReportActions?.[report.parentReportID ?? '']?.[report.parentReportActionID ?? '']; if (parentReportAction?.actorAccountID === currentUserAccountID && ReportActionUtils.isTransactionThread(parentReportAction)) { - const transactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction?.originalMessage?.IOUTransactionID : null; + const transactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction?.originalMessage?.IOUTransactionID : undefined; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - if (TransactionUtils.hasMissingSmartscanFields(transaction ?? null) && !ReportUtils.isSettled(transaction?.reportID)) { + if (TransactionUtils.hasMissingSmartscanFields(transaction) && !ReportUtils.isSettled(transaction?.reportID)) { reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage'); } } else if ((ReportUtils.isIOUReport(report) || ReportUtils.isExpenseReport(report)) && report?.ownerAccountID === currentUserAccountID) { @@ -610,7 +610,7 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails } } } else if (ReportActionUtils.isMoneyRequestAction(lastReportAction)) { - const properSchemaForMoneyRequestMessage = ReportUtils.getReportPreviewMessage(report, lastReportAction, true, false, null, true); + const properSchemaForMoneyRequestMessage = ReportUtils.getReportPreviewMessage(report, lastReportAction, true, false, undefined, true); lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForMoneyRequestMessage); } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); @@ -621,11 +621,11 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails ReportActionUtils.isMoneyRequestAction(reportAction), ); const reportPreviewMessage = ReportUtils.getReportPreviewMessage( - !isEmptyObject(iouReport) ? iouReport : null, + !isEmptyObject(iouReport) ? iouReport : undefined, lastIOUMoneyReportAction, true, ReportUtils.isChatReport(report), - null, + undefined, true, lastReportAction, ); @@ -788,7 +788,7 @@ function createOption( // Disabling this line for safeness as nullish coalescing works only if the value is undefined or null // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing result.searchText = getSearchText(report, reportName, personalDetailList, !!result.isChatRoom || !!result.isPolicyExpenseChat, !!result.isThread); - result.icons = ReportUtils.getIcons(report, personalDetails, personalDetail?.avatar, personalDetail?.login, personalDetail?.accountID, null); + result.icons = ReportUtils.getIcons(report, personalDetails, personalDetail?.avatar, personalDetail?.login, personalDetail?.accountID, undefined); result.subtitle = subtitle; return result; @@ -810,7 +810,7 @@ function getReportOption(participant: Participant): ReportUtils.OptionData { const option = createOption( visibleParticipantAccountIDs, allPersonalDetails ?? {}, - !isEmptyObject(report) ? report : null, + !isEmptyObject(report) ? report : undefined, {}, { showChatPreviewLine: false, @@ -838,7 +838,7 @@ function getReportOption(participant: Participant): ReportUtils.OptionData { * Get the option for a policy expense report. */ function getPolicyExpenseReportOption(participant: Participant | ReportUtils.OptionData): ReportUtils.OptionData { - const expenseReport = ReportUtils.isPolicyExpenseChat(participant) ? ReportUtils.getReport(participant.reportID) : null; + const expenseReport = ReportUtils.isPolicyExpenseChat(participant) ? ReportUtils.getReport(participant.reportID) : undefined; const visibleParticipantAccountIDs = Object.entries(expenseReport?.participants ?? {}) .filter(([, reportParticipant]) => reportParticipant && !reportParticipant.hidden) @@ -847,7 +847,7 @@ function getPolicyExpenseReportOption(participant: Participant | ReportUtils.Opt const option = createOption( visibleParticipantAccountIDs, allPersonalDetails ?? {}, - !isEmptyObject(expenseReport) ? expenseReport : null, + !isEmptyObject(expenseReport) ? expenseReport : undefined, {}, { showChatPreviewLine: false, @@ -1640,7 +1640,7 @@ function getUserToInviteOption({ login: searchValue, }, }; - const userToInvite = createOption([optimisticAccountID], personalDetailsExtended, null, reportActions, { + const userToInvite = createOption([optimisticAccountID], personalDetailsExtended, undefined, reportActions, { showChatPreviewLine, }); userToInvite.isOptimisticAccount = true; @@ -1774,7 +1774,7 @@ function getOptions( const {parentReportID, parentReportActionID} = report ?? {}; const canGetParentReport = parentReportID && parentReportActionID && allReportActions; const parentReportActions = allReportActions ? allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`] ?? {} : {}; - const parentReportAction = canGetParentReport ? parentReportActions[parentReportActionID] ?? null : null; + const parentReportAction = canGetParentReport ? parentReportActions[parentReportActionID] : undefined; const doesReportHaveViolations = (betas?.includes(CONST.BETAS.VIOLATIONS) && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction)) ?? false; diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 46d37c54f087..1d2a97fa6345 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -642,7 +642,7 @@ function isOnHoldByTransactionID(transactionID: string): boolean { return false; } - return isOnHold(allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? null); + return isOnHold(allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]); } /** diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index f7e90f775b65..a185edd9f566 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -68,7 +68,7 @@ Onyx.connect({ return; } - myPersonalDetails = value[currentUserAccountID]; + myPersonalDetails = value[currentUserAccountID] ?? undefined; }, }); diff --git a/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts b/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts index 193fdfe5f1eb..02ff54d2fc59 100644 --- a/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts +++ b/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts @@ -32,7 +32,7 @@ export default function () { if (typeof reportActionDraft !== 'string') { return; } - newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = null; + newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = undefined; if (isEmptyObject(reportActionDraft)) { return; diff --git a/src/libs/migrations/RemoveEmptyReportActionsDrafts.ts b/src/libs/migrations/RemoveEmptyReportActionsDrafts.ts index 48493a82d641..24debda2e492 100644 --- a/src/libs/migrations/RemoveEmptyReportActionsDrafts.ts +++ b/src/libs/migrations/RemoveEmptyReportActionsDrafts.ts @@ -54,7 +54,7 @@ export default function (): Promise { if (isEmptyObject(newReportActionsDraftsForReport)) { Log.info('[Migrate Onyx] NO REMAINING'); // Clear if there are no drafts remaining - newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = null; + newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = undefined; } else if (hasUnmigratedDraft) { // Only migrate if there are unmigrated drafts, there's no need to overwrite this onyx key with the same data newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = newReportActionsDraftsForReport; diff --git a/src/libs/migrations/TransactionBackupsToCollection.ts b/src/libs/migrations/TransactionBackupsToCollection.ts index 8b963d7fa0c2..6e823f88acb5 100644 --- a/src/libs/migrations/TransactionBackupsToCollection.ts +++ b/src/libs/migrations/TransactionBackupsToCollection.ts @@ -38,7 +38,7 @@ export default function (): Promise { onyxData[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`] = transaction; // Delete the transaction backup stored in the transaction collection - onyxData[transactionOnyxKey] = null; + onyxData[transactionOnyxKey] = undefined; } }); diff --git a/src/pages/EditReportFieldPage.tsx b/src/pages/EditReportFieldPage.tsx index 6cc93d05ebbc..227e9b316798 100644 --- a/src/pages/EditReportFieldPage.tsx +++ b/src/pages/EditReportFieldPage.tsx @@ -51,7 +51,7 @@ function EditReportFieldPage({route, policy, report}: EditReportFieldPageProps) const styles = useThemeStyles(); const fieldKey = ReportUtils.getReportFieldKey(route.params.fieldID); const reportField = report?.fieldList?.[fieldKey] ?? policy?.fieldList?.[fieldKey]; - const isDisabled = ReportUtils.isReportFieldDisabled(report, reportField ?? null, policy); + const isDisabled = ReportUtils.isReportFieldDisabled(report, reportField, policy); const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false); const {translate} = useLocalize(); diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index b16fb86f9b21..215301981c4e 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -387,8 +387,7 @@ export default memo( withOnyx({ guideCalendarLink: { key: ONYXKEYS.ACCOUNT, - selector: (account) => account?.guideCalendarLink ?? null, - initialValue: null, + selector: (account) => account?.guideCalendarLink, }, parentReport: { key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID ?? report?.reportID}`, diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 46ebdd751762..7cdd79b3b3b9 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -129,9 +129,9 @@ function BaseReportActionContextMenu({ const reportAction: OnyxEntry = useMemo(() => { if (isEmptyObject(reportActions) || reportActionID === '0') { - return null; + return; } - return reportActions[reportActionID] ?? null; + return reportActions[reportActionID]; }, [reportActions, reportActionID]); const shouldEnableArrowNavigation = !isMini && (isVisible || shouldKeepOpen); diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx index 6cb688ff2558..d927c3088e75 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx @@ -34,7 +34,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef(); - const reportActionRef = useRef>(null); + const reportActionRef = useRef>(undefined); const reportActionIDRef = useRef('0'); const originalReportIDRef = useRef('0'); const selectionRef = useRef(''); @@ -131,7 +131,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef { reportActionIDRef.current = '0'; - reportActionRef.current = null; + reportActionRef.current = undefined; }; /** diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 5c203520148d..087f94291974 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -283,7 +283,7 @@ function ComposerWithSuggestions( const {isSmallScreenWidth} = useWindowDimensions(); const maxComposerLines = isSmallScreenWidth ? CONST.COMPOSER.MAX_LINES_SMALL_SCREEN : CONST.COMPOSER.MAX_LINES; - const parentReportAction = parentReportActions?.[parentReportActionID ?? ''] ?? null; + const parentReportAction = parentReportActions?.[parentReportActionID ?? '']; const shouldAutoFocus = !modal?.isVisible && isFocused && (shouldFocusInputOnScreenFocus || (isEmptyChat && !ReportActionsUtils.isTransactionThread(parentReportAction))) && shouldShowComposeInput; diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 4b248bf14131..da2de49e755c 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -1049,7 +1049,7 @@ export default withOnyx({ }, linkedTransactionRouteError: { key: ({action}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${(action as OnyxTypes.OriginalMessageIOU)?.originalMessage?.IOUTransactionID ?? 0}`, - selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? null, + selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? undefined, }, })( memo(ReportActionItem, (prevProps, nextProps) => { diff --git a/src/pages/iou/request/step/IOURequestStepDate.tsx b/src/pages/iou/request/step/IOURequestStepDate.tsx index 3a221b9a56db..d054dad5c11d 100644 --- a/src/pages/iou/request/step/IOURequestStepDate.tsx +++ b/src/pages/iou/request/step/IOURequestStepDate.tsx @@ -74,7 +74,7 @@ function IOURequestStepDate({ const parentReportAction = reportActions?.[(isEditingSplitBill ? reportActionID : report?.parentReportActionID) ?? 0]; const canEditingSplitBill = isEditingSplitBill && session && parentReportAction && session.accountID === parentReportAction.actorAccountID && TransactionUtils.areRequiredFieldsEmpty(transaction); - const canEditMoneyRequest = isEditing && ReportUtils.canEditFieldOfMoneyRequest(parentReportAction ?? null, CONST.EDIT_REQUEST_FIELD.DATE); + const canEditMoneyRequest = isEditing && ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DATE); // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFound = !IOUUtils.isValidMoneyRequestType(iouType) || (isEditing && !canEditMoneyRequest && !canEditingSplitBill); diff --git a/src/pages/tasks/NewTaskPage.tsx b/src/pages/tasks/NewTaskPage.tsx index 5eb55b68417c..cc02caf2156d 100644 --- a/src/pages/tasks/NewTaskPage.tsx +++ b/src/pages/tasks/NewTaskPage.tsx @@ -52,7 +52,7 @@ function NewTaskPage({task, reports, personalDetails}: NewTaskPageProps) { const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); const [errorMessage, setErrorMessage] = useState(''); - const [parentReport, setParentReport] = useState>(null); + const [parentReport, setParentReport] = useState>(); const hasDestinationError = task?.skipConfirmation && !task?.parentReportID; const isAllowedToCreateTask = useMemo(() => isEmptyObject(parentReport) || ReportUtils.isAllowedToComment(parentReport), [parentReport]); From cfb7b2de4405e10fad0ab3a8393afe3cf391a453 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 31 May 2024 12:08:24 +0200 Subject: [PATCH 07/46] migrate more files --- src/libs/ReportUtils.ts | 20 +-- src/libs/actions/IOU.ts | 124 +++++++++--------- src/libs/actions/PersonalDetails.ts | 2 +- src/libs/actions/Policy/Policy.ts | 8 +- .../actions/ReimbursementAccount/store.ts | 2 +- src/libs/actions/Task.ts | 12 +- src/libs/migrations/PronounsMigration.ts | 2 +- src/pages/FlagCommentPage.tsx | 4 +- 8 files changed, 83 insertions(+), 91 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 31661f6bc186..d3dbfc4ec0cf 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -674,7 +674,7 @@ function getPolicyType(report: OnyxEntry, policies: OnyxCollection | undefined | EmptyObject, returnEmptyIfNotFound = false, policy: OnyxEntry = undefined): string { +function getPolicyName(report: OnyxEntry | undefined | EmptyObject, returnEmptyIfNotFound = false, policy?: OnyxEntry): string { const noPolicyFound = returnEmptyIfNotFound ? '' : Localize.translateLocal('workspace.common.unavailable'); if (isEmptyObject(report)) { return noPolicyFound; @@ -1925,7 +1925,7 @@ function getIcons( defaultIcon: AvatarSource | null = null, defaultName = '', defaultAccountID = -1, - policy: OnyxEntry = undefined, + policy?: OnyxEntry, ): Icon[] { if (isEmptyObject(report)) { const fallbackIcon: Icon = { @@ -2361,7 +2361,7 @@ function getMoneyRequestSpendBreakdown(report: OnyxEntry, allReportsDict /** * Get the title for a policy expense chat which depends on the role of the policy member seeing this report */ -function getPolicyExpenseChatName(report: OnyxEntry, policy: OnyxEntry | undefined = undefined): string | undefined { +function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry): string | undefined { const ownerAccountID = report?.ownerAccountID; const personalDetails = allPersonalDetails?.[ownerAccountID ?? -1]; const login = personalDetails ? personalDetails.login : null; @@ -2503,7 +2503,7 @@ function getAvailableReportFields(report: Report, policyReportFields: PolicyRepo /** * Get the title for an IOU or expense chat which will be showing the payer and the amount */ -function getMoneyRequestReportName(report: OnyxEntry, policy: OnyxEntry | undefined = undefined): string { +function getMoneyRequestReportName(report: OnyxEntry, policy?: OnyxEntry): string { const isReportSettled = isSettled(report?.reportID ?? ''); const reportFields = isReportSettled ? report?.fieldList : getReportFieldsByPolicyID(report?.policyID ?? ''); const titleReportField = getFormulaTypeReportField(reportFields ?? {}); @@ -2822,7 +2822,7 @@ function getReportPreviewMessage( iouReportAction: OnyxEntry | EmptyObject = {}, shouldConsiderScanningReceiptOrPendingRoute = false, isPreviewMessageForParentChatReport = false, - policy: OnyxEntry = undefined, + policy?: OnyxEntry, isForListPreview = false, originalReportAction: OnyxEntry | EmptyObject = iouReportAction, ): string { @@ -4126,7 +4126,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, * @param [comment] - User comment for the IOU. * @param [transaction] - optimistic first transaction of preview */ -function buildOptimisticReportPreview(chatReport: OnyxEntry, iouReport: Report, comment = '', transaction: OnyxEntry = undefined, childReportID?: string): ReportAction { +function buildOptimisticReportPreview(chatReport: OnyxEntry, iouReport: Report, comment = '', transaction?: OnyxEntry, childReportID?: string): ReportAction { const hasReceipt = TransactionUtils.hasReceipt(transaction); const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction); const message = getReportPreviewMessage(iouReport); @@ -4289,7 +4289,7 @@ function updateReportPreview( reportPreviewAction: ReportPreviewAction, isPayRequest = false, comment = '', - transaction: OnyxEntry = undefined, + transaction?: OnyxEntry, ): ReportPreviewAction { const hasReceipt = TransactionUtils.hasReceipt(transaction); const recentReceiptTransactions = reportPreviewAction?.childRecentReceiptTransactionIDs ?? {}; @@ -4380,13 +4380,13 @@ function buildOptimisticTaskReportAction( function buildOptimisticChatReport( participantList: number[], reportName: string = CONST.REPORT.DEFAULT_REPORT_NAME, - chatType: ValueOf | undefined = undefined, + chatType?: ValueOf, policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE, ownerAccountID: number = CONST.REPORT.OWNER_ACCOUNT_ID_FAKE, isOwnPolicyExpenseChat = false, oldPolicyName = '', - visibility: ValueOf | undefined = undefined, - writeCapability: ValueOf | undefined = undefined, + visibility?: ValueOf, + writeCapability?: ValueOf, notificationPreference: NotificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, parentReportActionID = '', parentReportID = '', diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 8df04497f5e8..bf735e03c5eb 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -165,7 +165,7 @@ Onyx.connect({ }, }); -let allReports: OnyxCollection = null; +let allReports: OnyxCollection; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, waitForCollectionCallback: true, @@ -291,10 +291,8 @@ function getReportPreviewAction(chatReportID: string, iouReportID: string): Onyx const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`] ?? {}; // Find the report preview action from the chat report - return ( - Object.values(reportActions).find( - (reportAction) => reportAction && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && reportAction.originalMessage.linkedReportID === iouReportID, - ) ?? null + return Object.values(reportActions).find( + (reportAction) => reportAction && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && reportAction.originalMessage.linkedReportID === iouReportID, ); } @@ -1886,11 +1884,11 @@ function getMoneyRequestInformation( // STEP 2: Get the Expense/IOU report. If the moneyRequestReportID has been provided, we want to add the transaction to this specific report. // If no such reportID has been provided, let's use the chatReport.iouReportID property. In case that is not present, build a new optimistic Expense/IOU report. - let iouReport: OnyxEntry = null; + let iouReport: OnyxEntry; if (moneyRequestReportID) { - iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null; + iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`]; } else { - iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null; + iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`]; } const shouldCreateNewMoneyRequestReport = ReportUtils.shouldCreateNewMoneyRequestReport(iouReport, chatReport); @@ -2112,14 +2110,14 @@ function getTrackExpenseInformation( // For this, first use the chatReport.iouReportID property. Build a new optimistic expense report if needed. const shouldUseMoneyReport = !!isPolicyExpenseChat; - let iouReport: OnyxEntry = null; + let iouReport: OnyxEntry; let shouldCreateNewMoneyRequestReport = false; if (shouldUseMoneyReport) { if (moneyRequestReportID) { - iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null; + iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`]; } else { - iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null; + iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`]; } shouldCreateNewMoneyRequestReport = ReportUtils.shouldCreateNewMoneyRequestReport(iouReport, chatReport); @@ -2202,9 +2200,9 @@ function getTrackExpenseInformation( linkedTrackedExpenseReportAction, ); - let reportPreviewAction: OnyxEntry = null; + let reportPreviewAction: OnyxEntry; if (shouldUseMoneyReport && iouReport) { - reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID); + reportPreviewAction = shouldCreateNewMoneyRequestReport ? undefined : getReportPreviewAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, false, comment, optimisticTransaction); @@ -2216,7 +2214,7 @@ function getTrackExpenseInformation( } } - let actionableTrackExpenseWhisper: OnyxEntry = null; + let actionableTrackExpenseWhisper: OnyxEntry; if (!isPolicyExpenseChat) { actionableTrackExpenseWhisper = ReportUtils.buildOptimisticActionableTrackExpenseWhisper(iouAction, optimisticTransaction.transactionID); } @@ -2440,12 +2438,12 @@ function getUpdateMoneyRequestParams( const errorFields = Object.fromEntries(Object.keys(pendingFields).map((key) => [key, {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}])); // Step 2: Get all the collections being updated - const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; + const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`] ?? null; + const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`]; const isFromExpenseReport = ReportUtils.isExpenseReport(iouReport); const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); - let updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : null; + let updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : undefined; const transactionDetails = ReportUtils.getTransactionDetails(updatedTransaction); if (transactionDetails?.waypoints) { @@ -2688,7 +2686,7 @@ function getUpdateMoneyRequestParams( failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, - value: transactionThread, + value: transactionThread ?? null, }); return { @@ -2725,11 +2723,11 @@ function getUpdateTrackExpenseParams( const errorFields = Object.fromEntries(Object.keys(pendingFields).map((key) => [key, {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}])); // Step 2: Get all the collections being updated - const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; + const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`] ?? null; + const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`]; const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); - let updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, false) : null; + let updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, false) : undefined; const transactionDetails = ReportUtils.getTransactionDetails(updatedTransaction); if (transactionDetails?.waypoints) { @@ -2869,7 +2867,7 @@ function getUpdateTrackExpenseParams( failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, - value: transactionThread, + value: transactionThread ?? null, }); return { @@ -2890,8 +2888,8 @@ function updateMoneyRequestDate( const transactionChanges: TransactionChanges = { created: value, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); @@ -2930,8 +2928,8 @@ function updateMoneyRequestMerchant( const transactionChanges: TransactionChanges = { merchant: value, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); @@ -3018,8 +3016,8 @@ function updateMoneyRequestDistance({ waypoints, routes, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); @@ -3058,8 +3056,8 @@ function updateMoneyRequestDescription( const transactionChanges: TransactionChanges = { comment, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); @@ -4020,7 +4018,7 @@ function createSplitsAndOnyxData( } // STEP 2: Get existing IOU/Expense report and update its total OR build a new optimistic one - let oneOnOneIOUReport: OneOnOneIOUReport = oneOnOneChatReport.iouReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneOnOneChatReport.iouReportID}`] : null; + let oneOnOneIOUReport: OneOnOneIOUReport = oneOnOneChatReport.iouReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneOnOneChatReport.iouReportID}`] : undefined; const shouldCreateNewOneOnOneIOUReport = ReportUtils.shouldCreateNewMoneyRequestReport(oneOnOneIOUReport, oneOnOneChatReport); if (!oneOnOneIOUReport || shouldCreateNewOneOnOneIOUReport) { @@ -4122,10 +4120,10 @@ function createSplitsAndOnyxData( optimisticTransactionThread, optimisticCreatedActionForTransactionThread, shouldCreateNewOneOnOneIOUReport, - null, - null, - null, - null, + undefined, + undefined, + undefined, + undefined, true, ); @@ -4729,18 +4727,18 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA } } - let oneOnOneChatReport: OnyxTypes.Report | null; + let oneOnOneChatReport: OnyxTypes.Report | undefined; let isNewOneOnOneChatReport = false; if (isPolicyExpenseChat) { // The workspace chat reportID is saved in the splits array when starting a split expense with a workspace - oneOnOneChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.chatReportID}`] ?? null; + oneOnOneChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.chatReportID}`]; } else { const existingChatReport = ReportUtils.getChatByParticipants(participant.accountID ? [participant.accountID, sessionAccountID] : []); isNewOneOnOneChatReport = !existingChatReport; oneOnOneChatReport = existingChatReport ?? ReportUtils.buildOptimisticChatReport(participant.accountID ? [participant.accountID, sessionAccountID] : []); } - let oneOnOneIOUReport: OneOnOneIOUReport = oneOnOneChatReport?.iouReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneOnOneChatReport.iouReportID}`] : null; + let oneOnOneIOUReport: OneOnOneIOUReport = oneOnOneChatReport?.iouReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneOnOneChatReport.iouReportID}`] : undefined; const shouldCreateNewOneOnOneIOUReport = ReportUtils.shouldCreateNewMoneyRequestReport(oneOnOneIOUReport, oneOnOneChatReport); if (!oneOnOneIOUReport || shouldCreateNewOneOnOneIOUReport) { @@ -4810,10 +4808,10 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA optimisticTransactionThread, optimisticCreatedActionForTransactionThread, shouldCreateNewOneOnOneIOUReport, - null, - null, - null, - null, + undefined, + undefined, + undefined, + undefined, true, ); @@ -4885,15 +4883,15 @@ function editRegularMoneyRequest( policyCategories: OnyxTypes.PolicyCategories, ) { // STEP 1: Get all collections we're updating - const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; + const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`] ?? null; - const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`] ?? null; + const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`]; + const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`]; const isFromExpenseReport = ReportUtils.isExpenseReport(iouReport); // STEP 2: Build new modified expense report action. const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, isFromExpenseReport, policy); - const updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : null; + const updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : undefined; // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct // Should only update if the transaction matches the currency of the report, else we wait for the update @@ -4950,7 +4948,7 @@ function editRegularMoneyRequest( { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, - value: updatedTransaction, + value: updatedTransaction ?? null, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -5088,7 +5086,7 @@ function editRegularMoneyRequest( { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`, - value: chatReport, + value: chatReport ?? null, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -5183,13 +5181,13 @@ function updateMoneyRequestAmountAndCurrency({ taxCode, taxAmount, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { - data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy ?? null); + data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); } else { - data = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, policy ?? null, policyTagList ?? null, policyCategories ?? null, true); + data = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, policy, policyTagList, policyCategories, true); } const {params, onyxData} = data; API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_AMOUNT_AND_CURRENCY, params, onyxData); @@ -5198,15 +5196,15 @@ function updateMoneyRequestAmountAndCurrency({ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.ReportAction, isSingleTransactionView = false) { // STEP 1: Get all collections we're updating const iouReportID = reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? reportAction.originalMessage.IOUReportID : ''; - const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`] ?? null; + const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`]; const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`]; const reportPreviewAction = getReportPreviewAction(iouReport?.chatReportID ?? '', iouReport?.reportID ?? ''); const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; const transactionThreadID = reportAction.childReportID; - let transactionThread = null; + let transactionThread; if (transactionThreadID) { - transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`] ?? null; + transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`]; } // STEP 2: Decide if we need to: @@ -5242,7 +5240,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor iouReportLastMessageText.length === 0 && !ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && (!transactionThreadID || shouldDeleteTransactionThread); // STEP 4: Update the iouReport and reportPreview with new totals and messages if it wasn't deleted - let updatedIOUReport: OnyxTypes.Report | null; + let updatedIOUReport: OnyxTypes.Report | undefined; const currency = TransactionUtils.getCurrency(transaction); const updatedReportPreviewAction: OnyxTypes.ReportAction | EmptyObject = {...reportPreviewAction}; updatedReportPreviewAction.pendingAction = shouldDeleteIOUReport ? CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE : CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE; @@ -5323,7 +5321,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`, - value: updatedIOUReport, + value: updatedIOUReport ?? null, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -5356,8 +5354,8 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor value: { hasOutstandingChildRequest: false, iouReportID: null, - lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport?.chatReportID ?? '', {[reportPreviewAction?.reportActionID ?? '']: null})?.lastMessageText, - lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(iouReport?.chatReportID ?? '', {[reportPreviewAction?.reportActionID ?? '']: null})?.created, + lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport?.chatReportID ?? '', {[reportPreviewAction?.reportActionID ?? '']: undefined})?.lastMessageText, + lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(iouReport?.chatReportID ?? '', {[reportPreviewAction?.reportActionID ?? '']: undefined})?.created, }, }); } @@ -5414,7 +5412,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor failureData.push({ onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`, - value: transactionThread, + value: transactionThread ?? null, }); } @@ -5438,12 +5436,12 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor ? { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`, - value: iouReport, + value: iouReport ?? null, } : { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`, - value: iouReport, + value: iouReport ?? null, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -5502,7 +5500,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor function deleteTrackExpense(chatReportID: string, transactionID: string, reportAction: OnyxTypes.ReportAction, isSingleTransactionView = false) { // STEP 1: Get all collections we're updating - const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`] ?? null; + const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]; if (!ReportUtils.isSelfDM(chatReport)) { return deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView); } diff --git a/src/libs/actions/PersonalDetails.ts b/src/libs/actions/PersonalDetails.ts index b9cea5c9447c..daeb4ad58802 100644 --- a/src/libs/actions/PersonalDetails.ts +++ b/src/libs/actions/PersonalDetails.ts @@ -37,7 +37,7 @@ Onyx.connect({ }, }); -let allPersonalDetails: OnyxEntry = null; +let allPersonalDetails: OnyxEntry; Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, callback: (val) => (allPersonalDetails = val), diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 72b76fb78f96..44e9a216a205 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -161,14 +161,14 @@ Onyx.connect({ }, }); -let allReports: OnyxCollection = null; +let allReports: OnyxCollection; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, waitForCollectionCallback: true, callback: (value) => (allReports = value), }); -let lastAccessedWorkspacePolicyID: OnyxEntry = null; +let lastAccessedWorkspacePolicyID: OnyxEntry; Onyx.connect({ key: ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID, callback: (value) => (lastAccessedWorkspacePolicyID = value), @@ -383,7 +383,7 @@ function deleteWorkspace(policyID: string, policyName: string) { // Reset the lastAccessedWorkspacePolicyID if (policyID === lastAccessedWorkspacePolicyID) { - updateLastAccessedWorkspace(null); + updateLastAccessedWorkspace(undefined); } } @@ -809,7 +809,7 @@ function removeMembers(accountIDs: number[], policyID: string) { const failureMembersState: OnyxCollection = {}; emailList.forEach((email) => { optimisticMembersState[email] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}; - successMembersState[email] = null; + successMembersState[email] = undefined; failureMembersState[email] = {errors: ErrorUtils.getMicroSecondOnyxError('workspace.people.error.genericRemove')}; }); diff --git a/src/libs/actions/ReimbursementAccount/store.ts b/src/libs/actions/ReimbursementAccount/store.ts index c82843020f66..644fcbdf4def 100644 --- a/src/libs/actions/ReimbursementAccount/store.ts +++ b/src/libs/actions/ReimbursementAccount/store.ts @@ -4,7 +4,7 @@ import BankAccount from '@libs/models/BankAccount'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; -let bankAccountList: OnyxEntry = null; +let bankAccountList: OnyxEntry; Onyx.connect({ key: ONYXKEYS.BANK_ACCOUNT_LIST, callback: (val) => { diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 55d898d3d4f3..32cc2aee1892 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -117,7 +117,7 @@ function createTaskAndNavigate( description: string, assigneeEmail: string, assigneeAccountID = 0, - assigneeChatReport: OnyxEntry = null, + assigneeChatReport?: OnyxEntry, policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE, ) { const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserAccountID, assigneeAccountID, parentReportID, title, description, policyID); @@ -508,13 +508,7 @@ function editTask(report: OnyxTypes.Report, {title, description}: OnyxTypes.Task Report.notifyNewAction(report.reportID, currentUserAccountID); } -function editTaskAssignee( - report: OnyxTypes.Report, - ownerAccountID: number, - assigneeEmail: string, - assigneeAccountID: number | null = 0, - assigneeChatReport: OnyxEntry = null, -) { +function editTaskAssignee(report: OnyxTypes.Report, ownerAccountID: number, assigneeEmail: string, assigneeAccountID: number | null = 0, assigneeChatReport?: OnyxEntry) { // Create the EditedReportAction on the task const editTaskReportAction = ReportUtils.buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID ?? 0); const reportName = report.reportName?.trim(); @@ -770,7 +764,7 @@ function getAssignee(assigneeAccountID: number, personalDetails: OnyxEntry, personalDetails: OnyxEntry): ShareDestination { - const report = reports?.[`report_${reportID}`] ?? null; + const report = reports?.[`report_${reportID}`]; const isOneOnOneChat = ReportUtils.isOneOnOneChat(report); diff --git a/src/libs/migrations/PronounsMigration.ts b/src/libs/migrations/PronounsMigration.ts index 5fe911ae7f98..cf9ffbed4ffb 100644 --- a/src/libs/migrations/PronounsMigration.ts +++ b/src/libs/migrations/PronounsMigration.ts @@ -23,7 +23,7 @@ function getCurrentUserPersonalDetailsFromOnyx(currentUserAccountID: number): Pr key: ONYXKEYS.PERSONAL_DETAILS_LIST, callback: (val) => { Onyx.disconnect(connectionID); - return resolve(val?.[currentUserAccountID] ?? null); + return resolve(val?.[currentUserAccountID] ?? undefined); }, }); }); diff --git a/src/pages/FlagCommentPage.tsx b/src/pages/FlagCommentPage.tsx index 53aac0ce2a8b..39e97924c53d 100644 --- a/src/pages/FlagCommentPage.tsx +++ b/src/pages/FlagCommentPage.tsx @@ -109,7 +109,7 @@ function FlagCommentPage({parentReportAction, route, report, parentReport, repor }, ]; - const getActionToFlag = useCallback((): OnyxTypes.ReportAction | null => { + const getActionToFlag = useCallback((): OnyxTypes.ReportAction | undefined => { let reportAction = reportActions?.[`${route.params.reportActionID.toString()}`]; // Handle threads if needed @@ -118,7 +118,7 @@ function FlagCommentPage({parentReportAction, route, report, parentReport, repor } if (!reportAction) { - return null; + return; } return reportAction; From 0778946f6a84127baf59e0e06411c4de6d9e40ef Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 31 May 2024 12:12:11 +0200 Subject: [PATCH 08/46] fix: migrate more files --- src/components/HeaderWithBackButton/index.tsx | 2 +- src/components/KYCWall/BaseKYCWall.tsx | 2 +- src/components/LHNOptionsList/LHNOptionsList.tsx | 12 ++++++------ src/components/LHNOptionsList/OptionRowLHN.tsx | 2 +- src/components/LHNOptionsList/OptionRowLHNData.tsx | 2 +- src/components/ReportActionItem/MoneyRequestView.tsx | 2 +- src/components/ShowContextMenuContext.ts | 8 ++++---- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/components/HeaderWithBackButton/index.tsx b/src/components/HeaderWithBackButton/index.tsx index 78cd92dbc223..b9bf479ab21d 100755 --- a/src/components/HeaderWithBackButton/index.tsx +++ b/src/components/HeaderWithBackButton/index.tsx @@ -30,7 +30,7 @@ function HeaderWithBackButton({ onCloseButtonPress = () => Navigation.dismissModal(), onDownloadButtonPress = () => {}, onThreeDotsButtonPress = () => {}, - report = null, + report, policy, policyAvatar, shouldShowReportAvatarWithDisplay = false, diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index 8c4a131284c8..818b4aff6b00 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -166,7 +166,7 @@ function KYCWall({ transferBalanceButtonRef.current = targetElement; - const isExpenseReport = ReportUtils.isExpenseReport(iouReport ?? null); + const isExpenseReport = ReportUtils.isExpenseReport(iouReport); const paymentCardList = fundList ?? {}; // Check to see if user has a valid payment method on file and display the add payment popover if they don't diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index 6405e3026b1a..80fca673a346 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -106,13 +106,13 @@ function LHNOptionsList({ */ const renderItem = useCallback( ({item: reportID}: RenderItemProps): ReactElement => { - const itemFullReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? null; - const itemReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? null; - const itemParentReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport?.parentReportID}`] ?? null; - const itemParentReportAction = itemParentReportActions?.[itemFullReport?.parentReportActionID ?? ''] ?? null; - const itemPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport?.policyID}`] ?? null; + const itemFullReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const itemReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; + const itemParentReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport?.parentReportID}`]; + const itemParentReportAction = itemParentReportActions?.[itemFullReport?.parentReportActionID ?? '']; + const itemPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport?.policyID}`]; const transactionID = itemParentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? itemParentReportAction.originalMessage.IOUTransactionID ?? '' : ''; - const itemTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? null; + const itemTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; const hasDraftComment = DraftCommentUtils.isValidDraftComment(draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`]); const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(itemReportActions); const lastReportAction = sortedReportActions[0]; diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index 52d2d0890baf..f0a8653b8d4a 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -123,7 +123,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti const formattedDate = DateUtils.getStatusUntilDate(statusClearAfterDate); const statusContent = formattedDate ? `${statusText ? `${statusText} ` : ''}(${formattedDate})` : statusText; const report = ReportUtils.getReport(optionItem.reportID ?? ''); - const isStatusVisible = !!emojiCode && ReportUtils.isOneOnOneChat(!isEmptyObject(report) ? report : null); + const isStatusVisible = !!emojiCode && ReportUtils.isOneOnOneChat(!isEmptyObject(report) ? report : undefined); const isGroupChat = ReportUtils.isGroupChat(optionItem) || ReportUtils.isDeprecatedGroupDM(optionItem); diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index c80017c39a3d..a2dd41eab0bd 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHNData.tsx @@ -35,7 +35,7 @@ function OptionRowLHNData({ const optionItemRef = useRef(); - const shouldDisplayViolations = canUseViolations && ReportUtils.shouldDisplayTransactionThreadViolations(fullReport, transactionViolations, parentReportAction ?? null); + const shouldDisplayViolations = canUseViolations && ReportUtils.shouldDisplayTransactionThreadViolations(fullReport, transactionViolations, parentReportAction); const optionItem = useMemo(() => { // Note: ideally we'd have this as a dependent selector in onyx! diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index f01fb049e943..c4a538cf68f1 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -98,7 +98,7 @@ function MoneyRequestView({ const session = useSession(); const {isOffline} = useNetwork(); const {translate, toLocaleDigit} = useLocalize(); - const parentReportAction = parentReportActions?.[report.parentReportActionID ?? ''] ?? null; + const parentReportAction = parentReportActions?.[report.parentReportActionID ?? '']; const isTrackExpense = ReportUtils.isTrackExpenseReport(report); const {canUseViolations, canUseP2PDistanceRequests} = usePermissions(isTrackExpense ? CONST.IOU.TYPE.TRACK : undefined); const moneyRequestReport = parentReport; diff --git a/src/components/ShowContextMenuContext.ts b/src/components/ShowContextMenuContext.ts index 3a996a8d2c64..ebd6f65e3aa0 100644 --- a/src/components/ShowContextMenuContext.ts +++ b/src/components/ShowContextMenuContext.ts @@ -18,10 +18,10 @@ type ShowContextMenuContextProps = { }; const ShowContextMenuContext = createContext({ - anchor: null, - report: null, - action: null, - transactionThreadReport: null, + anchor: undefined, + report: undefined, + action: undefined, + transactionThreadReport: undefined, checkIfContextMenuActive: () => {}, }); From 8c5ff84b230b97404923969675b7dda7568084a6 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 31 May 2024 13:17:29 +0200 Subject: [PATCH 09/46] fix: tests --- .../migrations/KeyReportActionsDraftByReportActionID.ts | 6 +++--- tests/unit/NetworkTest.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts b/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts index 02ff54d2fc59..5783d3f92953 100644 --- a/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts +++ b/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts @@ -1,4 +1,4 @@ -import type {OnyxEntry} from 'react-native-onyx'; +import type {OnyxInput} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import Log from '@libs/Log'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -27,12 +27,12 @@ export default function () { return resolve(); } - const newReportActionsDrafts: Record> = {}; + const newReportActionsDrafts: Record> = {}; Object.entries(allReportActionsDrafts).forEach(([onyxKey, reportActionDraft]) => { if (typeof reportActionDraft !== 'string') { return; } - newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = undefined; + newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = null; if (isEmptyObject(reportActionDraft)) { return; diff --git a/tests/unit/NetworkTest.ts b/tests/unit/NetworkTest.ts index 9c48de96d1a2..081b899c38ba 100644 --- a/tests/unit/NetworkTest.ts +++ b/tests/unit/NetworkTest.ts @@ -64,7 +64,7 @@ describe('NetworkTests', () => { // Given a test user login and account ID return TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN).then(() => { - expect(isOffline).toBe(null); + expect(isOffline).toBe(undefined); // Mock fetch() so that it throws a TypeError to simulate a bad network connection global.fetch = jest.fn().mockRejectedValue(new TypeError(CONST.ERROR.FAILED_TO_FETCH)); From 2bd8bdf481902606de99c91f6c7ab0b27adaa142 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 31 May 2024 17:04:05 +0200 Subject: [PATCH 10/46] update to onyx 2.0.44 --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index c87b206ecef8..fddd3f6021be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -102,7 +102,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "2.0.43", + "react-native-onyx": "2.0.44", "react-native-pager-view": "6.2.3", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", @@ -31466,9 +31466,9 @@ } }, "node_modules/react-native-onyx": { - "version": "2.0.43", - "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.43.tgz", - "integrity": "sha512-V6YLDfxAxP1wbVN0TAmHiTe+jfOjDevxYc0XHq3fSchpUNGDNG03sKN6OmsJM1rXRPODCOPyHrTUFjrwr+m7tg==", + "version": "2.0.44", + "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.44.tgz", + "integrity": "sha512-AomPlr/UwVTx7qzG30QhhkhxlWkhlPzpjh6r9gdMrBoPO0uLJChIDclXouGc62bI9q3MmvOJ+uXw1erctPLMHA==", "dependencies": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", diff --git a/package.json b/package.json index 0ea3f8adf37f..a4a3dc81e305 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "2.0.43", + "react-native-onyx": "2.0.44", "react-native-pager-view": "6.2.3", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", From 1d4e46290c707bd10244e333d57a029e006b381b Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Tue, 4 Jun 2024 17:42:15 +0200 Subject: [PATCH 11/46] fix: Onyx.connect callback types --- src/libs/API/parameters/BeginAppleSignInParams.ts | 4 ++-- src/libs/API/parameters/BeginGoogleSignInParams.ts | 4 ++-- src/libs/API/parameters/SignInUserParams.ts | 2 +- src/libs/API/parameters/SignInUserWithLinkParams.ts | 2 +- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 2 +- src/libs/Network/NetworkStore.ts | 4 ++-- src/libs/actions/App.ts | 10 +++++----- src/libs/actions/Device/index.ts | 4 ++-- src/libs/actions/MapboxToken.ts | 8 ++++---- src/libs/actions/OnyxUpdates.ts | 4 ++-- src/libs/actions/PriorityMode.ts | 6 +++--- src/libs/actions/PushNotification.ts | 4 ++-- .../ReimbursementAccount/resetFreePlanBankAccount.ts | 1 - src/libs/actions/Session/index.ts | 6 +++--- src/libs/actions/TransactionEdit.ts | 2 +- src/libs/actions/Welcome.ts | 2 +- .../KeyReportActionsDraftByReportActionID.ts | 4 ++-- src/libs/migrations/NVPMigration.ts | 2 +- src/types/utils/CollectionDataSet.ts | 6 +++--- tests/unit/MigrationTest.ts | 10 +++++----- 20 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/libs/API/parameters/BeginAppleSignInParams.ts b/src/libs/API/parameters/BeginAppleSignInParams.ts index c427d99fcef9..be8fc72ad052 100644 --- a/src/libs/API/parameters/BeginAppleSignInParams.ts +++ b/src/libs/API/parameters/BeginAppleSignInParams.ts @@ -2,8 +2,8 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; type BeginAppleSignInParams = { - idToken: string | undefined | null; - preferredLocale: ValueOf | null; + idToken: string | undefined; + preferredLocale: ValueOf | undefined; }; export default BeginAppleSignInParams; diff --git a/src/libs/API/parameters/BeginGoogleSignInParams.ts b/src/libs/API/parameters/BeginGoogleSignInParams.ts index fae84d76b0d9..c2c7dd252bba 100644 --- a/src/libs/API/parameters/BeginGoogleSignInParams.ts +++ b/src/libs/API/parameters/BeginGoogleSignInParams.ts @@ -2,8 +2,8 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; type BeginGoogleSignInParams = { - token: string | null; - preferredLocale: ValueOf | null; + token: string | undefined; + preferredLocale: ValueOf | undefined; }; export default BeginGoogleSignInParams; diff --git a/src/libs/API/parameters/SignInUserParams.ts b/src/libs/API/parameters/SignInUserParams.ts index 9fe973c42862..5484ab0e2098 100644 --- a/src/libs/API/parameters/SignInUserParams.ts +++ b/src/libs/API/parameters/SignInUserParams.ts @@ -4,7 +4,7 @@ import type CONST from '@src/CONST'; type SignInUserParams = { twoFactorAuthCode?: string; email?: string; - preferredLocale: ValueOf | null; + preferredLocale?: ValueOf; validateCode?: string; deviceInfo: string; }; diff --git a/src/libs/API/parameters/SignInUserWithLinkParams.ts b/src/libs/API/parameters/SignInUserWithLinkParams.ts index ae3589d4e305..51294aec3e31 100644 --- a/src/libs/API/parameters/SignInUserWithLinkParams.ts +++ b/src/libs/API/parameters/SignInUserWithLinkParams.ts @@ -5,7 +5,7 @@ type SignInUserWithLinkParams = { accountID: number; validateCode?: string; twoFactorAuthCode?: string; - preferredLocale: ValueOf | null; + preferredLocale?: ValueOf; deviceInfo: string; }; diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index a160b6765f87..410caf77e3c4 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -127,7 +127,7 @@ Onyx.connect({ Onyx.connect({ key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, - callback: (value: OnyxEntry) => { + callback: (value) => { lastUpdateIDAppliedToClient = value; }, }); diff --git a/src/libs/Network/NetworkStore.ts b/src/libs/Network/NetworkStore.ts index 086beddc970e..62229ef6c345 100644 --- a/src/libs/Network/NetworkStore.ts +++ b/src/libs/Network/NetworkStore.ts @@ -5,7 +5,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type Credentials from '@src/types/onyx/Credentials'; -let credentials: Credentials | null = null; +let credentials: Credentials | undefined; let authToken: string | null = null; let authTokenType: ValueOf | null; let currentUserEmail: string | null = null; @@ -85,7 +85,7 @@ Onyx.connect({ }, }); -function getCredentials(): Credentials | null { +function getCredentials(): Credentials | undefined { return credentials; } diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index bc6ee1f592e5..7f610c31fc89 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -44,24 +44,24 @@ type PolicyParamsForOpenOrReconnect = { type Locale = ValueOf; -let currentUserAccountID: number | null; +let currentUserAccountID: number | undefined; let currentUserEmail: string; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (val) => { - currentUserAccountID = val?.accountID ?? null; + currentUserAccountID = val?.accountID; currentUserEmail = val?.email ?? ''; }, }); -let isSidebarLoaded: boolean | null; +let isSidebarLoaded: boolean | undefined; Onyx.connect({ key: ONYXKEYS.IS_SIDEBAR_LOADED, callback: (val) => (isSidebarLoaded = val), initWithStoredValues: false, }); -let preferredLocale: string | null = null; +let preferredLocale: string | undefined; Onyx.connect({ key: ONYXKEYS.NVP_PREFERRED_LOCALE, callback: (val) => { @@ -74,7 +74,7 @@ Onyx.connect({ }, }); -let priorityMode: ValueOf | null; +let priorityMode: ValueOf | undefined; Onyx.connect({ key: ONYXKEYS.NVP_PRIORITY_MODE, callback: (nextPriorityMode) => { diff --git a/src/libs/actions/Device/index.ts b/src/libs/actions/Device/index.ts index ed700c06a97f..8ebd83164381 100644 --- a/src/libs/actions/Device/index.ts +++ b/src/libs/actions/Device/index.ts @@ -4,12 +4,12 @@ import ONYXKEYS from '@src/ONYXKEYS'; import generateDeviceID from './generateDeviceID'; import getDeviceInfo from './getDeviceInfo'; -let deviceID: string | null = null; +let deviceID: string | undefined; /** * @returns - device ID string or null in case of failure */ -function getDeviceID(): Promise { +function getDeviceID(): Promise { return new Promise((resolve) => { if (deviceID) { resolve(deviceID); diff --git a/src/libs/actions/MapboxToken.ts b/src/libs/actions/MapboxToken.ts index 3b98f79698ba..923f5590b2bd 100644 --- a/src/libs/actions/MapboxToken.ts +++ b/src/libs/actions/MapboxToken.ts @@ -9,18 +9,18 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {MapboxAccessToken, Network} from '@src/types/onyx'; -let authToken: string | null; +let authToken: string | undefined; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (value) => { - authToken = value?.authToken ?? null; + authToken = value?.authToken; }, }); let connectionIDForToken: number | null; let connectionIDForNetwork: number | null; let appStateSubscription: NativeEventSubscription | null; -let currentToken: MapboxAccessToken | null; +let currentToken: MapboxAccessToken | undefined; let refreshTimeoutID: NodeJS.Timeout | undefined; let isCurrentlyFetchingToken = false; const REFRESH_INTERVAL = 1000 * 60 * 25; @@ -117,7 +117,7 @@ const init = () => { } if (!connectionIDForNetwork) { - let network: Network | null; + let network: Network | undefined; connectionIDForNetwork = Onyx.connect({ key: ONYXKEYS.NETWORK, callback: (value) => { diff --git a/src/libs/actions/OnyxUpdates.ts b/src/libs/actions/OnyxUpdates.ts index fc651b0599b5..341027f1db65 100644 --- a/src/libs/actions/OnyxUpdates.ts +++ b/src/libs/actions/OnyxUpdates.ts @@ -13,7 +13,7 @@ import * as QueuedOnyxUpdates from './QueuedOnyxUpdates'; // This key needs to be separate from ONYXKEYS.ONYX_UPDATES_FROM_SERVER so that it can be updated without triggering the callback when the server IDs are updated. If that // callback were triggered it would lead to duplicate processing of server updates. -let lastUpdateIDAppliedToClient: number | null = 0; +let lastUpdateIDAppliedToClient: number | undefined = 0; Onyx.connect({ key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, callback: (val) => (lastUpdateIDAppliedToClient = val), @@ -102,7 +102,7 @@ function apply({lastUpdateID, type, request, response, updates}: OnyxUpdatesFrom return Promise.resolve(); } - if (lastUpdateID && (lastUpdateIDAppliedToClient === null || Number(lastUpdateID) > lastUpdateIDAppliedToClient)) { + if (lastUpdateID && (lastUpdateIDAppliedToClient === undefined || Number(lastUpdateID) > lastUpdateIDAppliedToClient)) { Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, Number(lastUpdateID)); } if (type === CONST.ONYX_UPDATE_TYPES.HTTPS && request && response) { diff --git a/src/libs/actions/PriorityMode.ts b/src/libs/actions/PriorityMode.ts index 77347967b6cd..d73c35f1a202 100644 --- a/src/libs/actions/PriorityMode.ts +++ b/src/libs/actions/PriorityMode.ts @@ -21,7 +21,7 @@ let isReadyPromise = new Promise((resolve) => { resolveIsReadyPromise = resolve; }); -let currentUserAccountID: number | undefined | null; +let currentUserAccountID: number | undefined; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (val) => { @@ -59,7 +59,7 @@ Onyx.connect({ }, }); -let isInFocusMode: boolean | undefined; +let isInFocusMode: boolean; Onyx.connect({ key: ONYXKEYS.NVP_PRIORITY_MODE, callback: (priorityMode) => { @@ -70,7 +70,7 @@ Onyx.connect({ }, }); -let hasTriedFocusMode: boolean | undefined | null; +let hasTriedFocusMode: boolean | undefined; Onyx.connect({ key: ONYXKEYS.NVP_TRY_FOCUS_MODE, callback: (val) => { diff --git a/src/libs/actions/PushNotification.ts b/src/libs/actions/PushNotification.ts index bc4d4eb05c5a..d4caf7925d4c 100644 --- a/src/libs/actions/PushNotification.ts +++ b/src/libs/actions/PushNotification.ts @@ -8,7 +8,7 @@ let isUserOptedInToPushNotifications = false; Onyx.connect({ key: ONYXKEYS.PUSH_NOTIFICATIONS_ENABLED, callback: (value) => { - if (value === null) { + if (value === undefined) { return; } isUserOptedInToPushNotifications = value; @@ -35,7 +35,7 @@ function setPushNotificationOptInStatus(isOptingIn: boolean) { value: isUserOptedInToPushNotifications, }, ]; - API.write(commandName, {deviceID}, {optimisticData, failureData}); + API.write(commandName, {deviceID: deviceID ?? null}, {optimisticData, failureData}); }); } diff --git a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts index 3ad8b9ffe599..f8d887fec47a 100644 --- a/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts +++ b/src/libs/actions/ReimbursementAccount/resetFreePlanBankAccount.ts @@ -76,7 +76,6 @@ function resetFreePlanBankAccount(bankAccountID: number | undefined, session: On key: ONYXKEYS.PLAID_LINK_TOKEN, value: '', }, - // @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT { onyxMethod: Onyx.METHOD.SET, key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 303517558206..309e78053959 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -88,7 +88,7 @@ Onyx.connect({ callback: (value) => (stashedCredentials = value ?? {}), }); -let preferredLocale: ValueOf | null = null; +let preferredLocale: ValueOf | undefined; Onyx.connect({ key: ONYXKEYS.NVP_PREFERRED_LOCALE, callback: (val) => (preferredLocale = val), @@ -414,7 +414,7 @@ function beginSignIn(email: string) { * Given an idToken from Sign in with Apple, checks the API to see if an account * exists for that email address and signs the user in if so. */ -function beginAppleSignIn(idToken: string | undefined | null) { +function beginAppleSignIn(idToken: string | undefined) { const {optimisticData, successData, failureData} = signInAttemptState(); const params: BeginAppleSignInParams = {idToken, preferredLocale}; @@ -426,7 +426,7 @@ function beginAppleSignIn(idToken: string | undefined | null) { * Shows Google sign-in process, and if an auth token is successfully obtained, * passes the token on to the Expensify API to sign in with */ -function beginGoogleSignIn(token: string | null) { +function beginGoogleSignIn(token: string | undefined) { const {optimisticData, successData, failureData} = signInAttemptState(); const params: BeginGoogleSignInParams = {token, preferredLocale}; diff --git a/src/libs/actions/TransactionEdit.ts b/src/libs/actions/TransactionEdit.ts index 970b34591103..98423ca48d0a 100644 --- a/src/libs/actions/TransactionEdit.ts +++ b/src/libs/actions/TransactionEdit.ts @@ -33,7 +33,7 @@ function restoreOriginalTransactionFromBackup(transactionID: string, isDraft: bo Onyx.disconnect(connectionID); // Use set to completely overwrite the original transaction - Onyx.set(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, backupTransaction); + Onyx.set(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, backupTransaction ?? null); removeBackupTransaction(transactionID); }, }); diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index 2dbe47608ab9..3f70dc0d962d 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -80,7 +80,7 @@ Onyx.connect({ key: ONYXKEYS.NVP_ONBOARDING, initWithStoredValues: false, callback: (value) => { - if (value === null) { + if (value === undefined) { return; } diff --git a/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts b/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts index 5783d3f92953..9ec85cf35745 100644 --- a/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts +++ b/src/libs/migrations/KeyReportActionsDraftByReportActionID.ts @@ -1,4 +1,4 @@ -import type {OnyxInput} from 'react-native-onyx'; +import type {OnyxInputValue} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import Log from '@libs/Log'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -27,7 +27,7 @@ export default function () { return resolve(); } - const newReportActionsDrafts: Record> = {}; + const newReportActionsDrafts: Record> = {}; Object.entries(allReportActionsDrafts).forEach(([onyxKey, reportActionDraft]) => { if (typeof reportActionDraft !== 'string') { return; diff --git a/src/libs/migrations/NVPMigration.ts b/src/libs/migrations/NVPMigration.ts index dcab130186d3..7af3bc927c6b 100644 --- a/src/libs/migrations/NVPMigration.ts +++ b/src/libs/migrations/NVPMigration.ts @@ -32,7 +32,7 @@ export default function () { key: oldKey as OnyxKey, callback: (value) => { Onyx.disconnect(connectionID); - if (value === null) { + if (value === undefined) { resolveWhenDone(); return; } diff --git a/src/types/utils/CollectionDataSet.ts b/src/types/utils/CollectionDataSet.ts index 1fe1b52f0a03..c48d1568534e 100644 --- a/src/types/utils/CollectionDataSet.ts +++ b/src/types/utils/CollectionDataSet.ts @@ -1,12 +1,12 @@ -import type {OnyxInput} from 'react-native-onyx'; +import type {OnyxInputValue} from 'react-native-onyx'; import type {OnyxCollectionKey, OnyxCollectionValuesMapping} from '@src/ONYXKEYS'; /** Helps with typing a collection item update inside Onyx.multiSet call */ -type CollectionDataSet = Record<`${TCollectionKey}${string}`, OnyxInput>; +type CollectionDataSet = Record<`${TCollectionKey}${string}`, OnyxInputValue>; const toCollectionDataSet = ( collectionKey: TCollectionKey, - collection: Array>, + collection: Array>, idSelector: (collectionValue: OnyxCollectionValuesMapping[TCollectionKey]) => string, ) => { const collectionDataSet = collection.reduce>((result, collectionValue) => { diff --git a/tests/unit/MigrationTest.ts b/tests/unit/MigrationTest.ts index b628ee324ba5..09615b4d9fb5 100644 --- a/tests/unit/MigrationTest.ts +++ b/tests/unit/MigrationTest.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import Onyx from 'react-native-onyx'; -import type {OnyxInput} from 'react-native-onyx'; +import type {OnyxInputValue} from 'react-native-onyx'; import CONST from '@src/CONST'; import Log from '@src/libs/Log'; import CheckForPreviousReportActionID from '@src/libs/migrations/CheckForPreviousReportActionID'; @@ -262,10 +262,10 @@ describe('Migrations', () => { it('Should move individual draft to a draft collection of report', () => { const setQueries: ReportActionsDraftCollectionDataSet = {}; - setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_1`] = 'a' as unknown as OnyxInput; - setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_2`] = 'b' as unknown as OnyxInput; + setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_1`] = 'a' as unknown as OnyxInputValue; + setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_2`] = 'b' as unknown as OnyxInputValue; setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}2`] = {3: 'c'}; - setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}2_4`] = 'd' as unknown as OnyxInput; + setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}2_4`] = 'd' as unknown as OnyxInputValue; return Onyx.multiSet(setQueries) .then(KeyReportActionsDraftByReportActionID) @@ -320,7 +320,7 @@ describe('Migrations', () => { it("Shouldn't move empty individual draft to a draft collection of report", () => { const setQueries: ReportActionsDraftCollectionDataSet = {}; - setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_1`] = '' as unknown as OnyxInput; + setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1_1`] = '' as unknown as OnyxInputValue; setQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}1`] = {}; return Onyx.multiSet(setQueries) From 7b71d22c879ab5bbfc73567736cdb46e5885e090 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Tue, 4 Jun 2024 18:04:25 +0200 Subject: [PATCH 12/46] fix: remaining TS errors --- src/components/SignInButtons/AppleSignIn/index.ios.tsx | 2 +- src/libs/API/parameters/BeginAppleSignInParams.ts | 2 +- src/libs/API/parameters/BeginGoogleSignInParams.ts | 2 +- src/libs/actions/Session/index.ts | 4 ++-- src/pages/home/report/ReportActionItemMessageEdit.tsx | 4 ++-- tests/unit/NetworkTest.ts | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/SignInButtons/AppleSignIn/index.ios.tsx b/src/components/SignInButtons/AppleSignIn/index.ios.tsx index 4df8375edad8..1a663aeecdba 100644 --- a/src/components/SignInButtons/AppleSignIn/index.ios.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.ios.tsx @@ -35,7 +35,7 @@ function appleSignInRequest(): Promise { function AppleSignIn() { const handleSignIn = () => { appleSignInRequest() - .then((token) => Session.beginAppleSignIn(token)) + .then((token) => Session.beginAppleSignIn(token ?? null)) .catch((error: {code: AppleError}) => { if (error.code === appleAuth.Error.CANCELED) { return null; diff --git a/src/libs/API/parameters/BeginAppleSignInParams.ts b/src/libs/API/parameters/BeginAppleSignInParams.ts index be8fc72ad052..e16ae04a5b9b 100644 --- a/src/libs/API/parameters/BeginAppleSignInParams.ts +++ b/src/libs/API/parameters/BeginAppleSignInParams.ts @@ -2,7 +2,7 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; type BeginAppleSignInParams = { - idToken: string | undefined; + idToken: string | null; preferredLocale: ValueOf | undefined; }; diff --git a/src/libs/API/parameters/BeginGoogleSignInParams.ts b/src/libs/API/parameters/BeginGoogleSignInParams.ts index c2c7dd252bba..e64217cce1a7 100644 --- a/src/libs/API/parameters/BeginGoogleSignInParams.ts +++ b/src/libs/API/parameters/BeginGoogleSignInParams.ts @@ -2,7 +2,7 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; type BeginGoogleSignInParams = { - token: string | undefined; + token: string | null; preferredLocale: ValueOf | undefined; }; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 309e78053959..f5b3690bc0c7 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -414,7 +414,7 @@ function beginSignIn(email: string) { * Given an idToken from Sign in with Apple, checks the API to see if an account * exists for that email address and signs the user in if so. */ -function beginAppleSignIn(idToken: string | undefined) { +function beginAppleSignIn(idToken: string | null) { const {optimisticData, successData, failureData} = signInAttemptState(); const params: BeginAppleSignInParams = {idToken, preferredLocale}; @@ -426,7 +426,7 @@ function beginAppleSignIn(idToken: string | undefined) { * Shows Google sign-in process, and if an auth token is successfully obtained, * passes the token on to the Expensify API to sign in with */ -function beginGoogleSignIn(token: string | undefined) { +function beginGoogleSignIn(token: string | null) { const {optimisticData, successData, failureData} = signInAttemptState(); const params: BeginGoogleSignInParams = {token, preferredLocale}; diff --git a/src/pages/home/report/ReportActionItemMessageEdit.tsx b/src/pages/home/report/ReportActionItemMessageEdit.tsx index 6cb03e8dae05..b57b04bad677 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.tsx +++ b/src/pages/home/report/ReportActionItemMessageEdit.tsx @@ -130,7 +130,7 @@ function ReportActionItemMessageEdit( const unsubscribeOnyxModal = onyxSubscribe({ key: ONYXKEYS.MODAL, callback: (modalArg) => { - if (modalArg === null) { + if (modalArg === undefined) { return; } setModal(modalArg); @@ -140,7 +140,7 @@ function ReportActionItemMessageEdit( const unsubscribeOnyxFocused = onyxSubscribe({ key: ONYXKEYS.INPUT_FOCUSED, callback: (modalArg) => { - if (modalArg === null) { + if (modalArg === undefined) { return; } setOnyxFocused(modalArg); diff --git a/tests/unit/NetworkTest.ts b/tests/unit/NetworkTest.ts index 081b899c38ba..850e7d5c236a 100644 --- a/tests/unit/NetworkTest.ts +++ b/tests/unit/NetworkTest.ts @@ -53,7 +53,7 @@ describe('NetworkTests', () => { const TEST_USER_LOGIN = 'test@testguy.com'; const TEST_USER_ACCOUNT_ID = 1; - let isOffline: boolean | null = null; + let isOffline: boolean | undefined; Onyx.connect({ key: ONYXKEYS.NETWORK, From 475efaca690834c2ffa36aca6cc999f9566b784f Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Tue, 4 Jun 2024 18:05:46 +0200 Subject: [PATCH 13/46] fix: more TS errors --- src/components/SignInButtons/AppleSignIn/index.android.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SignInButtons/AppleSignIn/index.android.tsx b/src/components/SignInButtons/AppleSignIn/index.android.tsx index ec669590d029..6b6f9d355ce2 100644 --- a/src/components/SignInButtons/AppleSignIn/index.android.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.android.tsx @@ -36,7 +36,7 @@ function appleSignInRequest(): Promise { function AppleSignIn() { const handleSignIn = () => { appleSignInRequest() - .then((token) => Session.beginAppleSignIn(token)) + .then((token) => Session.beginAppleSignIn(token ?? null)) .catch((error: Record) => { if (error.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) { return null; From 8890183d69fb34362191313b8ba9ea29830d4a77 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Tue, 4 Jun 2024 19:41:51 +0200 Subject: [PATCH 14/46] fix: login not working --- src/libs/API/parameters/BeginAppleSignInParams.ts | 4 ++-- src/libs/API/parameters/BeginGoogleSignInParams.ts | 2 +- src/libs/API/parameters/SignInUserParams.ts | 2 +- src/libs/API/parameters/SignInUserWithLinkParams.ts | 2 +- src/libs/actions/Device/index.ts | 8 ++++---- src/libs/actions/Session/index.ts | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libs/API/parameters/BeginAppleSignInParams.ts b/src/libs/API/parameters/BeginAppleSignInParams.ts index e16ae04a5b9b..c427d99fcef9 100644 --- a/src/libs/API/parameters/BeginAppleSignInParams.ts +++ b/src/libs/API/parameters/BeginAppleSignInParams.ts @@ -2,8 +2,8 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; type BeginAppleSignInParams = { - idToken: string | null; - preferredLocale: ValueOf | undefined; + idToken: string | undefined | null; + preferredLocale: ValueOf | null; }; export default BeginAppleSignInParams; diff --git a/src/libs/API/parameters/BeginGoogleSignInParams.ts b/src/libs/API/parameters/BeginGoogleSignInParams.ts index e64217cce1a7..fae84d76b0d9 100644 --- a/src/libs/API/parameters/BeginGoogleSignInParams.ts +++ b/src/libs/API/parameters/BeginGoogleSignInParams.ts @@ -3,7 +3,7 @@ import type CONST from '@src/CONST'; type BeginGoogleSignInParams = { token: string | null; - preferredLocale: ValueOf | undefined; + preferredLocale: ValueOf | null; }; export default BeginGoogleSignInParams; diff --git a/src/libs/API/parameters/SignInUserParams.ts b/src/libs/API/parameters/SignInUserParams.ts index 5484ab0e2098..9fe973c42862 100644 --- a/src/libs/API/parameters/SignInUserParams.ts +++ b/src/libs/API/parameters/SignInUserParams.ts @@ -4,7 +4,7 @@ import type CONST from '@src/CONST'; type SignInUserParams = { twoFactorAuthCode?: string; email?: string; - preferredLocale?: ValueOf; + preferredLocale: ValueOf | null; validateCode?: string; deviceInfo: string; }; diff --git a/src/libs/API/parameters/SignInUserWithLinkParams.ts b/src/libs/API/parameters/SignInUserWithLinkParams.ts index 51294aec3e31..ae3589d4e305 100644 --- a/src/libs/API/parameters/SignInUserWithLinkParams.ts +++ b/src/libs/API/parameters/SignInUserWithLinkParams.ts @@ -5,7 +5,7 @@ type SignInUserWithLinkParams = { accountID: number; validateCode?: string; twoFactorAuthCode?: string; - preferredLocale?: ValueOf; + preferredLocale: ValueOf | null; deviceInfo: string; }; diff --git a/src/libs/actions/Device/index.ts b/src/libs/actions/Device/index.ts index 8ebd83164381..7ef3a4fd289f 100644 --- a/src/libs/actions/Device/index.ts +++ b/src/libs/actions/Device/index.ts @@ -4,12 +4,12 @@ import ONYXKEYS from '@src/ONYXKEYS'; import generateDeviceID from './generateDeviceID'; import getDeviceInfo from './getDeviceInfo'; -let deviceID: string | undefined; +let deviceID: string | null = null; /** * @returns - device ID string or null in case of failure */ -function getDeviceID(): Promise { +function getDeviceID(): Promise { return new Promise((resolve) => { if (deviceID) { resolve(deviceID); @@ -20,8 +20,8 @@ function getDeviceID(): Promise { key: ONYXKEYS.DEVICE_ID, callback: (id) => { Onyx.disconnect(connectionID); - deviceID = id; - return resolve(id); + deviceID = id ?? null; + return resolve(id ?? null); }, }); }); diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index f5b3690bc0c7..f116484d12d5 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -88,10 +88,10 @@ Onyx.connect({ callback: (value) => (stashedCredentials = value ?? {}), }); -let preferredLocale: ValueOf | undefined; +let preferredLocale: ValueOf | null = null; Onyx.connect({ key: ONYXKEYS.NVP_PREFERRED_LOCALE, - callback: (val) => (preferredLocale = val), + callback: (val) => (preferredLocale = val ?? null), }); function isSupportAuthToken(): boolean { @@ -414,7 +414,7 @@ function beginSignIn(email: string) { * Given an idToken from Sign in with Apple, checks the API to see if an account * exists for that email address and signs the user in if so. */ -function beginAppleSignIn(idToken: string | null) { +function beginAppleSignIn(idToken: string | undefined | null) { const {optimisticData, successData, failureData} = signInAttemptState(); const params: BeginAppleSignInParams = {idToken, preferredLocale}; From cc278f473a5d62e3182085bb4e6d92de9ea095c7 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 10:22:43 +0200 Subject: [PATCH 15/46] fix: login --- src/libs/Network/NetworkStore.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/Network/NetworkStore.ts b/src/libs/Network/NetworkStore.ts index 62229ef6c345..0fe338fcdc9a 100644 --- a/src/libs/Network/NetworkStore.ts +++ b/src/libs/Network/NetworkStore.ts @@ -5,7 +5,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type Credentials from '@src/types/onyx/Credentials'; -let credentials: Credentials | undefined; +let credentials: Credentials | null; let authToken: string | null = null; let authTokenType: ValueOf | null; let currentUserEmail: string | null = null; @@ -35,7 +35,7 @@ let isReadyPromise = new Promise((resolve) => { * If the values are undefined we haven't read them yet. If they are null or have a value then we have and the network is "ready". */ function checkRequiredData() { - if (authToken === undefined || credentials === undefined) { + if (authToken === null || credentials === null) { return; } @@ -62,7 +62,7 @@ Onyx.connect({ Onyx.connect({ key: ONYXKEYS.CREDENTIALS, callback: (val) => { - credentials = val; + credentials = val ?? null; checkRequiredData(); }, }); @@ -85,7 +85,7 @@ Onyx.connect({ }, }); -function getCredentials(): Credentials | undefined { +function getCredentials(): Credentials | null { return credentials; } From a00b9b0433b1397a31ab45439a606f49c2d4e277 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 10:23:49 +0200 Subject: [PATCH 16/46] set credentials to null by default --- src/libs/Network/NetworkStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Network/NetworkStore.ts b/src/libs/Network/NetworkStore.ts index 0fe338fcdc9a..753d9dd20f52 100644 --- a/src/libs/Network/NetworkStore.ts +++ b/src/libs/Network/NetworkStore.ts @@ -5,7 +5,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type Credentials from '@src/types/onyx/Credentials'; -let credentials: Credentials | null; +let credentials: Credentials | null = null; let authToken: string | null = null; let authTokenType: ValueOf | null; let currentUserEmail: string | null = null; From 2d26f6d18625bda622b28e5fd1c3ea597a93bf3c Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 10:33:37 +0200 Subject: [PATCH 17/46] fix: cannot login issue --- src/libs/Network/NetworkStore.ts | 2 +- src/libs/actions/PriorityMode.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/Network/NetworkStore.ts b/src/libs/Network/NetworkStore.ts index 753d9dd20f52..a2247a74097f 100644 --- a/src/libs/Network/NetworkStore.ts +++ b/src/libs/Network/NetworkStore.ts @@ -35,7 +35,7 @@ let isReadyPromise = new Promise((resolve) => { * If the values are undefined we haven't read them yet. If they are null or have a value then we have and the network is "ready". */ function checkRequiredData() { - if (authToken === null || credentials === null) { + if (authToken === undefined || credentials === undefined) { return; } diff --git a/src/libs/actions/PriorityMode.ts b/src/libs/actions/PriorityMode.ts index d73c35f1a202..b8b22908b94b 100644 --- a/src/libs/actions/PriorityMode.ts +++ b/src/libs/actions/PriorityMode.ts @@ -59,7 +59,7 @@ Onyx.connect({ }, }); -let isInFocusMode: boolean; +let isInFocusMode: boolean | undefined; Onyx.connect({ key: ONYXKEYS.NVP_PRIORITY_MODE, callback: (priorityMode) => { From 923133c995809fc132cbf4adc1154fbbc40d4bc4 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 14:35:20 +0200 Subject: [PATCH 18/46] fix: initial network load --- src/libs/Network/NetworkStore.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/Network/NetworkStore.ts b/src/libs/Network/NetworkStore.ts index a2247a74097f..db62812761df 100644 --- a/src/libs/Network/NetworkStore.ts +++ b/src/libs/Network/NetworkStore.ts @@ -5,8 +5,8 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type Credentials from '@src/types/onyx/Credentials'; -let credentials: Credentials | null = null; -let authToken: string | null = null; +let credentials: Credentials | null | undefined; +let authToken: string | null | undefined; let authTokenType: ValueOf | null; let currentUserEmail: string | null = null; let offline = false; @@ -86,7 +86,7 @@ Onyx.connect({ }); function getCredentials(): Credentials | null { - return credentials; + return credentials ?? null; } function isOffline(): boolean { @@ -94,7 +94,7 @@ function isOffline(): boolean { } function getAuthToken(): string | null { - return authToken; + return authToken ?? null; } function isSupportRequest(command: string): boolean { From 224ed07850958af35dffab8bc587d7bfa3cdd10a Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 15:25:34 +0200 Subject: [PATCH 19/46] add OnyxInputOrEntry type --- src/types/onyx/OnyxInputOrEntry.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/types/onyx/OnyxInputOrEntry.ts diff --git a/src/types/onyx/OnyxInputOrEntry.ts b/src/types/onyx/OnyxInputOrEntry.ts new file mode 100644 index 000000000000..27fdd474bf8d --- /dev/null +++ b/src/types/onyx/OnyxInputOrEntry.ts @@ -0,0 +1,5 @@ +import type {OnyxEntry, OnyxInputValue} from 'react-native-onyx'; + +type OnyxInputOrEntry = OnyxEntry | OnyxInputValue; + +export default OnyxInputOrEntry; From 41824e512b1286a1c6defd30de23b56d12e26aba Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 15:25:39 +0200 Subject: [PATCH 20/46] add to index --- src/types/onyx/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index 85f383aa74ce..5a70ddd48d9e 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -28,6 +28,7 @@ import type MapboxAccessToken from './MapboxAccessToken'; import type Modal from './Modal'; import type Network from './Network'; import type NewGroupChatDraft from './NewGroupChatDraft'; +import type OnyxInputOrEntry from './OnyxInputOrEntry'; import type {OnyxUpdateEvent, OnyxUpdatesFromServer} from './OnyxUpdatesFromServer'; import type {DecisionName, OriginalMessageIOU} from './OriginalMessage'; import type PersonalBankAccount from './PersonalBankAccount'; @@ -111,6 +112,7 @@ export type { MapboxAccessToken, Modal, Network, + OnyxInputOrEntry, OnyxUpdateEvent, OnyxUpdatesFromServer, PersonalBankAccount, From 8ba588f689388dffc130c1353336c52416132714 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 16:48:30 +0200 Subject: [PATCH 21/46] fix: IOU --- src/libs/DistanceRequestUtils.ts | 8 +- src/libs/IOUUtils.ts | 5 +- src/libs/ReportActionsUtils.ts | 45 +++++---- src/libs/ReportUtils.ts | 37 +++++--- src/libs/TransactionUtils.ts | 32 +++---- src/libs/actions/IOU.ts | 158 ++++++++++++++++--------------- 6 files changed, 151 insertions(+), 134 deletions(-) diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index a652b4e2d491..3d48562451e0 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -4,7 +4,7 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; import type {RateAndUnit} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {LastSelectedDistanceRates, Report, Transaction} from '@src/types/onyx'; +import type {LastSelectedDistanceRates, OnyxInputOrEntry, Report, Transaction} from '@src/types/onyx'; import type {Unit} from '@src/types/onyx/Policy'; import type Policy from '@src/types/onyx/Policy'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; @@ -40,10 +40,10 @@ Onyx.connect({ const METERS_TO_KM = 0.001; // 1 kilometer is 1000 meters const METERS_TO_MILES = 0.000621371; // There are approximately 0.000621371 miles in a meter -function getMileageRates(policy: OnyxEntry, includeDisabledRates = false): Record { +function getMileageRates(policy: OnyxInputOrEntry, includeDisabledRates = false): Record { const mileageRates: Record = {}; - if (!policy || !policy?.customUnits) { + if (!policy?.customUnits) { return mileageRates; } @@ -79,7 +79,7 @@ function getMileageRates(policy: OnyxEntry, includeDisabledRates = false * @returns [currency] - The currency associated with the rate. * @returns [unit] - The unit of measurement for the distance. */ -function getDefaultMileageRate(policy: OnyxEntry | EmptyObject): MileageRate | undefined { +function getDefaultMileageRate(policy: OnyxInputOrEntry | EmptyObject): MileageRate | undefined { if (isEmptyObject(policy) || !policy?.customUnits) { return undefined; } diff --git a/src/libs/IOUUtils.ts b/src/libs/IOUUtils.ts index 9ff4f5fb8d11..5f6d99332336 100644 --- a/src/libs/IOUUtils.ts +++ b/src/libs/IOUUtils.ts @@ -1,8 +1,7 @@ -import type {OnyxEntry} from 'react-native-onyx'; import type {IOUAction, IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; -import type {Report, Transaction} from '@src/types/onyx'; +import type {OnyxInputOrEntry, Report, Transaction} from '@src/types/onyx'; import type {IOURequestType} from './actions/IOU'; import * as CurrencyUtils from './CurrencyUtils'; import Navigation from './Navigation/Navigation'; @@ -60,7 +59,7 @@ function calculateAmount(numberOfParticipants: number, total: number, currency: * @param isDeleting - whether the user is deleting the expense * @param isUpdating - whether the user is updating the expense */ -function updateIOUOwnerAndTotal>( +function updateIOUOwnerAndTotal>( iouReport: TReport, actorAccountID: number, amount: number, diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index b979ed01a9f0..eb84afd82072 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1,12 +1,13 @@ import fastMerge from 'expensify-common/lib/fastMerge'; import _ from 'lodash'; import lodashFindLast from 'lodash/findLast'; -import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import type {OnyxCollection, OnyxCollectionInput, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {OnyxInputOrEntry} from '@src/types/onyx'; import type { ActionName, ChangeLog, @@ -100,11 +101,11 @@ Onyx.connect({ let environmentURL: string; Environment.getEnvironmentURL().then((url: string) => (environmentURL = url)); -function isCreatedAction(reportAction: OnyxEntry): boolean { +function isCreatedAction(reportAction: OnyxInputOrEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED; } -function isDeletedAction(reportAction: OnyxEntry): boolean { +function isDeletedAction(reportAction: OnyxInputOrEntry): boolean { const message = reportAction?.message ?? []; // A legacy deleted comment has either an empty array or an object with html field with empty string as value @@ -113,34 +114,34 @@ function isDeletedAction(reportAction: OnyxEntry): boolean { +function isDeletedParentAction(reportAction: OnyxInputOrEntry): boolean { return (reportAction?.message?.[0]?.isDeletedParentAction ?? false) && (reportAction?.childVisibleActionCount ?? 0) > 0; } -function isReversedTransaction(reportAction: OnyxEntry) { +function isReversedTransaction(reportAction: OnyxInputOrEntry) { return (reportAction?.message?.[0]?.isReversedTransaction ?? false) && ((reportAction as ReportAction)?.childVisibleActionCount ?? 0) > 0; } -function isPendingRemove(reportAction: OnyxEntry | EmptyObject): boolean { +function isPendingRemove(reportAction: OnyxInputOrEntry | EmptyObject): boolean { if (isEmptyObject(reportAction)) { return false; } return reportAction?.message?.[0]?.moderationDecision?.decision === CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE; } -function isMoneyRequestAction(reportAction: OnyxEntry): reportAction is ReportAction & OriginalMessageIOU { +function isMoneyRequestAction(reportAction: OnyxInputOrEntry): reportAction is ReportAction & OriginalMessageIOU { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU; } -function isReportPreviewAction(reportAction: OnyxEntry): boolean { +function isReportPreviewAction(reportAction: OnyxInputOrEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW; } -function isReportActionSubmitted(reportAction: OnyxEntry): boolean { +function isReportActionSubmitted(reportAction: OnyxInputOrEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED; } -function isModifiedExpenseAction(reportAction: OnyxEntry | ReportAction | Record): boolean { +function isModifiedExpenseAction(reportAction: OnyxInputOrEntry | ReportAction | Record): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE; } @@ -148,7 +149,7 @@ function isModifiedExpenseAction(reportAction: OnyxEntry | ReportA * We are in the process of deprecating reportAction.originalMessage and will be setting the db version of "message" to reportAction.message in the future see: https://github.com/Expensify/App/issues/39797 * In the interim, we must check to see if we have an object or array for the reportAction.message, if we have an array we will use the originalMessage as this means we have not yet migrated. */ -function getWhisperedTo(reportAction: OnyxEntry | EmptyObject): number[] { +function getWhisperedTo(reportAction: OnyxInputOrEntry | EmptyObject): number[] { const originalMessage = reportAction?.originalMessage; const message = reportAction?.message; @@ -163,25 +164,25 @@ function getWhisperedTo(reportAction: OnyxEntry | EmptyObject): nu return []; } -function isWhisperAction(reportAction: OnyxEntry | EmptyObject): boolean { +function isWhisperAction(reportAction: OnyxInputOrEntry | EmptyObject): boolean { return getWhisperedTo(reportAction).length > 0; } /** * Checks whether the report action is a whisper targeting someone other than the current user. */ -function isWhisperActionTargetedToOthers(reportAction: OnyxEntry): boolean { +function isWhisperActionTargetedToOthers(reportAction: OnyxInputOrEntry): boolean { if (!isWhisperAction(reportAction)) { return false; } return !getWhisperedTo(reportAction).includes(currentUserAccountID ?? 0); } -function isReimbursementQueuedAction(reportAction: OnyxEntry) { +function isReimbursementQueuedAction(reportAction: OnyxInputOrEntry) { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_QUEUED; } -function isMemberChangeAction(reportAction: OnyxEntry) { +function isMemberChangeAction(reportAction: OnyxInputOrEntry) { return ( reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.REMOVE_FROM_ROOM || @@ -216,7 +217,7 @@ function isThreadParentMessage(reportAction: OnyxEntry, reportID: * * @deprecated Use Onyx.connect() or withOnyx() instead */ -function getParentReportAction(report: OnyxEntry | EmptyObject): ReportAction | EmptyObject { +function getParentReportAction(report: OnyxInputOrEntry | EmptyObject): ReportAction | EmptyObject { if (!report?.parentReportID || !report.parentReportActionID) { return {}; } @@ -597,7 +598,7 @@ function isResolvedActionTrackExpense(reportAction: OnyxEntry): bo * Checks if a reportAction is fit for display as report last action, meaning that * it satisfies shouldReportActionBeVisible, it's not whisper action and not deleted. */ -function shouldReportActionBeVisibleAsLastAction(reportAction: OnyxEntry): boolean { +function shouldReportActionBeVisibleAsLastAction(reportAction: OnyxInputOrEntry): boolean { if (!reportAction) { return false; } @@ -638,8 +639,8 @@ function replaceBaseURLInPolicyChangeLogAction(reportAction: ReportAction): Repo return updatedReportAction; } -function getLastVisibleAction(reportID: string, actionsToMerge: OnyxCollection = {}): OnyxEntry { - const reportActions = Object.values(fastMerge(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {}, actionsToMerge ?? {}, true)); +function getLastVisibleAction(reportID: string, actionsToMerge: OnyxCollection | OnyxCollectionInput = {}): OnyxEntry { + const reportActions = Object.values(fastMerge(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {}, actionsToMerge ?? {}, true)) as Array; const visibleReportActions = Object.values(reportActions ?? {}).filter((action): action is ReportAction => shouldReportActionBeVisibleAsLastAction(action)); const sortedReportActions = getSortedReportActions(visibleReportActions, true); if (sortedReportActions.length === 0) { @@ -648,7 +649,11 @@ function getLastVisibleAction(reportID: string, actionsToMerge: OnyxCollection = {}, reportAction: OnyxEntry | undefined = undefined): LastVisibleMessage { +function getLastVisibleMessage( + reportID: string, + actionsToMerge: OnyxCollection | OnyxCollectionInput = {}, + reportAction: OnyxInputOrEntry | undefined = undefined, +): LastVisibleMessage { const lastVisibleAction = reportAction ?? getLastVisibleAction(reportID, actionsToMerge); const message = lastVisibleAction?.message?.[0]; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index eab6bf03a19e..1e68a5eb24bc 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -22,6 +22,7 @@ import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import type { Beta, + OnyxInputOrEntry, PersonalDetails, PersonalDetailsList, Policy, @@ -596,7 +597,7 @@ function getCurrentUserDisplayNameOrEmail(): string | undefined { return currentUserPersonalDetails?.displayName ?? currentUserEmail; } -function getChatType(report: OnyxEntry | Participant | EmptyObject): ValueOf | undefined { +function getChatType(report: OnyxInputOrEntry | Participant | EmptyObject): ValueOf | undefined { return report?.chatType; } @@ -717,7 +718,7 @@ function isInvoiceReport(report: OnyxEntry | EmptyObject): boolean { /** * Checks if a report is an Expense report. */ -function isExpenseReport(report: OnyxEntry | EmptyObject): boolean { +function isExpenseReport(report: OnyxInputOrEntry | EmptyObject): boolean { return report?.type === CONST.REPORT.TYPE.EXPENSE; } @@ -1028,7 +1029,7 @@ function isWorkspaceTaskReport(report: OnyxEntry): boolean { /** * Returns true if report has a parent */ -function isThread(report: OnyxEntry): boolean { +function isThread(report: OnyxInputOrEntry): boolean { return Boolean(report?.parentReportID && report?.parentReportActionID); } @@ -1043,7 +1044,7 @@ function isDM(report: OnyxEntry): boolean { return isChatReport(report) && !getChatType(report) && !isThread(report); } -function isSelfDM(report: OnyxEntry): boolean { +function isSelfDM(report: OnyxInputOrEntry): boolean { return getChatType(report) === CONST.REPORT.CHAT_TYPE.SELF_DM; } @@ -1402,7 +1403,7 @@ function isIOURequest(report: OnyxEntry): boolean { * A Track Expense Report is a thread where the parent the parentReportAction is a transaction, and * parentReportAction has type of track. */ -function isTrackExpenseReport(report: OnyxEntry): boolean { +function isTrackExpenseReport(report: OnyxInputOrEntry): boolean { if (isThread(report)) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); return !isEmptyObject(parentReportAction) && ReportActionsUtils.isTrackExpenseAction(parentReportAction); @@ -2573,7 +2574,7 @@ function getMoneyRequestReportName(report: OnyxEntry, policy?: OnyxEntry * into a flat object. Used for displaying transactions and sending them in API commands */ -function getTransactionDetails(transaction: OnyxEntry, createdDateFormat: string = CONST.DATE.FNS_FORMAT_STRING): TransactionDetails | undefined { +function getTransactionDetails(transaction: OnyxInputOrEntry, createdDateFormat: string = CONST.DATE.FNS_FORMAT_STRING): TransactionDetails | undefined { if (!transaction) { return; } @@ -3019,10 +3020,10 @@ function getReportPreviewMessage( * At the moment, we only allow changing one transaction field at a time. */ function getModifiedExpenseOriginalMessage( - oldTransaction: OnyxEntry, + oldTransaction: OnyxInputOrEntry, transactionChanges: TransactionChanges, isFromExpenseReport: boolean, - policy: OnyxEntry, + policy: OnyxInputOrEntry, ): ExpenseOriginalMessage { const originalMessage: ExpenseOriginalMessage = {}; // Remark: Comment field is the only one which has new/old prefixes for the keys (newComment/ oldComment), @@ -4179,7 +4180,13 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, * @param [comment] - User comment for the IOU. * @param [transaction] - optimistic first transaction of preview */ -function buildOptimisticReportPreview(chatReport: OnyxEntry, iouReport: Report, comment = '', transaction?: OnyxEntry, childReportID?: string): ReportAction { +function buildOptimisticReportPreview( + chatReport: OnyxInputOrEntry, + iouReport: Report, + comment = '', + transaction?: OnyxInputOrEntry, + childReportID?: string, +): ReportAction { const hasReceipt = TransactionUtils.hasReceipt(transaction); const isReceiptBeingScanned = hasReceipt && TransactionUtils.isReceiptBeingScanned(transaction); const message = getReportPreviewMessage(iouReport); @@ -4255,11 +4262,11 @@ function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOURe * Builds an optimistic modified expense action with a randomly generated reportActionID. */ function buildOptimisticModifiedExpenseReportAction( - transactionThread: OnyxEntry, - oldTransaction: OnyxEntry, + transactionThread: OnyxInputOrEntry, + oldTransaction: OnyxInputOrEntry, transactionChanges: TransactionChanges, isFromExpenseReport: boolean, - policy: OnyxEntry, + policy: OnyxInputOrEntry, ): OptimisticModifiedExpenseReportAction { const originalMessage = getModifiedExpenseOriginalMessage(oldTransaction, transactionChanges, isFromExpenseReport, policy); return { @@ -5556,7 +5563,7 @@ function getReportPolicyID(reportID?: string): string | undefined { /** * Check if the chat report is linked to an iou that is waiting for the current user to add a credit bank account. */ -function hasIOUWaitingOnCurrentUserBankAccount(chatReport: OnyxEntry): boolean { +function hasIOUWaitingOnCurrentUserBankAccount(chatReport: OnyxInputOrEntry): boolean { if (chatReport?.iouReportID) { const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.iouReportID}`]; if (iouReport?.isWaitingOnBankAccount && iouReport?.ownerAccountID === currentUserAccountID) { @@ -6621,7 +6628,7 @@ function hasMissingPaymentMethod(userWallet: OnyxEntry, iouReportID: * - we have one, but it's waiting on the payee adding a bank account * - we have one, but we can't add more transactions to it due to: report is approved or settled, or report is processing and policy isn't on Instant submit reporting frequency */ -function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxEntry | undefined, chatReport: OnyxEntry): boolean { +function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxInputOrEntry | undefined, chatReport: OnyxInputOrEntry): boolean { return !existingIOUReport || hasIOUWaitingOnCurrentUserBankAccount(chatReport) || !canAddOrDeleteTransactions(existingIOUReport); } @@ -6772,7 +6779,7 @@ function createDraftTransactionAndNavigateToParticipantSelector(transactionID: s /** * @returns the object to update `report.hasOutstandingChildRequest` */ -function getOutstandingChildRequest(iouReport: OnyxEntry | EmptyObject): OutstandingChildRequest { +function getOutstandingChildRequest(iouReport: OnyxInputOrEntry | EmptyObject): OutstandingChildRequest { if (!iouReport || isEmptyObject(iouReport)) { return {}; } diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index cb65f1732505..69cbb9d5f6cb 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -4,7 +4,7 @@ import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy, RecentWaypoint, Report, TaxRate, TaxRates, Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx'; +import type {OnyxInputOrEntry, Policy, RecentWaypoint, Report, TaxRate, TaxRates, Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx'; import type {Comment, Receipt, TransactionChanges, TransactionPendingFieldsKey, Waypoint, WaypointCollection} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type {IOURequestType} from './actions/IOU'; @@ -148,7 +148,7 @@ function hasEReceipt(transaction: Transaction | undefined | null): boolean { return !!transaction?.hasEReceipt; } -function hasReceipt(transaction: OnyxEntry | undefined): boolean { +function hasReceipt(transaction: OnyxInputOrEntry | undefined): boolean { return !!transaction?.receipt?.state || hasEReceipt(transaction); } @@ -274,7 +274,7 @@ function getUpdatedTransaction(transaction: Transaction, transactionChanges: Tra * Return the comment field (referred to as description in the App) from the transaction. * The comment does not have its modifiedComment counterpart. */ -function getDescription(transaction: OnyxEntry): string { +function getDescription(transaction: OnyxInputOrEntry): string { // Casting the description to string to avoid wrong data types (e.g. number) being returned from the API return transaction?.comment?.comment?.toString() ?? ''; } @@ -282,7 +282,7 @@ function getDescription(transaction: OnyxEntry): string { /** * Return the amount field from the transaction, return the modifiedAmount if present. */ -function getAmount(transaction: OnyxEntry, isFromExpenseReport = false, isFromTrackedExpense = false): number { +function getAmount(transaction: OnyxInputOrEntry, isFromExpenseReport = false, isFromTrackedExpense = false): number { // IOU requests cannot have negative values, but they can be stored as negative values, let's return absolute value if (!isFromExpenseReport || isFromTrackedExpense) { const amount = transaction?.modifiedAmount ?? 0; @@ -308,7 +308,7 @@ function getAmount(transaction: OnyxEntry, isFromExpenseReport = fa /** * Return the tax amount field from the transaction. */ -function getTaxAmount(transaction: OnyxEntry, isFromExpenseReport: boolean): number { +function getTaxAmount(transaction: OnyxInputOrEntry, isFromExpenseReport: boolean): number { // IOU requests cannot have negative values but they can be stored as negative values, let's return absolute value if (!isFromExpenseReport) { return Math.abs(transaction?.taxAmount ?? 0); @@ -322,14 +322,14 @@ function getTaxAmount(transaction: OnyxEntry, isFromExpenseReport: /** * Return the tax code from the transaction. */ -function getTaxCode(transaction: OnyxEntry): string { +function getTaxCode(transaction: OnyxInputOrEntry): string { return transaction?.taxCode ?? ''; } /** * Return the currency field from the transaction, return the modifiedCurrency if present. */ -function getCurrency(transaction: OnyxEntry): string { +function getCurrency(transaction: OnyxInputOrEntry): string { const currency = transaction?.modifiedCurrency ?? ''; if (currency) { return currency; @@ -362,11 +362,11 @@ function isFetchingWaypointsFromServer(transaction: OnyxEntry): boo /** * Return the merchant field from the transaction, return the modifiedMerchant if present. */ -function getMerchant(transaction: OnyxEntry): string { +function getMerchant(transaction: OnyxInputOrEntry): string { return transaction?.modifiedMerchant ? transaction.modifiedMerchant : transaction?.merchant ?? ''; } -function getDistance(transaction: OnyxEntry): number { +function getDistance(transaction: OnyxInputOrEntry): number { return transaction?.comment?.customUnit?.quantity ?? 0; } @@ -387,7 +387,7 @@ function getWaypoints(transaction: OnyxEntry): WaypointCollection | /** * Return the category from the transaction. This "category" field has no "modified" complement. */ -function getCategory(transaction: OnyxEntry): string { +function getCategory(transaction: OnyxInputOrEntry): string { return transaction?.category ?? ''; } @@ -401,7 +401,7 @@ function getCardID(transaction: Transaction): number { /** * Return the billable field from the transaction. This "billable" field has no "modified" complement. */ -function getBillable(transaction: OnyxEntry): boolean { +function getBillable(transaction: OnyxInputOrEntry): boolean { return transaction?.billable ?? false; } @@ -436,7 +436,7 @@ function getTagArrayFromName(tagName: string): string[] { * Return the tag from the transaction. When the tagIndex is passed, return the tag based on the index. * This "tag" field has no "modified" complement. */ -function getTag(transaction: OnyxEntry, tagIndex?: number): string { +function getTag(transaction: OnyxInputOrEntry, tagIndex?: number): string { if (tagIndex !== undefined) { const tagsArray = getTagArrayFromName(transaction?.tag ?? ''); return tagsArray[tagIndex] ?? ''; @@ -452,7 +452,7 @@ function getTagForDisplay(transaction: OnyxEntry, tagIndex?: number /** * Return the created field from the transaction, return the modifiedCreated if present. */ -function getCreated(transaction: OnyxEntry, dateFormat: string = CONST.DATE.FNS_FORMAT_STRING): string { +function getCreated(transaction: OnyxInputOrEntry, dateFormat: string = CONST.DATE.FNS_FORMAT_STRING): string { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const created = transaction?.modifiedCreated ? transaction.modifiedCreated : transaction?.created || ''; @@ -497,7 +497,7 @@ function isPosted(transaction: Transaction): boolean { return transaction.status === CONST.TRANSACTION.STATUS.POSTED; } -function isReceiptBeingScanned(transaction: OnyxEntry): boolean { +function isReceiptBeingScanned(transaction: OnyxInputOrEntry): boolean { return [CONST.IOU.RECEIPT_STATE.SCANREADY, CONST.IOU.RECEIPT_STATE.SCANNING].some((value) => value === transaction?.receipt?.state); } @@ -679,7 +679,7 @@ function getEnabledTaxRateCount(options: TaxRates) { /** * Check if the customUnitRateID has a value default for P2P distance requests */ -function isCustomUnitRateIDForP2P(transaction: OnyxEntry): boolean { +function isCustomUnitRateIDForP2P(transaction: OnyxInputOrEntry): boolean { return transaction?.comment?.customUnit?.customUnitRateID === CONST.CUSTOM_UNITS.FAKE_P2P_ID; } @@ -690,7 +690,7 @@ function hasReservationList(transaction: Transaction | undefined | null): boolea /** * Get rate ID from the transaction object */ -function getRateID(transaction: OnyxEntry): string | undefined { +function getRateID(transaction: OnyxInputOrEntry): string | undefined { return transaction?.comment?.customUnit?.customUnitRateID?.toString(); } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index d904e64ba4cf..819bd7564955 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1,7 +1,7 @@ import {format} from 'date-fns'; import fastMerge from 'expensify-common/lib/fastMerge'; import Str from 'expensify-common/lib/str'; -import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import ReceiptGeneric from '@assets/images/receipt-generic.png'; @@ -288,12 +288,14 @@ Onyx.connect({ /** * Find the report preview action from given chat report and iou report */ -function getReportPreviewAction(chatReportID: string, iouReportID: string): OnyxEntry { +function getReportPreviewAction(chatReportID: string, iouReportID: string): OnyxInputValue { const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`] ?? {}; // Find the report preview action from the chat report - return Object.values(reportActions).find( - (reportAction) => reportAction && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && reportAction.originalMessage.linkedReportID === iouReportID, + return ( + Object.values(reportActions).find( + (reportAction) => reportAction && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && reportAction.originalMessage.linkedReportID === iouReportID, + ) ?? null ); } @@ -449,7 +451,7 @@ function getReceiptError(receipt?: Receipt, filename?: string, isScanRequest = t /** Builds the Onyx data for an expense */ function buildOnyxDataForMoneyRequest( - chatReport: OnyxEntry, + chatReport: OnyxTypes.OnyxInputOrEntry, iouReport: OnyxTypes.Report, transaction: OnyxTypes.Transaction, chatCreatedAction: OptimisticCreatedReportAction, @@ -463,9 +465,9 @@ function buildOnyxDataForMoneyRequest( transactionThreadReport: OptimisticChatReport | EmptyObject, transactionThreadCreatedReportAction: OptimisticCreatedReportAction | EmptyObject, shouldCreateNewMoneyRequestReport: boolean, - policy?: OnyxEntry, - policyTagList?: OnyxEntry, - policyCategories?: OnyxEntry, + policy?: OnyxTypes.OnyxInputOrEntry, + policyTagList?: OnyxTypes.OnyxInputOrEntry, + policyCategories?: OnyxTypes.OnyxInputOrEntry, optimisticNextStep?: OnyxTypes.ReportNextStep | null, isOneOnOneSplit = false, existingTransactionThreadReportID?: string, @@ -1151,20 +1153,20 @@ function buildOnyxDataForInvoice( /** Builds the Onyx data for track expense */ function buildOnyxDataForTrackExpense( - chatReport: OnyxEntry, - iouReport: OnyxEntry, + chatReport: OnyxInputValue, + iouReport: OnyxInputValue, transaction: OnyxTypes.Transaction, iouCreatedAction: OptimisticCreatedReportAction, iouAction: OptimisticIOUReportAction, - reportPreviewAction: OnyxEntry, + reportPreviewAction: OnyxInputValue, transactionThreadReport: OptimisticChatReport | EmptyObject, transactionThreadCreatedReportAction: OptimisticCreatedReportAction | EmptyObject, shouldCreateNewMoneyRequestReport: boolean, - policy?: OnyxEntry, - policyTagList?: OnyxEntry, - policyCategories?: OnyxEntry, + policy?: OnyxInputValue, + policyTagList?: OnyxInputValue, + policyCategories?: OnyxInputValue, existingTransactionThreadReportID?: string, - actionableTrackExpenseWhisper?: OnyxEntry, + actionableTrackExpenseWhisper?: OnyxInputValue, ): [OnyxUpdate[], OnyxUpdate[], OnyxUpdate[]] { const isScanRequest = TransactionUtils.isScanRequest(transaction); const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction); @@ -1885,11 +1887,11 @@ function getMoneyRequestInformation( // STEP 2: Get the Expense/IOU report. If the moneyRequestReportID has been provided, we want to add the transaction to this specific report. // If no such reportID has been provided, let's use the chatReport.iouReportID property. In case that is not present, build a new optimistic Expense/IOU report. - let iouReport: OnyxEntry; + let iouReport: OnyxInputValue = null; if (moneyRequestReportID) { - iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`]; + iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null; } else { - iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`]; + iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null; } const shouldCreateNewMoneyRequestReport = ReportUtils.shouldCreateNewMoneyRequestReport(iouReport, chatReport); @@ -2111,14 +2113,14 @@ function getTrackExpenseInformation( // For this, first use the chatReport.iouReportID property. Build a new optimistic expense report if needed. const shouldUseMoneyReport = !!isPolicyExpenseChat; - let iouReport: OnyxEntry; + let iouReport: OnyxInputValue = null; let shouldCreateNewMoneyRequestReport = false; if (shouldUseMoneyReport) { if (moneyRequestReportID) { - iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`]; + iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null; } else { - iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`]; + iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null; } shouldCreateNewMoneyRequestReport = ReportUtils.shouldCreateNewMoneyRequestReport(iouReport, chatReport); @@ -2201,9 +2203,9 @@ function getTrackExpenseInformation( linkedTrackedExpenseReportAction, ); - let reportPreviewAction: OnyxEntry; + let reportPreviewAction: OnyxInputValue = null; if (shouldUseMoneyReport && iouReport) { - reportPreviewAction = shouldCreateNewMoneyRequestReport ? undefined : getReportPreviewAction(chatReport.reportID, iouReport.reportID); + reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { reportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction as ReportPreviewAction, false, comment, optimisticTransaction); @@ -2215,7 +2217,7 @@ function getTrackExpenseInformation( } } - let actionableTrackExpenseWhisper: OnyxEntry; + let actionableTrackExpenseWhisper: OnyxInputValue = null; if (!isPolicyExpenseChat) { actionableTrackExpenseWhisper = ReportUtils.buildOptimisticActionableTrackExpenseWhisper(iouAction, optimisticTransaction.transactionID); } @@ -2354,7 +2356,11 @@ function createDistanceRequest( /** * Compute the diff amount when we update the transaction */ -function calculateDiffAmount(iouReport: OnyxEntry, updatedTransaction: OnyxEntry, transaction: OnyxEntry): number { +function calculateDiffAmount( + iouReport: OnyxTypes.OnyxInputOrEntry, + updatedTransaction: OnyxTypes.OnyxInputOrEntry, + transaction: OnyxEntry, +): number { if (!iouReport) { return 0; } @@ -2382,10 +2388,10 @@ function calculateDiffAmount(iouReport: OnyxEntry, updatedTran } function calculateAmountForUpdatedWaypoint( - transaction: OnyxEntry, + transaction: OnyxTypes.OnyxInputOrEntry, transactionChanges: TransactionChanges, - policy: OnyxEntry, - iouReport: OnyxEntry, + policy: OnyxTypes.OnyxInputOrEntry, + iouReport: OnyxTypes.OnyxInputOrEntry, ) { let updatedAmount: number = CONST.IOU.DEFAULT_AMOUNT; let updatedMerchant = Localize.translateLocal('iou.fieldPending'); @@ -2424,9 +2430,9 @@ function getUpdateMoneyRequestParams( transactionID: string, transactionThreadReportID: string, transactionChanges: TransactionChanges, - policy: OnyxEntry, - policyTagList: OnyxEntry, - policyCategories: OnyxEntry, + policy: OnyxTypes.OnyxInputOrEntry, + policyTagList: OnyxTypes.OnyxInputOrEntry, + policyCategories: OnyxTypes.OnyxInputOrEntry, onlyIncludeChangedFields: boolean, ): UpdateMoneyRequestData { const optimisticData: OnyxUpdate[] = []; @@ -2439,12 +2445,12 @@ function getUpdateMoneyRequestParams( const errorFields = Object.fromEntries(Object.keys(pendingFields).map((key) => [key, {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}])); // Step 2: Get all the collections being updated - const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; + const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`]; + const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`] ?? null; const isFromExpenseReport = ReportUtils.isExpenseReport(iouReport); const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); - let updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : undefined; + let updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : null; const transactionDetails = ReportUtils.getTransactionDetails(updatedTransaction); if (transactionDetails?.waypoints) { @@ -2712,7 +2718,7 @@ function getUpdateTrackExpenseParams( transactionThreadReportID: string, transactionChanges: TransactionChanges, onlyIncludeChangedFields: boolean, - policy: OnyxEntry, + policy: OnyxTypes.OnyxInputOrEntry, ): UpdateMoneyRequestData { const optimisticData: OnyxUpdate[] = []; const successData: OnyxUpdate[] = []; @@ -2724,11 +2730,11 @@ function getUpdateTrackExpenseParams( const errorFields = Object.fromEntries(Object.keys(pendingFields).map((key) => [key, {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}])); // Step 2: Get all the collections being updated - const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; + const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`]; + const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`] ?? null; const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); - let updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, false) : undefined; + let updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, false) : null; const transactionDetails = ReportUtils.getTransactionDetails(updatedTransaction); if (transactionDetails?.waypoints) { @@ -2868,7 +2874,7 @@ function getUpdateTrackExpenseParams( failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, - value: transactionThread ?? null, + value: transactionThread, }); return { @@ -2889,8 +2895,8 @@ function updateMoneyRequestDate( const transactionChanges: TransactionChanges = { created: value, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); @@ -3057,8 +3063,8 @@ function updateMoneyRequestDescription( const transactionChanges: TransactionChanges = { comment, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); @@ -4019,7 +4025,7 @@ function createSplitsAndOnyxData( } // STEP 2: Get existing IOU/Expense report and update its total OR build a new optimistic one - let oneOnOneIOUReport: OneOnOneIOUReport = oneOnOneChatReport.iouReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneOnOneChatReport.iouReportID}`] : undefined; + let oneOnOneIOUReport: OneOnOneIOUReport = oneOnOneChatReport.iouReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneOnOneChatReport.iouReportID}`] : null; const shouldCreateNewOneOnOneIOUReport = ReportUtils.shouldCreateNewMoneyRequestReport(oneOnOneIOUReport, oneOnOneChatReport); if (!oneOnOneIOUReport || shouldCreateNewOneOnOneIOUReport) { @@ -4121,10 +4127,10 @@ function createSplitsAndOnyxData( optimisticTransactionThread, optimisticCreatedActionForTransactionThread, shouldCreateNewOneOnOneIOUReport, - undefined, - undefined, - undefined, - undefined, + null, + null, + null, + null, true, ); @@ -4728,18 +4734,18 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA } } - let oneOnOneChatReport: OnyxTypes.Report | undefined; + let oneOnOneChatReport: OnyxTypes.Report | null; let isNewOneOnOneChatReport = false; if (isPolicyExpenseChat) { // The workspace chat reportID is saved in the splits array when starting a split expense with a workspace - oneOnOneChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.chatReportID}`]; + oneOnOneChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.chatReportID}`] ?? null; } else { const existingChatReport = ReportUtils.getChatByParticipants(participant.accountID ? [participant.accountID, sessionAccountID] : []); isNewOneOnOneChatReport = !existingChatReport; oneOnOneChatReport = existingChatReport ?? ReportUtils.buildOptimisticChatReport(participant.accountID ? [participant.accountID, sessionAccountID] : []); } - let oneOnOneIOUReport: OneOnOneIOUReport = oneOnOneChatReport?.iouReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneOnOneChatReport.iouReportID}`] : undefined; + let oneOnOneIOUReport: OneOnOneIOUReport = oneOnOneChatReport?.iouReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oneOnOneChatReport.iouReportID}`] : null; const shouldCreateNewOneOnOneIOUReport = ReportUtils.shouldCreateNewMoneyRequestReport(oneOnOneIOUReport, oneOnOneChatReport); if (!oneOnOneIOUReport || shouldCreateNewOneOnOneIOUReport) { @@ -4809,10 +4815,10 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA optimisticTransactionThread, optimisticCreatedActionForTransactionThread, shouldCreateNewOneOnOneIOUReport, - undefined, - undefined, - undefined, - undefined, + null, + null, + null, + null, true, ); @@ -4884,15 +4890,15 @@ function editRegularMoneyRequest( policyCategories: OnyxTypes.PolicyCategories, ) { // STEP 1: Get all collections we're updating - const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; + const transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`]; - const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`]; + const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread?.parentReportID}`] ?? null; + const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`] ?? null; const isFromExpenseReport = ReportUtils.isExpenseReport(iouReport); // STEP 2: Build new modified expense report action. const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, isFromExpenseReport, policy); - const updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : undefined; + const updatedTransaction = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : null; // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct // Should only update if the transaction matches the currency of the report, else we wait for the update @@ -4949,7 +4955,7 @@ function editRegularMoneyRequest( { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, - value: updatedTransaction ?? null, + value: updatedTransaction, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -5087,7 +5093,7 @@ function editRegularMoneyRequest( { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`, - value: chatReport ?? null, + value: chatReport, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -5182,13 +5188,13 @@ function updateMoneyRequestAmountAndCurrency({ taxCode, taxAmount, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { - data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); + data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy ?? null); } else { - data = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, policy, policyTagList, policyCategories, true); + data = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, policy ?? null, policyTagList ?? null, policyCategories ?? null, true); } const {params, onyxData} = data; API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_AMOUNT_AND_CURRENCY, params, onyxData); @@ -5197,15 +5203,15 @@ function updateMoneyRequestAmountAndCurrency({ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.ReportAction, isSingleTransactionView = false) { // STEP 1: Get all collections we're updating const iouReportID = reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? reportAction.originalMessage.IOUReportID : ''; - const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`]; + const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`] ?? null; const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`]; const reportPreviewAction = getReportPreviewAction(iouReport?.chatReportID ?? '', iouReport?.reportID ?? ''); const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; const transactionThreadID = reportAction.childReportID; - let transactionThread; + let transactionThread = null; if (transactionThreadID) { - transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`]; + transactionThread = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`] ?? null; } // STEP 2: Decide if we need to: @@ -5241,7 +5247,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor iouReportLastMessageText.length === 0 && !ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && (!transactionThreadID || shouldDeleteTransactionThread); // STEP 4: Update the iouReport and reportPreview with new totals and messages if it wasn't deleted - let updatedIOUReport: OnyxTypes.Report | undefined; + let updatedIOUReport: OnyxTypes.Report | null; const currency = TransactionUtils.getCurrency(transaction); const updatedReportPreviewAction: OnyxTypes.ReportAction | EmptyObject = {...reportPreviewAction}; updatedReportPreviewAction.pendingAction = shouldDeleteIOUReport ? CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE : CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE; @@ -5355,8 +5361,8 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor value: { hasOutstandingChildRequest: false, iouReportID: null, - lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport?.chatReportID ?? '', {[reportPreviewAction?.reportActionID ?? '']: undefined})?.lastMessageText, - lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(iouReport?.chatReportID ?? '', {[reportPreviewAction?.reportActionID ?? '']: undefined})?.created, + lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport?.chatReportID ?? '', {[reportPreviewAction?.reportActionID ?? '']: null})?.lastMessageText, + lastVisibleActionCreated: ReportActionsUtils.getLastVisibleAction(iouReport?.chatReportID ?? '', {[reportPreviewAction?.reportActionID ?? '']: null})?.created, }, }); } @@ -5413,7 +5419,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor failureData.push({ onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`, - value: transactionThread ?? null, + value: transactionThread, }); } @@ -5437,12 +5443,12 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor ? { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`, - value: iouReport ?? null, + value: iouReport, } : { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`, - value: iouReport ?? null, + value: iouReport, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -5501,7 +5507,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor function deleteTrackExpense(chatReportID: string, transactionID: string, reportAction: OnyxTypes.ReportAction, isSingleTransactionView = false) { // STEP 1: Get all collections we're updating - const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]; + const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`] ?? null; if (!ReportUtils.isSelfDM(chatReport)) { return deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView); } @@ -5878,7 +5884,7 @@ function getPayMoneyRequestParams( let currentNextStep = null; let optimisticNextStep = null; if (!isInvoiceReport) { - currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`]; + currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`] ?? null; optimisticNextStep = NextStepUtils.buildNextStep(iouReport, CONST.REPORT.STATUS_NUM.REIMBURSED, {isPaidWithExpensify: paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA}); } From dd7e9dd421ff8d67ab4c97e98590c49db6a53cb9 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 17:12:10 +0200 Subject: [PATCH 22/46] fix: remaining IOU issues --- src/libs/actions/IOU.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 819bd7564955..a7bccc7c80f7 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1,7 +1,7 @@ import {format} from 'date-fns'; import fastMerge from 'expensify-common/lib/fastMerge'; import Str from 'expensify-common/lib/str'; -import type {OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} from 'react-native-onyx'; +import type {OnyxCollection, OnyxCollectionInput, OnyxEntry, OnyxInputValue, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import ReceiptGeneric from '@assets/images/receipt-generic.png'; @@ -166,11 +166,11 @@ Onyx.connect({ }, }); -let allReports: OnyxCollection; +let allReports: OnyxCollection | null = null; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, waitForCollectionCallback: true, - callback: (value) => (allReports = value), + callback: (value) => (allReports = value ?? null), }); let allTransactions: NonNullable> = {}; @@ -2693,7 +2693,7 @@ function getUpdateMoneyRequestParams( failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, - value: transactionThread ?? null, + value: transactionThread, }); return { @@ -2935,8 +2935,8 @@ function updateMoneyRequestMerchant( const transactionChanges: TransactionChanges = { merchant: value, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); @@ -3023,8 +3023,8 @@ function updateMoneyRequestDistance({ waypoints, routes, }; - const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`]; + const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; let data: UpdateMoneyRequestData; if (ReportUtils.isTrackExpenseReport(transactionThreadReport) && ReportUtils.isSelfDM(parentReport)) { data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, true, policy); @@ -5328,7 +5328,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`, - value: updatedIOUReport ?? null, + value: updatedIOUReport, }, { onyxMethod: Onyx.METHOD.MERGE, From 11c8e94e06f89df877e071c1aa6e0da6c4175c11 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 17:14:43 +0200 Subject: [PATCH 23/46] rename type --- src/libs/ReportActionsUtils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index eb84afd82072..d5b13b8f36cc 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1,7 +1,7 @@ import fastMerge from 'expensify-common/lib/fastMerge'; import _ from 'lodash'; import lodashFindLast from 'lodash/findLast'; -import type {OnyxCollection, OnyxCollectionInput, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import type {OnyxCollection, OnyxCollectionInputValue, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; @@ -639,7 +639,7 @@ function replaceBaseURLInPolicyChangeLogAction(reportAction: ReportAction): Repo return updatedReportAction; } -function getLastVisibleAction(reportID: string, actionsToMerge: OnyxCollection | OnyxCollectionInput = {}): OnyxEntry { +function getLastVisibleAction(reportID: string, actionsToMerge: OnyxCollection | OnyxCollectionInputValue = {}): OnyxEntry { const reportActions = Object.values(fastMerge(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {}, actionsToMerge ?? {}, true)) as Array; const visibleReportActions = Object.values(reportActions ?? {}).filter((action): action is ReportAction => shouldReportActionBeVisibleAsLastAction(action)); const sortedReportActions = getSortedReportActions(visibleReportActions, true); @@ -651,7 +651,7 @@ function getLastVisibleAction(reportID: string, actionsToMerge: OnyxCollection | OnyxCollectionInput = {}, + actionsToMerge: OnyxCollection | OnyxCollectionInputValue = {}, reportAction: OnyxInputOrEntry | undefined = undefined, ): LastVisibleMessage { const lastVisibleAction = reportAction ?? getLastVisibleAction(reportID, actionsToMerge); From 3105b2ed4cc2166b2ba12de10cd555a4166aec08 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 17:26:34 +0200 Subject: [PATCH 24/46] fix: minor issues --- src/libs/actions/Policy/Policy.ts | 10 +++++----- src/pages/iou/SplitBillDetailsPage.tsx | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index ced9f20b1dcd..a27b6bd6b243 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -3,7 +3,7 @@ import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import Str from 'expensify-common/lib/str'; import {escapeRegExp} from 'lodash'; import lodashClone from 'lodash/clone'; -import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import type {NullishDeep, OnyxCollection, OnyxCollectionInputValue, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import * as API from '@libs/API'; @@ -798,12 +798,12 @@ function removeMembers(accountIDs: number[], policyID: string) { const announceRoomMembers = removeOptimisticAnnounceRoomMembers(policy.id, policy.name, accountIDs); - const optimisticMembersState: OnyxCollection = {}; - const successMembersState: OnyxCollection = {}; - const failureMembersState: OnyxCollection = {}; + const optimisticMembersState: OnyxCollectionInputValue = {}; + const successMembersState: OnyxCollectionInputValue = {}; + const failureMembersState: OnyxCollectionInputValue = {}; emailList.forEach((email) => { optimisticMembersState[email] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}; - successMembersState[email] = undefined; + successMembersState[email] = null; failureMembersState[email] = {errors: ErrorUtils.getMicroSecondOnyxError('workspace.people.error.genericRemove')}; }); diff --git a/src/pages/iou/SplitBillDetailsPage.tsx b/src/pages/iou/SplitBillDetailsPage.tsx index 04f3bc92560b..ff8970a3a0a7 100644 --- a/src/pages/iou/SplitBillDetailsPage.tsx +++ b/src/pages/iou/SplitBillDetailsPage.tsx @@ -120,7 +120,7 @@ function SplitBillDetailsPage({personalDetails, report, route, reportActions, tr )} {!!participants.length && ( Date: Wed, 5 Jun 2024 17:28:21 +0200 Subject: [PATCH 25/46] fix: initial hasTriedFocusMode --- src/libs/actions/PriorityMode.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/PriorityMode.ts b/src/libs/actions/PriorityMode.ts index b8b22908b94b..3679df575e9c 100644 --- a/src/libs/actions/PriorityMode.ts +++ b/src/libs/actions/PriorityMode.ts @@ -70,11 +70,11 @@ Onyx.connect({ }, }); -let hasTriedFocusMode: boolean | undefined; +let hasTriedFocusMode: boolean | null | undefined; Onyx.connect({ key: ONYXKEYS.NVP_TRY_FOCUS_MODE, callback: (val) => { - hasTriedFocusMode = val; + hasTriedFocusMode = val ?? null; // eslint-disable-next-line @typescript-eslint/no-use-before-define checkRequiredData(); From 72f1cdd069f9a4f82ffe075a5852c9d1fb38de72 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 17:29:20 +0200 Subject: [PATCH 26/46] fix: PushNotification --- src/libs/actions/PushNotification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/PushNotification.ts b/src/libs/actions/PushNotification.ts index d4caf7925d4c..f1b629f69754 100644 --- a/src/libs/actions/PushNotification.ts +++ b/src/libs/actions/PushNotification.ts @@ -35,7 +35,7 @@ function setPushNotificationOptInStatus(isOptingIn: boolean) { value: isUserOptedInToPushNotifications, }, ]; - API.write(commandName, {deviceID: deviceID ?? null}, {optimisticData, failureData}); + API.write(commandName, {deviceID: deviceID}, {optimisticData, failureData}); }); } From 0bde2bfaffb0a908585873477695aa34f7730e51 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 17:46:46 +0200 Subject: [PATCH 27/46] fix: PersonalDetailsUtils --- src/libs/PersonalDetailsUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index d58ac4d5218c..2ec6a2869487 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -4,7 +4,7 @@ import Onyx from 'react-native-onyx'; import type {CurrentUserPersonalDetails} from '@components/withCurrentUserPersonalDetails'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetails, PersonalDetailsList, PrivatePersonalDetails} from '@src/types/onyx'; +import type {OnyxInputOrEntry, PersonalDetails, PersonalDetailsList, PrivatePersonalDetails} from '@src/types/onyx'; import type {OnyxData} from '@src/types/onyx/Request'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import * as LocalePhoneNumber from './LocalePhoneNumber'; @@ -250,7 +250,7 @@ function getEffectiveDisplayName(personalDetail?: PersonalDetails): string | und /** * Creates a new displayName for a user based on passed personal details or login. */ -function createDisplayName(login: string, passedPersonalDetails: Pick | OnyxEntry): string { +function createDisplayName(login: string, passedPersonalDetails: Pick | OnyxInputOrEntry): string { // If we have a number like +15857527441@expensify.sms then let's remove @expensify.sms and format it // so that the option looks cleaner in our UI. const userLogin = LocalePhoneNumber.formatPhoneNumber(login); From 38bf7036474ec1d07cedfbeba94f4d4f6d5f805f Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 17:46:52 +0200 Subject: [PATCH 28/46] fix: User --- src/libs/actions/User.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index a185edd9f566..89ebd9f62122 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -60,7 +60,7 @@ Onyx.connect({ }, }); -let myPersonalDetails: OnyxEntry | EmptyObject = {}; +let myPersonalDetails: OnyxEntry | EmptyObject | null = {}; Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, callback: (value) => { @@ -68,7 +68,7 @@ Onyx.connect({ return; } - myPersonalDetails = value[currentUserAccountID] ?? undefined; + myPersonalDetails = value[currentUserAccountID]; }, }); From f13c27e883f6dfe9b4154b6f1d337f20775acaa2 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 18:05:12 +0200 Subject: [PATCH 29/46] fix: ReportScreen null values --- src/components/HeaderWithBackButton/types.ts | 2 +- src/components/MoneyReportHeader.tsx | 2 +- src/components/MoneyRequestHeader.tsx | 4 +- src/libs/PolicyUtils.ts | 10 ++--- src/libs/ReportActionsUtils.ts | 2 +- src/libs/ReportUtils.ts | 40 +++++++++---------- src/libs/actions/IOU.ts | 14 +++++-- src/pages/home/HeaderView.tsx | 2 +- src/pages/home/ReportScreen.tsx | 10 ++--- .../ComposerWithSuggestions.tsx | 2 +- src/pages/home/report/ReportActionItem.tsx | 2 +- .../report/ReportActionItemParentAction.tsx | 2 +- src/pages/home/report/ReportActionsList.tsx | 2 +- .../report/ReportActionsListItemRenderer.tsx | 2 +- src/pages/home/report/ReportActionsView.tsx | 2 +- src/pages/home/report/ReportFooter.tsx | 2 +- 16 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/components/HeaderWithBackButton/types.ts b/src/components/HeaderWithBackButton/types.ts index 6b08dd74dc8b..1f6b92099e59 100644 --- a/src/components/HeaderWithBackButton/types.ts +++ b/src/components/HeaderWithBackButton/types.ts @@ -102,7 +102,7 @@ type HeaderWithBackButtonProps = Partial & { report?: OnyxEntry; /** The report's policy, if we're showing the details for a report and need info about it for AvatarWithDisplay */ - policy?: OnyxEntry; + policy?: OnyxEntry | null; /** Single execution function to prevent concurrent navigation actions */ singleExecution?: (action: Action) => Action; diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index ec52a6158ad7..538e0454a535 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -35,7 +35,7 @@ type MoneyReportHeaderProps = { report: OnyxTypes.Report; /** The policy tied to the expense report */ - policy: OnyxEntry; + policy: OnyxEntry | null; /** Array of report actions for the report */ reportActions: OnyxTypes.ReportAction[]; diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index abd70753b461..9dc298ba9661 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -35,10 +35,10 @@ type MoneyRequestHeaderProps = { report: Report; /** The policy which the report is tied to */ - policy: OnyxEntry; + policy: OnyxEntry | null; /** The report action the transaction is tied to from the parent report */ - parentReportAction: OnyxEntry; + parentReportAction: OnyxEntry | null; /** Whether we should display the header as in narrow layout */ shouldUseNarrowLayout?: boolean; diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 7487e1fd5146..c1d299743a08 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -6,7 +6,7 @@ import type {SelectorType} from '@components/SelectionScreen'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {Policy, PolicyCategories, PolicyEmployeeList, PolicyTagList, PolicyTags, TaxRate} from '@src/types/onyx'; +import type {OnyxInputOrEntry, Policy, PolicyCategories, PolicyEmployeeList, PolicyTagList, PolicyTags, TaxRate} from '@src/types/onyx'; import type {PolicyFeatureName, Rate, Tenant} from '@src/types/onyx/Policy'; import type PolicyEmployee from '@src/types/onyx/PolicyEmployee'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; @@ -142,7 +142,7 @@ function isExpensifyTeam(email: string | undefined): boolean { /** * Checks if the current user is an admin of the policy. */ -const isPolicyAdmin = (policy: OnyxEntry | EmptyObject, currentUserLogin?: string): boolean => +const isPolicyAdmin = (policy: OnyxInputOrEntry | EmptyObject, currentUserLogin?: string): boolean => (policy?.role ?? (currentUserLogin && policy?.employeeList?.[currentUserLogin]?.role)) === CONST.POLICY.ROLE.ADMIN; /** @@ -155,7 +155,7 @@ const isPolicyEmployee = (policyID: string, policies: OnyxCollection): b /** * Checks if the current user is an owner (creator) of the policy. */ -const isPolicyOwner = (policy: OnyxEntry | EmptyObject, currentUserAccountID: number): boolean => policy?.ownerAccountID === currentUserAccountID; +const isPolicyOwner = (policy: OnyxInputOrEntry | EmptyObject, currentUserAccountID: number): boolean => policy?.ownerAccountID === currentUserAccountID; /** * Create an object mapping member emails to their accountIDs. Filter for members without errors if includeMemberWithErrors is false, and get the login email from the personalDetail object using the accountID. @@ -297,14 +297,14 @@ function isTaxTrackingEnabled(isPolicyExpenseChat: boolean, policy: OnyxEntry | EmptyObject): boolean { +function isInstantSubmitEnabled(policy: OnyxInputOrEntry | EmptyObject): boolean { return policy?.type === CONST.POLICY.TYPE.FREE || (policy?.autoReporting === true && policy?.autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT); } /** * Checks if policy's approval mode is "optional", a.k.a. "Submit & Close" */ -function isSubmitAndClose(policy: OnyxEntry | EmptyObject): boolean { +function isSubmitAndClose(policy: OnyxInputOrEntry | EmptyObject): boolean { return policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL; } diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index d5b13b8f36cc..782d3daffaa1 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -239,7 +239,7 @@ function isSentMoneyReportAction(reportAction: OnyxEntry | EmptyObject): boolean { +function isTransactionThread(parentReportAction: OnyxInputOrEntry | EmptyObject): boolean { return ( parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && (parentReportAction.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE || diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 1e68a5eb24bc..70f02291bc69 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -668,7 +668,7 @@ function getPolicy(policyID: string | undefined): Policy | EmptyObject { * Get the policy type from a given report * @param policies must have Onyxkey prefix (i.e 'policy_') for keys */ -function getPolicyType(report: OnyxEntry, policies: OnyxCollection): string { +function getPolicyType(report: OnyxInputOrEntry, policies: OnyxCollection): string { return policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.type ?? ''; } @@ -711,7 +711,7 @@ function isChatReport(report: OnyxEntry | EmptyObject): boolean { return report?.type === CONST.REPORT.TYPE.CHAT; } -function isInvoiceReport(report: OnyxEntry | EmptyObject): boolean { +function isInvoiceReport(report: OnyxInputOrEntry | EmptyObject): boolean { return report?.type === CONST.REPORT.TYPE.INVOICE; } @@ -725,7 +725,7 @@ function isExpenseReport(report: OnyxInputOrEntry | EmptyObject): boolea /** * Checks if a report is an IOU report using report or reportID */ -function isIOUReport(reportOrID: OnyxEntry | string | EmptyObject): boolean { +function isIOUReport(reportOrID: OnyxInputOrEntry | string | EmptyObject): boolean { const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; return report?.type === CONST.REPORT.TYPE.IOU; } @@ -739,7 +739,7 @@ function isIOUReportUsingReport(report: OnyxEntry | EmptyObject): report /** * Checks if a report is a task report. */ -function isTaskReport(report: OnyxEntry): boolean { +function isTaskReport(report: OnyxInputOrEntry): boolean { return report?.type === CONST.REPORT.TYPE.TASK; } @@ -750,7 +750,7 @@ function isTaskReport(report: OnyxEntry): boolean { * There's another situation where you don't have access to the parentReportAction (because it was created in a chat you don't have access to) * In this case, we have added the key to the report itself */ -function isCanceledTaskReport(report: OnyxEntry | EmptyObject = {}, parentReportAction: OnyxEntry | EmptyObject = {}): boolean { +function isCanceledTaskReport(report: OnyxInputOrEntry | EmptyObject = {}, parentReportAction: OnyxInputOrEntry | EmptyObject = {}): boolean { if (!isEmptyObject(parentReportAction) && (parentReportAction?.message?.[0]?.isDeletedParentAction ?? false)) { return true; } @@ -767,7 +767,7 @@ function isCanceledTaskReport(report: OnyxEntry | EmptyObject = {}, pare * * @param parentReportAction - The parent report action of the report (Used to check if the task has been canceled) */ -function isOpenTaskReport(report: OnyxEntry, parentReportAction: OnyxEntry | EmptyObject = {}): boolean { +function isOpenTaskReport(report: OnyxInputOrEntry, parentReportAction: OnyxInputOrEntry | EmptyObject = {}): boolean { return ( isTaskReport(report) && !isCanceledTaskReport(report, parentReportAction) && report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN ); @@ -790,7 +790,7 @@ function isReportManager(report: OnyxEntry): boolean { /** * Checks if the supplied report has been approved */ -function isReportApproved(reportOrID: OnyxEntry | string | EmptyObject): boolean { +function isReportApproved(reportOrID: OnyxInputOrEntry | string | EmptyObject): boolean { const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; return report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED && report?.statusNum === CONST.REPORT.STATUS_NUM.APPROVED; } @@ -798,7 +798,7 @@ function isReportApproved(reportOrID: OnyxEntry | string | EmptyObject): /** * Checks if the supplied report is an expense report in Open state and status. */ -function isOpenExpenseReport(report: OnyxEntry | EmptyObject): boolean { +function isOpenExpenseReport(report: OnyxInputOrEntry | EmptyObject): boolean { return isExpenseReport(report) && report?.stateNum === CONST.REPORT.STATE_NUM.OPEN && report?.statusNum === CONST.REPORT.STATUS_NUM.OPEN; } @@ -898,7 +898,7 @@ function isUserCreatedPolicyRoom(report: OnyxEntry): boolean { /** * Whether the provided report is a Policy Expense chat. */ -function isPolicyExpenseChat(report: OnyxEntry | Participant | EmptyObject): boolean { +function isPolicyExpenseChat(report: OnyxInputOrEntry | Participant | EmptyObject): boolean { return getChatType(report) === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT || (report?.isPolicyExpenseChat ?? false); } @@ -938,7 +938,7 @@ function isGroupPolicy(policyType: string): boolean { /** * Whether the provided report belongs to a Free, Collect or Control policy */ -function isReportInGroupPolicy(report: OnyxEntry, policy?: OnyxEntry): boolean { +function isReportInGroupPolicy(report: OnyxInputOrEntry, policy?: OnyxInputOrEntry): boolean { const policyType = policy?.type ?? getPolicyType(report, allPolicies); return isGroupPolicy(policyType); } @@ -1244,7 +1244,7 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry): boolean /** * Whether the provided report is an archived room */ -function isArchivedRoom(report: OnyxEntry | EmptyObject, reportNameValuePairs?: OnyxEntry | EmptyObject): boolean { +function isArchivedRoom(report: OnyxInputOrEntry | EmptyObject, reportNameValuePairs?: OnyxInputOrEntry | EmptyObject): boolean { if (reportNameValuePairs) { return reportNameValuePairs.isArchived; } @@ -1422,7 +1422,7 @@ function isMoneyRequest(reportOrID: OnyxEntry | string): boolean { /** * Checks if a report is an IOU or expense report. */ -function isMoneyRequestReport(reportOrID: OnyxEntry | EmptyObject | string): boolean { +function isMoneyRequestReport(reportOrID: OnyxInputOrEntry | EmptyObject | string): boolean { const report = typeof reportOrID === 'object' ? reportOrID : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? undefined; return isIOUReport(report) || isExpenseReport(report); } @@ -2347,7 +2347,7 @@ function hasNonReimbursableTransactions(iouReportID: string | undefined): boolea return transactions.filter((transaction) => transaction.reimbursable === false).length > 0; } -function getMoneyRequestSpendBreakdown(report: OnyxEntry, allReportsDict?: OnyxCollection): SpendBreakdown { +function getMoneyRequestSpendBreakdown(report: OnyxInputOrEntry, allReportsDict?: OnyxCollection): SpendBreakdown { const allAvailableReports = allReportsDict ?? allReports; let moneyRequestReport; if (isMoneyRequestReport(report) || isInvoiceReport(report)) { @@ -2728,7 +2728,7 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxEntry, field * - It's an expense where conditions for editability are defined in canEditMoneyRequest method * - It's not pending deletion */ -function canEditReportAction(reportAction: OnyxEntry): boolean { +function canEditReportAction(reportAction: OnyxInputOrEntry): boolean { const isCommentOrIOU = reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU; return Boolean( @@ -6390,7 +6390,7 @@ function shouldDisplayThreadReplies(reportAction: OnyxEntry, repor /** * Check if money report has any transactions updated optimistically */ -function hasUpdatedTotal(report: OnyxEntry, policy: OnyxEntry): boolean { +function hasUpdatedTotal(report: OnyxInputOrEntry, policy: OnyxInputOrEntry): boolean { if (!report) { return true; } @@ -6406,7 +6406,7 @@ function hasUpdatedTotal(report: OnyxEntry, policy: OnyxEntry): /** * Return held and full amount formatted with used currency */ -function getNonHeldAndFullAmount(iouReport: OnyxEntry, policy: OnyxEntry): string[] { +function getNonHeldAndFullAmount(iouReport: OnyxInputOrEntry, policy: OnyxInputOrEntry): string[] { const transactions = TransactionUtils.getAllReportTransactions(iouReport?.reportID ?? ''); const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction); @@ -6560,7 +6560,7 @@ function getOptimisticDataForParentReportAction(reportID: string, lastVisibleAct }); } -function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry | EmptyObject): boolean { +function canBeAutoReimbursed(report: OnyxInputOrEntry, policy: OnyxInputOrEntry | EmptyObject): boolean { if (isEmptyObject(policy)) { return false; } @@ -6577,7 +6577,7 @@ function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry): boolean { +function isReportOwner(report: OnyxInputOrEntry): boolean { return report?.ownerAccountID === currentUserPersonalDetails?.accountID; } @@ -6647,14 +6647,14 @@ function hasActionsWithErrors(reportID: string): boolean { return Object.values(reportActions).some((action) => !isEmptyObject(action.errors)); } -function isNonAdminOrOwnerOfPolicyExpenseChat(report: OnyxEntry, policy: OnyxEntry): boolean { +function isNonAdminOrOwnerOfPolicyExpenseChat(report: OnyxInputOrEntry, policy: OnyxInputOrEntry): boolean { return isPolicyExpenseChat(report) && !(PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPolicyOwner(policy, currentUserAccountID ?? -1) || isReportOwner(report)); } /** * Whether the user can join a report */ -function canJoinChat(report: OnyxEntry, parentReportAction: OnyxEntry, policy: OnyxEntry): boolean { +function canJoinChat(report: OnyxInputOrEntry, parentReportAction: OnyxInputOrEntry, policy: OnyxInputOrEntry): boolean { // We disabled thread functions for whisper action // So we should not show join option for existing thread on whisper message that has already been left, or manually leave it if (ReportActionsUtils.isWhisperAction(parentReportAction)) { diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index a7bccc7c80f7..661671f4f692 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1,7 +1,7 @@ import {format} from 'date-fns'; import fastMerge from 'expensify-common/lib/fastMerge'; import Str from 'expensify-common/lib/str'; -import type {OnyxCollection, OnyxCollectionInput, OnyxEntry, OnyxInputValue, OnyxUpdate} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import ReceiptGeneric from '@assets/images/receipt-generic.png'; @@ -6044,7 +6044,11 @@ function sendMoneyWithWallet(report: OnyxEntry, amount: number Report.notifyNewAction(params.chatReportID, managerID); } -function canApproveIOU(iouReport: OnyxEntry | EmptyObject, chatReport: OnyxEntry | EmptyObject, policy: OnyxEntry | EmptyObject) { +function canApproveIOU( + iouReport: OnyxTypes.OnyxInputOrEntry | EmptyObject, + chatReport: OnyxTypes.OnyxInputOrEntry | EmptyObject, + policy: OnyxTypes.OnyxInputOrEntry | EmptyObject, +) { if (isEmptyObject(chatReport)) { return false; } @@ -6071,7 +6075,11 @@ function canApproveIOU(iouReport: OnyxEntry | EmptyObject, cha return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled && !isArchivedReport; } -function canIOUBePaid(iouReport: OnyxEntry | EmptyObject, chatReport: OnyxEntry | EmptyObject, policy: OnyxEntry | EmptyObject) { +function canIOUBePaid( + iouReport: OnyxTypes.OnyxInputOrEntry | EmptyObject, + chatReport: OnyxTypes.OnyxInputOrEntry | EmptyObject, + policy: OnyxTypes.OnyxInputOrEntry | EmptyObject, +) { const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); const isChatReportArchived = ReportUtils.isArchivedRoom(chatReport); const iouSettled = ReportUtils.isSettled(iouReport?.reportID); diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index db7a4af0c0cb..22a104984f2c 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -62,7 +62,7 @@ type HeaderViewProps = HeaderViewOnyxProps & { report: OnyxTypes.Report; /** The report action the transaction is tied to from the parent report */ - parentReportAction: OnyxEntry; + parentReportAction: OnyxEntry | null; /** The reportID of the current report */ reportID: string; diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 38899fc013f7..b8f3fd4f03f3 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -102,9 +102,9 @@ function isEmpty(report: OnyxTypes.Report): boolean { return !Object.values(report).some((value) => value !== undefined && value !== ''); } -function getParentReportAction(parentReportActions: OnyxEntry, parentReportActionID: string | undefined): OnyxEntry { +function getParentReportAction(parentReportActions: OnyxEntry, parentReportActionID: string | undefined): OnyxEntry | null { if (!parentReportActions || !parentReportActionID) { - return; + return null; } return parentReportActions[parentReportActionID ?? '0']; } @@ -290,15 +290,15 @@ function ReportScreen({ const hasHelpfulErrors = Object.keys(report?.errorFields ?? {}).some((key) => key !== 'notFound'); const shouldHideReport = !hasHelpfulErrors && !ReportUtils.canAccessReport(report, policies, betas); - const lastReportAction: OnyxEntry = useMemo( + const lastReportAction: OnyxEntry | null = useMemo( () => reportActions.length ? [...reportActions, parentReportAction].find((action) => ReportUtils.canEditReportAction(action) && !ReportActionsUtils.isMoneyRequestAction(action)) - : undefined, + : null, [reportActions, parentReportAction], ); const isSingleTransactionView = ReportUtils.isMoneyRequest(report) || ReportUtils.isTrackExpenseReport(report); - const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; + const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`] ?? null; const isTopMostReportId = currentReportID === reportIDFromRoute; const didSubscribeToReportLeavingEvents = useRef(false); diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 2a461c1c012a..6224532d66e5 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -157,7 +157,7 @@ type ComposerWithSuggestionsProps = ComposerWithSuggestionsOnyxProps & isEmptyChat?: boolean; /** The last report action */ - lastReportAction?: OnyxEntry; + lastReportAction?: OnyxEntry | null; /** Whether to include chronos */ includeChronos?: boolean; diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 366dbd25ae1c..b645f6410051 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -125,7 +125,7 @@ type ReportActionItemProps = { reportActions: OnyxTypes.ReportAction[]; /** Report action belonging to the report's parent */ - parentReportAction: OnyxEntry; + parentReportAction: OnyxEntry | null; /** The transaction thread report's parentReportAction */ /** It's used by withOnyx HOC */ diff --git a/src/pages/home/report/ReportActionItemParentAction.tsx b/src/pages/home/report/ReportActionItemParentAction.tsx index e97c51377476..13e807d93903 100644 --- a/src/pages/home/report/ReportActionItemParentAction.tsx +++ b/src/pages/home/report/ReportActionItemParentAction.tsx @@ -38,7 +38,7 @@ type ReportActionItemParentActionProps = { reportActions: OnyxTypes.ReportAction[]; /** Report actions belonging to the report's parent */ - parentReportAction: OnyxEntry; + parentReportAction: OnyxEntry | null; /** Whether we should display "Replies" divider */ shouldDisplayReplyDivider: boolean; diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index c700fea4fb85..6378c4bacfeb 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -48,7 +48,7 @@ type ReportActionsListProps = WithCurrentUserPersonalDetailsProps & { reportActions: OnyxTypes.ReportAction[]; /** The report's parentReportAction */ - parentReportAction: OnyxEntry; + parentReportAction: OnyxEntry | null; /** The transaction thread report's parentReportAction */ parentReportActionForTransactionThread: OnyxEntry; diff --git a/src/pages/home/report/ReportActionsListItemRenderer.tsx b/src/pages/home/report/ReportActionsListItemRenderer.tsx index 18118e48f7cb..303dfc4a4bd2 100644 --- a/src/pages/home/report/ReportActionsListItemRenderer.tsx +++ b/src/pages/home/report/ReportActionsListItemRenderer.tsx @@ -15,7 +15,7 @@ type ReportActionsListItemRendererProps = { reportActions: ReportAction[]; /** The report's parentReportAction */ - parentReportAction: OnyxEntry; + parentReportAction: OnyxEntry | null; /** The transaction thread report's parentReportAction */ parentReportActionForTransactionThread: OnyxEntry; diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index d3eaf9136164..5fd65b6fb6b1 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -53,7 +53,7 @@ type ReportActionsViewProps = ReportActionsViewOnyxProps & { reportActions?: OnyxTypes.ReportAction[]; /** The report's parentReportAction */ - parentReportAction: OnyxEntry; + parentReportAction: OnyxEntry | null; /** The report metadata loading states */ isLoadingInitialReportActions?: boolean; diff --git a/src/pages/home/report/ReportFooter.tsx b/src/pages/home/report/ReportFooter.tsx index ac56fe916bc9..6070a87f8f92 100644 --- a/src/pages/home/report/ReportFooter.tsx +++ b/src/pages/home/report/ReportFooter.tsx @@ -43,7 +43,7 @@ type ReportFooterProps = ReportFooterOnyxProps & { reportNameValuePairs?: OnyxEntry; /** The last report action */ - lastReportAction?: OnyxEntry; + lastReportAction?: OnyxEntry | null; /** Whether the chat is empty */ isEmptyChat?: boolean; From a93bafdcfe26d8396d2a189101c5079a28a9f0de Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 18:12:58 +0200 Subject: [PATCH 30/46] fix: ReportActionCompose --- src/libs/ReportUtils.ts | 2 +- src/pages/home/report/ReportActionItem.tsx | 4 ++-- src/pages/home/report/ReportActionItemSingle.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 70f02291bc69..036df1a148eb 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6704,7 +6704,7 @@ function canLeaveChat(report: OnyxEntry, policy: OnyxEntry): boo return (isChatThread(report) && !!report?.notificationPreference?.length) || isUserCreatedPolicyRoom(report) || isNonAdminOrOwnerOfPolicyExpenseChat(report, policy); } -function getReportActionActorAccountID(reportAction: OnyxEntry, iouReport: OnyxEntry | undefined): number | undefined { +function getReportActionActorAccountID(reportAction: OnyxInputOrEntry, iouReport: OnyxInputOrEntry | undefined): number | undefined { switch (reportAction?.actionName) { case CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW: return iouReport ? iouReport.managerID : reportAction?.actorAccountID; diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index b645f6410051..99831136332d 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -110,7 +110,7 @@ type ReportActionItemOnyxProps = { transaction: OnyxEntry; /** The transaction (linked with the report action) route error */ - linkedTransactionRouteError: OnyxEntry; + linkedTransactionRouteError: NonNullable> | null; }; type ReportActionItemProps = { @@ -1069,7 +1069,7 @@ export default withOnyx({ }, linkedTransactionRouteError: { key: ({action}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${(action as OnyxTypes.OriginalMessageIOU)?.originalMessage?.IOUTransactionID ?? 0}`, - selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? undefined, + selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? null, }, modal: { key: ONYXKEYS.MODAL, diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index f71db06c2d44..dc6e8d8d876c 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -30,7 +30,7 @@ import ReportActionItemFragment from './ReportActionItemFragment'; type ReportActionItemSingleProps = Partial & { /** All the data of the action */ - action: OnyxEntry; + action: OnyxEntry | null; /** Styles for the outermost View */ wrapperStyle?: StyleProp; From ad4186a0630e3521f68e0fa385529d52027dff1f Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 18:17:01 +0200 Subject: [PATCH 31/46] fix: props --- src/pages/home/report/ReportActionItem.tsx | 2 +- src/pages/home/report/ReportActionsList.tsx | 2 +- src/pages/home/report/ReportActionsListItemRenderer.tsx | 2 +- src/pages/home/report/ReportActionsView.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 99831136332d..d3a8fae497fa 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -130,7 +130,7 @@ type ReportActionItemProps = { /** The transaction thread report's parentReportAction */ /** It's used by withOnyx HOC */ // eslint-disable-next-line react/no-unused-prop-types - parentReportActionForTransactionThread?: OnyxEntry; + parentReportActionForTransactionThread?: OnyxEntry | null; /** All the data of the action item */ action: OnyxTypes.ReportAction; diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 6378c4bacfeb..7e3835f265f4 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -51,7 +51,7 @@ type ReportActionsListProps = WithCurrentUserPersonalDetailsProps & { parentReportAction: OnyxEntry | null; /** The transaction thread report's parentReportAction */ - parentReportActionForTransactionThread: OnyxEntry; + parentReportActionForTransactionThread: OnyxEntry | null; /** Sorted actions prepared for display */ sortedReportActions: OnyxTypes.ReportAction[]; diff --git a/src/pages/home/report/ReportActionsListItemRenderer.tsx b/src/pages/home/report/ReportActionsListItemRenderer.tsx index 303dfc4a4bd2..0390536e98a9 100644 --- a/src/pages/home/report/ReportActionsListItemRenderer.tsx +++ b/src/pages/home/report/ReportActionsListItemRenderer.tsx @@ -18,7 +18,7 @@ type ReportActionsListItemRendererProps = { parentReportAction: OnyxEntry | null; /** The transaction thread report's parentReportAction */ - parentReportActionForTransactionThread: OnyxEntry; + parentReportActionForTransactionThread: OnyxEntry | null; /** Position index of the report action in the overall report FlatList view */ index: number; diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 5fd65b6fb6b1..cea902cee9ec 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -164,7 +164,7 @@ function ReportActionsView({ const parentReportActionForTransactionThread = useMemo( () => isEmptyObject(transactionThreadReportActions) - ? undefined + ? null : (allReportActions.find((action) => action.reportActionID === transactionThreadReport?.parentReportActionID) as OnyxEntry), [allReportActions, transactionThreadReportActions, transactionThreadReport?.parentReportActionID], ); From 3d8e6f64a1e36d20cc93cad9d9a38dab41c8848a Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 18:39:57 +0200 Subject: [PATCH 32/46] remove unnecessary null coallescing --- src/components/SignInButtons/AppleSignIn/index.android.tsx | 2 +- src/components/SignInButtons/AppleSignIn/index.ios.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/SignInButtons/AppleSignIn/index.android.tsx b/src/components/SignInButtons/AppleSignIn/index.android.tsx index 6b6f9d355ce2..ec669590d029 100644 --- a/src/components/SignInButtons/AppleSignIn/index.android.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.android.tsx @@ -36,7 +36,7 @@ function appleSignInRequest(): Promise { function AppleSignIn() { const handleSignIn = () => { appleSignInRequest() - .then((token) => Session.beginAppleSignIn(token ?? null)) + .then((token) => Session.beginAppleSignIn(token)) .catch((error: Record) => { if (error.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) { return null; diff --git a/src/components/SignInButtons/AppleSignIn/index.ios.tsx b/src/components/SignInButtons/AppleSignIn/index.ios.tsx index 1a663aeecdba..4df8375edad8 100644 --- a/src/components/SignInButtons/AppleSignIn/index.ios.tsx +++ b/src/components/SignInButtons/AppleSignIn/index.ios.tsx @@ -35,7 +35,7 @@ function appleSignInRequest(): Promise { function AppleSignIn() { const handleSignIn = () => { appleSignInRequest() - .then((token) => Session.beginAppleSignIn(token ?? null)) + .then((token) => Session.beginAppleSignIn(token)) .catch((error: {code: AppleError}) => { if (error.code === appleAuth.Error.CANCELED) { return null; From e6bcbe6243a232adf547227841313bd61aba5db9 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 18:49:51 +0200 Subject: [PATCH 33/46] fix: OptionsListUtils --- .../shouldShowPushNotification.ts | 2 +- src/libs/OptionsListUtils.ts | 33 ++++++++++--------- src/libs/ReportActionsUtils.ts | 8 ++--- src/libs/ReportUtils.ts | 22 ++++++------- src/libs/TransactionUtils.ts | 2 +- 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts index 8dbc28f035a6..fd6029857ded 100644 --- a/src/libs/Notification/PushNotification/shouldShowPushNotification.ts +++ b/src/libs/Notification/PushNotification/shouldShowPushNotification.ts @@ -24,7 +24,7 @@ export default function shouldShowPushNotification(pushPayload: PushPayload): bo return true; } - const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData(data.onyxData); + const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData(data.onyxData ?? null); const shouldShow = Report.shouldShowReportActionNotification(String(data.reportID), reportAction, true); Log.info(`[PushNotification] ${shouldShow ? 'Showing' : 'Not showing'} notification`); return shouldShow; diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index a14db7d4e501..fddca6c9caf9 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -15,6 +15,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type { Beta, Login, + OnyxInputOrEntry, PersonalDetails, PersonalDetailsList, Policy, @@ -361,7 +362,7 @@ function getAvatarsForAccountIDs(accountIDs: number[], personalDetails: OnyxEntr * Returns the personal details for an array of accountIDs * @returns keys of the object are emails, values are PersonalDetails objects. */ -function getPersonalDetailsForAccountIDs(accountIDs: number[] | undefined, personalDetails: OnyxEntry): PersonalDetailsList { +function getPersonalDetailsForAccountIDs(accountIDs: number[] | undefined, personalDetails: OnyxInputOrEntry): PersonalDetailsList { const personalDetailsForAccountIDs: PersonalDetailsList = {}; if (!personalDetails) { return personalDetailsForAccountIDs; @@ -478,7 +479,7 @@ function uniqFast(items: string[]): string[] { * Array.prototype.push.apply is faster than using the spread operator. */ function getSearchText( - report: OnyxEntry, + report: OnyxInputOrEntry, reportName: string, personalDetailList: Array>, isChatRoomOrPolicyExpenseChat: boolean, @@ -527,13 +528,13 @@ function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry< return Object.assign(prevReportActionErrors, action.errors); }, {}); - const parentReportAction: OnyxEntry = - !report?.parentReportID || !report?.parentReportActionID ? undefined : allReportActions?.[report.parentReportID ?? '']?.[report.parentReportActionID ?? '']; + const parentReportAction: OnyxEntry | null = + !report?.parentReportID || !report?.parentReportActionID ? null : allReportActions?.[report.parentReportID ?? '']?.[report.parentReportActionID ?? ''] ?? null; if (ReportActionUtils.wasActionTakenByCurrentUser(parentReportAction) && ReportActionUtils.isTransactionThread(parentReportAction)) { - const transactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction?.originalMessage?.IOUTransactionID : undefined; + const transactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction?.originalMessage?.IOUTransactionID : null; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - if (TransactionUtils.hasMissingSmartscanFields(transaction) && !ReportUtils.isSettled(transaction?.reportID)) { + if (TransactionUtils.hasMissingSmartscanFields(transaction ?? null) && !ReportUtils.isSettled(transaction?.reportID)) { reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage'); } } else if ((ReportUtils.isIOUReport(report) || ReportUtils.isExpenseReport(report)) && report?.ownerAccountID === currentUserAccountID) { @@ -628,7 +629,7 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails } } } else if (ReportActionUtils.isMoneyRequestAction(lastReportAction)) { - const properSchemaForMoneyRequestMessage = ReportUtils.getReportPreviewMessage(report, lastReportAction, true, false, undefined, true); + const properSchemaForMoneyRequestMessage = ReportUtils.getReportPreviewMessage(report, lastReportAction, true, false, null, true); lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForMoneyRequestMessage); } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); @@ -639,11 +640,11 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails ReportActionUtils.isMoneyRequestAction(reportAction), ); const reportPreviewMessage = ReportUtils.getReportPreviewMessage( - !isEmptyObject(iouReport) ? iouReport : undefined, + !isEmptyObject(iouReport) ? iouReport : null, lastIOUMoneyReportAction, true, ReportUtils.isChatReport(report), - undefined, + null, true, lastReportAction, ); @@ -678,8 +679,8 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails */ function createOption( accountIDs: number[], - personalDetails: OnyxEntry, - report: OnyxEntry, + personalDetails: OnyxInputOrEntry, + report: OnyxInputOrEntry, reportActions: ReportActions, config?: PreviewConfig, ): ReportUtils.OptionData { @@ -806,7 +807,7 @@ function createOption( // Disabling this line for safeness as nullish coalescing works only if the value is undefined or null // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing result.searchText = getSearchText(report, reportName, personalDetailList, !!result.isChatRoom || !!result.isPolicyExpenseChat, !!result.isThread); - result.icons = ReportUtils.getIcons(report, personalDetails, personalDetail?.avatar, personalDetail?.login, personalDetail?.accountID, undefined); + result.icons = ReportUtils.getIcons(report, personalDetails, personalDetail?.avatar, personalDetail?.login, personalDetail?.accountID, null); result.subtitle = subtitle; return result; @@ -856,7 +857,7 @@ function getReportOption(participant: Participant): ReportUtils.OptionData { * Get the option for a policy expense report. */ function getPolicyExpenseReportOption(participant: Participant | ReportUtils.OptionData): ReportUtils.OptionData { - const expenseReport = ReportUtils.isPolicyExpenseChat(participant) ? ReportUtils.getReport(participant.reportID) : undefined; + const expenseReport = ReportUtils.isPolicyExpenseChat(participant) ? ReportUtils.getReport(participant.reportID) : null; const visibleParticipantAccountIDs = Object.entries(expenseReport?.participants ?? {}) .filter(([, reportParticipant]) => reportParticipant && !reportParticipant.hidden) @@ -865,7 +866,7 @@ function getPolicyExpenseReportOption(participant: Participant | ReportUtils.Opt const option = createOption( visibleParticipantAccountIDs, allPersonalDetails ?? {}, - !isEmptyObject(expenseReport) ? expenseReport : undefined, + !isEmptyObject(expenseReport) ? expenseReport : null, {}, { showChatPreviewLine: false, @@ -1662,7 +1663,7 @@ function getUserToInviteOption({ login: searchValue, }, }; - const userToInvite = createOption([optimisticAccountID], personalDetailsExtended, undefined, reportActions, { + const userToInvite = createOption([optimisticAccountID], personalDetailsExtended, null, reportActions, { showChatPreviewLine, }); userToInvite.isOptimisticAccount = true; @@ -1795,7 +1796,7 @@ function getOptions( const {parentReportID, parentReportActionID} = report ?? {}; const canGetParentReport = parentReportID && parentReportActionID && allReportActions; const parentReportActions = allReportActions ? allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`] ?? {} : {}; - const parentReportAction = canGetParentReport ? parentReportActions[parentReportActionID] : undefined; + const parentReportAction = canGetParentReport ? parentReportActions[parentReportActionID] ?? null : null; const doesReportHaveViolations = (betas?.includes(CONST.BETAS.VIOLATIONS) && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction)) ?? false; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 782d3daffaa1..cdfb28ebe1d5 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -749,16 +749,16 @@ function getFirstVisibleReportActionID(sortedReportActions: ReportAction[] = [], /** * @returns The latest report action in the `onyxData` or `null` if one couldn't be found */ -function getLatestReportActionFromOnyxData(onyxData: OnyxUpdate[] | undefined): OnyxEntry { +function getLatestReportActionFromOnyxData(onyxData: OnyxUpdate[] | null): NonNullable> | null { const reportActionUpdate = onyxData?.find((onyxUpdate) => onyxUpdate.key.startsWith(ONYXKEYS.COLLECTION.REPORT_ACTIONS)); if (!reportActionUpdate) { - return undefined; + return null; } const reportActions = Object.values((reportActionUpdate.value as ReportActions) ?? {}); const sortedReportActions = getSortedReportActions(reportActions); - return sortedReportActions.at(-1); + return sortedReportActions.at(-1) ?? null; } /** @@ -1239,7 +1239,7 @@ function isLinkedTransactionHeld(reportActionID: string, reportID: string): bool /** * Check if the current user is the requestor of the action */ -function wasActionTakenByCurrentUser(reportAction: OnyxEntry): boolean { +function wasActionTakenByCurrentUser(reportAction: OnyxInputOrEntry): boolean { return currentUserAccountID === reportAction?.actorAccountID; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 036df1a148eb..e77e42e98317 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -675,7 +675,7 @@ function getPolicyType(report: OnyxInputOrEntry, policies: OnyxCollectio /** * Get the policy name from a given report */ -function getPolicyName(report: OnyxEntry | undefined | EmptyObject, returnEmptyIfNotFound = false, policy?: OnyxEntry): string { +function getPolicyName(report: OnyxInputOrEntry | undefined | EmptyObject, returnEmptyIfNotFound = false, policy?: OnyxInputOrEntry): string { const noPolicyFound = returnEmptyIfNotFound ? '' : Localize.translateLocal('workspace.common.unavailable'); if (isEmptyObject(report)) { return noPolicyFound; @@ -1753,7 +1753,7 @@ function getDefaultGroupAvatar(reportID?: string): IconAsset { * Returns the appropriate icons for the given chat report using the stored personalDetails. * The Avatar sources can be URLs or Icon components according to the chat type. */ -function getIconsForParticipants(participants: number[], personalDetails: OnyxEntry): Icon[] { +function getIconsForParticipants(participants: number[], personalDetails: OnyxInputOrEntry): Icon[] { const participantDetails: ParticipantDetails[] = []; const participantsList = participants || []; @@ -1796,7 +1796,7 @@ function getIconsForParticipants(participants: number[], personalDetails: OnyxEn /** * Given a report, return the associated workspace icon. */ -function getWorkspaceIcon(report: OnyxEntry, policy?: OnyxEntry): Icon { +function getWorkspaceIcon(report: OnyxInputOrEntry, policy?: OnyxInputOrEntry): Icon { const workspaceName = getPolicyName(report, false, policy); const policyExpenseChatAvatarSource = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL @@ -1942,12 +1942,12 @@ function getParticipants(reportID: string) { * The Avatar sources can be URLs or Icon components according to the chat type. */ function getIcons( - report: OnyxEntry, - personalDetails: OnyxEntry, + report: OnyxInputOrEntry, + personalDetails: OnyxInputOrEntry, defaultIcon: AvatarSource | null = null, defaultName = '', defaultAccountID = -1, - policy?: OnyxEntry, + policy?: OnyxInputOrEntry, ): Icon[] { if (isEmptyObject(report)) { const fallbackIcon: Icon = { @@ -2863,13 +2863,13 @@ function getTransactionReportName(reportAction: OnyxEntry | EmptyObject, - iouReportAction: OnyxEntry | EmptyObject = {}, + report: OnyxInputOrEntry | EmptyObject, + iouReportAction: OnyxInputOrEntry | EmptyObject = {}, shouldConsiderScanningReceiptOrPendingRoute = false, isPreviewMessageForParentChatReport = false, - policy?: OnyxEntry, + policy?: OnyxInputOrEntry, isForListPreview = false, - originalReportAction: OnyxEntry | EmptyObject = iouReportAction, + originalReportAction: OnyxInputOrEntry | EmptyObject = iouReportAction, ): string { const reportActionMessage = iouReportAction?.message?.[0]?.html ?? ''; @@ -5170,7 +5170,7 @@ function shouldHideReport(report: OnyxEntry, currentReportId: string): b /** * Checks to see if a report's parentAction is an expense that contains a violation */ -function doesTransactionThreadHaveViolations(report: OnyxEntry, transactionViolations: OnyxCollection, parentReportAction: OnyxEntry): boolean { +function doesTransactionThreadHaveViolations(report: OnyxInputOrEntry, transactionViolations: OnyxCollection, parentReportAction: OnyxInputOrEntry): boolean { if (parentReportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { return false; } diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 69cbb9d5f6cb..41689f48bd15 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -508,7 +508,7 @@ function didRceiptScanSucceed(transaction: OnyxEntry): boolean { /** * Check if the transaction has a non-smartscanning receipt and is missing required fields */ -function hasMissingSmartscanFields(transaction: OnyxEntry): boolean { +function hasMissingSmartscanFields(transaction: OnyxInputOrEntry): boolean { return Boolean(transaction && !isDistanceRequest(transaction) && !isReceiptBeingScanned(transaction) && areRequiredFieldsEmpty(transaction)); } From 57ae9612c118fb52302459b19b47f04bc9f8e7a3 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 19:02:46 +0200 Subject: [PATCH 34/46] fix: RemoveEMptyActionDrafts --- src/libs/migrations/RemoveEmptyReportActionsDrafts.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/migrations/RemoveEmptyReportActionsDrafts.ts b/src/libs/migrations/RemoveEmptyReportActionsDrafts.ts index 24debda2e492..e063bdd67093 100644 --- a/src/libs/migrations/RemoveEmptyReportActionsDrafts.ts +++ b/src/libs/migrations/RemoveEmptyReportActionsDrafts.ts @@ -1,5 +1,5 @@ import _ from 'lodash'; -import type {OnyxEntry} from 'react-native-onyx'; +import type {OnyxEntry, OnyxInputValue} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import Log from '@libs/Log'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -24,7 +24,7 @@ export default function (): Promise { return resolve(); } - const newReportActionsDrafts: Record> = {}; + const newReportActionsDrafts: Record> = {}; Object.entries(allReportActionsDrafts).forEach(([onyxKey, reportActionDrafts]) => { const newReportActionsDraftsForReport: Record = {}; @@ -54,7 +54,7 @@ export default function (): Promise { if (isEmptyObject(newReportActionsDraftsForReport)) { Log.info('[Migrate Onyx] NO REMAINING'); // Clear if there are no drafts remaining - newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = undefined; + newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = null; } else if (hasUnmigratedDraft) { // Only migrate if there are unmigrated drafts, there's no need to overwrite this onyx key with the same data newReportActionsDrafts[onyxKey as ReportActionsDraftsKey] = newReportActionsDraftsForReport; From afce282578001b4730ca729004ab8f83727d51f7 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 19:05:01 +0200 Subject: [PATCH 35/46] fix: null values --- src/libs/migrations/PronounsMigration.ts | 6 +++--- src/libs/migrations/TransactionBackupsToCollection.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/migrations/PronounsMigration.ts b/src/libs/migrations/PronounsMigration.ts index cf9ffbed4ffb..81744fde298c 100644 --- a/src/libs/migrations/PronounsMigration.ts +++ b/src/libs/migrations/PronounsMigration.ts @@ -17,13 +17,13 @@ function getCurrentUserAccountIDFromOnyx(): Promise { }); } -function getCurrentUserPersonalDetailsFromOnyx(currentUserAccountID: number): Promise> { +function getCurrentUserPersonalDetailsFromOnyx(currentUserAccountID: number): Promise> | null> { return new Promise((resolve) => { const connectionID = Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, callback: (val) => { Onyx.disconnect(connectionID); - return resolve(val?.[currentUserAccountID] ?? undefined); + return resolve(val?.[currentUserAccountID] ?? null); }, }); }); @@ -35,7 +35,7 @@ function getCurrentUserPersonalDetailsFromOnyx(currentUserAccountID: number): Pr export default function (): Promise { return getCurrentUserAccountIDFromOnyx() .then(getCurrentUserPersonalDetailsFromOnyx) - .then((currentUserPersonalDetails: OnyxEntry) => { + .then((currentUserPersonalDetails) => { if (!currentUserPersonalDetails) { return; } diff --git a/src/libs/migrations/TransactionBackupsToCollection.ts b/src/libs/migrations/TransactionBackupsToCollection.ts index 6e823f88acb5..53fa7e855e72 100644 --- a/src/libs/migrations/TransactionBackupsToCollection.ts +++ b/src/libs/migrations/TransactionBackupsToCollection.ts @@ -1,4 +1,4 @@ -import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import type {OnyxCollection, OnyxCollectionInputValue, OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import Log from '@libs/Log'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -26,7 +26,7 @@ export default function (): Promise { return resolve(); } - const onyxData: OnyxCollection = {}; + const onyxData: OnyxCollectionInputValue = {}; // Find all the transaction backups available Object.keys(transactions).forEach((transactionOnyxKey: string) => { @@ -38,7 +38,7 @@ export default function (): Promise { onyxData[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`] = transaction; // Delete the transaction backup stored in the transaction collection - onyxData[transactionOnyxKey] = undefined; + onyxData[transactionOnyxKey] = null; } }); From 38f0931968123a0819c901cda25eee0893d54053 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 19:07:11 +0200 Subject: [PATCH 36/46] fix: FlagCommentPage --- src/libs/ReportUtils.ts | 16 ++++++++++------ src/pages/FlagCommentPage.tsx | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e77e42e98317..0d3cd42feb16 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1036,7 +1036,7 @@ function isThread(report: OnyxInputOrEntry): boolean { /** * Returns true if report is of type chat and has a parent and is therefore a Thread. */ -function isChatThread(report: OnyxEntry): boolean { +function isChatThread(report: OnyxInputOrEntry): boolean { return isThread(report) && report?.type === CONST.REPORT.TYPE.CHAT; } @@ -1059,7 +1059,7 @@ function isSystemChat(report: OnyxEntry): boolean { /** * Only returns true if this is our main 1:1 DM report with Concierge */ -function isConciergeChatReport(report: OnyxEntry): boolean { +function isConciergeChatReport(report: OnyxInputOrEntry): boolean { const participantAccountIDs = Object.keys(report?.participants ?? {}) .map(Number) .filter((accountID) => accountID !== currentUserAccountID); @@ -5170,7 +5170,11 @@ function shouldHideReport(report: OnyxEntry, currentReportId: string): b /** * Checks to see if a report's parentAction is an expense that contains a violation */ -function doesTransactionThreadHaveViolations(report: OnyxInputOrEntry, transactionViolations: OnyxCollection, parentReportAction: OnyxInputOrEntry): boolean { +function doesTransactionThreadHaveViolations( + report: OnyxInputOrEntry, + transactionViolations: OnyxCollection, + parentReportAction: OnyxInputOrEntry, +): boolean { if (parentReportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { return false; } @@ -5407,7 +5411,7 @@ function getAllPolicyReports(policyID: string): Array> { /** * Returns true if Chronos is one of the chat participants (1:1) */ -function chatIncludesChronos(report: OnyxEntry | EmptyObject): boolean { +function chatIncludesChronos(report: OnyxInputOrEntry | EmptyObject): boolean { const participantAccountIDs = Object.keys(report?.participants ?? {}).map(Number); return participantAccountIDs.includes(CONST.ACCOUNT_ID.CHRONOS); } @@ -5419,7 +5423,7 @@ function chatIncludesChronos(report: OnyxEntry | EmptyObject): boolean { * - It's a welcome message whisper * - It's an ADD_COMMENT that is not an attachment */ -function canFlagReportAction(reportAction: OnyxEntry, reportID: string | undefined): boolean { +function canFlagReportAction(reportAction: OnyxInputOrEntry, reportID: string | undefined): boolean { let report = getReport(reportID); // If the childReportID exists in reportAction and is equal to the reportID, @@ -5452,7 +5456,7 @@ function canFlagReportAction(reportAction: OnyxEntry, reportID: st /** * Whether flag comment page should show */ -function shouldShowFlagComment(reportAction: OnyxEntry, report: OnyxEntry): boolean { +function shouldShowFlagComment(reportAction: OnyxInputOrEntry, report: OnyxInputOrEntry): boolean { return ( canFlagReportAction(reportAction, report?.reportID) && !isArchivedRoom(report) && diff --git a/src/pages/FlagCommentPage.tsx b/src/pages/FlagCommentPage.tsx index 39e97924c53d..53aac0ce2a8b 100644 --- a/src/pages/FlagCommentPage.tsx +++ b/src/pages/FlagCommentPage.tsx @@ -109,7 +109,7 @@ function FlagCommentPage({parentReportAction, route, report, parentReport, repor }, ]; - const getActionToFlag = useCallback((): OnyxTypes.ReportAction | undefined => { + const getActionToFlag = useCallback((): OnyxTypes.ReportAction | null => { let reportAction = reportActions?.[`${route.params.reportActionID.toString()}`]; // Handle threads if needed @@ -118,7 +118,7 @@ function FlagCommentPage({parentReportAction, route, report, parentReport, repor } if (!reportAction) { - return; + return null; } return reportAction; From a90bfa23c90261c0558d59669b65e8acd5434be5 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 19:11:59 +0200 Subject: [PATCH 37/46] fix: lastReportAction --- src/pages/home/ReportScreen.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index b8f3fd4f03f3..bf8b20f97e9a 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -290,10 +290,10 @@ function ReportScreen({ const hasHelpfulErrors = Object.keys(report?.errorFields ?? {}).some((key) => key !== 'notFound'); const shouldHideReport = !hasHelpfulErrors && !ReportUtils.canAccessReport(report, policies, betas); - const lastReportAction: OnyxEntry | null = useMemo( + const lastReportAction: NonNullable> | null = useMemo( () => reportActions.length - ? [...reportActions, parentReportAction].find((action) => ReportUtils.canEditReportAction(action) && !ReportActionsUtils.isMoneyRequestAction(action)) + ? [...reportActions, parentReportAction].find((action) => ReportUtils.canEditReportAction(action) && !ReportActionsUtils.isMoneyRequestAction(action)) ?? null : null, [reportActions, parentReportAction], ); From 7a44c68736571263273ea514a804409eb6c9cff0 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 19:18:34 +0200 Subject: [PATCH 38/46] fix: BaseReportActionContextMenu --- src/languages/types.ts | 8 ++++---- src/libs/ReportUtils.ts | 4 ++-- .../report/ContextMenu/BaseReportActionContextMenu.tsx | 6 +++--- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/languages/types.ts b/src/languages/types.ts index ef984b9e640a..c364b56a8741 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -1,5 +1,5 @@ import type {OnyxEntry} from 'react-native-onyx'; -import type {ReportAction} from '@src/types/onyx'; +import type {OnyxInputOrEntry, ReportAction} from '@src/types/onyx'; import type {Unit} from '@src/types/onyx/Policy'; import type en from './en'; @@ -41,15 +41,15 @@ type LocalTimeParams = { }; type EditActionParams = { - action: OnyxEntry; + action: OnyxInputOrEntry; }; type DeleteActionParams = { - action: OnyxEntry; + action: OnyxInputOrEntry; }; type DeleteConfirmationParams = { - action: OnyxEntry; + action: OnyxInputOrEntry; }; type BeginningOfChatHistoryDomainRoomPartOneParams = { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0d3cd42feb16..48f48bbeef2b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1362,7 +1362,7 @@ function isWorkspaceThread(report: OnyxEntry): boolean { /** * Returns true if reportAction is the first chat preview of a Thread */ -function isThreadFirstChat(reportAction: OnyxEntry, reportID: string): boolean { +function isThreadFirstChat(reportAction: OnyxInputOrEntry, reportID: string): boolean { return reportAction?.childReportID?.toString() === reportID; } @@ -5935,7 +5935,7 @@ function canUserPerformWriteAction(report: OnyxEntry, reportNameValuePai /** * Returns ID of the original report from which the given reportAction is first created. */ -function getOriginalReportID(reportID: string, reportAction: OnyxEntry): string | undefined { +function getOriginalReportID(reportID: string, reportAction: OnyxInputOrEntry): string | undefined { const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; const currentReportAction = reportActions?.[reportAction?.reportActionID ?? ''] ?? null; const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(reportID, reportActions ?? ([] as ReportAction[])); diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 7cdd79b3b3b9..1454d7ff1beb 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -127,11 +127,11 @@ function BaseReportActionContextMenu({ const {isOffline} = useNetwork(); const threedotRef = useRef(null); - const reportAction: OnyxEntry = useMemo(() => { + const reportAction: NonNullable> | null = useMemo(() => { if (isEmptyObject(reportActions) || reportActionID === '0') { - return; + return null; } - return reportActions[reportActionID]; + return reportActions[reportActionID] ?? null; }, [reportActions, reportActionID]); const shouldEnableArrowNavigation = !isMini && (isVisible || shouldKeepOpen); diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index efcd08c35a00..d232b4bc789b 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -28,7 +28,7 @@ import * as Report from '@userActions/Report'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; -import type {Beta, ReportAction, ReportActionReactions, Transaction} from '@src/types/onyx'; +import type {Beta, OnyxInputOrEntry, ReportAction, ReportActionReactions, Transaction} from '@src/types/onyx'; import type IconAsset from '@src/types/utils/IconAsset'; import type {ContextMenuAnchor} from './ReportActionContextMenu'; import {hideContextMenu, showDeleteModal} from './ReportActionContextMenu'; @@ -54,9 +54,9 @@ function setClipboardMessage(content: string) { type ShouldShow = ( type: string, - reportAction: OnyxEntry, + reportAction: OnyxInputOrEntry, isArchivedRoom: boolean, - betas: OnyxEntry, + betas: OnyxInputOrEntry, menuTarget: MutableRefObject | undefined, isChronosReport: boolean, reportID: string, From 263dd3cb749658d56d463549b64a5358ef32eace Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 19:21:06 +0200 Subject: [PATCH 39/46] fix: MoneyRequestView --- src/components/ReportActionItem/MoneyRequestView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index b527e205d680..2987638c759d 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -99,7 +99,7 @@ function MoneyRequestView({ const session = useSession(); const {isOffline} = useNetwork(); const {translate, toLocaleDigit} = useLocalize(); - const parentReportAction = parentReportActions?.[report.parentReportActionID ?? '']; + const parentReportAction = parentReportActions?.[report.parentReportActionID ?? ''] ?? null; const isTrackExpense = ReportUtils.isTrackExpenseReport(report); const {canUseViolations, canUseP2PDistanceRequests} = usePermissions(isTrackExpense ? CONST.IOU.TYPE.TRACK : undefined); const moneyRequestReport = parentReport; From 7afdf8fd48e0011b36010136a22243e5105f6a63 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 19:21:10 +0200 Subject: [PATCH 40/46] ReportUtils --- src/libs/ReportActionsUtils.ts | 2 +- src/libs/ReportUtils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index cdfb28ebe1d5..867a0ae6c11a 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -857,7 +857,7 @@ function isTrackExpenseAction(reportAction: OnyxEntry): boolean { +function isPayAction(reportAction: OnyxInputOrEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && (reportAction.originalMessage as IOUMessage).type === CONST.IOU.REPORT_ACTION_TYPE.PAY; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 48f48bbeef2b..4f9523653ac2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2618,7 +2618,7 @@ function getTransactionCommentObject(transaction: OnyxEntry): Comme * This is used in conjunction with canEditRestrictedField to control editing of specific fields like amount, currency, created, receipt, and distance. * On its own, it only controls allowing/disallowing navigating to the editing pages or showing/hiding the 'Edit' icon on report actions */ -function canEditMoneyRequest(reportAction: OnyxEntry): boolean { +function canEditMoneyRequest(reportAction: OnyxInputOrEntry): boolean { const isDeleted = ReportActionsUtils.isDeletedAction(reportAction); if (isDeleted) { @@ -2669,7 +2669,7 @@ function canEditMoneyRequest(reportAction: OnyxEntry): boolean { * Checks if the current user can edit the provided property of an expense * */ -function canEditFieldOfMoneyRequest(reportAction: OnyxEntry, fieldToEdit: ValueOf): boolean { +function canEditFieldOfMoneyRequest(reportAction: OnyxInputOrEntry, fieldToEdit: ValueOf): boolean { // A list of fields that cannot be edited by anyone, once an expense has been settled const restrictedFields: string[] = [ CONST.EDIT_REQUEST_FIELD.AMOUNT, From 007402af15ce88158ed86e3134c6f14aab1872eb Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 21:25:15 +0200 Subject: [PATCH 41/46] fix: remaining files --- src/components/ShowContextMenuContext.ts | 2 +- src/libs/DistanceRequestUtils.ts | 2 +- src/libs/PolicyUtils.ts | 6 +++--- .../ContextMenu/PopoverReportActionContextMenu.tsx | 6 +++--- .../home/report/withReportAndReportActionOrNotFound.tsx | 8 ++++---- src/pages/iou/request/step/IOURequestStepCategory.tsx | 2 +- src/pages/iou/request/step/IOURequestStepDescription.tsx | 2 +- src/pages/workspace/AccessOrNotFoundWrapper.tsx | 9 ++++++--- 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/components/ShowContextMenuContext.ts b/src/components/ShowContextMenuContext.ts index ebd6f65e3aa0..7ae3ca4fb825 100644 --- a/src/components/ShowContextMenuContext.ts +++ b/src/components/ShowContextMenuContext.ts @@ -18,7 +18,7 @@ type ShowContextMenuContextProps = { }; const ShowContextMenuContext = createContext({ - anchor: undefined, + anchor: null, report: undefined, action: undefined, transactionThreadReport: undefined, diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index 3d48562451e0..2ace3b1b301a 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -43,7 +43,7 @@ const METERS_TO_MILES = 0.000621371; // There are approximately 0.000621371 mile function getMileageRates(policy: OnyxInputOrEntry, includeDisabledRates = false): Record { const mileageRates: Record = {}; - if (!policy?.customUnits) { + if (!policy || !policy?.customUnits) { return mileageRates; } diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index c1d299743a08..3316be85a94a 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -34,7 +34,7 @@ Onyx.connect({ * Filter out the active policies, which will exclude policies with pending deletion * These are policies that we can use to create reports with in NewDot. */ -function getActivePolicies(policies: OnyxCollection): Policy[] { +function getActivePolicies(policies: OnyxCollection | null): Policy[] { return Object.values(policies ?? {}).filter( (policy): policy is Policy => !!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id, ); @@ -406,13 +406,13 @@ function getPolicy(policyID: string | undefined): Policy | EmptyObject { } /** Return active policies where current user is an admin */ -function getActiveAdminWorkspaces(policies: OnyxCollection): Policy[] { +function getActiveAdminWorkspaces(policies: OnyxCollection | null): Policy[] { const activePolicies = getActivePolicies(policies); return activePolicies.filter((policy) => shouldShowPolicy(policy, NetworkStore.isOffline()) && isPolicyAdmin(policy)); } /** Whether the user can send invoice */ -function canSendInvoice(policies: OnyxCollection): boolean { +function canSendInvoice(policies: OnyxCollection | null): boolean { return getActiveAdminWorkspaces(policies).length > 0; } diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx index d927c3088e75..177e5922189d 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx @@ -34,7 +34,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef(); - const reportActionRef = useRef>(undefined); + const reportActionRef = useRef> | null>(null); const reportActionIDRef = useRef('0'); const originalReportIDRef = useRef('0'); const selectionRef = useRef(''); @@ -131,7 +131,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef { reportActionIDRef.current = '0'; - reportActionRef.current = undefined; + reportActionRef.current = null; }; /** @@ -294,7 +294,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef; /** The report's parentReportAction */ - parentReportAction: OnyxEntry; + parentReportAction: NonNullable> | null; /** The policies which the user has access to */ policies: OnyxCollection; @@ -129,12 +129,12 @@ export default function `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : 0}`, - selector: (parentReportActions: OnyxEntry, props?: WithOnyxState): OnyxEntry => { + selector: (parentReportActions: OnyxEntry, props?: WithOnyxState): NonNullable> | null => { const parentReportActionID = props?.report?.parentReportActionID; if (!parentReportActionID) { - return; + return null; } - return parentReportActions?.[parentReportActionID]; + return parentReportActions?.[parentReportActionID] ?? null; }, canEvict: false, }, diff --git a/src/pages/iou/request/step/IOURequestStepCategory.tsx b/src/pages/iou/request/step/IOURequestStepCategory.tsx index f0d8cba2f297..fd5c60537c38 100644 --- a/src/pages/iou/request/step/IOURequestStepCategory.tsx +++ b/src/pages/iou/request/step/IOURequestStepCategory.tsx @@ -89,7 +89,7 @@ function IOURequestStepCategory({ const transactionCategory = ReportUtils.getTransactionDetails(isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction : transaction)?.category; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const reportAction = reportActions?.[report?.parentReportActionID || reportActionID]; + const reportAction = reportActions?.[report?.parentReportActionID || reportActionID] ?? null; const shouldShowCategory = (ReportUtils.isReportInGroupPolicy(report) || ReportUtils.isGroupPolicy(policy?.type ?? '')) && diff --git a/src/pages/iou/request/step/IOURequestStepDescription.tsx b/src/pages/iou/request/step/IOURequestStepDescription.tsx index 5ff15b4c57e9..e8388a92e602 100644 --- a/src/pages/iou/request/step/IOURequestStepDescription.tsx +++ b/src/pages/iou/request/step/IOURequestStepDescription.tsx @@ -138,7 +138,7 @@ function IOURequestStepDescription({ }; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- nullish coalescing doesn't achieve the same result in this case - const reportAction = reportActions?.[report?.parentReportActionID || reportActionID]; + const reportAction = reportActions?.[report?.parentReportActionID || reportActionID] ?? null; const isEditing = action === CONST.IOU.ACTION.EDIT; const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; const canEditSplitBill = isSplitBill && reportAction && session?.accountID === reportAction.actorAccountID && TransactionUtils.areRequiredFieldsEmpty(transaction); diff --git a/src/pages/workspace/AccessOrNotFoundWrapper.tsx b/src/pages/workspace/AccessOrNotFoundWrapper.tsx index 0c08eba92b40..796a067833c0 100644 --- a/src/pages/workspace/AccessOrNotFoundWrapper.tsx +++ b/src/pages/workspace/AccessOrNotFoundWrapper.tsx @@ -28,7 +28,7 @@ const ACCESS_VARIANTS = { policy: OnyxEntry, login: string, report: OnyxEntry, - allPolicies: OnyxCollection, + allPolicies: NonNullable> | null, iouType?: IOUType, ) => !!iouType && @@ -36,7 +36,10 @@ const ACCESS_VARIANTS = { // Allow the user to submit the expense if we are submitting the expense in global menu or the report can create the expense (isEmptyObject(report?.reportID) || ReportUtils.canCreateRequest(report, policy, iouType)) && (iouType !== CONST.IOU.TYPE.INVOICE || PolicyUtils.canSendInvoice(allPolicies)), -} as const satisfies Record, iouType?: IOUType) => boolean>; +} as const satisfies Record< + string, + (policy: OnyxTypes.Policy, login: string, report: OnyxTypes.Report, allPolicies: NonNullable> | null, iouType?: IOUType) => boolean +>; type AccessVariant = keyof typeof ACCESS_VARIANTS; type AccessOrNotFoundWrapperOnyxProps = { @@ -122,7 +125,7 @@ function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps const isPageAccessible = accessVariants.reduce((acc, variant) => { const accessFunction = ACCESS_VARIANTS[variant]; - return acc && accessFunction(policy, login, report, allPolicies, iouType); + return acc && accessFunction(policy, login, report, allPolicies ?? null, iouType); }, true); const isPolicyNotAccessible = isEmptyObject(policy) || (Object.keys(policy).length === 1 && !isEmptyObject(policy.errors)) || !policy?.id; From 8ec33e815cffc0c881bc43a5d2c27b035ba82a78 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 5 Jun 2024 21:56:23 +0200 Subject: [PATCH 42/46] fix: remaining TS errors --- src/components/AvatarWithDisplayName.tsx | 2 +- src/libs/ReportActionsUtils.ts | 8 ++++---- src/libs/ReportUtils.ts | 10 +++++----- .../home/report/ContextMenu/ContextMenuActions.tsx | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/AvatarWithDisplayName.tsx b/src/components/AvatarWithDisplayName.tsx index 61a07a50736b..6b1849c2c77d 100644 --- a/src/components/AvatarWithDisplayName.tsx +++ b/src/components/AvatarWithDisplayName.tsx @@ -34,7 +34,7 @@ type AvatarWithDisplayNameProps = AvatarWithDisplayNamePropsWithOnyx & { report: OnyxEntry; /** The policy which the user has access to and which the report is tied to */ - policy?: OnyxEntry; + policy?: OnyxEntry | null; /** The size of the avatar */ size?: ValueOf; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 867a0ae6c11a..4e4a888c26e5 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -581,7 +581,7 @@ function shouldHideNewMarker(reportAction: OnyxEntry): boolean { * Checks whether an action is actionable track expense. * */ -function isActionableTrackExpense(reportAction: OnyxEntry): reportAction is ReportActionBase & OriginalMessageActionableTrackedExpenseWhisper { +function isActionableTrackExpense(reportAction: OnyxInputOrEntry): reportAction is ReportActionBase & OriginalMessageActionableTrackedExpenseWhisper { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER; } @@ -838,7 +838,7 @@ function isCreatedTaskReportAction(reportAction: OnyxEntry): boole /** * A helper method to identify if the message is deleted or not. */ -function isMessageDeleted(reportAction: OnyxEntry): boolean { +function isMessageDeleted(reportAction: OnyxInputOrEntry): boolean { return reportAction?.message?.[0]?.isDeletedParentAction ?? false; } @@ -849,7 +849,7 @@ function getNumberOfMoneyRequests(reportPreviewAction: OnyxEntry): return reportPreviewAction?.childMoneyRequestCount ?? 0; } -function isSplitBillAction(reportAction: OnyxEntry): boolean { +function isSplitBillAction(reportAction: OnyxInputOrEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && reportAction.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT; } @@ -953,7 +953,7 @@ function getAllReportActions(reportID: string): ReportActions { * Check whether a report action is an attachment (a file, such as an image or a zip). * */ -function isReportActionAttachment(reportAction: OnyxEntry): boolean { +function isReportActionAttachment(reportAction: OnyxInputOrEntry): boolean { const message = reportAction?.message?.[0]; if (reportAction && ('isAttachment' in reportAction || 'attachmentInfo' in reportAction)) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 4f9523653ac2..0b1750cbd647 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1497,7 +1497,7 @@ function getReportNotificationPreference(report: OnyxEntry): string | nu /** * Checks if the current user is the action's author */ -function isActionCreator(reportAction: OnyxEntry | Partial): boolean { +function isActionCreator(reportAction: OnyxInputOrEntry | Partial): boolean { return reportAction?.actorAccountID === currentUserAccountID; } @@ -1505,7 +1505,7 @@ function isActionCreator(reportAction: OnyxEntry | Partial | Partial): NotificationPreference { +function getChildReportNotificationPreference(reportAction: OnyxInputOrEntry | Partial): NotificationPreference { const childReportNotificationPreference = reportAction?.childReportNotificationPreference ?? ''; if (childReportNotificationPreference) { return childReportNotificationPreference; @@ -1541,7 +1541,7 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry): bool * Can only delete if the author is this user and the action is an ADD_COMMENT action or an IOU action in an unsettled report, or if the user is a * policy admin */ -function canDeleteReportAction(reportAction: OnyxEntry, reportID: string): boolean { +function canDeleteReportAction(reportAction: OnyxInputOrEntry, reportID: string): boolean { const report = getReport(reportID); const isActionOwner = reportAction?.actorAccountID === currentUserAccountID; @@ -6386,7 +6386,7 @@ function hasOnlyHeldExpenses(iouReportID: string): boolean { /** * Checks if thread replies should be displayed */ -function shouldDisplayThreadReplies(reportAction: OnyxEntry, reportID: string): boolean { +function shouldDisplayThreadReplies(reportAction: OnyxInputOrEntry, reportID: string): boolean { const hasReplies = (reportAction?.childVisibleActionCount ?? 0) > 0; return hasReplies && !!reportAction?.childCommenterCount && !isThreadFirstChat(reportAction, reportID); } @@ -6436,7 +6436,7 @@ function getNonHeldAndFullAmount(iouReport: OnyxInputOrEntry, policy: On * - The action is a whisper action and it's neither a report preview nor IOU action * - The action is the thread's first chat */ -function shouldDisableThread(reportAction: OnyxEntry, reportID: string): boolean { +function shouldDisableThread(reportAction: OnyxInputOrEntry, reportID: string): boolean { const isSplitBillAction = ReportActionsUtils.isSplitBillAction(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction); diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index d232b4bc789b..f6f006502b08 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -34,7 +34,7 @@ import type {ContextMenuAnchor} from './ReportActionContextMenu'; import {hideContextMenu, showDeleteModal} from './ReportActionContextMenu'; /** Gets the HTML version of the message in an action */ -function getActionHtml(reportAction: OnyxEntry): string { +function getActionHtml(reportAction: OnyxInputOrEntry): string { const message = reportAction?.message?.at(-1) ?? null; return message?.html ?? ''; } From f2bb29c8a2ad4aaabc9ea0af608c9491f8adea32 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 6 Jun 2024 12:23:26 +0200 Subject: [PATCH 43/46] rename SignInPage components (these were my edits originally) --- src/pages/signin/SignInPage.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/signin/SignInPage.tsx b/src/pages/signin/SignInPage.tsx index 112d350087b1..32d8b1d85740 100644 --- a/src/pages/signin/SignInPage.tsx +++ b/src/pages/signin/SignInPage.tsx @@ -126,7 +126,7 @@ function getRenderOptions({ }; } -function SignInPageInner({credentials, account, activeClients = [], preferredLocale, shouldEnableMaxHeight = true}: SignInPageInnerProps) { +function SignInPage({credentials, account, activeClients = [], preferredLocale, shouldEnableMaxHeight = true}: SignInPageInnerProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate, formatPhoneNumber} = useLocalize(); @@ -251,7 +251,7 @@ function SignInPageInner({credentials, account, activeClients = [], preferredLoc shouldShowOfflineIndicator={false} shouldEnableMaxHeight={shouldEnableMaxHeight} style={[styles.signInPage, StyleUtils.getSafeAreaPadding({...safeAreaInsets, bottom: 0, top: isInNarrowPaneModal ? 0 : safeAreaInsets.top}, 1)]} - testID={SignInPageInner.displayName} + testID={SignInPageThemeWrapper.displayName} > - @@ -309,6 +307,8 @@ function SignInPage(props: SignInPageProps) { ); } +SignInPageThemeWrapper.displayName = 'SignInPage'; + export default withOnyx({ account: {key: ONYXKEYS.ACCOUNT}, credentials: {key: ONYXKEYS.CREDENTIALS}, @@ -323,4 +323,4 @@ export default withOnyx({ preferredLocale: { key: ONYXKEYS.NVP_PREFERRED_LOCALE, }, -})(SignInPage); +})(SignInPageThemeWrapper); From 5ad5b932841589bd7e158f62ef21f83430511ba4 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 6 Jun 2024 17:43:33 +0200 Subject: [PATCH 44/46] fix: imports --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index cf416cb30326..969afd90eefa 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1,6 +1,6 @@ import {format} from 'date-fns'; import {fastMerge, Str} from 'expensify-common'; -import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import ReceiptGeneric from '@assets/images/receipt-generic.png'; From d931437a84caad6a6d817e9c51e2df242020fa9e Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 7 Jun 2024 20:39:45 +0200 Subject: [PATCH 45/46] fix: Member.ts --- src/libs/actions/Policy/Member.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/Policy/Member.ts b/src/libs/actions/Policy/Member.ts index ee2f02b68252..fc28a01b043c 100644 --- a/src/libs/actions/Policy/Member.ts +++ b/src/libs/actions/Policy/Member.ts @@ -1,5 +1,5 @@ import {ExpensiMark} from 'expensify-common'; -import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import type {NullishDeep, OnyxCollection, OnyxCollectionInputValue, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import * as API from '@libs/API'; import type { @@ -232,9 +232,9 @@ function removeMembers(accountIDs: number[], policyID: string) { const announceRoomMembers = removeOptimisticAnnounceRoomMembers(policy.id, policy.name, accountIDs); - const optimisticMembersState: OnyxCollection = {}; - const successMembersState: OnyxCollection = {}; - const failureMembersState: OnyxCollection = {}; + const optimisticMembersState: OnyxCollectionInputValue = {}; + const successMembersState: OnyxCollectionInputValue = {}; + const failureMembersState: OnyxCollectionInputValue = {}; emailList.forEach((email) => { optimisticMembersState[email] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}; successMembersState[email] = null; @@ -530,9 +530,9 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount // create onyx data for policy expense chats for each new member const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs); - const optimisticMembersState: OnyxCollection = {}; - const successMembersState: OnyxCollection = {}; - const failureMembersState: OnyxCollection = {}; + const optimisticMembersState: OnyxCollectionInputValue = {}; + const successMembersState: OnyxCollectionInputValue = {}; + const failureMembersState: OnyxCollectionInputValue = {}; logins.forEach((email) => { optimisticMembersState[email] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, role: CONST.POLICY.ROLE.USER}; successMembersState[email] = {pendingAction: null}; From 2e70512af3166fb27aa32a4d84d8d9c368a9ec2d Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 7 Jun 2024 22:34:57 +0200 Subject: [PATCH 46/46] update to onyx 2.0.47 --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1cd720fce733..c2395f385e92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -102,7 +102,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "2.0.44", + "react-native-onyx": "2.0.47", "react-native-pager-view": "6.2.3", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", @@ -31472,17 +31472,17 @@ } }, "node_modules/react-native-onyx": { - "version": "2.0.44", - "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.44.tgz", - "integrity": "sha512-AomPlr/UwVTx7qzG30QhhkhxlWkhlPzpjh6r9gdMrBoPO0uLJChIDclXouGc62bI9q3MmvOJ+uXw1erctPLMHA==", + "version": "2.0.47", + "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.47.tgz", + "integrity": "sha512-ZPJ3Be3g/LZQ5hBxytK9+ODdJVuFY6uN/pIPy3KhcXB9LTWnWh/RkphVu9vyEcAAR8gCOYItGgZBGiug9VJNAg==", "dependencies": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", "underscore": "^1.13.6" }, "engines": { - "node": ">=20.10.0", - "npm": ">=10.2.3" + "node": ">=20.14.0", + "npm": ">=10.7.0" }, "peerDependencies": { "idb-keyval": "^6.2.1", diff --git a/package.json b/package.json index 3571bc51eaed..913430b21bf5 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "2.0.44", + "react-native-onyx": "2.0.47", "react-native-pager-view": "6.2.3", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0",