From 0612e06f93d3d183c65e3bb0ec0aef8af8433dbb Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Wed, 18 Dec 2024 16:00:37 +0000 Subject: [PATCH 1/6] fix: undo default values to comply with eslint rules --- src/ROUTES.ts | 12 ++++----- src/libs/actions/Report.ts | 53 +++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index b9544d81bece..6fb72ea731f4 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -296,7 +296,7 @@ const ROUTES = { REPORT: 'r', REPORT_WITH_ID: { route: 'r/:reportID?/:reportActionID?', - getRoute: (reportID: string, reportActionID?: string, referrer?: string) => { + getRoute: (reportID = '', reportActionID?: string, referrer?: string) => { const baseRoute = reportActionID ? (`r/${reportID}/${reportActionID}` as const) : (`r/${reportID}` as const); const referrerParam = referrer ? `?referrer=${encodeURIComponent(referrer)}` : ''; return `${baseRoute}${referrerParam}` as const; @@ -698,7 +698,7 @@ const ROUTES = { WORKSPACE_NEW_ROOM: 'workspace/new-room', WORKSPACE_INITIAL: { route: 'settings/workspaces/:policyID', - getRoute: (policyID: string, backTo?: string) => `${getUrlWithBackToParam(`settings/workspaces/${policyID}`, backTo)}` as const, + getRoute: (policyID = '', backTo?: string) => `${getUrlWithBackToParam(`settings/workspaces/${policyID}`, backTo)}` as const, }, WORKSPACE_INVITE: { route: 'settings/workspaces/:policyID/invite', @@ -923,7 +923,7 @@ const ROUTES = { }, WORKSPACE_MEMBERS: { route: 'settings/workspaces/:policyID/members', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/members` as const, + getRoute: (policyID = '') => `settings/workspaces/${policyID}/members` as const, }, WORKSPACE_MEMBERS_IMPORT: { route: 'settings/workspaces/:policyID/members/import', @@ -935,7 +935,7 @@ const ROUTES = { }, POLICY_ACCOUNTING: { route: 'settings/workspaces/:policyID/accounting', - getRoute: (policyID: string, newConnectionName?: ConnectionName, integrationToDisconnect?: ConnectionName, shouldDisconnectIntegrationBeforeConnecting?: boolean) => { + getRoute: (policyID = '', newConnectionName?: ConnectionName, integrationToDisconnect?: ConnectionName, shouldDisconnectIntegrationBeforeConnecting?: boolean) => { let queryParams = ''; if (newConnectionName) { queryParams += `?newConnectionName=${newConnectionName}`; @@ -972,7 +972,7 @@ const ROUTES = { }, WORKSPACE_CATEGORIES: { route: 'settings/workspaces/:policyID/categories', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/categories` as const, + getRoute: (policyID = '') => `settings/workspaces/${policyID}/categories` as const, }, WORKSPACE_CATEGORY_SETTINGS: { route: 'settings/workspaces/:policyID/category/:categoryName', @@ -1037,7 +1037,7 @@ const ROUTES = { }, WORKSPACE_MORE_FEATURES: { route: 'settings/workspaces/:policyID/more-features', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/more-features` as const, + getRoute: (policyID = '') => `settings/workspaces/${policyID}/more-features` as const, }, WORKSPACE_TAGS: { route: 'settings/workspaces/:policyID/tags', diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 7baf66adc5c5..62597024baac 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -804,11 +804,11 @@ function clearAvatarErrors(reportID: string) { * @param participantAccountIDList The list of accountIDs that are included in a new chat, not including the user creating it */ function openReport( - reportID: string, + reportID = '', reportActionID?: string, participantLoginList: string[] = [], newReportObject?: ReportUtils.OptimisticChatReport, - parentReportActionID = '-1', + parentReportActionID = '', isFromDeepLink = false, participantAccountIDList: number[] = [], avatar?: File | CustomRNImageManipulatorResult, @@ -1065,7 +1065,7 @@ function openReport( failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReportObject.parentReportID}`, - value: {[parentReportActionID]: {childReportID: '-1', childType: ''}}, + value: {[parentReportActionID]: {childReportID: '', childType: ''}}, }); } } @@ -1142,12 +1142,12 @@ function navigateToAndOpenReport( const report = isEmptyObject(chat) ? newChat : chat; // We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server - openReport(report?.reportID ?? '', '', userLogins, newChat, undefined, undefined, undefined, avatarFile); + openReport(report?.reportID, '', userLogins, newChat, undefined, undefined, undefined, avatarFile); if (shouldDismissModal) { Navigation.dismissModalWithReport(report); } else { Navigation.navigateWithSwitchPolicyID({route: ROUTES.HOME}); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report?.reportID ?? '-1'), actionType); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report?.reportID), actionType); } } @@ -1165,7 +1165,7 @@ function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[]) const report = chat ?? newChat; // We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server - openReport(report?.reportID ?? '', '', [], newChat, '0', false, participantAccountIDs); + openReport(report?.reportID, '', [], newChat, '0', false, participantAccountIDs); Navigation.dismissModalWithReport(report); } @@ -1176,8 +1176,8 @@ function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[]) * @param parentReportAction the parent comment of a thread * @param parentReportID The reportID of the parent */ -function navigateToAndOpenChildReport(childReportID = '-1', parentReportAction: Partial = {}, parentReportID = '0') { - if (childReportID !== '-1' && childReportID !== '0') { +function navigateToAndOpenChildReport(childReportID = '', parentReportAction: Partial = {}, parentReportID = '0') { + if (childReportID !== '' && childReportID !== '0') { Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(childReportID)); } else { const participantAccountIDs = [...new Set([currentUserAccountID, Number(parentReportAction.actorAccountID)])]; @@ -1357,7 +1357,7 @@ function readNewestAction(reportID: string, shouldResetUnreadMarker = false) { * Sets the last read time on a report */ function markCommentAsUnread(reportID: string, reportActionCreated: string) { - if (reportID === '-1') { + if (reportID === '') { Log.warn('7339cd6c-3263-4f89-98e5-730f0be15784 Invalid report passed to MarkCommentAsUnread. Not calling the API because it wil fail.'); return; } @@ -1482,7 +1482,7 @@ function handleReportChanged(report: OnyxEntry) { const currCallback = callback; callback = () => { currCallback(); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID ?? '-1'), CONST.NAVIGATION.TYPE.UP); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID), CONST.NAVIGATION.TYPE.UP); }; // The report screen will listen to this event and transfer the draft comment to the existing report @@ -1503,7 +1503,7 @@ function handleReportChanged(report: OnyxEntry) { return; } - saveReportDraftComment(report.preexistingReportID ?? '-1', draftReportComment, callback); + saveReportDraftComment(report.preexistingReportID, draftReportComment, callback); return; } @@ -1928,10 +1928,13 @@ function updateRoomVisibility(reportID: string, previousValue: RoomVisibility | * @param parentReportID The reportID of the parent * @param prevNotificationPreference The previous notification preference for the child report */ -function toggleSubscribeToChildReport(childReportID = '-1', parentReportAction: Partial = {}, parentReportID = '-1', prevNotificationPreference?: NotificationPreference) { - if (childReportID !== '-1') { +function toggleSubscribeToChildReport(childReportID = '', parentReportAction: Partial = {}, parentReportID = '', prevNotificationPreference?: NotificationPreference) { + if (childReportID !== '') { openReport(childReportID); - const parentReportActionID = parentReportAction?.reportActionID ?? '-1'; + // updateNotificationPreference cannot default parentReportActionID to '', + // otherwise it's behaviour will change + // eslint-disable-next-line rulesdir/no-default-id-values + const parentReportActionID = parentReportAction?.reportActionID ?? ''; if (!prevNotificationPreference || prevNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { updateNotificationPreference(childReportID, prevNotificationPreference, CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, parentReportID, parentReportActionID); } else { @@ -2889,7 +2892,7 @@ function navigateToMostRecentReport(currentReport: OnyxEntry) { const lastAccessedReportID = ReportUtils.findLastAccessedReport(false, false, undefined, currentReport?.reportID)?.reportID; if (lastAccessedReportID) { - const lastAccessedReportRoute = ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID ?? '-1'); + const lastAccessedReportRoute = ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID); Navigation.goBack(lastAccessedReportRoute); } else { const isChatThread = ReportUtils.isChatThread(currentReport); @@ -3587,14 +3590,14 @@ function prepareOnboardingOptimisticData( const taskDescription = typeof task.description === 'function' ? task.description({ - adminsRoomLink: `${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID ?? '-1')}`, - workspaceCategoriesLink: `${environmentURL}/${ROUTES.WORKSPACE_CATEGORIES.getRoute(onboardingPolicyID ?? '-1')}`, - workspaceMembersLink: `${environmentURL}/${ROUTES.WORKSPACE_MEMBERS.getRoute(onboardingPolicyID ?? '-1')}`, - workspaceMoreFeaturesLink: `${environmentURL}/${ROUTES.WORKSPACE_MORE_FEATURES.getRoute(onboardingPolicyID ?? '-1')}`, + adminsRoomLink: `${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID)}`, + workspaceCategoriesLink: `${environmentURL}/${ROUTES.WORKSPACE_CATEGORIES.getRoute(onboardingPolicyID)}`, + workspaceMembersLink: `${environmentURL}/${ROUTES.WORKSPACE_MEMBERS.getRoute(onboardingPolicyID)}`, + workspaceMoreFeaturesLink: `${environmentURL}/${ROUTES.WORKSPACE_MORE_FEATURES.getRoute(onboardingPolicyID)}`, navatticURL: getNavatticURL(environment, engagementChoice), integrationName, - workspaceAccountingLink: `${environmentURL}/${ROUTES.POLICY_ACCOUNTING.getRoute(onboardingPolicyID ?? '-1')}`, - workspaceSettingsLink: `${environmentURL}/${ROUTES.WORKSPACE_INITIAL.getRoute(onboardingPolicyID ?? '-1')}`, + workspaceAccountingLink: `${environmentURL}/${ROUTES.POLICY_ACCOUNTING.getRoute(onboardingPolicyID)}`, + workspaceSettingsLink: `${environmentURL}/${ROUTES.WORKSPACE_INITIAL.getRoute(onboardingPolicyID)}`, }) : task.description; const taskTitle = @@ -3644,7 +3647,9 @@ function prepareOnboardingOptimisticData( type: 'task', task: task.type, taskReportID: currentTask.reportID, - parentReportID: currentTask.parentReportID ?? '-1', + // API expects a string, that's why policyID must default to a string + // eslint-disable-next-line rulesdir/no-default-id-values + parentReportID: currentTask.parentReportID ?? '', parentReportActionID: taskReportAction.reportAction.reportActionID, assigneeChatReportID: '', createdTaskReportActionID: taskCreatedAction.reportActionID, @@ -4087,7 +4092,9 @@ function searchForReports(searchInput: string, policyID?: string) { }, ]; - const searchForRoomToMentionParams: SearchForRoomsToMentionParams = {query: searchInput, policyID: policyID ?? '-1'}; + // API expects a string, that's why policyID must default to a string + // eslint-disable-next-line rulesdir/no-default-id-values + const searchForRoomToMentionParams: SearchForRoomsToMentionParams = {query: searchInput, policyID: policyID ?? ''}; const searchForReportsParams: SearchForReportsParams = {searchInput, canCancel: true}; // We want to cancel all pending SearchForReports API calls before making another one From f927a37c761a025fbd387fb479e8e64302de37b5 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Wed, 18 Dec 2024 16:13:48 +0000 Subject: [PATCH 2/6] doc: fix typo in comment --- src/libs/actions/Report.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 62597024baac..f9b38e710cd3 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3647,7 +3647,7 @@ function prepareOnboardingOptimisticData( type: 'task', task: task.type, taskReportID: currentTask.reportID, - // API expects a string, that's why policyID must default to a string + // API expects a string, that's why parentReportID must default to a string // eslint-disable-next-line rulesdir/no-default-id-values parentReportID: currentTask.parentReportID ?? '', parentReportActionID: taskReportAction.reportAction.reportActionID, From 7f97310a357521a923701592da948366bc671831 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Thu, 19 Dec 2024 23:20:24 +0000 Subject: [PATCH 3/6] chore: apply suggestions and follow guidelines --- src/ROUTES.ts | 12 +-- .../AddCommentOrAttachementParams.ts | 2 +- .../SearchForRoomsToMentionParams.ts | 2 +- src/libs/ReportActionsUtils.ts | 10 +- src/libs/ReportUtils.ts | 2 +- src/libs/actions/Report.ts | 92 ++++++++++--------- .../report/ContextMenu/ContextMenuActions.tsx | 10 +- 7 files changed, 69 insertions(+), 61 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index c363d1d48533..58d28a46a7b8 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -296,7 +296,7 @@ const ROUTES = { REPORT: 'r', REPORT_WITH_ID: { route: 'r/:reportID?/:reportActionID?', - getRoute: (reportID = '', reportActionID?: string, referrer?: string) => { + getRoute: (reportID: string, reportActionID?: string, referrer?: string) => { const baseRoute = reportActionID ? (`r/${reportID}/${reportActionID}` as const) : (`r/${reportID}` as const); const referrerParam = referrer ? `?referrer=${encodeURIComponent(referrer)}` : ''; return `${baseRoute}${referrerParam}` as const; @@ -698,7 +698,7 @@ const ROUTES = { WORKSPACE_NEW_ROOM: 'workspace/new-room', WORKSPACE_INITIAL: { route: 'settings/workspaces/:policyID', - getRoute: (policyID = '', backTo?: string) => `${getUrlWithBackToParam(`settings/workspaces/${policyID}`, backTo)}` as const, + getRoute: (policyID: string, backTo?: string) => `${getUrlWithBackToParam(`settings/workspaces/${policyID}`, backTo)}` as const, }, WORKSPACE_INVITE: { route: 'settings/workspaces/:policyID/invite', @@ -927,7 +927,7 @@ const ROUTES = { }, WORKSPACE_MEMBERS: { route: 'settings/workspaces/:policyID/members', - getRoute: (policyID = '') => `settings/workspaces/${policyID}/members` as const, + getRoute: (policyID: string) => `settings/workspaces/${policyID}/members` as const, }, WORKSPACE_MEMBERS_IMPORT: { route: 'settings/workspaces/:policyID/members/import', @@ -939,7 +939,7 @@ const ROUTES = { }, POLICY_ACCOUNTING: { route: 'settings/workspaces/:policyID/accounting', - getRoute: (policyID = '', newConnectionName?: ConnectionName, integrationToDisconnect?: ConnectionName, shouldDisconnectIntegrationBeforeConnecting?: boolean) => { + getRoute: (policyID: string, newConnectionName?: ConnectionName, integrationToDisconnect?: ConnectionName, shouldDisconnectIntegrationBeforeConnecting?: boolean) => { let queryParams = ''; if (newConnectionName) { queryParams += `?newConnectionName=${newConnectionName}`; @@ -976,7 +976,7 @@ const ROUTES = { }, WORKSPACE_CATEGORIES: { route: 'settings/workspaces/:policyID/categories', - getRoute: (policyID = '') => `settings/workspaces/${policyID}/categories` as const, + getRoute: (policyID: string) => `settings/workspaces/${policyID}/categories` as const, }, WORKSPACE_CATEGORY_SETTINGS: { route: 'settings/workspaces/:policyID/category/:categoryName', @@ -1041,7 +1041,7 @@ const ROUTES = { }, WORKSPACE_MORE_FEATURES: { route: 'settings/workspaces/:policyID/more-features', - getRoute: (policyID = '') => `settings/workspaces/${policyID}/more-features` as const, + getRoute: (policyID: string) => `settings/workspaces/${policyID}/more-features` as const, }, WORKSPACE_TAGS: { route: 'settings/workspaces/:policyID/tags', diff --git a/src/libs/API/parameters/AddCommentOrAttachementParams.ts b/src/libs/API/parameters/AddCommentOrAttachementParams.ts index d1b653f26de1..14307fe0fe29 100644 --- a/src/libs/API/parameters/AddCommentOrAttachementParams.ts +++ b/src/libs/API/parameters/AddCommentOrAttachementParams.ts @@ -1,7 +1,7 @@ import type {FileObject} from '@components/AttachmentModal'; type AddCommentOrAttachementParams = { - reportID: string; + reportID?: string; reportActionID?: string; commentReportActionID?: string | null; reportComment?: string; diff --git a/src/libs/API/parameters/SearchForRoomsToMentionParams.ts b/src/libs/API/parameters/SearchForRoomsToMentionParams.ts index 6a4efe7aed6b..adc2bdd2e4eb 100644 --- a/src/libs/API/parameters/SearchForRoomsToMentionParams.ts +++ b/src/libs/API/parameters/SearchForRoomsToMentionParams.ts @@ -1,6 +1,6 @@ type SearchForRoomsToMentionParams = { query: string; - policyID: string; + policyID?: string; }; export default SearchForRoomsToMentionParams; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index dd17adbda338..d12a406c9a61 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -772,7 +772,11 @@ function replaceBaseURLInPolicyChangeLogAction(reportAction: ReportAction): Repo return updatedReportAction; } -function getLastVisibleAction(reportID: string, canUserPerformWriteAction?: boolean, actionsToMerge: Record | null> = {}): OnyxEntry { +function getLastVisibleAction( + reportID: string | undefined, + canUserPerformWriteAction?: boolean, + actionsToMerge: Record | null> = {}, +): OnyxEntry { let reportActions: Array = []; if (!isEmpty(actionsToMerge)) { reportActions = Object.values(fastMerge(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {}, actionsToMerge ?? {}, true)) as Array< @@ -802,12 +806,12 @@ function formatLastMessageText(lastMessageText: string) { } function getLastVisibleMessage( - reportID: string, + reportID: string | undefined, canUserPerformWriteAction?: boolean, actionsToMerge: Record | null> = {}, reportAction: OnyxInputOrEntry | undefined = undefined, ): LastVisibleMessage { - const lastVisibleAction = reportAction ?? getLastVisibleAction(reportID, canUserPerformWriteAction, actionsToMerge); + const lastVisibleAction = reportAction ?? (reportID ? getLastVisibleAction(reportID, canUserPerformWriteAction, actionsToMerge) : undefined); const message = getReportActionMessage(lastVisibleAction); if (message && isReportMessageAttachment(message)) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c20ec7386b0a..0d3d244d9592 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4535,7 +4535,7 @@ function buildOptimisticTaskCommentReportAction( taskTitle: string, taskAssigneeAccountID: number, text: string, - parentReportID: string, + parentReportID: string | undefined, actorAccountID?: number, createdOffset = 0, ): OptimisticReportAction { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 8f7de936601f..cfe7b7ba1c0c 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -151,9 +151,9 @@ type TaskForParameters = type: 'task'; task: string; taskReportID: string; - parentReportID: string; + parentReportID?: string; parentReportActionID: string; - assigneeChatReportID: string; + assigneeChatReportID?: string; createdTaskReportActionID: string; completedTaskReportActionID?: string; title: string; @@ -803,11 +803,11 @@ function clearAvatarErrors(reportID: string) { * @param participantAccountIDList The list of accountIDs that are included in a new chat, not including the user creating it */ function openReport( - reportID = '', + reportID: string | undefined, reportActionID?: string, participantLoginList: string[] = [], newReportObject?: ReportUtils.OptimisticChatReport, - parentReportActionID = '', + parentReportActionID?: string, isFromDeepLink = false, participantAccountIDList: number[] = [], avatar?: File | CustomRNImageManipulatorResult, @@ -1064,7 +1064,7 @@ function openReport( failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReportObject.parentReportID}`, - value: {[parentReportActionID]: {childReportID: '', childType: ''}}, + value: {[parentReportActionID]: {childReportID: undefined, childType: ''}}, }); } } @@ -1146,7 +1146,7 @@ function navigateToAndOpenReport( Navigation.dismissModalWithReport(report); } else { Navigation.navigateWithSwitchPolicyID({route: ROUTES.HOME}); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report?.reportID), actionType); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(`${report?.reportID}`), actionType); } } @@ -1175,8 +1175,8 @@ function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[]) * @param parentReportAction the parent comment of a thread * @param parentReportID The reportID of the parent */ -function navigateToAndOpenChildReport(childReportID = '', parentReportAction: Partial = {}, parentReportID = '0') { - if (childReportID !== '' && childReportID !== '0') { +function navigateToAndOpenChildReport(childReportID: string | undefined, parentReportAction: Partial = {}, parentReportID?: string) { + if (childReportID) { Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(childReportID)); } else { const participantAccountIDs = [...new Set([currentUserAccountID, Number(parentReportAction.actorAccountID)])]; @@ -1355,8 +1355,8 @@ function readNewestAction(reportID: string, shouldResetUnreadMarker = false) { /** * Sets the last read time on a report */ -function markCommentAsUnread(reportID: string, reportActionCreated: string) { - if (reportID === '') { +function markCommentAsUnread(reportID: string | undefined, reportActionCreated: string) { + if (!reportID) { Log.warn('7339cd6c-3263-4f89-98e5-730f0be15784 Invalid report passed to MarkCommentAsUnread. Not calling the API because it wil fail.'); return; } @@ -1458,36 +1458,38 @@ function handleReportChanged(report: OnyxEntry) { return; } + const {reportID, preexistingReportID, parentReportID, parentReportActionID} = report; + // Handle cleanup of stale optimistic IOU report and its report preview separately - if (report?.reportID && report.preexistingReportID && ReportUtils.isMoneyRequestReport(report) && report?.parentReportActionID) { - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, { - [report.parentReportActionID]: null, + if (reportID && preexistingReportID && ReportUtils.isMoneyRequestReport(report) && parentReportActionID) { + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, { + [parentReportActionID]: null, }); - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, null); + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, null); return; } // It is possible that we optimistically created a DM/group-DM for a set of users for which a report already exists. // In this case, the API will let us know by returning a preexistingReportID. // We should clear out the optimistically created report and re-route the user to the preexisting report. - if (report?.reportID && report.preexistingReportID) { + if (reportID && preexistingReportID) { let callback = () => { - Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, null); - Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.preexistingReportID}`, {...report, reportID: report.preexistingReportID, preexistingReportID: null}); - Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`, null); + Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, null); + Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${preexistingReportID}`, {...report, reportID: preexistingReportID, preexistingReportID: null}); + Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, null); }; // Only re-route them if they are still looking at the optimistically created report - if (Navigation.getActiveRoute().includes(`/r/${report.reportID}`)) { + if (Navigation.getActiveRoute().includes(`/r/${reportID}`)) { const currCallback = callback; callback = () => { currCallback(); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID), CONST.NAVIGATION.TYPE.UP); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(preexistingReportID), CONST.NAVIGATION.TYPE.UP); }; // The report screen will listen to this event and transfer the draft comment to the existing report // This will allow the newest draft comment to be transferred to the existing report - DeviceEventEmitter.emit(`switchToPreExistingReport_${report.reportID}`, { - preexistingReportID: report.preexistingReportID, + DeviceEventEmitter.emit(`switchToPreExistingReport_${reportID}`, { + preexistingReportID, callback, }); @@ -1496,20 +1498,20 @@ function handleReportChanged(report: OnyxEntry) { // In case the user is not on the report screen, we will transfer the report draft comment directly to the existing report // after that clear the optimistically created report - const draftReportComment = allReportDraftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`]; + const draftReportComment = allReportDraftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`]; if (!draftReportComment) { callback(); return; } - saveReportDraftComment(report.preexistingReportID, draftReportComment, callback); + saveReportDraftComment(preexistingReportID, draftReportComment, callback); return; } - if (report?.reportID) { + if (reportID) { if (ReportUtils.isConciergeChatReport(report)) { - conciergeChatReportID = report.reportID; + conciergeChatReportID = reportID; } } } @@ -1927,10 +1929,15 @@ function updateRoomVisibility(reportID: string, previousValue: RoomVisibility | * @param parentReportID The reportID of the parent * @param prevNotificationPreference The previous notification preference for the child report */ -function toggleSubscribeToChildReport(childReportID = '', parentReportAction: Partial = {}, parentReportID = '', prevNotificationPreference?: NotificationPreference) { - if (childReportID !== '') { +function toggleSubscribeToChildReport( + childReportID: string | undefined, + parentReportAction: Partial = {}, + parentReportID?: string, + prevNotificationPreference?: NotificationPreference, +) { + if (childReportID) { openReport(childReportID); - const parentReportActionID = parentReportAction?.reportActionID ?? '-1'; + const parentReportActionID = parentReportAction?.reportActionID; if (!prevNotificationPreference || ReportUtils.isHiddenForCurrentUser(prevNotificationPreference)) { updateNotificationPreference(childReportID, prevNotificationPreference, CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, parentReportID, parentReportActionID); } else { @@ -3064,8 +3071,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, value: { [report.parentReportActionID]: { - childReportNotificationPreference: - report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? ReportUtils.getDefaultNotificationPreferenceForReport(report), + childReportNotificationPreference: report?.participants?.[currentUserAccountID]?.notificationPreference ?? ReportUtils.getDefaultNotificationPreferenceForReport(report), }, }, }); @@ -3540,7 +3546,7 @@ function prepareOnboardingOptimisticData( const integrationName = userReportedIntegration ? CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration] : ''; const adminsChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${adminsChatReportID}`]; const targetChatReport = shouldPostTasksInAdminsRoom ? adminsChatReport : ReportUtils.getChatByParticipants([CONST.ACCOUNT_ID.CONCIERGE, currentUserAccountID]); - const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {}; + const {reportID: targetChatReportID, policyID: targetChatPolicyID} = targetChatReport ?? {}; const assignedGuideEmail = getPolicy(targetChatPolicyID)?.assignedGuide?.email ?? 'Setup Specialist'; const assignedGuidePersonalDetail = Object.values(allPersonalDetails ?? {}).find((personalDetail) => personalDetail?.login === assignedGuideEmail); let assignedGuideAccountID: number; @@ -3592,14 +3598,14 @@ function prepareOnboardingOptimisticData( const taskDescription = typeof task.description === 'function' ? task.description({ - adminsRoomLink: `${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID)}`, - workspaceCategoriesLink: `${environmentURL}/${ROUTES.WORKSPACE_CATEGORIES.getRoute(onboardingPolicyID)}`, - workspaceMembersLink: `${environmentURL}/${ROUTES.WORKSPACE_MEMBERS.getRoute(onboardingPolicyID)}`, - workspaceMoreFeaturesLink: `${environmentURL}/${ROUTES.WORKSPACE_MORE_FEATURES.getRoute(onboardingPolicyID)}`, + adminsRoomLink: `${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(`${adminsChatReportID}`)}`, + workspaceCategoriesLink: `${environmentURL}/${ROUTES.WORKSPACE_CATEGORIES.getRoute(`${onboardingPolicyID}`)}`, + workspaceMembersLink: `${environmentURL}/${ROUTES.WORKSPACE_MEMBERS.getRoute(`${onboardingPolicyID}`)}`, + workspaceMoreFeaturesLink: `${environmentURL}/${ROUTES.WORKSPACE_MORE_FEATURES.getRoute(`${onboardingPolicyID}`)}`, navatticURL: getNavatticURL(environment, engagementChoice), integrationName, - workspaceAccountingLink: `${environmentURL}/${ROUTES.POLICY_ACCOUNTING.getRoute(onboardingPolicyID)}`, - workspaceSettingsLink: `${environmentURL}/${ROUTES.WORKSPACE_INITIAL.getRoute(onboardingPolicyID)}`, + workspaceAccountingLink: `${environmentURL}/${ROUTES.POLICY_ACCOUNTING.getRoute(`${onboardingPolicyID}`)}`, + workspaceSettingsLink: `${environmentURL}/${ROUTES.WORKSPACE_INITIAL.getRoute(`${onboardingPolicyID}`)}`, }) : task.description; const taskTitle = @@ -3649,13 +3655,11 @@ function prepareOnboardingOptimisticData( type: 'task', task: task.type, taskReportID: currentTask.reportID, - // API expects a string, that's why parentReportID must default to a string - // eslint-disable-next-line rulesdir/no-default-id-values - parentReportID: currentTask.parentReportID ?? '', + parentReportID: currentTask.parentReportID, parentReportActionID: taskReportAction.reportAction.reportActionID, - assigneeChatReportID: '', + assigneeChatReportID: undefined, createdTaskReportActionID: taskCreatedAction.reportActionID, - completedTaskReportActionID: completedTaskReportAction?.reportActionID ?? undefined, + completedTaskReportActionID: completedTaskReportAction?.reportActionID, title: currentTask.reportName ?? '', description: taskDescription ?? '', })); @@ -4096,7 +4100,7 @@ function searchForReports(searchInput: string, policyID?: string) { // API expects a string, that's why policyID must default to a string // eslint-disable-next-line rulesdir/no-default-id-values - const searchForRoomToMentionParams: SearchForRoomsToMentionParams = {query: searchInput, policyID: policyID ?? ''}; + const searchForRoomToMentionParams: SearchForRoomsToMentionParams = {query: searchInput, policyID}; const searchForReportsParams: SearchForReportsParams = {searchInput, canCancel: true}; // We want to cancel all pending SearchForReports API calls before making another one diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index b8cdde2ecff3..eef578df94ba 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -193,11 +193,11 @@ const ContextMenuActions: ContextMenuAction[] = [ // is false, so we need to pass true here to override this condition. ReportActionComposeFocusManager.focus(true); }); - Report.navigateToAndOpenChildReport(reportAction?.childReportID ?? '-1', reportAction, originalReportID); + Report.navigateToAndOpenChildReport(reportAction?.childReportID, reportAction, originalReportID); }); return; } - Report.navigateToAndOpenChildReport(reportAction?.childReportID ?? '-1', reportAction, originalReportID); + Report.navigateToAndOpenChildReport(reportAction?.childReportID, reportAction, originalReportID); }, getDescription: () => {}, }, @@ -208,7 +208,7 @@ const ContextMenuActions: ContextMenuAction[] = [ successIcon: Expensicons.Checkmark, shouldShow: ({type, isUnreadChat}) => type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION || (type === CONST.CONTEXT_MENU_TYPES.REPORT && !isUnreadChat), onPress: (closePopover, {reportAction, reportID}) => { - const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction) ?? '-1'; + const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); Report.markCommentAsUnread(originalReportID, reportAction?.created); if (closePopover) { hideContextMenu(true, ReportActionComposeFocusManager.focus); @@ -324,13 +324,13 @@ const ContextMenuActions: ContextMenuAction[] = [ if (closePopover) { hideContextMenu(false, () => { ReportActionComposeFocusManager.focus(); - Report.toggleSubscribeToChildReport(reportAction?.childReportID ?? '-1', reportAction, originalReportID, childReportNotificationPreference); + Report.toggleSubscribeToChildReport(reportAction?.childReportID, reportAction, originalReportID, childReportNotificationPreference); }); return; } ReportActionComposeFocusManager.focus(); - Report.toggleSubscribeToChildReport(reportAction?.childReportID ?? '-1', reportAction, originalReportID, childReportNotificationPreference); + Report.toggleSubscribeToChildReport(reportAction?.childReportID, reportAction, originalReportID, childReportNotificationPreference); }, getDescription: () => {}, }, From 4be070e8a8d63dc1e0972c501cd097e3c322e4a0 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Fri, 20 Dec 2024 20:30:34 +0000 Subject: [PATCH 4/6] chore: resolve eslint issues --- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index eef578df94ba..a57c997ee6c0 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -239,9 +239,9 @@ const ContextMenuActions: ContextMenuAction[] = [ onPress: (closePopover, {reportID, reportAction, draftMessage}) => { if (ReportActionsUtils.isMoneyRequestAction(reportAction)) { hideContextMenu(false); - const childReportID = reportAction?.childReportID ?? '-1'; + const childReportID = reportAction?.childReportID; Report.openReport(childReportID); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(childReportID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(`${childReportID}`)); return; } const editAction = () => { From 3d6e6a3bf8772d7ff3c3e668e2623d5d1a82f16c Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Wed, 8 Jan 2025 19:05:09 +0000 Subject: [PATCH 5/6] refactor: make optimistic task.parentReportID required --- src/libs/ReportUtils.ts | 39 ++++++++++++++++++++------------------ src/libs/actions/Report.ts | 28 ++++++++++++++++----------- src/libs/actions/Task.ts | 2 +- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f9cb364bd085..9feef8b92d7d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -10,7 +10,7 @@ import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {SvgProps} from 'react-native-svg'; import type {OriginalMessageIOU, OriginalMessageModifiedExpense} from 'src/types/onyx/OriginalMessage'; -import type {TupleToUnion, ValueOf} from 'type-fest'; +import type {SetRequired, TupleToUnion, ValueOf} from 'type-fest'; import type {FileObject} from '@components/AttachmentModal'; import {FallbackAvatar, IntacctSquare, NetSuiteSquare, QBOSquare, XeroSquare} from '@components/Icon/Expensicons'; import * as defaultGroupAvatars from '@components/Icon/GroupDefaultAvatars'; @@ -404,22 +404,25 @@ type OptimisticModifiedExpenseReportAction = Pick< | 'delegateAccountID' > & {reportID?: string}; -type OptimisticTaskReport = Pick< - Report, - | 'reportID' - | 'reportName' - | 'description' - | 'ownerAccountID' - | 'participants' - | 'managerID' - | 'type' - | 'parentReportID' - | 'policyID' - | 'stateNum' - | 'statusNum' - | 'parentReportActionID' - | 'lastVisibleActionCreated' - | 'hasParentAccess' +type OptimisticTaskReport = SetRequired< + Pick< + Report, + | 'reportID' + | 'reportName' + | 'description' + | 'ownerAccountID' + | 'participants' + | 'managerID' + | 'type' + | 'parentReportID' + | 'policyID' + | 'stateNum' + | 'statusNum' + | 'parentReportActionID' + | 'lastVisibleActionCreated' + | 'hasParentAccess' + >, + 'parentReportID' >; type TransactionDetails = { @@ -6217,8 +6220,8 @@ function buildOptimisticWorkspaceChats(policyID: string, policyName: string, exp function buildOptimisticTaskReport( ownerAccountID: number, + parentReportID: string, assigneeAccountID = 0, - parentReportID?: string, title?: string, description?: string, policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index d1e8e563a07b..bd7f425c06ae 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -151,7 +151,7 @@ type TaskForParameters = type: 'task'; task: string; taskReportID: string; - parentReportID?: string; + parentReportID: string; parentReportActionID: string; assigneeChatReportID?: string; createdTaskReportActionID: string; @@ -893,6 +893,9 @@ function openReport( } const onboardingData = prepareOnboardingOptimisticData(choice, onboardingMessage); + if (!onboardingData) { + return; + } optimisticData.push(...onboardingData.optimisticData, { onyxMethod: Onyx.METHOD.MERGE, @@ -3584,10 +3587,15 @@ function prepareOnboardingOptimisticData( // Guides are assigned and tasks are posted in the #admins room for the MANAGE_TEAM onboarding action, except for emails that have a '+'. const shouldPostTasksInAdminsRoom = engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM && !currentUserEmail?.includes('+'); - const integrationName = userReportedIntegration ? CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration] : ''; const adminsChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${adminsChatReportID}`]; const targetChatReport = shouldPostTasksInAdminsRoom ? adminsChatReport : ReportUtils.getChatByParticipants([CONST.ACCOUNT_ID.CONCIERGE, currentUserAccountID]); const {reportID: targetChatReportID, policyID: targetChatPolicyID} = targetChatReport ?? {}; + + if (!targetChatReportID) { + return null; + } + + const integrationName = userReportedIntegration ? CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration] : ''; const assignedGuideEmail = getPolicy(targetChatPolicyID)?.assignedGuide?.email ?? 'Setup Specialist'; const assignedGuidePersonalDetail = Object.values(allPersonalDetails ?? {}).find((personalDetail) => personalDetail?.login === assignedGuideEmail); let assignedGuideAccountID: number; @@ -3657,8 +3665,8 @@ function prepareOnboardingOptimisticData( : task.title; const currentTask = ReportUtils.buildOptimisticTaskReport( actorAccountID, - currentUserAccountID, targetChatReportID, + currentUserAccountID, taskTitle, taskDescription, targetChatPolicyID, @@ -4149,14 +4157,12 @@ function completeOnboarding( userReportedIntegration?: OnboardingAccounting, wasInvited?: boolean, ) { - const {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters} = prepareOnboardingOptimisticData( - engagementChoice, - data, - adminsChatReportID, - onboardingPolicyID, - userReportedIntegration, - wasInvited, - ); + const onboardingData = prepareOnboardingOptimisticData(engagementChoice, data, adminsChatReportID, onboardingPolicyID, userReportedIntegration, wasInvited); + if (!onboardingData) { + return; + } + + const {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters} = onboardingData; const parameters: CompleteGuidedSetupParams = { engagementChoice, diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 2b4b8fe73ccc..76d6db7642a3 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -123,7 +123,7 @@ function createTaskAndNavigate( policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE, isCreatedUsingMarkdown = false, ) { - const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserAccountID, assigneeAccountID, parentReportID, title, description, policyID); + const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserAccountID, parentReportID, assigneeAccountID, title, description, policyID); const assigneeChatReportID = assigneeChatReport?.reportID ?? '-1'; const taskReportID = optimisticTaskReport.reportID; From 0d5a338b1b1a3acc3cb58f9fb5b58eb041e08a96 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Wed, 8 Jan 2025 23:51:16 +0000 Subject: [PATCH 6/6] refactor: apply suggestions --- .eslintrc.changed.js | 1 - src/ROUTES.ts | 39 ++++++++++++++++++++++++++++++++------ src/libs/actions/Report.ts | 14 +++++++------- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/.eslintrc.changed.js b/.eslintrc.changed.js index 55472b10ea86..650b4541d7ec 100644 --- a/.eslintrc.changed.js +++ b/.eslintrc.changed.js @@ -12,7 +12,6 @@ module.exports = { { files: [ 'src/libs/actions/IOU.ts', - 'src/libs/actions/Report.ts', 'src/libs/actions/Task.ts', 'src/libs/OptionsListUtils.ts', 'src/libs/TransactionUtils/index.ts', diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 062da712cd7f..cf83dce1f0a6 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -3,6 +3,7 @@ import type {SearchQueryString} from './components/Search/types'; import type CONST from './CONST'; import type {IOUAction, IOUType} from './CONST'; import type {IOURequestType} from './libs/actions/IOU'; +import Log from './libs/Log'; import type {ExitReason} from './types/form/ExitSurveyReasonForm'; import type {ConnectionName, SageIntacctMappingName} from './types/onyx/Policy'; import type AssertTypesNotEqual from './types/utils/AssertTypesNotEqual'; @@ -296,7 +297,10 @@ const ROUTES = { REPORT: 'r', REPORT_WITH_ID: { route: 'r/:reportID?/:reportActionID?', - getRoute: (reportID: string, reportActionID?: string, referrer?: string) => { + getRoute: (reportID: string | undefined, reportActionID?: string, referrer?: string) => { + if (!reportID) { + Log.warn('Invalid reportID while building route REPORT_WITH_ID'); + } const baseRoute = reportActionID ? (`r/${reportID}/${reportActionID}` as const) : (`r/${reportID}` as const); const referrerParam = referrer ? `?referrer=${encodeURIComponent(referrer)}` : ''; return `${baseRoute}${referrerParam}` as const; @@ -731,7 +735,12 @@ const ROUTES = { WORKSPACE_NEW_ROOM: 'workspace/new-room', WORKSPACE_INITIAL: { route: 'settings/workspaces/:policyID', - getRoute: (policyID: string, backTo?: string) => `${getUrlWithBackToParam(`settings/workspaces/${policyID}`, backTo)}` as const, + getRoute: (policyID: string | undefined, backTo?: string) => { + if (!policyID) { + Log.warn('Invalid policyID while building route WORKSPACE_INITIAL'); + } + return `${getUrlWithBackToParam(`settings/workspaces/${policyID}`, backTo)}` as const; + }, }, WORKSPACE_INVITE: { route: 'settings/workspaces/:policyID/invite', @@ -960,7 +969,12 @@ const ROUTES = { }, WORKSPACE_MEMBERS: { route: 'settings/workspaces/:policyID/members', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/members` as const, + getRoute: (policyID: string | undefined) => { + if (!policyID) { + Log.warn('Invalid policyID while building route WORKSPACE_MEMBERS'); + } + return `settings/workspaces/${policyID}/members` as const; + }, }, WORKSPACE_MEMBERS_IMPORT: { route: 'settings/workspaces/:policyID/members/import', @@ -972,7 +986,10 @@ const ROUTES = { }, POLICY_ACCOUNTING: { route: 'settings/workspaces/:policyID/accounting', - getRoute: (policyID: string, newConnectionName?: ConnectionName, integrationToDisconnect?: ConnectionName, shouldDisconnectIntegrationBeforeConnecting?: boolean) => { + getRoute: (policyID: string | undefined, newConnectionName?: ConnectionName, integrationToDisconnect?: ConnectionName, shouldDisconnectIntegrationBeforeConnecting?: boolean) => { + if (!policyID) { + Log.warn('Invalid policyID while building route POLICY_ACCOUNTING'); + } let queryParams = ''; if (newConnectionName) { queryParams += `?newConnectionName=${newConnectionName}`; @@ -1010,7 +1027,12 @@ const ROUTES = { }, WORKSPACE_CATEGORIES: { route: 'settings/workspaces/:policyID/categories', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/categories` as const, + getRoute: (policyID: string | undefined) => { + if (!policyID) { + Log.warn('Invalid policyID while building route WORKSPACE_CATEGORIES'); + } + return `settings/workspaces/${policyID}/categories` as const; + }, }, WORKSPACE_CATEGORY_SETTINGS: { route: 'settings/workspaces/:policyID/category/:categoryName', @@ -1075,7 +1097,12 @@ const ROUTES = { }, WORKSPACE_MORE_FEATURES: { route: 'settings/workspaces/:policyID/more-features', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/more-features` as const, + getRoute: (policyID: string | undefined) => { + if (!policyID) { + Log.warn('Invalid policyID while building route WORKSPACE_MORE_FEATURES'); + } + return `settings/workspaces/${policyID}/more-features` as const; + }, }, WORKSPACE_TAGS: { route: 'settings/workspaces/:policyID/tags', diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index bd7f425c06ae..9711949193bf 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1145,7 +1145,7 @@ function navigateToAndOpenReport( Navigation.dismissModalWithReport(report); } else { Navigation.navigateWithSwitchPolicyID({route: ROUTES.HOME}); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(`${report?.reportID}`), actionType); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report?.reportID), actionType); } } @@ -3647,14 +3647,14 @@ function prepareOnboardingOptimisticData( const taskDescription = typeof task.description === 'function' ? task.description({ - adminsRoomLink: `${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(`${adminsChatReportID}`)}`, - workspaceCategoriesLink: `${environmentURL}/${ROUTES.WORKSPACE_CATEGORIES.getRoute(`${onboardingPolicyID}`)}`, - workspaceMembersLink: `${environmentURL}/${ROUTES.WORKSPACE_MEMBERS.getRoute(`${onboardingPolicyID}`)}`, - workspaceMoreFeaturesLink: `${environmentURL}/${ROUTES.WORKSPACE_MORE_FEATURES.getRoute(`${onboardingPolicyID}`)}`, + adminsRoomLink: `${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID)}`, + workspaceCategoriesLink: `${environmentURL}/${ROUTES.WORKSPACE_CATEGORIES.getRoute(onboardingPolicyID)}`, + workspaceMembersLink: `${environmentURL}/${ROUTES.WORKSPACE_MEMBERS.getRoute(onboardingPolicyID)}`, + workspaceMoreFeaturesLink: `${environmentURL}/${ROUTES.WORKSPACE_MORE_FEATURES.getRoute(onboardingPolicyID)}`, navatticURL: getNavatticURL(environment, engagementChoice), integrationName, - workspaceAccountingLink: `${environmentURL}/${ROUTES.POLICY_ACCOUNTING.getRoute(`${onboardingPolicyID}`)}`, - workspaceSettingsLink: `${environmentURL}/${ROUTES.WORKSPACE_INITIAL.getRoute(`${onboardingPolicyID}`)}`, + workspaceAccountingLink: `${environmentURL}/${ROUTES.POLICY_ACCOUNTING.getRoute(onboardingPolicyID)}`, + workspaceSettingsLink: `${environmentURL}/${ROUTES.WORKSPACE_INITIAL.getRoute(onboardingPolicyID)}`, }) : task.description; const taskTitle =