Skip to content

Commit

Permalink
integrate autocompleted tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
rezkiy37 committed Apr 19, 2024
1 parent 4e5a21b commit b1c34f1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3621,6 +3621,7 @@ const CONST = {
tasks: [
{
type: 'createWorkspace',
autoCompleted: true,
title: 'Create a workspace',
subtitle: 'Create a workspace to track expenses, scan receipts, chat, and more.',
message:
Expand All @@ -3633,6 +3634,7 @@ const CONST = {
},
{
type: 'trackExpense',
autoCompleted: false,
title: 'Track an expense',
subtitle: 'Track an expense in any currency, in just a few clicks.',
message:
Expand All @@ -3659,6 +3661,7 @@ const CONST = {
tasks: [
{
type: 'submitExpense',
autoCompleted: false,
title: 'Submit an expense',
subtitle: 'Submit an expense by entering an amount or scanning a receipt.',
message:
Expand All @@ -3673,6 +3676,7 @@ const CONST = {
},
{
type: 'enableWallet',
autoCompleted: false,
title: 'Enable your wallet',
subtitle: 'You’ll need to enable your Expensify Wallet to get paid back. Don’t worry, it’s easy!',
message:
Expand All @@ -3698,6 +3702,7 @@ const CONST = {
tasks: [
{
type: 'createWorkspace',
autoCompleted: true,
title: 'Create a workspace',
subtitle: 'Create a workspace to track expenses, scan receipts, chat, and more.',
message:
Expand All @@ -3710,6 +3715,7 @@ const CONST = {
},
{
type: 'meetGuide',
autoCompleted: false,
title: 'Meet your setup specialist',
subtitle: '',
message: ({adminsRoomLink, guideCalendarLink}: {adminsRoomLink: string; guideCalendarLink: string}) =>
Expand All @@ -3719,6 +3725,7 @@ const CONST = {
},
{
type: 'setupCategories',
autoCompleted: false,
title: 'Set up categories',
subtitle: 'Set up categories so your team can code expenses for easy reporting.',
message:
Expand All @@ -3734,6 +3741,7 @@ const CONST = {
},
{
type: 'addExpenseApprovals',
autoCompleted: false,
title: 'Add expense approvals',
subtitle: 'Add expense approvals to review your team’s spend and keep it under control.',
message:
Expand All @@ -3749,6 +3757,7 @@ const CONST = {
},
{
type: 'inviteTeam',
autoCompleted: false,
title: 'Invite your team',
subtitle: 'Invite your team to Expensify so they can start tracking expenses today.',
message:
Expand Down Expand Up @@ -3776,6 +3785,7 @@ const CONST = {
tasks: [
{
type: 'trackExpense',
autoCompleted: false,
title: 'Track an expense',
subtitle: 'Track an expense in any currency, whether you have a receipt or not.',
message:
Expand All @@ -3802,6 +3812,7 @@ const CONST = {
tasks: [
{
type: 'startChat',
autoCompleted: false,
title: 'Start a chat',
subtitle: 'Start a chat with a friend or group using their email or phone number.',
message:
Expand All @@ -3817,6 +3828,7 @@ const CONST = {
},
{
type: 'splitExpense',
autoCompleted: false,
title: 'Split an expense',
subtitle: 'Split an expense right in your chat with one or more friends.',
message:
Expand All @@ -3831,6 +3843,7 @@ const CONST = {
},
{
type: 'enableWallet',
autoCompleted: false,
title: 'Enable your wallet',
subtitle: 'You’ll need to enable your Expensify Wallet to get paid back. Don’t worry, it’s easy!',
message:
Expand Down
12 changes: 9 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3919,15 +3919,21 @@ function updateReportPreview(iouReport: OnyxEntry<Report>, reportPreviewAction:
};
}

function buildOptimisticTaskReportAction(taskReportID: string, actionName: OriginalMessageActionName, message = ''): OptimisticTaskReportAction {
function buildOptimisticTaskReportAction(
taskReportID: string,
actionName: OriginalMessageActionName,
message = '',
actorAccountID = currentUserAccountID,
createdOffset = 0,
): OptimisticTaskReportAction {
const originalMessage = {
taskReportID,
type: actionName,
text: message,
};
return {
actionName,
actorAccountID: currentUserAccountID,
actorAccountID,
automatic: false,
avatar: getCurrentUserAvatarOrDefault(),
isAttachment: false,
Expand All @@ -3948,7 +3954,7 @@ function buildOptimisticTaskReportAction(taskReportID: string, actionName: Origi
],
reportActionID: NumberUtils.rand64(),
shouldShow: true,
created: DateUtils.getDBTime(),
created: DateUtils.getDBTimeWithSkew(Date.now() + createdOffset),
isFirstItem: false,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
};
Expand Down
30 changes: 24 additions & 6 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type TaskForParameters =
parentReportActionID: string;
assigneeChatReportID: string;
createdTaskReportActionID: string;
completedTaskReportActionID: string;
completedTaskReportActionID?: string;
title: string;
description: string;
}
Expand Down Expand Up @@ -3065,7 +3065,9 @@ function completeOnboarding(
})
: task.message;
const instructionComment = ReportUtils.buildOptimisticAddCommentReportAction(taskMessage, undefined, actorAccountID, 1, isTaskMessageFunction ? undefined : false);
const completedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete');
const completedTaskReportAction = task.autoCompleted
? ReportUtils.buildOptimisticTaskReportAction(currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete', actorAccountID, 2)
: null;

return {
task,
Expand Down Expand Up @@ -3098,7 +3100,7 @@ function completeOnboarding(
parentReportActionID: taskReportAction.reportAction.reportActionID,
assigneeChatReportID: '',
createdTaskReportActionID: taskCreatedAction.reportActionID,
completedTaskReportActionID: completedTaskReportAction.reportActionID,
completedTaskReportActionID: completedTaskReportAction?.reportActionID ?? undefined,
title: currentTask.reportName ?? '',
description: currentTask.description ?? '',
},
Expand Down Expand Up @@ -3146,8 +3148,6 @@ function completeOnboarding(
key: `${ONYXKEYS.COLLECTION.REPORT}${currentTask.reportID}`,
value: {
...currentTask,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
pendingFields: {
createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
Expand All @@ -3163,7 +3163,6 @@ function completeOnboarding(
value: {
[taskCreatedAction.reportActionID]: taskCreatedAction as ReportAction,
[instructionCommentAction.reportActionID]: instructionCommentAction as ReportAction,
[completedTaskReportAction.reportActionID]: completedTaskReportAction as ReportAction,
},
},
];
Expand All @@ -3180,6 +3179,25 @@ function completeOnboarding(
});
}

if (completedTaskReportAction) {
tasksForOptimisticDataAcc.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`,
value: {
[completedTaskReportAction.reportActionID]: completedTaskReportAction as ReportAction,
},
});

tasksForOptimisticDataAcc.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${currentTask.reportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
},
});
}

return tasksForOptimisticDataAcc;
},
[],
Expand Down

0 comments on commit b1c34f1

Please sign in to comment.