Skip to content

Commit

Permalink
Update Report.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ugogiordano authored Dec 29, 2024
1 parent fdb8dd8 commit 6702f9f
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<TaskForParameters>(({task, currentTask, taskCreatedAction, taskReportAction, taskDescription, completedTaskReportAction}) => ({
type: 'task',
task: task.type,
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 6702f9f

Please sign in to comment.