From 6ab6a13fba69b8e87eae7d5c0ca1f39881578b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Thu, 25 Apr 2024 15:57:46 -0600 Subject: [PATCH 01/11] Display submitted message in report action --- src/pages/home/report/ReportActionItem.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index efb2d8ba73fb..cde76434f382 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -39,6 +39,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import ControlSelection from '@libs/ControlSelection'; +import * as CurrencyUtils from '@libs/CurrencyUtils'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import * as ErrorUtils from '@libs/ErrorUtils'; import focusTextInputAfterAnimation from '@libs/focusTextInputAfterAnimation'; @@ -580,6 +581,9 @@ function ReportActionItem({ } else if (ReportActionsUtils.isOldDotReportAction(action)) { // This handles all historical actions from OldDot that we just want to display the message text children = ; + } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { + const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(report.total), report.currency); + children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) { children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT) { From 8388c28b4d7c999b644efba595cfe3468a190e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Thu, 25 Apr 2024 16:11:57 -0600 Subject: [PATCH 02/11] Fix ts error --- src/pages/home/report/ReportActionItem.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index cde76434f382..d3c0430ba02e 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -582,7 +582,7 @@ function ReportActionItem({ // This handles all historical actions from OldDot that we just want to display the message text children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { - const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(report.total), report.currency); + const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(report?.total ?? 0), report.currency); children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) { children = ; From 39d7f11c826e9a43295970c2ddbf857d0b161195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Wed, 1 May 2024 15:25:54 -0600 Subject: [PATCH 03/11] Set SUBMITTED message to clipboard --- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 013bc484fc63..8e0eddf7ceb6 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -30,6 +30,7 @@ import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; import type {Beta, ReportAction, ReportActionReactions, Transaction} from '@src/types/onyx'; import type IconAsset from '@src/types/utils/IconAsset'; +import * as CurrencyUtils from '@libs/CurrencyUtils'; import type {ContextMenuAnchor} from './ReportActionContextMenu'; import {hideContextMenu, showDeleteModal} from './ReportActionContextMenu'; @@ -360,6 +361,10 @@ const ContextMenuActions: ContextMenuAction[] = [ setClipboardMessage(mentionWhisperMessage); } else if (ReportActionsUtils.isActionableTrackExpense(reportAction)) { setClipboardMessage('What would you like to do with this expense?'); + } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { + const expenseReport = ReportUtils.getReport(reportID); + const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(expenseReport?.total ?? 0), expenseReport?.currency); + setClipboardMessage(Localize.translateLocal('iou.submittedAmount', {formattedAmount})); } 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 e7bb1533279afe058e97793d06a51087c7989e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Wed, 1 May 2024 15:34:45 -0600 Subject: [PATCH 04/11] Fix linting --- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 8e0eddf7ceb6..5021e888ea84 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -12,6 +12,7 @@ import MiniQuickEmojiReactions from '@components/Reactions/MiniQuickEmojiReactio import QuickEmojiReactions from '@components/Reactions/QuickEmojiReactions'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import Clipboard from '@libs/Clipboard'; +import * as CurrencyUtils from '@libs/CurrencyUtils'; import EmailUtils from '@libs/EmailUtils'; import * as Environment from '@libs/Environment/Environment'; import fileDownload from '@libs/fileDownload'; @@ -30,7 +31,6 @@ import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; import type {Beta, ReportAction, ReportActionReactions, Transaction} from '@src/types/onyx'; import type IconAsset from '@src/types/utils/IconAsset'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; import type {ContextMenuAnchor} from './ReportActionContextMenu'; import {hideContextMenu, showDeleteModal} from './ReportActionContextMenu'; From 6a1300f89f114c1d629897ee0b09fd62bba2ab2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 1 Jul 2024 13:49:05 -0600 Subject: [PATCH 05/11] Display correct submitted message optimistically --- src/libs/ReportUtils.ts | 81 ++--------------------------------------- 1 file changed, 3 insertions(+), 78 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b17fe7266079..b55e04d5195b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3953,79 +3953,6 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa return expenseReport; } -function getIOUSubmittedMessage(report: OnyxEntry) { - const policy = getPolicy(report?.policyID); - - if (report?.ownerAccountID !== currentUserAccountID && policy?.role === CONST.POLICY.ROLE.ADMIN) { - const ownerPersonalDetail = getPersonalDetailsForAccountID(report?.ownerAccountID ?? -1); - const ownerDisplayName = `${ownerPersonalDetail.displayName ?? ''}${ownerPersonalDetail.displayName !== ownerPersonalDetail.login ? ` (${ownerPersonalDetail.login})` : ''}`; - - return [ - { - style: 'normal', - text: 'You (on behalf of ', - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - }, - { - style: 'strong', - text: ownerDisplayName, - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - }, - { - style: 'normal', - text: ' via admin-submit)', - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - }, - { - style: 'normal', - text: ' submitted this report', - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - }, - { - style: 'normal', - text: ' to ', - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - }, - { - style: 'strong', - text: 'you', - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - }, - ]; - } - - const submittedToPersonalDetail = getPersonalDetailsForAccountID(PolicyUtils.getSubmitToAccountID(policy, report?.ownerAccountID ?? 0)); - let submittedToDisplayName = `${submittedToPersonalDetail.displayName ?? ''}${ - submittedToPersonalDetail.displayName !== submittedToPersonalDetail.login ? ` (${submittedToPersonalDetail.login})` : '' - }`; - if (submittedToPersonalDetail?.accountID === currentUserAccountID) { - submittedToDisplayName = 'yourself'; - } - - return [ - { - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - style: 'strong', - text: 'You', - }, - { - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - style: 'normal', - text: ' submitted this report', - }, - { - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - style: 'normal', - text: ' to ', - }, - { - type: CONST.REPORT.MESSAGE.TYPE.TEXT, - style: 'strong', - text: submittedToDisplayName, - }, - ]; -} - /** * @param iouReportID - the report ID of the IOU report the action belongs to * @param type - IOUReportAction type. Can be oneOf(create, decline, cancel, pay, split) @@ -4037,11 +3964,6 @@ function getIOUSubmittedMessage(report: OnyxEntry) { */ function getIOUReportActionMessage(iouReportID: string, type: string, total: number, comment: string, currency: string, paymentType = '', isSettlingUp = false): Message[] { const report = getReportOrDraftReport(iouReportID); - - if (type === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { - return getIOUSubmittedMessage(!isEmptyObject(report) ? report : undefined); - } - const amount = type === CONST.IOU.REPORT_ACTION_TYPE.PAY && !isEmptyObject(report) ? CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(report).totalDisplaySpend, currency) @@ -4078,6 +4000,9 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num case CONST.IOU.REPORT_ACTION_TYPE.PAY: iouMessage = isSettlingUp ? `paid ${amount}${paymentMethodMessage}` : `sent ${amount}${comment && ` for ${comment}`}${paymentMethodMessage}`; break; + case CONST.REPORT.ACTIONS.TYPE.SUBMITTED: + iouMessage = Localize.translateLocal('iou.submittedAmount', {formattedAmount: amount}); + break; default: break; } From 6ade994a4d044d6433a9c3e807d38d31c09dcaf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 1 Jul 2024 14:10:34 -0600 Subject: [PATCH 06/11] Use parentReport in thread reports --- src/pages/home/report/ReportActionItem.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index d9835085ee46..72111449f7e5 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -618,7 +618,8 @@ function ReportActionItem({ // This handles all historical actions from OldDot that we just want to display the message text children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { - const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(report?.total ?? 0), report.currency); + const linkedReport = ReportUtils.isChatThread(report) ? parentReport : report; + const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(linkedReport?.total ?? 0), linkedReport?.currency); children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) { children = ; From b2fc3e0c76a6f226fce4b266f802e007a25ea351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 1 Jul 2024 14:44:49 -0600 Subject: [PATCH 07/11] Restore getIOUSubmittedMessage and update it --- src/libs/ReportUtils.ts | 8 ++++++++ src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 5 ++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b55e04d5195b..6d6b46e5b8a7 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3953,6 +3953,13 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa return expenseReport; } +function getIOUSubmittedMessage(reportID: string) { + const report = getReportOrDraftReport(reportID); + const linkedReport = isChatThread(report) ? getParentReport(report) : report; + const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(linkedReport?.total ?? 0), linkedReport?.currency); + return Localize.translateLocal('iou.submittedAmount', {formattedAmount}); +} + /** * @param iouReportID - the report ID of the IOU report the action belongs to * @param type - IOUReportAction type. Can be oneOf(create, decline, cancel, pay, split) @@ -7054,6 +7061,7 @@ export { getGroupChatName, getIOUReportActionDisplayMessage, getIOUReportActionMessage, + getIOUSubmittedMessage, getIcons, getIconsForParticipants, getIndicatedMissingPaymentMethod, diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index af44dcad497e..d167b7bd2a2d 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -398,9 +398,8 @@ const ContextMenuActions: ContextMenuAction[] = [ } else if (ReportActionsUtils.isActionableTrackExpense(reportAction)) { setClipboardMessage(CONST.ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE); } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { - const expenseReport = ReportUtils.getReport(reportID); - const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(expenseReport?.total ?? 0), expenseReport?.currency); - setClipboardMessage(Localize.translateLocal('iou.submittedAmount', {formattedAmount})); + const displayMessage = ReportUtils.getIOUSubmittedMessage(reportID); + Clipboard.setString(displayMessage); } 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 cf856b2217485c73e5e01801383e01b048138836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 1 Jul 2024 14:48:39 -0600 Subject: [PATCH 08/11] Re-use getIOUSubmittedMessage in ReportActionItem --- src/pages/home/report/ReportActionItem.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 72111449f7e5..693165e71996 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -618,9 +618,7 @@ function ReportActionItem({ // This handles all historical actions from OldDot that we just want to display the message text children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { - const linkedReport = ReportUtils.isChatThread(report) ? parentReport : report; - const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(linkedReport?.total ?? 0), linkedReport?.currency); - children = ; + children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) { children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT) { From 026bdd5b72fe509892bab47b5bae66494e03d0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 1 Jul 2024 14:49:17 -0600 Subject: [PATCH 09/11] Remove CurrencyUtils --- src/pages/home/report/ReportActionItem.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 693165e71996..f0b36667e1dd 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -39,7 +39,6 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import ControlSelection from '@libs/ControlSelection'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import * as ErrorUtils from '@libs/ErrorUtils'; import focusTextInputAfterAnimation from '@libs/focusTextInputAfterAnimation'; From d736969b3221e4b7ed454efd8b01ea0fedfe7fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Mon, 1 Jul 2024 14:49:51 -0600 Subject: [PATCH 10/11] Remove CurrencyUtils from ContextMenuAction --- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index d167b7bd2a2d..7102c9878dca 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -11,7 +11,6 @@ import MiniQuickEmojiReactions from '@components/Reactions/MiniQuickEmojiReactio import QuickEmojiReactions from '@components/Reactions/QuickEmojiReactions'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import Clipboard from '@libs/Clipboard'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; import EmailUtils from '@libs/EmailUtils'; import * as Environment from '@libs/Environment/Environment'; import fileDownload from '@libs/fileDownload'; From 1e67f73b5cb96de83880dc80f7729ea0d772b487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Tue, 2 Jul 2024 14:21:21 -0600 Subject: [PATCH 11/11] refactor: Update getIcons function to use getReportActionActorAccountID --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 6d6b46e5b8a7..74b6d0fd37fe 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1960,7 +1960,7 @@ function getIcons( if (isChatThread(report)) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); - const actorAccountID = parentReportAction?.actorAccountID; + const actorAccountID = getReportActionActorAccountID(parentReportAction, report); const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[actorAccountID ?? -1], '', false); const actorIcon = { id: actorAccountID,