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/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 c1f4057199ee..a5976d7ef5fa 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -810,7 +810,7 @@ function getLastVisibleMessage( 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 8a5ae8b1d102..fc1cff8a82d4 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 = { @@ -4595,7 +4598,7 @@ function buildOptimisticTaskCommentReportAction( taskTitle: string, taskAssigneeAccountID: number, text: string, - parentReportID: string, + parentReportID: string | undefined, actorAccountID?: number, createdOffset = 0, ): OptimisticReportAction { @@ -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 1e157b983483..9711949193bf 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -153,7 +153,7 @@ type TaskForParameters = taskReportID: string; parentReportID: string; parentReportActionID: string; - assigneeChatReportID: string; + assigneeChatReportID?: string; createdTaskReportActionID: string; completedTaskReportActionID?: string; title: string; @@ -800,11 +800,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: string | undefined, reportActionID?: string, participantLoginList: string[] = [], newReportObject?: ReportUtils.OptimisticChatReport, - parentReportActionID = '-1', + parentReportActionID?: string, isFromDeepLink = false, participantAccountIDList: number[] = [], avatar?: File | CustomRNImageManipulatorResult, @@ -893,6 +893,9 @@ function openReport( } const onboardingData = prepareOnboardingOptimisticData(choice, onboardingMessage); + if (!onboardingData) { + return; + } optimisticData.push(...onboardingData.optimisticData, { onyxMethod: Onyx.METHOD.MERGE, @@ -1060,7 +1063,7 @@ function openReport( failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReportObject.parentReportID}`, - value: {[parentReportActionID]: {childReportID: '-1', childType: ''}}, + value: {[parentReportActionID]: {childReportID: undefined, childType: ''}}, }); } } @@ -1137,12 +1140,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); } } @@ -1160,7 +1163,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); } @@ -1171,8 +1174,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: 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)])]; @@ -1363,8 +1366,8 @@ function readNewestAction(reportID: string | undefined, shouldResetUnreadMarker /** * Sets the last read time on a report */ -function markCommentAsUnread(reportID: string, reportActionCreated: string) { - if (reportID === '-1') { +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; } @@ -1466,36 +1469,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 ?? '-1'), 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, }); @@ -1504,20 +1509,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 ?? '-1', draftReportComment, callback); + saveReportDraftComment(preexistingReportID, draftReportComment, callback); return; } - if (report?.reportID) { + if (reportID) { if (ReportUtils.isConciergeChatReport(report)) { - conciergeChatReportID = report.reportID; + conciergeChatReportID = reportID; } } } @@ -1932,10 +1937,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 = '-1', parentReportAction: Partial = {}, parentReportID = '-1', prevNotificationPreference?: NotificationPreference) { - if (childReportID !== '-1') { +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 { @@ -2908,7 +2918,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); @@ -3083,8 +3093,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), }, }, }); @@ -3578,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 ?? {}; + 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; @@ -3633,14 +3647,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 = @@ -3651,8 +3665,8 @@ function prepareOnboardingOptimisticData( : task.title; const currentTask = ReportUtils.buildOptimisticTaskReport( actorAccountID, - currentUserAccountID, targetChatReportID, + currentUserAccountID, taskTitle, taskDescription, targetChatPolicyID, @@ -3704,11 +3718,11 @@ function prepareOnboardingOptimisticData( type: 'task', task: task.type, taskReportID: currentTask.reportID, - parentReportID: currentTask.parentReportID ?? '-1', + 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 ?? '', })); @@ -4143,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, @@ -4226,7 +4238,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}; const searchForReportsParams: SearchForReportsParams = {searchInput, canCancel: true}; // We want to cancel all pending SearchForReports API calls before making another one 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; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index b8cdde2ecff3..a57c997ee6c0 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); @@ -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 = () => { @@ -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: () => {}, },