diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 7f8b75f353e1..fa40bfad4e63 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -363,7 +363,7 @@ const ROUTES = { }, REPORT_WITH_ID_DETAILS: { route: 'r/:reportID/details', - getRoute: (reportID: string, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/details`, backTo), + getRoute: (reportID: string | undefined, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/details`, backTo), }, REPORT_WITH_ID_DETAILS_EXPORT: { route: 'r/:reportID/details/export/:connectionName', @@ -399,7 +399,7 @@ const ROUTES = { }, REPORT_DESCRIPTION: { route: 'r/:reportID/description', - getRoute: (reportID: string, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/description` as const, backTo), + getRoute: (reportID: string | undefined, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/description` as const, backTo), }, TASK_ASSIGNEE: { route: 'r/:reportID/assignee', @@ -1479,7 +1479,7 @@ const ROUTES = { TRANSACTION_DUPLICATE_REVIEW_PAGE: { route: 'r/:threadReportID/duplicates/review', - getRoute: (threadReportID: string, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review` as const, backTo), + getRoute: (threadReportID: string | undefined, backTo?: string) => getUrlWithBackToParam(`r/${threadReportID}/duplicates/review` as const, backTo), }, TRANSACTION_DUPLICATE_REVIEW_MERCHANT_PAGE: { route: 'r/:threadReportID/duplicates/review/merchant', diff --git a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx index 42b3a1d8cfc3..24e67aa76bde 100644 --- a/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx +++ b/src/components/AnchorForAttachmentsOnly/BaseAnchorForAttachmentsOnly.tsx @@ -51,7 +51,7 @@ function BaseAnchorForAttachmentsOnly({style, source = '', displayName = '', onP if (isDisabled) { return; } - showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs)); + showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs)); }} shouldUseHapticsOnLongPress accessibilityLabel={displayName} diff --git a/src/components/BrokenConnectionDescription.tsx b/src/components/BrokenConnectionDescription.tsx index c54bd0058f99..a1b9bd62ffa2 100644 --- a/src/components/BrokenConnectionDescription.tsx +++ b/src/components/BrokenConnectionDescription.tsx @@ -14,7 +14,7 @@ import TextLink from './TextLink'; type BrokenConnectionDescriptionProps = { /** Transaction id of the corresponding report */ - transactionID: string; + transactionID: string | undefined; /** Current report */ report: OnyxEntry; @@ -40,13 +40,13 @@ function BrokenConnectionDescription({transactionID, policy, report}: BrokenConn return translate('violations.brokenConnection530Error'); } - if (isPolicyAdmin && !ReportUtils.isCurrentUserSubmitter(report?.reportID ?? '')) { + if (isPolicyAdmin && !ReportUtils.isCurrentUserSubmitter(report?.reportID)) { return ( <> {`${translate('violations.adminBrokenConnectionError')}`} Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policy?.id ?? '-1'))} + onPress={() => Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policy?.id))} >{`${translate('workspace.common.companyCards')}`} . diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx index 10a1b756b209..4c8e941acb87 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/ImageRenderer.tsx @@ -117,7 +117,14 @@ function ImageRenderer({tnode}: ImageRendererProps) { if (isDisabled) { return; } - showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs)); + showContextMenuForReport( + event, + anchor, + report?.reportID, + action, + checkIfContextMenuActive, + ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs), + ); }} shouldUseHapticsOnLongPress accessibilityRole={CONST.ROLE.BUTTON} diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx index 96bdf8e9e1e8..7de4802b3a0f 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx @@ -91,7 +91,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona if (isDisabled) { return; } - showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs)); + showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs)); }} onPress={(event) => { event.preventDefault(); diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx index b1e5c21500f0..1db7df36fb8c 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx @@ -43,7 +43,7 @@ function PreRenderer({TDefaultRenderer, onPressIn, onPressOut, onLongPress, ...d if (isDisabled) { return; } - showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs)); + showContextMenuForReport(event, anchor, report?.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs)); }} shouldUseHapticsOnLongPress role={CONST.ROLE.PRESENTATION} diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 36310e4eb588..6c7a43758374 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -56,7 +56,7 @@ type MoneyReportHeaderProps = { /** The reportID of the transaction thread report associated with this current report, if any */ // eslint-disable-next-line react/no-unused-prop-types - transactionThreadReportID?: string | null; + transactionThreadReportID: string | undefined; /** Method to trigger when pressing close button of the header */ onBackButtonPress: () => void; @@ -67,8 +67,8 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout(); const route = useRoute(); - const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID ?? '-1'}`); - const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID ?? '-1'}`); + const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID}`); + const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`); const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`); const [session] = useOnyx(ONYXKEYS.SESSION); const requestParentReportAction = useMemo(() => { @@ -83,7 +83,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea const transaction = transactions?.[ `${ONYXKEYS.COLLECTION.TRANSACTION}${ - ReportActionsUtils.isMoneyRequestAction(requestParentReportAction) ? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID ?? -1 : -1 + ReportActionsUtils.isMoneyRequestAction(requestParentReportAction) && ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID }` ] ?? undefined; @@ -96,7 +96,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(moneyRequestReport); const isOnHold = TransactionUtils.isOnHold(transaction); const isDeletedParentAction = !!requestParentReportAction && ReportActionsUtils.isDeletedAction(requestParentReportAction); - const isDuplicate = TransactionUtils.isDuplicate(transaction?.transactionID ?? ''); + const isDuplicate = TransactionUtils.isDuplicate(transaction?.transactionID); // Only the requestor can delete the request, admins can only edit it. const isActionOwner = @@ -115,12 +115,12 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea const hasScanningReceipt = ReportUtils.getTransactionsWithReceipts(moneyRequestReport?.reportID).some((t) => TransactionUtils.isReceiptBeingScanned(t)); const hasOnlyPendingTransactions = allTransactions.length > 0 && allTransactions.every((t) => TransactionUtils.isExpensifyCardTransaction(t) && TransactionUtils.isPending(t)); const transactionIDs = allTransactions.map((t) => t.transactionID); - const hasAllPendingRTERViolations = TransactionUtils.allHavePendingRTERViolation([transaction?.transactionID ?? '-1']); - const shouldShowBrokenConnectionViolation = TransactionUtils.shouldShowBrokenConnectionViolation(transaction?.transactionID ?? '-1', moneyRequestReport, policy); - const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(moneyRequestReport?.reportID ?? ''); + const hasAllPendingRTERViolations = TransactionUtils.allHavePendingRTERViolation([transaction?.transactionID]); + const shouldShowBrokenConnectionViolation = TransactionUtils.shouldShowBrokenConnectionViolation(transaction?.transactionID, moneyRequestReport, policy); + const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(moneyRequestReport?.reportID); const isPayAtEndExpense = TransactionUtils.isPayAtEndExpense(transaction); - const isArchivedReport = ReportUtils.isArchivedRoomWithID(moneyRequestReport?.reportID); - const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID ?? '-1'}`, {selector: ReportUtils.getArchiveReason}); + const isArchivedReport = ReportUtils.isArchivedReport(moneyRequestReport); + const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID}`, {selector: ReportUtils.getArchiveReason}); const getCanIOUBePaid = useCallback( (onlyShowPayElsewhere = false) => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy, transaction ? [transaction] : undefined, onlyShowPayElsewhere), @@ -131,8 +131,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea const onlyShowPayElsewhere = useMemo(() => !canIOUBePaid && getCanIOUBePaid(true), [canIOUBePaid, getCanIOUBePaid]); const shouldShowMarkAsCashButton = - hasAllPendingRTERViolations || - (shouldShowBrokenConnectionViolation && (!PolicyUtils.isPolicyAdmin(policy) || ReportUtils.isCurrentUserSubmitter(moneyRequestReport?.reportID ?? ''))); + hasAllPendingRTERViolations || (shouldShowBrokenConnectionViolation && (!PolicyUtils.isPolicyAdmin(policy) || ReportUtils.isCurrentUserSubmitter(moneyRequestReport?.reportID))); const shouldShowPayButton = canIOUBePaid || onlyShowPayElsewhere; @@ -145,6 +144,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea const shouldShowSubmitButton = !!moneyRequestReport && + !isArchivedReport && isDraft && reimbursableSpend !== 0 && !hasAllPendingRTERViolations && @@ -215,10 +215,10 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea const deleteTransaction = useCallback(() => { if (requestParentReportAction) { const iouTransactionID = ReportActionsUtils.isMoneyRequestAction(requestParentReportAction) - ? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID ?? '-1' - : '-1'; + ? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID + : undefined; if (ReportActionsUtils.isTrackExpenseAction(requestParentReportAction)) { - navigateBackToAfterDelete.current = IOU.deleteTrackExpense(moneyRequestReport?.reportID ?? '-1', iouTransactionID, requestParentReportAction, true); + navigateBackToAfterDelete.current = IOU.deleteTrackExpense(moneyRequestReport?.reportID, iouTransactionID, requestParentReportAction, true); } else { navigateBackToAfterDelete.current = IOU.deleteMoneyRequest(iouTransactionID, requestParentReportAction, true); } @@ -232,10 +232,13 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea return; } const iouTransactionID = ReportActionsUtils.isMoneyRequestAction(requestParentReportAction) - ? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID ?? '-1' - : '-1'; - const reportID = transactionThreadReport?.reportID ?? '-1'; + ? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID + : undefined; + const reportID = transactionThreadReport?.reportID; + if (!iouTransactionID || !reportID) { + return; + } TransactionActions.markAsCash(iouTransactionID, reportID); }, [requestParentReportAction, transactionThreadReport?.reportID]); @@ -265,7 +268,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea icon: getStatusIcon(Expensicons.Hourglass), description: ( @@ -354,7 +357,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea text={translate('iou.reviewDuplicates')} style={styles.p0} onPress={() => { - Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(transactionThreadReportID ?? '', Navigation.getReportRHPActiveRoute())); + Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(transactionThreadReportID, Navigation.getReportRHPActiveRoute())); }} /> @@ -422,7 +425,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea text={translate('iou.reviewDuplicates')} style={[styles.flex1, styles.pr0]} onPress={() => { - Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(transactionThreadReportID ?? '', Navigation.getReportRHPActiveRoute())); + Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(transactionThreadReportID, Navigation.getReportRHPActiveRoute())); }} /> )} diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 6b2ed42181b0..0d312b5d1a40 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -57,7 +57,7 @@ import { hasWarningTypeViolations, isAllowedToApproveExpenseReport, isAllowedToSubmitDraftExpenseReport, - isArchivedRoomWithID, + isArchivedReport, isInvoiceReport as isInvoiceReportUtils, isInvoiceRoom as isInvoiceRoomReportUtils, isOpenExpenseReport as isOpenExpenseReportUtils, @@ -242,10 +242,12 @@ function ReportPreview({ formattedMerchant = null; } + const isArchived = isArchivedReport(iouReport); const currentUserAccountID = getCurrentUserAccountID(); const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; const shouldShowSubmitButton = isOpenExpenseReport && + !isArchived && reimbursableSpend !== 0 && !showRTERViolationMessage && !shouldShowBrokenConnectionViolation && @@ -426,15 +428,14 @@ function ReportPreview({ const shouldShowPendingSubtitle = numberOfPendingRequests === 1 && numberOfRequests === 1; const isPayAtEndExpense = isPayAtEndExpenseReport(iouReportID, allTransactions); - const isArchivedReport = isArchivedRoomWithID(iouReportID); const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, {selector: getArchiveReason}); const getPendingMessageProps: () => PendingMessageProps = () => { if (isPayAtEndExpense) { - if (!isArchivedReport) { + if (!isArchived) { return {shouldShow: true, messageIcon: Expensicons.Hourglass, messageDescription: translate('iou.bookingPending')}; } - if (isArchivedReport && archiveReason === CONST.REPORT.ARCHIVE_REASON.BOOKING_END_DATE_HAS_PASSED) { + if (isArchived && archiveReason === CONST.REPORT.ARCHIVE_REASON.BOOKING_END_DATE_HAS_PASSED) { return { shouldShow: true, messageIcon: Expensicons.Box, diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index cc7dbed1f6e9..08f0d17172a1 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -34,8 +34,8 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) { const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || -1}`); - const isArchivedRoom = ReportUtils.isArchivedRoom(report, reportNameValuePairs); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`); + const isArchivedRoom = ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs); const isChatRoom = ReportUtils.isChatRoom(report); const isSelfDM = ReportUtils.isSelfDM(report); const isInvoiceRoom = ReportUtils.isInvoiceRoom(report); @@ -110,7 +110,7 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) { if (!canEditPolicyDescription) { return; } - Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(policy?.id ?? '-1')); + Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(policy?.id)); }} style={[styles.renderHTML, canEditPolicyDescription ? styles.cursorPointer : styles.cursorText]} accessibilityLabel={translate('reportDescriptionPage.roomDescription')} @@ -135,7 +135,7 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) { return; } const activeRoute = Navigation.getActiveRoute(); - Navigation.navigate(ROUTES.REPORT_DESCRIPTION.getRoute(report?.reportID ?? '-1', activeRoute)); + Navigation.navigate(ROUTES.REPORT_DESCRIPTION.getRoute(report?.reportID, activeRoute)); }} style={[styles.renderHTML, canEditReportDescription ? styles.cursorPointer : styles.cursorText]} accessibilityLabel={translate('reportDescriptionPage.roomDescription')} @@ -164,10 +164,10 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) { onPress={() => { const activeRoute = Navigation.getActiveRoute(); if (canEditReportDescription) { - Navigation.navigate(ROUTES.REPORT_DESCRIPTION.getRoute(report?.reportID ?? '-1', activeRoute)); + Navigation.navigate(ROUTES.REPORT_DESCRIPTION.getRoute(report?.reportID, activeRoute)); return; } - Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '-1', activeRoute)); + Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID, activeRoute)); }} style={styles.renderHTML} accessibilityLabel={translate('reportDescriptionPage.roomDescription')} diff --git a/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx b/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx index 832b5eef45f0..b484fc10e8cc 100644 --- a/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx +++ b/src/components/VideoPlayerPreview/VideoPlayerThumbnail.tsx @@ -57,7 +57,14 @@ function VideoPlayerThumbnail({thumbnailUrl, onPress, accessibilityLabel, isDele if (isDisabled) { return; } - showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs)); + showContextMenuForReport( + event, + anchor, + report?.reportID, + action, + checkIfContextMenuActive, + ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs), + ); }} shouldUseHapticsOnLongPress > diff --git a/src/hooks/useReportIDs.tsx b/src/hooks/useReportIDs.tsx index 878e83cf4d87..1f2b1db5b0a8 100644 --- a/src/hooks/useReportIDs.tsx +++ b/src/hooks/useReportIDs.tsx @@ -22,7 +22,7 @@ type ReportIDsContextProviderProps = { type ReportIDsContextValue = { orderedReportIDs: string[]; - currentReportID: string; + currentReportID: string | undefined; policyMemberAccountIDs: number[]; }; @@ -70,7 +70,7 @@ function ReportIDsContextProvider({ const getOrderedReportIDs = useCallback( (currentReportID?: string) => - SidebarUtils.getOrderedReportIDs(currentReportID ?? null, chatReports, betas, policies, priorityMode, transactionViolations, activeWorkspaceID, policyMemberAccountIDs), + SidebarUtils.getOrderedReportIDs(currentReportID, chatReports, betas, policies, priorityMode, transactionViolations, activeWorkspaceID, policyMemberAccountIDs), // we need reports draft in deps array to reload the list when a draft is added or removed // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps [chatReports, betas, policies, priorityMode, transactionViolations, activeWorkspaceID, policyMemberAccountIDs, draftAmount], @@ -94,12 +94,12 @@ function ReportIDsContextProvider({ derivedCurrentReportID !== '-1' && orderedReportIDs.indexOf(derivedCurrentReportID) === -1 ) { - return {orderedReportIDs: getOrderedReportIDs(derivedCurrentReportID), currentReportID: derivedCurrentReportID ?? '-1', policyMemberAccountIDs}; + return {orderedReportIDs: getOrderedReportIDs(derivedCurrentReportID), currentReportID: derivedCurrentReportID, policyMemberAccountIDs}; } return { orderedReportIDs, - currentReportID: derivedCurrentReportID ?? '-1', + currentReportID: derivedCurrentReportID, policyMemberAccountIDs, }; }, [getOrderedReportIDs, orderedReportIDs, derivedCurrentReportID, policyMemberAccountIDs, shouldUseNarrowLayout]); diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx index 80165073fda8..503b263d7cfa 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx @@ -70,7 +70,7 @@ function BottomTabBar({selectedTab}: BottomTabBarProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const {activeWorkspaceID} = useActiveWorkspace(); - const {currentReportID = null} = useCurrentReportID() ?? {}; + const {currentReportID} = useCurrentReportID() ?? {}; const [user] = useOnyx(ONYXKEYS.USER); const [betas] = useOnyx(ONYXKEYS.BETAS); const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE); diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/DebugTabView.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/DebugTabView.tsx index 354529941e0c..a59bd3d8e55d 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/DebugTabView.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/DebugTabView.tsx @@ -27,7 +27,7 @@ type DebugTabViewProps = { selectedTab?: string; chatTabBrickRoad: BrickRoad; activeWorkspaceID?: string; - currentReportID: string | null; + currentReportID: string | undefined; reports: OnyxCollection; betas: OnyxEntry; policies: OnyxCollection; diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index d23e19780d78..5314391e2166 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -509,7 +509,7 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails const lastOriginalReportAction = reportID ? lastReportActions[reportID] : undefined; let lastMessageTextFromReport = ''; - if (report?.private_isArchived) { + if (ReportUtils.isArchivedNonExpenseReport(report)) { const archiveReason = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (ReportActionUtils.isClosedAction(lastOriginalReportAction) && ReportActionUtils.getOriginalMessage(lastOriginalReportAction)?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c6be9d960ed4..cdad73b0e94d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1645,21 +1645,29 @@ function isClosedExpenseReportWithNoExpenses(report: OnyxEntry): boolean * Whether the provided report is an archived room */ // eslint-disable-next-line @typescript-eslint/no-unused-vars -function isArchivedRoom(report: OnyxInputOrEntry | SearchReport, reportNameValuePairs?: OnyxInputOrEntry): boolean { +function isArchivedNonExpenseReport(report: OnyxInputOrEntry | SearchReport, reportNameValuePairs?: OnyxInputOrEntry): boolean { + return !(isExpenseReport(report) || isExpenseRequest(report)) && !!report?.private_isArchived; +} + +/** + * Whether the provided report is an archived report + */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function isArchivedReport(report: OnyxInputOrEntry | SearchReport, reportNameValuePairs?: OnyxInputOrEntry): boolean { return !!report?.private_isArchived; } /** * Whether the report with the provided reportID is an archived room */ -function isArchivedRoomWithID(reportOrID?: string | SearchReport) { +function isArchivedNonExpenseReportWithID(reportOrID?: string | SearchReport) { if (!reportOrID) { return false; } // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const report = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID; - return isArchivedRoom(report); + return isArchivedNonExpenseReport(report); } /** @@ -1968,7 +1976,7 @@ function getChildReportNotificationPreference(reportAction: OnyxInputOrEntry): boolean { - if (!isMoneyRequestReport(moneyRequestReport) || isArchivedRoom(moneyRequestReport)) { + if (!isMoneyRequestReport(moneyRequestReport) || isArchivedReport(moneyRequestReport)) { return false; } @@ -2570,7 +2578,7 @@ function getIcons( }; return [domainIcon]; } - if (isAdminRoom(report) || isAnnounceRoom(report) || isChatRoom(report) || isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (isAdminRoom(report) || isAnnounceRoom(report) || isChatRoom(report) || isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID))) { const icons = [getWorkspaceIcon(report, policy)]; if (isInvoiceRoom(report)) { @@ -2959,8 +2967,8 @@ function getReasonAndReportActionThatRequiresAttention( } if ( - isArchivedRoom(optionOrReport, getReportNameValuePairs(optionOrReport?.reportID)) || - isArchivedRoom(getReportOrDraftReport(optionOrReport.parentReportID), getReportNameValuePairs(optionOrReport?.reportID)) + isArchivedReport(optionOrReport, getReportNameValuePairs(optionOrReport?.reportID)) || + isArchivedReport(getReportOrDraftReport(optionOrReport.parentReportID), getReportNameValuePairs(optionOrReport?.reportID)) ) { return null; } @@ -3099,7 +3107,7 @@ function getPolicyExpenseChatName(report: OnyxEntry, policy?: OnyxEntry< // If this user is not admin and this policy expense chat has been archived because of account merging, this must be an old workspace chat // of the account which was merged into the current user's account. Use the name of the policy as the name of the report. - if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID))) { const lastAction = getLastVisibleActionReportActionsUtils(report?.reportID); const archiveReason = isClosedAction(lastAction) ? getOriginalMessage(lastAction)?.reason : CONST.REPORT.ARCHIVE_REASON.DEFAULT; if (archiveReason === CONST.REPORT.ARCHIVE_REASON.ACCOUNT_MERGED && policyExpenseChatRole !== CONST.POLICY.ROLE.ADMIN) { @@ -4180,7 +4188,7 @@ function getReportName( if (isChatThread(report)) { if (!isEmptyObject(parentReportAction) && isTransactionThread(parentReportAction)) { formattedName = getTransactionReportName(parentReportAction); - if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID))) { formattedName += ` (${translateLocal('common.archived')})`; } return formatReportLastMessageText(formattedName); @@ -4209,7 +4217,7 @@ function getReportName( if (isAdminRoom(report) || isUserCreatedPolicyRoom(report)) { return getAdminRoomInvitedParticipants(parentReportAction, reportActionMessage); } - if (reportActionMessage && isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (reportActionMessage && isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID))) { return `${reportActionMessage} (${translateLocal('common.archived')})`; } if (!isEmptyObject(parentReportAction) && isModifiedExpenseAction(parentReportAction)) { @@ -4258,7 +4266,7 @@ function getReportName( formattedName = getInvoicesChatName(report, invoiceReceiverPolicy); } - if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID))) { formattedName += ` (${translateLocal('common.archived')})`; } @@ -4337,7 +4345,7 @@ function getChatRoomSubtitle(report: OnyxEntry): string | undefined { if ((isPolicyExpenseChat(report) && !!report?.isOwnPolicyExpenseChat) || isExpenseReport(report)) { return translateLocal('workspace.common.workspace'); } - if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (isArchivedReport(report, getReportNameValuePairs(report?.reportID))) { return report?.oldPolicyName ?? ''; } return getPolicyName(report); @@ -4363,7 +4371,7 @@ function getParentNavigationSubtitle(report: OnyxEntry, invoiceReceiverP if (isInvoiceReport(report) || isInvoiceRoom(parentReport)) { let reportName = `${getPolicyName(parentReport)} & ${getInvoicePayerName(parentReport, invoiceReceiverPolicy)}`; - if (isArchivedRoom(parentReport, getReportNameValuePairs(parentReport?.reportID))) { + if (isArchivedNonExpenseReport(parentReport, getReportNameValuePairs(parentReport?.reportID))) { reportName += ` (${translateLocal('common.archived')})`; } @@ -6548,7 +6556,7 @@ function isIOUOwnedByCurrentUser(report: OnyxEntry, allReportsDict?: Ony */ function canSeeDefaultRoom(report: OnyxEntry, policies: OnyxCollection, betas: OnyxEntry): boolean { // Include archived rooms - if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID))) { return true; } @@ -6691,7 +6699,7 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(report: O ? undefined : allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]; - if (!isArchivedRoom(report)) { + if (!isArchivedReport(report)) { if (wasActionTakenByCurrentUser(parentReportAction) && isTransactionThread(parentReportAction)) { const transactionID = isMoneyRequestAction(parentReportAction) ? getOriginalMessage(parentReportAction)?.IOUTransactionID : null; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; @@ -6800,7 +6808,7 @@ function reasonForReportToBeInOptionList({ // So we allow showing rooms with no participants–in any other circumstances we should never have these reports with no participants in Onyx. !isChatRoom(report) && !isChatThread(report) && - !isArchivedRoom(report, getReportNameValuePairs(report?.reportID)) && + !isArchivedReport(report, getReportNameValuePairs(report?.reportID)) && !isMoneyRequestReport(report) && !isTaskReport(report) && !isSelfDM(report) && @@ -6887,7 +6895,7 @@ function reasonForReportToBeInOptionList({ } // Archived reports should always be shown when in default (most recent) mode. This is because you should still be able to access and search for the chats to find them. - if (isInDefaultMode && isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (isInDefaultMode && isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID))) { return CONST.REPORT_IN_LHN_REASONS.IS_ARCHIVED; } @@ -6953,7 +6961,7 @@ function getChatByParticipants(newParticipantList: number[], reports: OnyxCollec */ function getInvoiceChatByParticipants(receiverID: string | number, receiverType: InvoiceReceiverType, policyID?: string, reports: OnyxCollection = allReports): OnyxEntry { return Object.values(reports ?? {}).find((report) => { - if (!report || !isInvoiceRoom(report) || isArchivedRoom(report)) { + if (!report || !isInvoiceRoom(report) || isArchivedNonExpenseReport(report)) { return false; } @@ -7049,7 +7057,7 @@ function canFlagReportAction(reportAction: OnyxInputOrEntry, repor function shouldShowFlagComment(reportAction: OnyxInputOrEntry, report: OnyxInputOrEntry): boolean { return ( canFlagReportAction(reportAction, report?.reportID) && - !isArchivedRoom(report, getReportNameValuePairs(report?.reportID)) && + !isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)) && !chatIncludesChronos(report) && !isConciergeChatReport(report) && reportAction?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE @@ -7234,7 +7242,7 @@ function isGroupChatAdmin(report: OnyxEntry, accountID: number) { */ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, reportParticipants: number[], filterDeprecatedTypes = false): IOUType[] { // In any thread or task report, we do not allow any new expenses yet - if (isChatThread(report) || isTaskReport(report) || isInvoiceReport(report) || isSystemChat(report)) { + if (isChatThread(report) || isTaskReport(report) || isInvoiceReport(report) || isSystemChat(report) || isArchivedReport(report)) { return []; } @@ -7358,7 +7366,7 @@ function canLeaveInvoiceRoom(report: OnyxEntry): boolean { */ function canLeaveRoom(report: OnyxEntry, isPolicyEmployee: boolean): boolean { if (isInvoiceRoom(report)) { - if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) { + if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID))) { return false; } @@ -7429,7 +7437,7 @@ function getWhisperDisplayNames(participantAccountIDs?: number[]): string | unde * Show subscript on workspace chats / threads and expense requests */ function shouldReportShowSubscript(report: OnyxEntry): boolean { - if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID)) && !isWorkspaceThread(report)) { + if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)) && !isWorkspaceThread(report)) { return false; } @@ -7509,13 +7517,13 @@ function canUserPerformWriteAction(report: OnyxEntry) { } const reportNameValuePairs = getReportNameValuePairs(report?.reportID); - return !isArchivedRoom(report, reportNameValuePairs) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser && canWriteInReport(report); + return !isArchivedNonExpenseReport(report, reportNameValuePairs) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser && canWriteInReport(report); } /** * Returns ID of the original report from which the given reportAction is first created. */ -function getOriginalReportID(reportID: string, reportAction: OnyxInputOrEntry): string | undefined { +function getOriginalReportID(reportID: string | undefined, reportAction: OnyxInputOrEntry): string | undefined { const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; const currentReportAction = reportAction?.reportActionID ? reportActions?.[reportAction.reportActionID] : undefined; const transactionThreadReportID = getOneTransactionThreadReportID(reportID, reportActions ?? ([] as ReportAction[])); @@ -7582,7 +7590,7 @@ function getAllWorkspaceReports(policyID: string): Array> { function shouldDisableRename(report: OnyxEntry): boolean { if ( isDefaultRoom(report) || - isArchivedRoom(report, getReportNameValuePairs(report?.reportID)) || + isArchivedReport(report, getReportNameValuePairs(report?.reportID)) || isPublicRoom(report) || isThread(report) || isMoneyRequest(report) || @@ -7610,14 +7618,14 @@ function shouldDisableRename(report: OnyxEntry): boolean { * @param policy - the workspace the report is on, null if the user isn't a member of the workspace */ function canEditWriteCapability(report: OnyxEntry, policy: OnyxEntry): boolean { - return isPolicyAdminPolicyUtils(policy) && !isAdminRoom(report) && !isArchivedRoom(report, getReportNameValuePairs(report?.reportID)) && !isThread(report) && !isInvoiceRoom(report); + return isPolicyAdminPolicyUtils(policy) && !isAdminRoom(report) && !isArchivedReport(report, getReportNameValuePairs(report?.reportID)) && !isThread(report) && !isInvoiceRoom(report); } /** * @param policy - the workspace the report is on, null if the user isn't a member of the workspace */ function canEditRoomVisibility(report: OnyxEntry, policy: OnyxEntry): boolean { - return isPolicyAdminPolicyUtils(policy) && !isArchivedRoom(report, getReportNameValuePairs(report?.reportID)); + return isPolicyAdminPolicyUtils(policy) && !isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID)); } /** @@ -7834,7 +7842,7 @@ function isDeprecatedGroupDM(report: OnyxEntry): boolean { !isTaskReport(report) && !isInvoiceReport(report) && !isMoneyRequestReport(report) && - !isArchivedRoom(report, getReportNameValuePairs(report?.reportID)) && + !isArchivedReport(report, getReportNameValuePairs(report?.reportID)) && !Object.values(CONST.REPORT.CHAT_TYPE).some((chatType) => chatType === getChatType(report)) && Object.keys(report.participants ?? {}) .map(Number) @@ -7898,7 +7906,7 @@ function getRoom(type: ValueOf, policyID: string) function canEditReportDescription(report: OnyxEntry, policy: OnyxEntry): boolean { return ( !isMoneyRequestReport(report) && - !isArchivedRoom(report, getReportNameValuePairs(report?.reportID)) && + !isArchivedReport(report, getReportNameValuePairs(report?.reportID)) && isChatRoom(report) && !isChatThread(report) && !isEmpty(policy) && @@ -8060,14 +8068,14 @@ function shouldDisableThread(reportAction: OnyxInputOrEntry, repor const isReportPreviewActionLocal = isReportPreviewAction(reportAction); const isIOUAction = isMoneyRequestAction(reportAction); const isWhisperActionLocal = isWhisperAction(reportAction) || isActionableTrackExpense(reportAction); - const isArchivedReport = isArchivedRoom(getReportOrDraftReport(reportID), getReportNameValuePairs(reportID)); + const isArchived = isArchivedNonExpenseReport(getReportOrDraftReport(reportID), getReportNameValuePairs(reportID)); const isActionDisabled = CONST.REPORT.ACTIONS.THREAD_DISABLED.some((action: string) => action === reportAction?.actionName); return ( isActionDisabled || isSplitBillAction || (isDeletedActionLocal && !reportAction?.childVisibleActionCount) || - (isArchivedReport && !reportAction?.childVisibleActionCount) || + (isArchived && !reportAction?.childVisibleActionCount) || (isWhisperActionLocal && !isReportPreviewActionLocal && !isIOUAction) || isThreadReportParentAction ); @@ -8190,7 +8198,7 @@ function getQuickActionDetails( policyChatForActivePolicy: Report | undefined, reportNameValuePairs: ReportNameValuePairs, ): {quickActionAvatars: Icon[]; hideQABSubtitle: boolean} { - const isValidQuickActionReport = !(isEmptyObject(quickActionReport) || isArchivedRoom(quickActionReport, reportNameValuePairs)); + const isValidQuickActionReport = !(isEmptyObject(quickActionReport) || isArchivedReport(quickActionReport, reportNameValuePairs)); let hideQABSubtitle = false; let quickActionAvatars: Icon[] = []; if (isValidQuickActionReport) { @@ -8247,7 +8255,7 @@ function isAllowedToSubmitDraftExpenseReport(report: OnyxEntry): boolean */ function getIndicatedMissingPaymentMethod(userWallet: OnyxEntry, reportId: string | undefined, reportAction: ReportAction): MissingPaymentMethod | undefined { const isSubmitterOfUnsettledReport = isCurrentUserSubmitter(reportId) && !isSettled(reportId); - if (!isSubmitterOfUnsettledReport || !isReimbursementQueuedAction(reportAction)) { + if (!reportId || !isSubmitterOfUnsettledReport || !isReimbursementQueuedAction(reportAction)) { return undefined; } const paymentType = getOriginalMessage(reportAction)?.paymentType; @@ -8978,8 +8986,9 @@ export { isAllowedToComment, isAllowedToSubmitDraftExpenseReport, isAnnounceRoom, - isArchivedRoom, - isArchivedRoomWithID, + isArchivedNonExpenseReport, + isArchivedReport, + isArchivedNonExpenseReportWithID, isClosedReport, isCanceledTaskReport, isChatReport, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 18313d85e637..1ceeb705c7c2 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -100,7 +100,7 @@ function ensureSingleSpacing(text: string) { * @returns An array of reportIDs sorted in the proper order */ function getOrderedReportIDs( - currentReportId: string | null, + currentReportId: string | undefined, reports: OnyxCollection, betas: OnyxEntry, policies: OnyxCollection, @@ -123,13 +123,13 @@ function getOrderedReportIDs( if ((Object.values(CONST.REPORT.UNSUPPORTED_TYPE) as string[]).includes(report?.type ?? '')) { return; } - const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1'); + const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID, report?.parentReportActionID); const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations); const isHidden = ReportUtils.isHiddenForCurrentUser(report); const isFocused = report.reportID === currentReportId; const hasErrorsOtherThanFailedReceipt = ReportUtils.hasReportErrorsOtherThanFailedReceipt(report, doesReportHaveViolations, transactionViolations); const isReportInAccessible = report?.errorFields?.notFound; - if (ReportUtils.isOneTransactionThread(report.reportID, report.parentReportID ?? '0', parentReportAction)) { + if (ReportUtils.isOneTransactionThread(report.reportID, report.parentReportID, parentReportAction)) { return; } if (hasErrorsOtherThanFailedReceipt && !isReportInAccessible) { @@ -155,7 +155,7 @@ function getOrderedReportIDs( if ( ReportUtils.shouldReportBeInOptionList({ report, - currentReportId: currentReportId ?? '-1', + currentReportId, isInFocusMode, betas, policies: policies as OnyxCollection, @@ -200,15 +200,15 @@ function getOrderedReportIDs( }; const isPinned = report?.isPinned ?? false; - const reportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1'); + const reportAction = ReportActionsUtils.getReportAction(report?.parentReportID, report?.parentReportActionID); const reportNameValuePairs = ReportUtils.getReportNameValuePairs(report?.reportID); if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) { pinnedAndGBRReports.push(miniReport); } else if (report?.hasErrorsOtherThanFailedReceipt) { errorReports.push(miniReport); - } else if (hasValidDraftComment(report?.reportID ?? '-1')) { + } else if (hasValidDraftComment(report?.reportID)) { draftReports.push(miniReport); - } else if (ReportUtils.isArchivedRoom(report, reportNameValuePairs)) { + } else if (ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs)) { archivedReports.push(miniReport); } else { nonArchivedReports.push(miniReport); @@ -239,7 +239,7 @@ function getOrderedReportIDs( // Now that we have all the reports grouped and sorted, they must be flattened into an array and only return the reportID. // The order the arrays are concatenated in matters and will determine the order that the groups are displayed in the sidebar. - const LHNReports = [...pinnedAndGBRReports, ...errorReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report?.reportID ?? '-1'); + const LHNReports = [...pinnedAndGBRReports, ...errorReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report?.reportID).filter(Boolean) as string[]; Performance.markEnd(CONST.TIMING.GET_ORDERED_REPORT_IDS); return LHNReports; @@ -386,7 +386,7 @@ function getOptionData({ result.iouReportID = report.iouReportID; result.keyForList = String(report.reportID); result.hasOutstandingChildRequest = report.hasOutstandingChildRequest; - result.parentReportID = report.parentReportID ?? '-1'; + result.parentReportID = report.parentReportID; result.isWaitingOnBankAccount = report.isWaitingOnBankAccount; result.notificationPreference = ReportUtils.getReportNotificationPreference(report); result.isAllowedToComment = ReportUtils.canUserPerformWriteAction(report); @@ -519,7 +519,7 @@ function getOptionData({ } if (!hasMultipleParticipants) { - result.accountID = personalDetail?.accountID ?? -1; + result.accountID = personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID; result.login = personalDetail?.login ?? ''; result.phoneNumber = personalDetail?.phoneNumber ?? ''; } @@ -530,7 +530,15 @@ function getOptionData({ result.subtitle = subtitle; result.participantsList = participantPersonalDetailList; - result.icons = ReportUtils.getIcons(report, personalDetails, personalDetail?.avatar, personalDetail?.login, personalDetail?.accountID ?? -1, policy, invoiceReceiverPolicy); + result.icons = ReportUtils.getIcons( + report, + personalDetails, + personalDetail?.avatar, + personalDetail?.login, + personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID, + policy, + invoiceReceiverPolicy, + ); result.displayNamesWithTooltips = displayNamesWithTooltips; if (status) { diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index e3c54feefd87..ba70305a3996 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -795,7 +795,7 @@ function shouldShowBrokenConnectionViolation(transactionID: string | undefined, /** * Check if there is pending rter violation in all transactionViolations with given transactionIDs. */ -function allHavePendingRTERViolation(transactionIds: string[]): boolean { +function allHavePendingRTERViolation(transactionIds: Array): boolean { const transactionsWithRTERViolations = transactionIds.map((transactionId) => { const transactionViolations = getTransactionViolations(transactionId, allTransactionViolations); return hasPendingRTERViolation(transactionViolations); @@ -894,7 +894,7 @@ function getRecentTransactions(transactions: Record, size = 2): * @param transactionID - the transaction to check * @param checkDismissed - whether to check if the violation has already been dismissed as well */ -function isDuplicate(transactionID: string, checkDismissed = false): boolean { +function isDuplicate(transactionID: string | undefined, checkDismissed = false): boolean { const hasDuplicatedViolation = !!allTransactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]?.some( (violation: TransactionViolation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION, ); diff --git a/src/libs/WorkspacesSettingsUtils.ts b/src/libs/WorkspacesSettingsUtils.ts index 60dff1c97247..4e878f0924a8 100644 --- a/src/libs/WorkspacesSettingsUtils.ts +++ b/src/libs/WorkspacesSettingsUtils.ts @@ -140,7 +140,7 @@ function hasWorkspaceSettingsRBR(policy: Policy) { function getChatTabBrickRoadReport( policyID: string | undefined, - currentReportId: string | null, + currentReportId: string | undefined, reports: OnyxCollection, betas: OnyxEntry, policies: OnyxCollection, @@ -182,7 +182,7 @@ function getChatTabBrickRoadReport( function getChatTabBrickRoad( policyID: string | undefined, - currentReportId: string | null, + currentReportId: string | undefined, reports: OnyxCollection, betas: OnyxEntry, policies: OnyxCollection, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index e3f9abf84731..e0899d1ee0ae 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -108,7 +108,7 @@ import { getTransactionDetails, hasHeldExpenses as hasHeldExpensesReportUtils, hasNonReimbursableTransactions as hasNonReimbursableTransactionsReportUtils, - isArchivedRoom, + isArchivedReport, isDraftReport, isExpenseReport, isIndividualInvoiceRoom, @@ -7347,7 +7347,7 @@ function canApproveIOU( const isApproved = isReportApproved(iouReport); const iouSettled = isSettled(iouReport?.reportID); const reportNameValuePairs = chatReportRNVP ?? getReportNameValuePairs(iouReport?.reportID); - const isArchivedReport = isArchivedRoom(iouReport, reportNameValuePairs); + const isArchivedExpenseReport = isArchivedReport(iouReport, reportNameValuePairs); let isTransactionBeingScanned = false; const reportTransactions = getAllReportTransactions(iouReport?.reportID); for (const transaction of reportTransactions) { @@ -7360,7 +7360,7 @@ function canApproveIOU( } } - return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled && !isArchivedReport && !isTransactionBeingScanned; + return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled && !isArchivedExpenseReport && !isTransactionBeingScanned; } function canIOUBePaid( @@ -7375,7 +7375,7 @@ function canIOUBePaid( ) { const isPolicyExpenseChat = isPolicyExpenseChatReportUtils(chatReport); const reportNameValuePairs = chatReportRNVP ?? getReportNameValuePairs(chatReport?.reportID); - const isChatReportArchived = isArchivedRoom(chatReport, reportNameValuePairs); + const isChatReportArchived = isArchivedReport(chatReport, reportNameValuePairs); const iouSettled = isSettled(iouReport); if (isEmptyObject(iouReport)) { diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 2b4b8fe73ccc..a5a93ef9d211 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -1235,7 +1235,7 @@ function canModifyTask(taskReport: OnyxEntry, sessionAccountID const parentReport = getParentReport(taskReport); const reportNameValuePairs = ReportUtils.getReportNameValuePairs(parentReport?.reportID); - if (ReportUtils.isArchivedRoom(parentReport, reportNameValuePairs)) { + if (ReportUtils.isArchivedReport(parentReport, reportNameValuePairs)) { return false; } @@ -1256,7 +1256,7 @@ function canActionTask(taskReport: OnyxEntry, sessionAccountID const parentReport = getParentReport(taskReport); const reportNameValuePairs = ReportUtils.getReportNameValuePairs(parentReport?.reportID); - if (ReportUtils.isArchivedRoom(parentReport, reportNameValuePairs)) { + if (ReportUtils.isArchivedNonExpenseReport(parentReport, reportNameValuePairs)) { return false; } diff --git a/src/libs/actions/TransactionEdit.ts b/src/libs/actions/TransactionEdit.ts index a76cb8f25b75..56cb49b4163c 100644 --- a/src/libs/actions/TransactionEdit.ts +++ b/src/libs/actions/TransactionEdit.ts @@ -28,11 +28,19 @@ function createBackupTransaction(transaction: OnyxEntry) { /** * Removes a transaction from Onyx that was only used temporary in the edit flow */ -function removeBackupTransaction(transactionID: string) { +function removeBackupTransaction(transactionID: string | undefined) { + if (!transactionID) { + return; + } + Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transactionID}`, null); } -function restoreOriginalTransactionFromBackup(transactionID: string, isDraft: boolean) { +function restoreOriginalTransactionFromBackup(transactionID: string | undefined, isDraft: boolean) { + if (!transactionID) { + return; + } + connection = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transactionID}`, callback: (backupTransaction) => { @@ -58,7 +66,11 @@ function createDraftTransaction(transaction: OnyxEntry) { Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, newTransaction); } -function removeDraftTransaction(transactionID: string) { +function removeDraftTransaction(transactionID: string | undefined) { + if (!transactionID) { + return; + } + Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, null); } diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 11f3f3c48efa..b48a90e88d95 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -125,7 +125,7 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta const isUserCreatedPolicyRoom = useMemo(() => ReportUtils.isUserCreatedPolicyRoom(report), [report]); const isDefaultRoom = useMemo(() => ReportUtils.isDefaultRoom(report), [report]); const isChatThread = useMemo(() => ReportUtils.isChatThread(report), [report]); - const isArchivedRoom = useMemo(() => ReportUtils.isArchivedRoom(report, reportNameValuePairs), [report, reportNameValuePairs]); + const isArchivedRoom = useMemo(() => ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs), [report, reportNameValuePairs]); const isMoneyRequestReport = useMemo(() => ReportUtils.isMoneyRequestReport(report), [report]); const isMoneyRequest = useMemo(() => ReportUtils.isMoneyRequest(report), [report]); const isInvoiceReport = useMemo(() => ReportUtils.isInvoiceReport(report), [report]); @@ -668,8 +668,7 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta const shouldShowHoldAction = caseID !== CASES.DEFAULT && (canHoldUnholdReportAction.canHoldRequest || canHoldUnholdReportAction.canUnholdRequest) && - !ReportUtils.isArchivedRoom(transactionThreadReportID ? report : parentReport, parentReportNameValuePairs); - + !ReportUtils.isArchivedNonExpenseReport(transactionThreadReportID ? report : parentReport, parentReportNameValuePairs); const canJoin = ReportUtils.canJoinChat(report, parentReportAction, policy); const promotedActions = useMemo(() => { diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index e02a51b26502..1bb36bf89080 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -365,7 +365,7 @@ function ReportParticipantsPage({report, route}: ReportParticipantsPageProps) { style={[styles.defaultModalContainer]} testID={ReportParticipantsPage.displayName} > - + { diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 6877de271946..739b357c50b6 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -137,7 +137,7 @@ function BaseReportActionContextMenu({ const [user] = useOnyx(ONYXKEYS.USER); const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); const policyID = report?.policyID; - const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID ?? '-1'); + const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID); const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST); const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`); @@ -153,11 +153,11 @@ function BaseReportActionContextMenu({ const [download] = useOnyx(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`); const [childReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportAction?.childReportID}`); - const parentReportAction = ReportActionsUtils.getReportAction(childReport?.parentReportID ?? '', childReport?.parentReportActionID ?? ''); - const {reportActions: paginatedReportActions} = usePaginatedReportActions(childReport?.reportID ?? '-1'); + const parentReportAction = ReportActionsUtils.getReportAction(childReport?.parentReportID, childReport?.parentReportActionID); + const {reportActions: paginatedReportActions} = usePaginatedReportActions(childReport?.reportID); const transactionThreadReportID = useMemo( - () => ReportActionsUtils.getOneTransactionThreadReportID(childReport?.reportID ?? '-1', paginatedReportActions ?? [], isOffline), + () => ReportActionsUtils.getOneTransactionThreadReportID(childReport?.reportID, paginatedReportActions ?? [], isOffline), [childReport?.reportID, paginatedReportActions, isOffline], ); @@ -177,8 +177,7 @@ function BaseReportActionContextMenu({ }, [parentReportAction, isMoneyRequestReport, isInvoiceReport, paginatedReportActions, transactionThreadReport?.parentReportActionID]); const moneyRequestAction = transactionThreadReportID ? requestParentReportAction : parentReportAction; - - const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${childReport?.parentReportID ?? '-1'}`); + const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${childReport?.parentReportID}`); const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${childReport?.parentReportID}`); const isMoneyRequest = useMemo(() => ReportUtils.isMoneyRequest(childReport), [childReport]); @@ -187,7 +186,7 @@ function BaseReportActionContextMenu({ const isMoneyRequestOrReport = isMoneyRequestReport || isSingleTransactionView; const areHoldRequirementsMet = - !isInvoiceReport && isMoneyRequestOrReport && !ReportUtils.isArchivedRoom(transactionThreadReportID ? childReport : parentReport, parentReportNameValuePairs); + !isInvoiceReport && isMoneyRequestOrReport && !ReportUtils.isArchivedNonExpenseReport(transactionThreadReportID ? childReport : parentReport, parentReportNameValuePairs); const shouldEnableArrowNavigation = !isMini && (isVisible || shouldKeepOpen); let filteredContextMenuActions = ContextMenuActions.filter( @@ -287,7 +286,7 @@ function BaseReportActionContextMenu({ checkIfContextMenuActive?.(); setShouldKeepOpen(false); }, - ReportUtils.isArchivedRoomWithID(originalReportID), + ReportUtils.isArchivedNonExpenseReportWithID(originalReportID), ReportUtils.chatIncludesChronosWithID(originalReportID), undefined, undefined, @@ -307,7 +306,7 @@ function BaseReportActionContextMenu({ ) ? ReportActionsUtils.getOriginalMessage(reportAction) : undefined; - const cardID = cardIssuedActionOriginalMessage?.cardID ?? -1; + const cardID = cardIssuedActionOriginalMessage?.cardID ?? CONST.DEFAULT_NUMBER_ID; const isPolicyAdmin = PolicyUtils.isPolicyAdmin(PolicyUtils.getPolicy(policyID)); const card = isPolicyAdmin ? cardsList?.[cardID] : cardList[cardID]; diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index 0a80382552df..5670435aedde 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -909,7 +909,7 @@ function PureReportActionItem({ ref={textInputRef} shouldDisableEmojiPicker={ (ReportUtils.chatIncludesConcierge(report) && User.isBlockedFromConcierge(blockedFromConcierge)) || - ReportUtils.isArchivedRoom(report, reportNameValuePairs) + ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs) } isGroupPolicyReport={!!report?.policyID && report.policyID !== CONST.POLICY.ID_FAKE} /> diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 1887bf9d348a..4dde741879c5 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -15,34 +15,34 @@ import type {PureReportActionItemProps} from './PureReportActionItem'; import PureReportActionItem from './PureReportActionItem'; function ReportActionItem({action, report, ...props}: PureReportActionItemProps) { - const reportID = report?.reportID ?? ''; + const reportID = report?.reportID; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const originalReportID = useMemo(() => ReportUtils.getOriginalReportID(reportID, action) || '-1', [reportID, action]); + const originalReportID = useMemo(() => ReportUtils.getOriginalReportID(reportID, action), [reportID, action]); const [draftMessage] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`, { selector: (draftMessagesForReport) => { const matchingDraftMessage = draftMessagesForReport?.[action.reportActionID]; return typeof matchingDraftMessage === 'string' ? matchingDraftMessage : matchingDraftMessage?.message; }, }); - const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${ReportActionsUtils.getIOUReportIDFromReportActionPreview(action) ?? -1}`); + const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${ReportActionsUtils.getIOUReportIDFromReportActionPreview(action)}`); const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${action.reportActionID}`); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); const [linkedTransactionRouteError] = useOnyx( - `${ONYXKEYS.COLLECTION.TRANSACTION}${ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID ?? -1 : -1}`, + `${ONYXKEYS.COLLECTION.TRANSACTION}${ReportActionsUtils.isMoneyRequestAction(action) && ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID}`, {selector: (transaction) => transaction?.errorFields?.route ?? null}, ); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- This is needed to prevent the app from crashing when the app is using imported state. - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || '-1'}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`); const [isUserValidated] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.validated}); // The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || -1}`); + const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || undefined}`); const personalDetails = usePersonalDetails(); const blockedFromConcierge = useBlockedFromConcierge(); const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID); const linkedReport = ReportUtils.isChatThread(report) ? parentReport : report; - const missingPaymentMethod = ReportUtils.getIndicatedMissingPaymentMethod(userWallet, linkedReport?.reportID ?? '-1', action); + const missingPaymentMethod = ReportUtils.getIndicatedMissingPaymentMethod(userWallet, linkedReport?.reportID, action); return ( report.lastReadTime ? userActiveSince.current : report.lastReadTime; lastMessageTime.current = null; - const isArchivedReport = ReportUtils.isArchivedRoom(report); + const isArchivedReport = ReportUtils.isArchivedNonExpenseReport(report); const hasNewMessagesInView = scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD; const hasUnreadReportAction = sortedVisibleReportActions.some( (reportAction) => @@ -633,7 +633,7 @@ function ReportActionsList({ // Native mobile does not render updates flatlist the changes even though component did update called. // To notify there something changes we can use extraData prop to flatlist const extraData = useMemo( - () => [shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined, ReportUtils.isArchivedRoom(report, reportNameValuePairs)], + () => [shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined, ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs)], [unreadMarkerReportActionID, shouldUseNarrowLayout, report, reportNameValuePairs], ); const hideComposer = !ReportUtils.canUserPerformWriteAction(report); diff --git a/src/pages/home/report/ReportFooter.tsx b/src/pages/home/report/ReportFooter.tsx index 419c273edd26..e97e4c611922 100644 --- a/src/pages/home/report/ReportFooter.tsx +++ b/src/pages/home/report/ReportFooter.tsx @@ -106,7 +106,7 @@ function ReportFooter({ const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0}; - const isArchivedRoom = ReportUtils.isArchivedRoom(report, reportNameValuePairs); + const isArchivedRoom = ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs); const isSmallSizeLayout = windowWidth - (shouldUseNarrowLayout ? 0 : variables.sideBarWidth) < variables.anonymousReportFooterBreakpoint; diff --git a/src/pages/home/report/withReportAndPrivateNotesOrNotFound.tsx b/src/pages/home/report/withReportAndPrivateNotesOrNotFound.tsx index b27a2a2c9fb9..82e893500495 100644 --- a/src/pages/home/report/withReportAndPrivateNotesOrNotFound.tsx +++ b/src/pages/home/report/withReportAndPrivateNotesOrNotFound.tsx @@ -32,7 +32,7 @@ export default function (pageTitle: TranslationPaths) { const {isOffline} = useNetwork(); const [session] = useOnyx(ONYXKEYS.SESSION); const {route, report, reportMetadata} = props; - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); const accountID = ('accountID' in route.params && route.params.accountID) || ''; const isPrivateNotesFetchTriggered = reportMetadata?.isLoadingPrivateNotes !== undefined; const prevIsOffline = usePrevious(isOffline); @@ -56,7 +56,7 @@ export default function (pageTitle: TranslationPaths) { // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundPage = useMemo(() => { // Show not found view if the report is archived, or if the note is not of current user or if report is a self DM. - if (ReportUtils.isArchivedRoom(report, reportNameValuePairs) || isOtherUserNote || ReportUtils.isSelfDM(report)) { + if (ReportUtils.isArchivedReport(report, reportNameValuePairs) || isOtherUserNote || ReportUtils.isSelfDM(report)) { return true; } diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 393f396ece60..5c082e3d50f7 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -201,7 +201,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl const {canUseSpotnanaTravel} = usePermissions(); const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection, session?.email), [allPolicies, session?.email]); - const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs)); + const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedReport(quickActionReport, reportNameValuePairs)); const {environment} = useEnvironment(); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const navatticURL = getNavatticURL(environment, introSelected?.choice); diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 2b3d639deaa9..4814cd184ddf 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -56,9 +56,9 @@ function IOURequestStepAmount({ const focusTimeoutRef = useRef(null); const isSaveButtonPressed = useRef(false); const iouRequestType = getRequestType(transaction); - const policyID = report?.policyID ?? '-1'; + const policyID = report?.policyID; - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [draftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`); @@ -80,7 +80,7 @@ function IOURequestStepAmount({ return false; } - return !(ReportUtils.isArchivedRoom(report, reportNameValuePairs) || ReportUtils.isPolicyExpenseChat(report)); + return !(ReportUtils.isArchivedReport(report, reportNameValuePairs) || ReportUtils.isPolicyExpenseChat(report)); }, [report, isSplitBill, skipConfirmation, reportNameValuePairs]); useFocusEffect( @@ -108,7 +108,7 @@ function IOURequestStepAmount({ if (isSaveButtonPressed.current) { return; } - TransactionEdit.removeDraftTransaction(transaction?.transactionID ?? '-1'); + TransactionEdit.removeDraftTransaction(transaction?.transactionID); }; // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, []); @@ -169,10 +169,10 @@ function IOURequestStepAmount({ // In this case, the participants can be automatically assigned from the report and the user can skip the participants step and go straight // to the confirm step. // If the user is started this flow using the Create expense option (combined submit/track flow), they should be redirected to the participants page. - if (report?.reportID && !ReportUtils.isArchivedRoom(report, reportNameValuePairs) && iouType !== CONST.IOU.TYPE.CREATE) { + if (report?.reportID && !ReportUtils.isArchivedReport(report, reportNameValuePairs) && iouType !== CONST.IOU.TYPE.CREATE) { const selectedParticipants = IOU.setMoneyRequestParticipantsFromReport(transactionID, report); const participants = selectedParticipants.map((participant) => { - const participantAccountID = participant?.accountID ?? -1; + const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID; return participantAccountID ? OptionsListUtils.getParticipantsOption(participant, personalDetails) : OptionsListUtils.getReportOption(participant); }); const backendAmount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount)); @@ -288,7 +288,7 @@ function IOURequestStepAmount({ amount={Math.abs(transactionAmount)} skipConfirmation={shouldSkipConfirmation ?? false} iouType={iouType} - policyID={policy?.id ?? '-1'} + policyID={policy?.id} bankAccountRoute={ReportUtils.getBankAccountRoute(report)} ref={(e) => (textInput.current = e)} shouldKeepUserInput={transaction?.shouldShowOriginalAmount} diff --git a/src/pages/iou/request/step/IOURequestStepDistance.tsx b/src/pages/iou/request/step/IOURequestStepDistance.tsx index c089759f4a75..7e4027f10382 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistance.tsx @@ -66,7 +66,7 @@ function IOURequestStepDistance({ const {isOffline} = useNetwork(); const {translate} = useLocalize(); const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); const [transactionBackup] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transactionID}`); const policy = usePolicy(report?.policyID); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); @@ -122,7 +122,7 @@ function IOURequestStepDistance({ const isCreatingNewRequest = !(backTo || isEditing); const [recentWaypoints, {status: recentWaypointsStatus}] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS); const iouRequestType = TransactionUtils.getRequestType(transaction); - const customUnitRateID = TransactionUtils.getRateID(transaction) ?? '-1'; + const customUnitRateID = TransactionUtils.getRateID(transaction); // Sets `amount` and `split` share data before moving to the next step to avoid briefly showing `0.00` as the split share for participants const setDistanceRequestData = useCallback( @@ -138,9 +138,10 @@ function IOURequestStepDistance({ const mileageRates = DistanceRequestUtils.getMileageRates(IOUpolicy); const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(IOUpolicy); - const mileageRate: MileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) + const mileageRate: MileageRate | undefined = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction) - : mileageRates?.[customUnitRateID] ?? defaultMileageRate; + : // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + (customUnitRateID && mileageRates?.[customUnitRateID]) || defaultMileageRate; const {unit, rate} = mileageRate ?? {}; const distance = TransactionUtils.getDistanceInMeters(transaction, unit); @@ -148,7 +149,7 @@ function IOURequestStepDistance({ const amount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES, rate ?? 0); IOU.setMoneyRequestAmount(transactionID, amount, currency); - const participantAccountIDs: number[] | undefined = participants?.map((participant) => Number(participant.accountID ?? -1)); + const participantAccountIDs: number[] | undefined = participants?.map((participant) => Number(participant.accountID ?? CONST.DEFAULT_NUMBER_ID)); if (isSplitRequest && amount && currency && !isPolicyExpenseChat) { IOU.setSplitShares(transaction, amount, currency ?? '', participantAccountIDs ?? []); } @@ -165,7 +166,7 @@ function IOURequestStepDistance({ return ( iouType !== CONST.IOU.TYPE.SPLIT && - !ReportUtils.isArchivedRoom(report, reportNameValuePairs) && + !ReportUtils.isArchivedReport(report, reportNameValuePairs) && !(ReportUtils.isPolicyExpenseChat(report) && ((policy?.requiresCategory ?? false) || (policy?.requiresTag ?? false))) ); }, [report, skipConfirmation, policy, reportNameValuePairs, iouType]); @@ -225,10 +226,10 @@ function IOURequestStepDistance({ // If the user cancels out of the modal without without saving changes, then the original transaction // needs to be restored from the backup so that all changes are removed. if (transactionWasSaved.current) { - TransactionEdit.removeBackupTransaction(transaction?.transactionID ?? '-1'); + TransactionEdit.removeBackupTransaction(transaction?.transactionID); return; } - TransactionEdit.restoreOriginalTransactionFromBackup(transaction?.transactionID ?? '-1', IOUUtils.shouldUseTransactionDraft(action)); + TransactionEdit.restoreOriginalTransactionFromBackup(transaction?.transactionID, IOUUtils.shouldUseTransactionDraft(action)); // If the user opens IOURequestStepDistance in offline mode and then goes online, re-open the report to fill in missing fields from the transaction backup if (!transaction?.reportID) { @@ -297,10 +298,10 @@ function IOURequestStepDistance({ // In this case, the participants can be automatically assigned from the report and the user can skip the participants step and go straight // to the confirm step. // If the user started this flow using the Create expense option (combined submit/track flow), they should be redirected to the participants page. - if (report?.reportID && !ReportUtils.isArchivedRoom(report, reportNameValuePairs) && iouType !== CONST.IOU.TYPE.CREATE) { + if (report?.reportID && !ReportUtils.isArchivedReport(report, reportNameValuePairs) && iouType !== CONST.IOU.TYPE.CREATE) { const selectedParticipants = IOU.setMoneyRequestParticipantsFromReport(transactionID, report); const participants = selectedParticipants.map((participant) => { - const participantAccountID = participant?.accountID ?? -1; + const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID; return participantAccountID ? OptionsListUtils.getParticipantsOption(participant, personalDetails) : OptionsListUtils.getReportOption(participant); }); setDistanceRequestData(participants); @@ -455,14 +456,17 @@ function IOURequestStepDistance({ navigateBack(); return; } - IOU.updateMoneyRequestDistance({ - transactionID: transaction?.transactionID ?? '-1', - transactionThreadReportID: report?.reportID ?? '-1', - waypoints, - ...(hasRouteChanged ? {routes: transaction?.routes} : {}), - policy, - transactionBackup, - }); + + if (transaction?.transactionID && report?.reportID) { + IOU.updateMoneyRequestDistance({ + transactionID: transaction?.transactionID, + transactionThreadReportID: report?.reportID, + waypoints, + ...(hasRouteChanged ? {routes: transaction?.routes} : {}), + policy, + transactionBackup, + }); + } transactionWasSaved.current = true; navigateBack(); return; diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 990296d245fb..180868c8ca51 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -74,10 +74,10 @@ function IOURequestStepScan({ const [startLocationPermissionFlow, setStartLocationPermissionFlow] = useState(false); const [fileResize, setFileResize] = useState(null); const [fileSource, setFileSource] = useState(''); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? CONST.DEFAULT_NUMBER_ID}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); const policy = usePolicy(report?.policyID); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); - const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? CONST.DEFAULT_NUMBER_ID}`); + const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID}`); const platform = getPlatform(true); const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS); const isPlatformMuted = mutedPlatforms[platform]; @@ -99,7 +99,8 @@ function IOURequestStepScan({ } return ( - !ReportUtils.isArchivedRoom(report, reportNameValuePairs) && !(ReportUtils.isPolicyExpenseChat(report) && ((policy?.requiresCategory ?? false) || (policy?.requiresTag ?? false))) + !ReportUtils.isArchivedReport(report, reportNameValuePairs) && + !(ReportUtils.isPolicyExpenseChat(report) && ((policy?.requiresCategory ?? false) || (policy?.requiresTag ?? false))) ); }, [report, skipConfirmation, policy, reportNameValuePairs]); diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index fcf734781b3a..8dbe72d3f9fa 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -86,10 +86,10 @@ function IOURequestStepScan({ const [isQueriedPermissionState, setIsQueriedPermissionState] = useState(false); const getScreenshotTimeoutRef = useRef(null); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? CONST.DEFAULT_NUMBER_ID}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); const policy = usePolicy(report?.policyID); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); - const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? CONST.DEFAULT_NUMBER_ID}`); + const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID}`); const [isLoadingReceipt, setIsLoadingReceipt] = useState(false); const [videoConstraints, setVideoConstraints] = useState(); @@ -108,7 +108,8 @@ function IOURequestStepScan({ } return ( - !ReportUtils.isArchivedRoom(report, reportNameValuePairs) && !(ReportUtils.isPolicyExpenseChat(report) && ((policy?.requiresCategory ?? false) || (policy?.requiresTag ?? false))) + !ReportUtils.isArchivedReport(report, reportNameValuePairs) && + !(ReportUtils.isPolicyExpenseChat(report) && ((policy?.requiresCategory ?? false) || (policy?.requiresTag ?? false))) ); }, [report, skipConfirmation, policy, reportNameValuePairs]); diff --git a/src/pages/settings/Report/NotificationPreferencePage.tsx b/src/pages/settings/Report/NotificationPreferencePage.tsx index 9a90e3dd710f..434505ad473e 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.tsx +++ b/src/pages/settings/Report/NotificationPreferencePage.tsx @@ -23,11 +23,11 @@ type NotificationPreferencePageProps = WithReportOrNotFoundProps & PlatformStack function NotificationPreferencePage({report}: NotificationPreferencePageProps) { const route = useRoute>(); const {translate} = useLocalize(); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID || -1}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID || undefined}`); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); const currentNotificationPreference = ReportUtils.getReportNotificationPreference(report); const shouldDisableNotificationPreferences = - ReportUtils.isArchivedRoom(report, reportNameValuePairs) || + ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs) || ReportUtils.isSelfDM(report) || (!isMoneyRequestReport && ReportUtils.isHiddenForCurrentUser(currentNotificationPreference)); const notificationPreferenceOptions = Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE) diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index 0305843d05b0..2e9f70da7261 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -25,7 +25,7 @@ type ReportSettingsPageProps = WithReportOrNotFoundProps & PlatformStackScreenPr function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) { const backTo = route.params.backTo; - const reportID = report?.reportID ?? '-1'; + const reportID = report?.reportID; const styles = useThemeStyles(); const {translate} = useLocalize(); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`); @@ -33,7 +33,7 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps) const linkedWorkspace = useMemo(() => Object.values(policies ?? {}).find((policy) => policy && policy.id === report?.policyID), [policies, report?.policyID]); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); - const shouldDisableSettings = isEmptyObject(report) || ReportUtils.isArchivedRoom(report, reportNameValuePairs) || ReportUtils.isSelfDM(report); + const shouldDisableSettings = isEmptyObject(report) || ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs) || ReportUtils.isSelfDM(report); const notificationPreferenceValue = ReportUtils.getReportNotificationPreference(report); const notificationPreference = notificationPreferenceValue && !ReportUtils.isHiddenForCurrentUser(notificationPreferenceValue) diff --git a/src/pages/settings/Report/VisibilityPage.tsx b/src/pages/settings/Report/VisibilityPage.tsx index a1ddc3d5fe48..560b96383a57 100644 --- a/src/pages/settings/Report/VisibilityPage.tsx +++ b/src/pages/settings/Report/VisibilityPage.tsx @@ -24,10 +24,10 @@ type VisibilityProps = WithReportOrNotFoundProps & PlatformStackScreenProps>(); const [showConfirmModal, setShowConfirmModal] = useState(false); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || -1}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || undefined}`); const shouldGoBackToDetailsPage = useRef(false); - const shouldDisableVisibility = ReportUtils.isArchivedRoom(report, reportNameValuePairs); + const shouldDisableVisibility = ReportUtils.isArchivedNonExpenseReport(report, reportNameValuePairs); const {translate} = useLocalize(); const visibilityOptions = useMemo(