diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 0dda3cb2ed58..0e21139555cc 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3594,19 +3594,10 @@ function prepareOnboardingOptimisticData( reportComment: textComment.commentText, }; - // Sign-off welcome message - const welcomeSignOffComment = ReportUtils.buildOptimisticAddCommentReportAction(Localize.translateLocal('onboarding.welcomeSignOffTitle'), undefined, actorAccountID, 2); - const welcomeSignOffCommentAction: OptimisticAddCommentReportAction = welcomeSignOffComment.reportAction; - const welcomeSignOffMessage = { - reportID: targetChatReportID, - reportActionID: welcomeSignOffCommentAction.reportActionID, - reportComment: welcomeSignOffComment.commentText, - }; - let videoCommentAction: OptimisticAddCommentReportAction | null = null; let videoMessage: AddCommentOrAttachementParams | null = null; if ('video' in data && data.video) { - const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(CONST.ATTACHMENT_MESSAGE_TEXT, undefined, actorAccountID, 3); + const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(CONST.ATTACHMENT_MESSAGE_TEXT, undefined, actorAccountID, 2); videoCommentAction = videoComment.reportAction; videoMessage = { reportID: targetChatReportID, @@ -3682,6 +3673,20 @@ function prepareOnboardingOptimisticData( }; }); + // Sign-off welcome message + const welcomeSignOffComment = ReportUtils.buildOptimisticAddCommentReportAction( + Localize.translateLocal('onboarding.welcomeSignOffTitle'), + undefined, + actorAccountID, + tasksData.length + 3, + ); + const welcomeSignOffCommentAction: OptimisticAddCommentReportAction = welcomeSignOffComment.reportAction; + const welcomeSignOffMessage = { + reportID: targetChatReportID, + reportActionID: welcomeSignOffCommentAction.reportActionID, + reportComment: welcomeSignOffComment.commentText, + }; + const tasksForParameters = tasksData.map(({task, currentTask, taskCreatedAction, taskReportAction, taskDescription, completedTaskReportAction}) => ({ type: 'task', task: task.type, @@ -3837,8 +3842,7 @@ function prepareOnboardingOptimisticData( }, []); const optimisticData: OnyxUpdate[] = [...tasksForOptimisticData]; - const lastVisibleActionCreated = - tasksData.at(-1)?.completedTaskReportAction?.created ?? tasksData.at(-1)?.taskReportAction.reportAction.created ?? videoCommentAction?.created ?? welcomeSignOffCommentAction.created; + const lastVisibleActionCreated = welcomeSignOffCommentAction.created; optimisticData.push( { @@ -4029,6 +4033,32 @@ function prepareOnboardingOptimisticData( }); } + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: { + [welcomeSignOffCommentAction.reportActionID]: welcomeSignOffCommentAction as ReportAction, + }, + }); + + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: { + [welcomeSignOffCommentAction.reportActionID]: {pendingAction: null}, + }, + }); + + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: { + [welcomeSignOffCommentAction.reportActionID]: { + errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('report.genericAddCommentFailureMessage'), + } as ReportAction, + }, + }); + guidedSetupData.push(...tasksForParameters, {type: 'message', ...welcomeSignOffMessage}); return {optimisticData, successData, failureData, guidedSetupData, actorAccountID};