From b41756c208c8f94aaa7b18b5c6e0eba994cc6e24 Mon Sep 17 00:00:00 2001 From: tienifr Date: Sat, 4 May 2024 11:50:59 +0700 Subject: [PATCH 1/8] fix Self DM doesn't scroll down --- src/libs/API/parameters/TrackExpenseParams.ts | 1 + src/libs/ReportUtils.ts | 40 +++++++++++++++++++ src/libs/actions/IOU.ts | 30 +++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/libs/API/parameters/TrackExpenseParams.ts b/src/libs/API/parameters/TrackExpenseParams.ts index 5f15a6a3f521..d5e1de2e625b 100644 --- a/src/libs/API/parameters/TrackExpenseParams.ts +++ b/src/libs/API/parameters/TrackExpenseParams.ts @@ -26,6 +26,7 @@ type TrackExpenseParams = { transactionThreadReportID: string; createdReportActionIDForThread: string; waypoints?: string; + actionableWhisperReportActionID?: string; }; export default TrackExpenseParams; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9c5e437a874e..8241f4f4625a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4078,6 +4078,45 @@ function buildOptimisticReportPreview(chatReport: OnyxEntry, iouReport: }; } +/** + * Builds an optimistic ACTIONABLETRACKEXPENSEWHISPER action with a randomly generated reportActionID. + */ +function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOUReportAction, transactionID: string): ReportAction { + const created = DateUtils.getDBTime(); + const targetEmail = CONST.EMAIL.CONCIERGE; + const actorAccountID = PersonalDetailsUtils.getAccountIDsByLogins([targetEmail])[0]; + const reportActionID = NumberUtils.rand64(); + return { + actionName: CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER, + actorAccountID, + avatar: UserUtils.getDefaultAvatarURL(actorAccountID), + created, + lastModified: created, + message: [ + { + html: 'What would you like to do with this expense?', + text: 'What would you like to do with this expense?', + whisperedTo: [], + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + }, + ], + originalMessage: { + lastModified: created, + transactionID, + }, + person: [ + { + text: 'Expensify Concierge', + type: 'TEXT', + }, + ], + previousReportActionID: iouAction?.reportActionID, + reportActionID, + shouldShow: true, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }; +} + /** * Builds an optimistic modified expense action with a randomly generated reportActionID. */ @@ -6480,6 +6519,7 @@ export { buildOptimisticMovedTrackedExpenseModifiedReportAction, buildOptimisticRenamedRoomReportAction, buildOptimisticReportPreview, + buildOptimisticActionableTrackExpenseWhisper, buildOptimisticSubmittedReportAction, buildOptimisticTaskCommentReportAction, buildOptimisticTaskReport, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index e0b406ad9c45..ba83bee11a24 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -91,6 +91,7 @@ type TrackExpenseInformation = { reportPreviewAction?: OnyxTypes.ReportAction; transactionThreadReportID: string; createdReportActionIDForThread: string; + actionableWhisperReportActionID?: string; onyxData: OnyxData; }; @@ -1108,6 +1109,7 @@ function buildOnyxDataForTrackExpense( policyTagList?: OnyxEntry, policyCategories?: OnyxEntry, existingTransactionThreadReportID?: string, + actionableTrackExpenseWhisper?: OnyxEntry, ): [OnyxUpdate[], OnyxUpdate[], OnyxUpdate[]] { const isScanRequest = TransactionUtils.isScanRequest(transaction); const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction); @@ -1144,6 +1146,23 @@ function buildOnyxDataForTrackExpense( }, }, ); + + if (actionableTrackExpenseWhisper && !iouReport) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`, + value: { + [actionableTrackExpenseWhisper.reportActionID]: actionableTrackExpenseWhisper as OnyxTypes.ReportAction, + }, + }); + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + lastVisibleActionCreated: actionableTrackExpenseWhisper.created, + }, + }); + } } if (iouReport) { @@ -2090,6 +2109,11 @@ function getTrackExpenseInformation( } } + let actionableTrackExpenseWhisper: OnyxEntry = null; + if (!isPolicyExpenseChat) { + actionableTrackExpenseWhisper = ReportUtils.buildOptimisticActionableTrackExpenseWhisper(iouAction, optimisticTransaction.transactionID); + } + // STEP 5: Build Onyx Data const [optimisticData, successData, failureData] = buildOnyxDataForTrackExpense( chatReport, @@ -2104,6 +2128,8 @@ function getTrackExpenseInformation( policy, policyTagList, policyCategories, + undefined, + actionableTrackExpenseWhisper, ); return { @@ -2116,6 +2142,7 @@ function getTrackExpenseInformation( reportPreviewAction: reportPreviewAction ?? undefined, transactionThreadReportID: optimisticTransactionThread.reportID, createdReportActionIDForThread: optimisticCreatedActionForTransactionThread.reportActionID, + actionableWhisperReportActionID: actionableTrackExpenseWhisper?.reportActionID ?? '', onyxData: { optimisticData, successData, @@ -3405,7 +3432,6 @@ function trackExpense( gpsPoints?: GPSPoint, validWaypoints?: WaypointCollection, action?: IOUAction, - actionableWhisperReportActionID?: string, linkedTrackedExpenseReportAction?: OnyxTypes.ReportAction, linkedTrackedExpenseReportID?: string, ) { @@ -3425,6 +3451,7 @@ function trackExpense( reportPreviewAction, transactionThreadReportID, createdReportActionIDForThread, + actionableWhisperReportActionID, onyxData, } = getTrackExpenseInformation( currentChatReport, @@ -3536,6 +3563,7 @@ function trackExpense( transactionThreadReportID, createdReportActionIDForThread, waypoints: validWaypoints ? JSON.stringify(validWaypoints) : undefined, + actionableWhisperReportActionID, }; API.write(WRITE_COMMANDS.TRACK_EXPENSE, parameters, onyxData); From 5f3f4f9d8277eb8a3bc6903b6ce99e4e2239b16a Mon Sep 17 00:00:00 2001 From: tienifr Date: Sat, 4 May 2024 14:13:34 +0700 Subject: [PATCH 2/8] fix typecheck --- src/libs/actions/IOU.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index ba83bee11a24..3f8bb5ee41ad 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -91,7 +91,7 @@ type TrackExpenseInformation = { reportPreviewAction?: OnyxTypes.ReportAction; transactionThreadReportID: string; createdReportActionIDForThread: string; - actionableWhisperReportActionID?: string; + actionableWhisperReportActionIDParam?: string; onyxData: OnyxData; }; @@ -2142,7 +2142,7 @@ function getTrackExpenseInformation( reportPreviewAction: reportPreviewAction ?? undefined, transactionThreadReportID: optimisticTransactionThread.reportID, createdReportActionIDForThread: optimisticCreatedActionForTransactionThread.reportActionID, - actionableWhisperReportActionID: actionableTrackExpenseWhisper?.reportActionID ?? '', + actionableWhisperReportActionIDParam: actionableTrackExpenseWhisper?.reportActionID ?? '', onyxData: { optimisticData, successData, @@ -3432,6 +3432,7 @@ function trackExpense( gpsPoints?: GPSPoint, validWaypoints?: WaypointCollection, action?: IOUAction, + actionableWhisperReportActionID?: string, linkedTrackedExpenseReportAction?: OnyxTypes.ReportAction, linkedTrackedExpenseReportID?: string, ) { @@ -3451,7 +3452,7 @@ function trackExpense( reportPreviewAction, transactionThreadReportID, createdReportActionIDForThread, - actionableWhisperReportActionID, + actionableWhisperReportActionIDParam, onyxData, } = getTrackExpenseInformation( currentChatReport, @@ -3563,7 +3564,7 @@ function trackExpense( transactionThreadReportID, createdReportActionIDForThread, waypoints: validWaypoints ? JSON.stringify(validWaypoints) : undefined, - actionableWhisperReportActionID, + actionableWhisperReportActionID: actionableWhisperReportActionIDParam, }; API.write(WRITE_COMMANDS.TRACK_EXPENSE, parameters, onyxData); From 9970477d0999d245ee8a0dd8e9df8300cab90af0 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 10 May 2024 00:38:13 +0700 Subject: [PATCH 3/8] fix use addMillisecondsFromDateTime --- src/libs/ReportUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8a4d6dec7703..cb0be1015edd 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4106,7 +4106,7 @@ function buildOptimisticReportPreview(chatReport: OnyxEntry, iouReport: * Builds an optimistic ACTIONABLETRACKEXPENSEWHISPER action with a randomly generated reportActionID. */ function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOUReportAction, transactionID: string): ReportAction { - const created = DateUtils.getDBTime(); + const currentTime = DateUtils.getDBTime(); const targetEmail = CONST.EMAIL.CONCIERGE; const actorAccountID = PersonalDetailsUtils.getAccountIDsByLogins([targetEmail])[0]; const reportActionID = NumberUtils.rand64(); @@ -4114,8 +4114,8 @@ function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOURe actionName: CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER, actorAccountID, avatar: UserUtils.getDefaultAvatarURL(actorAccountID), - created, - lastModified: created, + created: DateUtils.addMillisecondsFromDateTime(currentTime, 1), + lastModified: DateUtils.addMillisecondsFromDateTime(currentTime, 1), message: [ { html: 'What would you like to do with this expense?', @@ -4125,7 +4125,7 @@ function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOURe }, ], originalMessage: { - lastModified: created, + lastModified: DateUtils.addMillisecondsFromDateTime(currentTime, 1), transactionID, }, person: [ From a1595701c4358bd2d9b5d7bebc23faacebf0d913 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 16 May 2024 11:01:46 +0700 Subject: [PATCH 4/8] fix resolve a few comment --- src/CONST.ts | 1 + src/libs/ReportUtils.ts | 2 +- src/libs/actions/IOU.ts | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index c7bdbb2b35e7..8e9a70626548 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -146,6 +146,7 @@ const CONST = { DISPLAY_NAME: { MAX_LENGTH: 50, RESERVED_NAMES: ['Expensify', 'Concierge'], + EXPENSIFY_CONCIERGE: 'Expensify Concierge', }, GPS: { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 40ddd5a683a2..231aafbbe848 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4143,7 +4143,7 @@ function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOURe }, person: [ { - text: 'Expensify Concierge', + text: CONST.DISPLAY_NAME.EXPENSIFY_CONCIERGE, type: 'TEXT', }, ], diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 6f79aba47241..62529024328b 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1205,8 +1205,21 @@ function buildOnyxDataForTrackExpense( key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, value: { lastVisibleActionCreated: actionableTrackExpenseWhisper.created, + lastMessageText: 'What would you like to do with this expense?', }, }); + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`, + value: { + [actionableTrackExpenseWhisper.reportActionID]: {pendingAction: null, errors: null}, + }, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`, + value: {[actionableTrackExpenseWhisper.reportActionID]: null}, + }); } } @@ -3669,9 +3682,11 @@ function trackExpense( transactionThreadReportID, createdReportActionIDForThread, waypoints: validWaypoints ? JSON.stringify(validWaypoints) : undefined, - actionableWhisperReportActionID: actionableWhisperReportActionIDParam, }; - + if (actionableWhisperReportActionIDParam) { + parameters.actionableWhisperReportActionID = actionableWhisperReportActionIDParam; + } + console.log('222222222', onyxData); API.write(WRITE_COMMANDS.TRACK_EXPENSE, parameters, onyxData); } } From f2b3b050a484ac68fa5b79fb3b16be32e4700e76 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 16 May 2024 11:02:44 +0700 Subject: [PATCH 5/8] fix remove console log --- src/libs/actions/IOU.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 62529024328b..cd6be5878039 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3686,7 +3686,6 @@ function trackExpense( if (actionableWhisperReportActionIDParam) { parameters.actionableWhisperReportActionID = actionableWhisperReportActionIDParam; } - console.log('222222222', onyxData); API.write(WRITE_COMMANDS.TRACK_EXPENSE, parameters, onyxData); } } From 5b50964cf1efb1ed4f6115a7431ef1efd9bff0f9 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 16 May 2024 11:15:34 +0700 Subject: [PATCH 6/8] fix typecheck --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index cd6be5878039..9c5a47b88b45 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1218,7 +1218,7 @@ function buildOnyxDataForTrackExpense( failureData.push({ onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`, - value: {[actionableTrackExpenseWhisper.reportActionID]: null}, + value: {[actionableTrackExpenseWhisper.reportActionID]: {} as ReportAction}, }); } } From 942e53faa394421870e6af4e21197d0704fcd23a Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 28 May 2024 16:36:18 +0700 Subject: [PATCH 7/8] fix create ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE --- src/CONST.ts | 2 +- src/libs/ReportUtils.ts | 4 ++-- src/libs/actions/IOU.ts | 2 +- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 8e9a70626548..559d62e744d9 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3737,7 +3737,7 @@ const CONST = { WELCOME_VIDEO_URL: `${CLOUDFRONT_URL}/videos/intro-1280.mp4`, ONBOARDING_CHOICES: {...onboardingChoices}, - + ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE: 'What would you like to do with this expense?', ONBOARDING_CONCIERGE: { [onboardingChoices.EMPLOYER]: '# Expensify is the fastest way to get paid back!\n' + diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 231aafbbe848..dd407b39df71 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4131,8 +4131,8 @@ function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOURe lastModified: DateUtils.addMillisecondsFromDateTime(currentTime, 1), message: [ { - html: 'What would you like to do with this expense?', - text: 'What would you like to do with this expense?', + html: CONST.ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE, + text: CONST.ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE, whisperedTo: [], type: CONST.REPORT.MESSAGE.TYPE.COMMENT, }, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 9c5a47b88b45..3387455a3c76 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1205,7 +1205,7 @@ function buildOnyxDataForTrackExpense( key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, value: { lastVisibleActionCreated: actionableTrackExpenseWhisper.created, - lastMessageText: 'What would you like to do with this expense?', + lastMessageText: CONST.ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE, }, }); successData.push({ diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 105eadffd436..cf92181d91b3 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -359,7 +359,7 @@ const ContextMenuActions: ContextMenuAction[] = [ const mentionWhisperMessage = ReportActionsUtils.getActionableMentionWhisperMessage(reportAction); setClipboardMessage(mentionWhisperMessage); } else if (ReportActionsUtils.isActionableTrackExpense(reportAction)) { - setClipboardMessage('What would you like to do with this expense?'); + setClipboardMessage(CONST.ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE); } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) { Clipboard.setString(Localize.translateLocal('iou.heldExpense')); } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.UNHOLD) { From 6ba00339653b70103e6c76eb7a9cf9d3d68a3969 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 28 May 2024 16:49:34 +0700 Subject: [PATCH 8/8] fix lint --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index b854fe035e21..6f642b424c34 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1197,7 +1197,7 @@ function buildOnyxDataForTrackExpense( onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`, value: { - [actionableTrackExpenseWhisper.reportActionID]: actionableTrackExpenseWhisper as OnyxTypes.ReportAction, + [actionableTrackExpenseWhisper.reportActionID]: actionableTrackExpenseWhisper, }, }); optimisticData.push({