From 880a34a6d6266fbcee789255f7f05ad852436f44 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Fri, 5 Apr 2024 12:52:45 +0200 Subject: [PATCH 1/6] feat: added new method for handliung onboarding, build new messages structure for onboarding --- src/CONST.ts | 240 +++++++++++++++++++++++++++++++++++++ src/libs/API/types.ts | 1 + src/libs/actions/Report.ts | 104 ++++++++++++++++ 3 files changed, 345 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index b07b622cec05..f317a2dca3fa 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3587,6 +3587,246 @@ const CONST = { "Expensify is best known for expense and corporate card management, but we do a lot more than that. Let me know what you're interested in and I'll help get you started.", }, + ONBOARDING_MESSAGES: { + [onboardingChoices.TRACK]: { + message: 'Here are some essential tasks to keep your business spend in shape for tax season.', + video: { + url: `${CLOUDFRONT_URL}/videos/intro-1280.mp4`, + thumbnailUrl: `${CLOUDFRONT_URL}/images/expensify__favicon.png`, + duration: 55, + width: 1280, + height: 960, + }, + tasks: [ + { + title: 'Create a workspace', + subtitle: 'Create a workspace to track expenses, scan receipts, chat, and more. ', + message: + 'Here’s how to create a workspace:\n' + + '\n' + + '1. Click your profile picture.\n' + + '2. Click Workspaces > New workspace.\n' + + '\n' + + 'Your new workspace is ready! It’ll keep all of your spend (and chats) in one place.', + }, + { + title: 'Track an expense', + subtitle: 'Track an expense in any currency, in just a few clicks.', + message: + 'Here’s how to track an expense:\n' + + '\n' + + '1. Click the green + button.\n' + + '2. Choose Track expense.\n' + + '3. Enter an amount or scan a receipt.\n' + + '4. Click Track.\n' + + '\n' + + 'And you’re done! Yep, it’s that easy.', + }, + ], + }, + [onboardingChoices.EMPLOYER]: { + message: 'Getting paid back is as easy as sending a message. Let’s go over the basics.', + video: { + url: `${CLOUDFRONT_URL}/videos/intro-1280.mp4`, + thumbnailUrl: `${CLOUDFRONT_URL}/images/expensify__favicon.png`, + duration: 55, + width: 1280, + height: 960, + }, + tasks: [ + { + title: 'Submit an expense', + subtitle: 'Submit an expense by entering an amount or scanning a receipt.', + message: + 'Here’s how to submit an expense:\n' + + '\n' + + '1. Click the green + button.\n' + + '2. Choose Submit expense.\n' + + '3. Enter an amount or scan a receipt.\n' + + '4. Add your reimburser to the request.\n' + + '\n' + + 'Then, send your request and wait for that sweet “Cha-ching!” when it’s complete.', + }, + { + title: 'Enable your wallet', + subtitle: 'You’ll need to enable your Expensify Wallet to get paid back. Don’t worry, it’s easy!', + message: + 'Here’s how to set up your wallet:\n' + + '\n' + + '1. Click your profile picture.\n' + + '2. Click Wallet > Enable wallet.\n' + + '3. Connect your bank account.\n' + + '\n' + + 'Once that’s done, you can request money from anyone and get paid back right into your personal bank account.', + }, + ], + }, + [onboardingChoices.MANAGE_TEAM]: { + message: 'Here are some important tasks to help get your team’s expenses under control.', + video: { + url: `${CLOUDFRONT_URL}/videos/intro-1280.mp4`, + thumbnailUrl: `${CLOUDFRONT_URL}/images/expensify__favicon.png`, + duration: 55, + width: 1280, + height: 960, + }, + tasks: [ + { + title: 'Create a workspace', + subtitle: 'Create a workspace to track expenses, scan receipts, chat, and more. ', + message: + 'Here’s how to create a workspace:\n' + + '\n' + + '1. Click your profile picture.\n' + + '2. Click Workspaces > New workspace.\n' + + '\n' + + 'Your new workspace is ready! It’ll keep all of your spend (and chats) in one place.', + }, + { + title: 'Meet your setup specialist', + subtitle: '', + message: + 'Meet your setup specialist, {guideName}, who can answer any questions as you get started with Expensify. Yes, a real human!\n' + + '\n' + + 'Chat with {guideName} in your [admins room]({adminsRoomID}) or [schedule a call]({guideCalendarLink}) today', + }, + { + title: 'Set up categories', + subtitle: 'Set up categories so your team can code expenses for easy reporting.', + message: + 'Here’s how to set up categories:\n' + + '\n' + + '1. Click your profile picture.\n' + + '2. Go to Workspaces > [your workspace].\n' + + '3. Click Categories.\n' + + '4. Enable and disable default categories.\n' + + '5. Click Add categories to make your own.\n' + + '\n' + + 'For more controls like requiring a category for every expense, click Settings. ', + }, + { + title: 'Add expense approvals', + subtitle: 'Add expense approvals to review your team’s spend and keep it under control.', + message: + 'Here’s how to add expense approvals:\n' + + '\n' + + '1. Click your profile picture.\n' + + '2. Go to Workspaces > [your workspace].\n' + + '3. Click More features.\n' + + '4. Enable Workflows.\n' + + '5. In Workflows, enable Add approvals.\n' + + '\n' + + 'You’ll be set as the expense approver. You can change this to any admin once you invite your team. ', + }, + { + title: 'Invite your team', + subtitle: 'Invite your team to Expensify so they can start tracking expenses today.', + message: + 'Here’s how to invite your team:\n' + + '\n' + + '1. Click your profile picture.\n' + + '2. Go to Workspaces > [your workspace].\n' + + '3. Click Members > Invite member.\n' + + '4. Enter emails or phone numbers. \n' + + '5. Add an invite message if you want.\n' + + '\n' + + 'That’s it! Happy expensing :)', + }, + ], + }, + [onboardingChoices.PERSONAL_SPEND]: { + message: 'Here’s how to track your spend in a few clicks.', + video: { + url: `${CLOUDFRONT_URL}/videos/intro-1280.mp4`, + thumbnailUrl: `${CLOUDFRONT_URL}/images/expensify__favicon.png`, + duration: 55, + width: 1280, + height: 960, + }, + tasks: [ + { + title: 'Track an expense', + subtitle: 'Track an expense in any currency, whether you have a receipt or not.', + message: + 'Here’s how to track an expense:\n' + + '\n' + + '1. Click the green + button.\n' + + '2. Choose Track expense.\n' + + '3. Enter an amount or scan a receipt.\n' + + '4. Click Track.\n' + + '\n' + + 'And you’re done! Yep, it’s that easy.', + }, + ], + }, + [onboardingChoices.CHAT_SPLIT]: { + message: 'Splitting bills with friends is as easy as sending a message. Here’s how.', + video: { + url: `${CLOUDFRONT_URL}/videos/intro-1280.mp4`, + thumbnailUrl: `${CLOUDFRONT_URL}/images/expensify__favicon.png`, + duration: 55, + width: 1280, + height: 960, + }, + tasks: [ + { + title: 'Start a chat', + subtitle: 'Start a chat with a friend or group using their email or phone number.', + message: + 'Here’s how to start a chat:\n' + + '\n' + + '1. rClick the green + button.\n' + + '2. Choose Start chat.\n' + + '3. Enter emails or phone numbers.\n' + + '\n' + + 'If any of your friends aren’t using Expensify already, they’ll be invited automatically. \n' + + '\n' + + 'Every chat will also turn into an email or text that they can respond to directly.', + }, + { + title: 'Split an expense', + subtitle: 'Split an expense right in your chat with one or more friends.', + message: + 'Here’s how to request money:\n' + + '\n' + + '1. Click the green + button.\n' + + '2. Choose Split expense.\n' + + '3. Scan a receipt or enter an amount.\n' + + '4. Add your friend(s) to the request.\n' + + '\n' + + 'Feel free to add more details if you want, or just send it off. Let’s get you paid back!', + }, + { + title: 'Enable your wallet', + subtitle: 'You’ll need to enable your Expensify Wallet to get paid back. Don’t worry, it’s easy!', + message: + 'Here’s how to enable your wallet:\n' + + '\n' + + '1. Click your profile picture.\n' + + '2. Click Wallet > Enable wallet.\n' + + '3. Add your bank account.\n' + + '\n' + + 'Once that’s done, you can request money from anyone and get paid right into your personal bank account.', + }, + ], + }, + [onboardingChoices.LOOKING_AROUND]: { + message: + '# Welcome to Expensify!\n' + + "Hi there, I'm Concierge. Chat with me here for anything you need.\n" + + '\n' + + "Expensify is best known for expense and corporate card management, but we do a lot more than that. Let me know what you're interested in and I'll help get you started.", + video: { + url: `${CLOUDFRONT_URL}/videos/intro-1280.mp4`, + thumbnailUrl: `${CLOUDFRONT_URL}/images/expensify__favicon.png`, + duration: 55, + width: 1280, + height: 960, + }, + tasks: [], + }, + }, + REPORT_FIELD_TITLE_FIELD_ID: 'text_title', MOBILE_PAGINATION_SIZE: 15, diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index fc19ba60693c..c33e96731bdc 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -134,6 +134,7 @@ const WRITE_COMMANDS = { REOPEN_TASK: 'ReopenTask', COMPLETE_TASK: 'CompleteTask', COMPLETE_ENGAGEMENT_MODAL: 'CompleteEngagementModal', + COMPLETE_GUIDED_SETUP: 'CompleteGuidedSetup', SET_NAME_VALUE_PAIR: 'SetNameValuePair', SET_REPORT_FIELD: 'Report_SetFields', DELETE_REPORT_FIELD: 'RemoveReportField', diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index d2f85362baf8..8fe56d93d634 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2774,6 +2774,109 @@ function getReportPrivateNote(reportID: string | undefined) { API.read(READ_COMMANDS.GET_REPORT_PRIVATE_NOTE, parameters, {optimisticData, successData, failureData}); } +function completeOnboarding(properties: { + data: ValueOf; + firstName: string; + lastName: string; + targetEmail: ValueOf; + engagementChoice: ValueOf; +}) { + const {data, engagementChoice, targetEmail, firstName, lastName} = properties; + const actorAccountID = PersonalDetailsUtils.getAccountIDsByLogins([targetEmail])[0]; + const targetChatReport = ReportUtils.getChatByParticipants([actorAccountID]); + const targetChatReportID = targetChatReport?.reportID ?? ''; + const targetChatPolicyID = targetChatReport?.policyID ?? ''; + + // Text message + const textComment = ReportUtils.buildOptimisticAddCommentReportAction(data.message, undefined); + const textCommentAction: OptimisticAddCommentReportAction = textComment.reportAction; + const textCommentText = textComment.commentText; + + const textMessage: AddCommentOrAttachementParams & {type: string} = { + reportID: targetChatReportID, + reportActionID: textCommentAction.reportActionID, + reportComment: textCommentText, + type: 'message', + }; + + // Video message + const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(CONST.ATTACHMENT_MESSAGE_TEXT, undefined); + const videoCommentAction: OptimisticAddCommentReportAction = videoComment.reportAction; + const videoCommentText = videoComment.commentText; + + const videoMessage: AddCommentOrAttachementParams & {type: string} & typeof data.video = { + reportID: targetChatReportID, + reportActionID: videoCommentAction.reportActionID, + reportComment: videoCommentText, + type: 'video', + ...data.video, + }; + + // tasks + const tasks = data.tasks.reduce((acc, curr) => { + const currTask = ReportUtils.buildOptimisticTaskReport(actorAccountID, undefined, targetChatReportID, curr.title, undefined, targetChatPolicyID); + const taskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(targetEmail); + const taskAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(currTask.reportID, curr.title, 0, `task for ${curr.title}`, targetChatReportID); + + // subtitle message + const subtitleComment = ReportUtils.buildOptimisticAddCommentReportAction(curr.subtitle, undefined, actorAccountID); + const subtitleCommentAction: OptimisticAddCommentReportAction = subtitleComment.reportAction; + const subtitleCommentText = subtitleComment.commentText; + + const subtitleMessage: AddCommentOrAttachementParams = { + reportID: currTask.reportID, + reportActionID: subtitleCommentAction.reportActionID, + reportComment: subtitleCommentText, + }; + + // instruction message + const instructionComment = ReportUtils.buildOptimisticAddCommentReportAction(curr.message, undefined, actorAccountID); + const instructionCommentAction: OptimisticAddCommentReportAction = instructionComment.reportAction; + const instructionCommentText = instructionComment.commentText; + + const instructionMessage: AddCommentOrAttachementParams = { + reportID: currTask.reportID, + reportActionID: instructionCommentAction.reportActionID, + reportComment: instructionCommentText, + }; + + return [ + ...acc, + { + parentReportActionID: taskAddCommentReport.reportAction.reportActionID, + parentReportID: currTask.parentReportID, + taskReportID: currTask.reportID, + createdTaskReportActionID: taskCreatedAction.reportActionID, + title: currTask.reportName, + description: currTask.description, + assigneeChatReportID: '', + type: 'task', + task: 'trackExpense', + }, + { + type: 'message', + ...subtitleMessage, + }, + { + type: 'message', + ...instructionMessage, + }, + ]; + }, []); + + const parameters = { + engagementChoice, + firstName, + lastName, + data: JSON.stringify([textMessage, videoMessage, ...tasks]), + }; + + // console.log('-------------------------------------'); + // console.log(JSON.stringify({...parameters, data: JSON.parse(parameters.data)}, ' ', 2)); + + API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {}); +} + /** * Completes the engagement modal that new NewDot users see when they first sign up/log in by doing the following: * @@ -3093,4 +3196,5 @@ export { setGroupDraft, clearGroupChat, startNewChat, + completeOnboarding, }; From c396f2af93022c2b13f38804517c122aa423a550 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Fri, 5 Apr 2024 16:31:47 +0200 Subject: [PATCH 2/6] feat: call method --- src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx index ae43f850018b..bd8a7ab40917 100644 --- a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx +++ b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx @@ -80,7 +80,14 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, on return; } - Report.completeEngagementModal(CONST.ONBOARDING_CONCIERGE[selectedPurpose], selectedPurpose); + // Report.completeEngagementModal(CONST.ONBOARDING_CONCIERGE[selectedPurpose], selectedPurpose); + Report.completeOnboarding({ + data: CONST.ONBOARDING_MESSAGES[selectedPurpose], + engagementChoice: selectedPurpose, + targetEmail: CONST.EMAIL.CONCIERGE, + firstName: 'Test', + lastName: 'Testovsky', + }); Navigation.dismissModal(); // Only navigate to concierge chat when central pane is visible From 9ad33297839823d773b05331be3ca8a522aae2eb Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Wed, 10 Apr 2024 08:41:54 +0200 Subject: [PATCH 3/6] feat: added optimistic data --- src/libs/actions/Report.ts | 133 ++++++++++++++++++++++++++++++++----- 1 file changed, 117 insertions(+), 16 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 8fe56d93d634..8b280e11973b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -71,6 +71,7 @@ import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import INPUT_IDS from '@src/types/form/NewRoomForm'; import type {PersonalDetails, PersonalDetailsList, PolicyReportField, RecentlyUsedReportFields, ReportActionReactions, ReportMetadata, ReportUserIsTyping} from '@src/types/onyx'; +import type * as OnyxTypes from '@src/types/onyx'; import type {Decision, OriginalMessageIOU} from '@src/types/onyx/OriginalMessage'; import type {NotificationPreference, RoomVisibility, WriteCapability} from '@src/types/onyx/Report'; import type Report from '@src/types/onyx/Report'; @@ -2788,38 +2789,50 @@ function completeOnboarding(properties: { const targetChatPolicyID = targetChatReport?.policyID ?? ''; // Text message - const textComment = ReportUtils.buildOptimisticAddCommentReportAction(data.message, undefined); + const textComment = ReportUtils.buildOptimisticAddCommentReportAction(data.message, undefined, actorAccountID); const textCommentAction: OptimisticAddCommentReportAction = textComment.reportAction; const textCommentText = textComment.commentText; - const textMessage: AddCommentOrAttachementParams & {type: string} = { + const textMessage: AddCommentOrAttachementParams = { reportID: targetChatReportID, reportActionID: textCommentAction.reportActionID, reportComment: textCommentText, - type: 'message', }; // Video message - const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(CONST.ATTACHMENT_MESSAGE_TEXT, undefined); + const videoComment = ReportUtils.buildOptimisticAddCommentReportAction(CONST.ATTACHMENT_MESSAGE_TEXT, undefined, actorAccountID); const videoCommentAction: OptimisticAddCommentReportAction = videoComment.reportAction; const videoCommentText = videoComment.commentText; - const videoMessage: AddCommentOrAttachementParams & {type: string} & typeof data.video = { + const videoMessage: AddCommentOrAttachementParams = { reportID: targetChatReportID, reportActionID: videoCommentAction.reportActionID, reportComment: videoCommentText, - type: 'video', - ...data.video, }; - // tasks - const tasks = data.tasks.reduce((acc, curr) => { - const currTask = ReportUtils.buildOptimisticTaskReport(actorAccountID, undefined, targetChatReportID, curr.title, undefined, targetChatPolicyID); + const tasksData = data.tasks.map((task) => { + const currTask = ReportUtils.buildOptimisticTaskReport(actorAccountID, undefined, targetChatReportID, task.title, undefined, targetChatPolicyID); const taskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(targetEmail); - const taskAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(currTask.reportID, curr.title, 0, `task for ${curr.title}`, targetChatReportID); + const taskAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(currTask.reportID, task.title, 0, `task for ${task.title}`, targetChatReportID); // subtitle message - const subtitleComment = ReportUtils.buildOptimisticAddCommentReportAction(curr.subtitle, undefined, actorAccountID); + const subtitleComment = ReportUtils.buildOptimisticAddCommentReportAction(task.subtitle, undefined, actorAccountID); + + // instruction message + const instructionComment = ReportUtils.buildOptimisticAddCommentReportAction(task.message, undefined, actorAccountID); + + return { + currTask, + taskCreatedAction, + taskAddCommentReport, + subtitleComment, + instructionComment, + }; + }); + + // tasks + const tasksForParameters = tasksData.reduce((acc, {currTask, taskCreatedAction, taskAddCommentReport, subtitleComment, instructionComment}) => { + // subtitle message const subtitleCommentAction: OptimisticAddCommentReportAction = subtitleComment.reportAction; const subtitleCommentText = subtitleComment.commentText; @@ -2830,7 +2843,6 @@ function completeOnboarding(properties: { }; // instruction message - const instructionComment = ReportUtils.buildOptimisticAddCommentReportAction(curr.message, undefined, actorAccountID); const instructionCommentAction: OptimisticAddCommentReportAction = instructionComment.reportAction; const instructionCommentText = instructionComment.commentText; @@ -2851,7 +2863,7 @@ function completeOnboarding(properties: { description: currTask.description, assigneeChatReportID: '', type: 'task', - task: 'trackExpense', + task: engagementChoice, }, { type: 'message', @@ -2864,17 +2876,101 @@ function completeOnboarding(properties: { ]; }, []); + const tasksForOptimisticData = tasksData.reduce((acc, {currTask, taskCreatedAction, subtitleComment, instructionComment}) => { + // subtitle message + const subtitleCommentAction: OptimisticAddCommentReportAction = subtitleComment.reportAction; + const subtitleCommentText = subtitleComment.commentText; + + const subtitleMessage: AddCommentOrAttachementParams = { + reportID: currTask.reportID, + reportActionID: subtitleCommentAction.reportActionID, + reportComment: subtitleCommentText, + }; + + // instruction message + const instructionCommentAction: OptimisticAddCommentReportAction = instructionComment.reportAction; + const instructionCommentText = instructionComment.commentText; + + const instructionMessage: AddCommentOrAttachementParams = { + reportID: currTask.reportID, + reportActionID: instructionCommentAction.reportActionID, + reportComment: instructionCommentText, + }; + + return [ + ...acc, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${currTask.reportID}`, + value: { + ...currTask, + pendingFields: { + createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + description: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + managerID: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + isOptimisticReport: true, + }, + }, + { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currTask.reportID}`, + value: {[taskCreatedAction.reportActionID]: taskCreatedAction as OnyxTypes.ReportAction}, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${currTask.reportID}`, + value: {[subtitleMessage.reportID ?? '']: subtitleMessage, [instructionMessage.reportID ?? '']: instructionMessage}, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: { + [subtitleCommentAction.reportActionID ?? '']: subtitleCommentAction as ReportAction, + [instructionCommentAction.reportActionID ?? '']: instructionCommentAction as ReportAction, + }, + }, + ]; + }, []); + + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${targetChatReportID}`, + value: {[textMessage.reportID ?? '']: textMessage, [videoMessage.reportID ?? '']: videoMessage}, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: {[textCommentAction.reportActionID ?? '']: textCommentAction as ReportAction, [videoCommentAction.reportActionID ?? '']: videoCommentAction as ReportAction}, + }, + ...tasksForOptimisticData, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.NVP_INTRO_SELECTED, + value: {choice: engagementChoice}, + }, + ]; + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: {[textCommentAction.reportActionID ?? '']: {pendingAction: null}, [videoCommentAction.reportActionID ?? '']: {pendingAction: null}}, + }, + ]; + const parameters = { engagementChoice, firstName, lastName, - data: JSON.stringify([textMessage, videoMessage, ...tasks]), + data: JSON.stringify([{type: 'message', ...textMessage}, {type: 'video', ...data.video, ...videoMessage}, ...tasksForParameters]), }; // console.log('-------------------------------------'); // console.log(JSON.stringify({...parameters, data: JSON.parse(parameters.data)}, ' ', 2)); - API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {}); + API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {optimisticData, successData}); } /** @@ -2949,6 +3045,11 @@ function completeEngagementModal(text: string, choice: ValueOf Date: Wed, 10 Apr 2024 08:47:26 +0200 Subject: [PATCH 4/6] feat: added optimistic data --- src/libs/actions/Report.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 8b280e11973b..3edd4515a1d2 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -726,6 +726,11 @@ function openReport( key: ONYXKEYS.PERSONAL_DETAILS_LIST, value: settledPersonalDetails, }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: settledPersonalDetails, + }); // Add the createdReportActionID parameter to the API call parameters.createdReportActionID = optimisticCreatedAction.reportActionID; @@ -1939,16 +1944,6 @@ function deleteReport(reportID: string) { Onyx.multiSet(onyxData); - // Clear the optimistic personal detail - const participantPersonalDetails: OnyxCollection = {}; - report?.participantAccountIDs?.forEach((accountID) => { - if (!allPersonalDetails?.[accountID]?.isOptimisticPersonalDetail) { - return; - } - participantPersonalDetails[accountID] = null; - }); - Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantPersonalDetails); - // Delete linked IOU report if (report?.iouReportID) { deleteReport(report.iouReportID); @@ -2900,7 +2895,7 @@ function completeOnboarding(properties: { return [ ...acc, { - onyxMethod: Onyx.METHOD.MERGE, + onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${currTask.reportID}`, value: { ...currTask, @@ -2967,9 +2962,6 @@ function completeOnboarding(properties: { data: JSON.stringify([{type: 'message', ...textMessage}, {type: 'video', ...data.video, ...videoMessage}, ...tasksForParameters]), }; - // console.log('-------------------------------------'); - // console.log(JSON.stringify({...parameters, data: JSON.parse(parameters.data)}, ' ', 2)); - API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {optimisticData, successData}); } From 1077782645bd53ca71eb3cc53d0cfbada1a29ec5 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Wed, 10 Apr 2024 11:01:34 +0200 Subject: [PATCH 5/6] feat: update method --- src/libs/actions/Report.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 3edd4515a1d2..3f288c29723c 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2920,7 +2920,7 @@ function completeOnboarding(properties: { }, { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currTask.reportID}`, value: { [subtitleCommentAction.reportActionID ?? '']: subtitleCommentAction as ReportAction, [instructionCommentAction.reportActionID ?? '']: instructionCommentAction as ReportAction, @@ -2940,7 +2940,6 @@ function completeOnboarding(properties: { key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, value: {[textCommentAction.reportActionID ?? '']: textCommentAction as ReportAction, [videoCommentAction.reportActionID ?? '']: videoCommentAction as ReportAction}, }, - ...tasksForOptimisticData, { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.NVP_INTRO_SELECTED, @@ -2962,7 +2961,7 @@ function completeOnboarding(properties: { data: JSON.stringify([{type: 'message', ...textMessage}, {type: 'video', ...data.video, ...videoMessage}, ...tasksForParameters]), }; - API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {optimisticData, successData}); + API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {}); } /** @@ -3037,11 +3036,6 @@ function completeEngagementModal(text: string, choice: ValueOf Date: Wed, 10 Apr 2024 18:16:35 +0200 Subject: [PATCH 6/6] fix: change params --- src/libs/actions/Report.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 3f288c29723c..0c8c8543c75c 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2945,6 +2945,7 @@ function completeOnboarding(properties: { key: ONYXKEYS.NVP_INTRO_SELECTED, value: {choice: engagementChoice}, }, + ...tasksForOptimisticData, ]; const successData: OnyxUpdate[] = [ { @@ -2958,7 +2959,7 @@ function completeOnboarding(properties: { engagementChoice, firstName, lastName, - data: JSON.stringify([{type: 'message', ...textMessage}, {type: 'video', ...data.video, ...videoMessage}, ...tasksForParameters]), + guidedSetupData: JSON.stringify([{type: 'message', ...textMessage}, {type: 'video', ...data.video, ...videoMessage}, ...tasksForParameters]), }; API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {});