From baf36ec3f2517d0a32724ea13f879496a1ce58df Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 10 Sep 2024 14:46:51 -0600 Subject: [PATCH 01/14] Add optional harvesting key for delayed auto submit --- src/types/onyx/OriginalMessage.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 763f221f56fe..7be85e0ecdb3 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -157,6 +157,9 @@ type OriginalMessageSubmitted = { /** Report ID of the expense */ expenseReportID: string; + + /** Was the report submitted via harvesting (delayed submit) */ + harvesting?: boolean; }; /** Model of `closed` report action */ From a019fe10c5fbd95b9bd28b4ddc3e7b0c15e55cea Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 10 Sep 2024 14:47:08 -0600 Subject: [PATCH 02/14] A few new consts for help sites --- src/CONST.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index cf3facb0d1d8..c2fa2263b03f 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -715,6 +715,8 @@ const CONST = { "https://help.expensify.com/articles/expensify-classic/connections/sage-intacct/Sage-Intacct-Troubleshooting#:~:text=First%20make%20sure%20that%20you,your%20company's%20Web%20Services%20authorizations.", PRICING: `https://www.expensify.com/pricing`, CUSTOM_REPORT_NAME_HELP_URL: 'https://help.expensify.com/articles/expensify-classic/spending-insights/Custom-Templates', + CONFIGURE_REIMBURSEMENT_SETTINGS_HELP_URL: 'https://help.expensify.com/articles/expensify-classic/workspaces/Configure-Reimbursement-Settings', + DELAYED_SUBMISSION_HELP_URL: 'https://help.expensify.com/articles/expensify-classic/reports/Automatically-submit-employee-reports', // Use Environment.getEnvironmentURL to get the complete URL with port number DEV_NEW_EXPENSIFY_URL: 'https://dev.new.expensify.com:', OLDDOT_URLS: { From 292c0a9d8bb4877c10efbb41a42a48c8c8af5d95 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 10 Sep 2024 14:48:15 -0600 Subject: [PATCH 03/14] New function for building automatically submitted report message --- src/libs/ReportUtils.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 076c6c1af3d5..30706e9469af 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4432,7 +4432,11 @@ function getFormattedAmount(reportAction: ReportAction) { return formattedAmount; } -function getIOUSubmittedMessage(reportAction: ReportAction) { +function getReportAutomaticallySubmittedMessage(reportAction: ReportAction) { + return Localize.translateLocal('iou.automaticallySubmittedAmount', {formattedAmount: getFormattedAmount(reportAction)}); +} + +function getIOUSubmittedMessage(reportAction: ReportAction) { return Localize.translateLocal('iou.submittedAmount', {formattedAmount: getFormattedAmount(reportAction)}); } @@ -7899,6 +7903,7 @@ export { getIOUForwardedMessage, getRejectedReportMessage, getWorkspaceNameUpdatedMessage, + getReportAutomaticallySubmittedMessage, getIOUSubmittedMessage, getIcons, getIconsForParticipants, From c69056990b006d295516058ac33a6c5183d356b7 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 10 Sep 2024 14:48:29 -0600 Subject: [PATCH 04/14] Conditionally show type of submitted message --- src/pages/home/report/ReportActionItem.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 6b504d863664..220e57359ff6 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -637,8 +637,18 @@ function ReportActionItem({ children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE) { children = ; - } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { - children = ; + } else if (ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { + const originalMessage = ReportActionsUtils.getOriginalMessage(action); + const wasSubmittedViaHarvesting = originalMessage?.harvesting ?? false; + if (wasSubmittedViaHarvesting) { + children = ( + + ${ReportUtils.getReportAutomaticallySubmittedMessage(action)}`}/> + + ); + } else { + children = ; + } } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) { children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { From 4181193d7aa87426cf7ed56b07bcdcd4696252fc Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 10 Sep 2024 14:52:44 -0600 Subject: [PATCH 05/14] Add in translations --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/languages/en.ts b/src/languages/en.ts index 298eb67ecab4..11c9188b68a8 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -809,6 +809,7 @@ export default { sendInvoice: ({amount}: RequestAmountParams) => `Send ${amount} invoice`, submitAmount: ({amount}: RequestAmountParams) => `submit ${amount}`, submittedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `submitted ${formattedAmount}${comment ? ` for ${comment}` : ''}`, + automaticallySubmittedAmount: ({formattedAmount}: RequestedAmountMessageParams) => `automatically submitted ${formattedAmount} via delayed submission`, trackedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `tracking ${formattedAmount}${comment ? ` for ${comment}` : ''}`, splitAmount: ({amount}: SplitAmountParams) => `split ${amount}`, didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `split ${formattedAmount}${comment ? ` for ${comment}` : ''}`, diff --git a/src/languages/es.ts b/src/languages/es.ts index 52ec2a57427b..936d7537530f 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -802,6 +802,7 @@ export default { sendInvoice: ({amount}: RequestAmountParams) => `Enviar factura de ${amount}`, submitAmount: ({amount}: RequestAmountParams) => `solicitar ${amount}`, submittedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `solicitó ${formattedAmount}${comment ? ` para ${comment}` : ''}`, + automaticallySubmittedAmount: ({formattedAmount}: RequestedAmountMessageParams) => `Se enviaron automáticamente ${formattedAmount} mediante envío diferido`, trackedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `realizó un seguimiento de ${formattedAmount}${comment ? ` para ${comment}` : ''}`, splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`, didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `dividió ${formattedAmount}${comment ? ` para ${comment}` : ''}`, From a307b5edd5f3e7b72db886517204f2a42513d0be Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 10 Sep 2024 14:59:35 -0600 Subject: [PATCH 06/14] Fix type issues --- src/libs/OptionsListUtils.ts | 2 +- src/libs/ReportUtils.ts | 2 +- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index f191c1d06532..22ac9ef174ed 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -658,7 +658,7 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(TaskUtils.getTaskReportActionMessage(lastReportAction).text); } else if (ReportActionUtils.isCreatedTaskReportAction(lastReportAction)) { lastMessageTextFromReport = TaskUtils.getTaskCreatedMessage(lastReportAction); - } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { + } else if (ReportActionUtils.isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { lastMessageTextFromReport = ReportUtils.getIOUSubmittedMessage(lastReportAction); } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) { lastMessageTextFromReport = ReportUtils.getIOUApprovedMessage(lastReportAction); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 30706e9469af..6b8f945bb654 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3701,7 +3701,7 @@ function getReportName( const parentReportAction = parentReportActionParam ?? ReportActionsUtils.getParentReportAction(report); const parentReportActionMessage = ReportActionsUtils.getReportActionMessage(parentReportAction); - if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { + if (ReportActionsUtils.isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { return getIOUSubmittedMessage(parentReportAction); } if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index a1e0b198c840..b3c2b3f9d4ef 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -439,7 +439,7 @@ const ContextMenuActions: ContextMenuAction[] = [ setClipboardMessage(CONST.ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE); } else if (ReportActionsUtils.isRenamedAction(reportAction)) { setClipboardMessage(ReportActionsUtils.getRenamedAction(reportAction)); - } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { + } else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { const displayMessage = ReportUtils.getIOUSubmittedMessage(reportAction); Clipboard.setString(displayMessage); } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) { From 68eb6a5dbab1d3f3f6f898c5249921c1cb8d967b Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 10 Sep 2024 16:02:39 -0600 Subject: [PATCH 07/14] Style fixes --- src/languages/en.ts | 3 ++- src/languages/es.ts | 3 ++- src/pages/home/report/ReportActionItem.tsx | 7 +++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 11c9188b68a8..44d394d2b920 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -809,7 +809,8 @@ export default { sendInvoice: ({amount}: RequestAmountParams) => `Send ${amount} invoice`, submitAmount: ({amount}: RequestAmountParams) => `submit ${amount}`, submittedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `submitted ${formattedAmount}${comment ? ` for ${comment}` : ''}`, - automaticallySubmittedAmount: ({formattedAmount}: RequestedAmountMessageParams) => `automatically submitted ${formattedAmount} via delayed submission`, + automaticallySubmittedAmount: ({formattedAmount}: RequestedAmountMessageParams) => + `automatically submitted ${formattedAmount} via delayed submission`, trackedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `tracking ${formattedAmount}${comment ? ` for ${comment}` : ''}`, splitAmount: ({amount}: SplitAmountParams) => `split ${amount}`, didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `split ${formattedAmount}${comment ? ` for ${comment}` : ''}`, diff --git a/src/languages/es.ts b/src/languages/es.ts index 936d7537530f..997200228510 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -802,7 +802,8 @@ export default { sendInvoice: ({amount}: RequestAmountParams) => `Enviar factura de ${amount}`, submitAmount: ({amount}: RequestAmountParams) => `solicitar ${amount}`, submittedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `solicitó ${formattedAmount}${comment ? ` para ${comment}` : ''}`, - automaticallySubmittedAmount: ({formattedAmount}: RequestedAmountMessageParams) => `Se enviaron automáticamente ${formattedAmount} mediante envío diferido`, + automaticallySubmittedAmount: ({formattedAmount}: RequestedAmountMessageParams) => + `Se enviaron automáticamente ${formattedAmount} mediante envío diferido`, trackedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `realizó un seguimiento de ${formattedAmount}${comment ? ` para ${comment}` : ''}`, splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`, didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `dividió ${formattedAmount}${comment ? ` para ${comment}` : ''}`, diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 220e57359ff6..4ef78442dc4e 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -638,12 +638,11 @@ function ReportActionItem({ } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE) { children = ; } else if (ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { - const originalMessage = ReportActionsUtils.getOriginalMessage(action); - const wasSubmittedViaHarvesting = originalMessage?.harvesting ?? false; + const wasSubmittedViaHarvesting = ReportActionsUtils.getOriginalMessage(action)?.harvesting ?? false; if (wasSubmittedViaHarvesting) { children = ( - - ${ReportUtils.getReportAutomaticallySubmittedMessage(action)}`}/> + + ${ReportUtils.getReportAutomaticallySubmittedMessage(action)}`} /> ); } else { From 8b6d3555a7ad291389a5f7c8dcad70ac39d8db17 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 17 Sep 2024 08:34:58 -0600 Subject: [PATCH 08/14] Update src/languages/es.ts Co-authored-by: Luthfi --- src/languages/es.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index b43c54c66f29..b3b6ceccd8a6 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -806,7 +806,7 @@ export default { submitAmount: ({amount}: RequestAmountParams) => `solicitar ${amount}`, submittedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `solicitó ${formattedAmount}${comment ? ` para ${comment}` : ''}`, automaticallySubmittedAmount: ({formattedAmount}: RequestedAmountMessageParams) => - `Se enviaron automáticamente ${formattedAmount} mediante envío diferido`, + `se enviaron automáticamente ${formattedAmount} mediante envío diferido`, trackedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `realizó un seguimiento de ${formattedAmount}${comment ? ` para ${comment}` : ''}`, splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`, didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `dividió ${formattedAmount}${comment ? ` para ${comment}` : ''}`, From e7523d944edb1dfd559679c6bdbe6f9878ad75ac Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 20 Sep 2024 10:38:17 -0600 Subject: [PATCH 09/14] Get user wallet with useOnyx --- src/pages/home/report/ReportActionItem.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index cff48f69f105..dc0e43bd5214 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -88,9 +88,6 @@ type ReportActionItemOnyxProps = { emojiReactions: OnyxEntry; - /** The user's wallet account */ - userWallet: OnyxEntry; - /** The transaction (linked with the report action) route error */ linkedTransactionRouteError: NonNullable> | null; }; @@ -164,7 +161,6 @@ function ReportActionItem({ isMostRecentIOUReportAction, parentReportAction, shouldDisplayNewMarker, - userWallet, shouldHideThreadDividerLine = false, shouldShowSubscriptAvatar = false, onPress = undefined, @@ -203,6 +199,7 @@ function ReportActionItem({ const popoverAnchorRef = useRef>(null); const downloadedPreviews = useRef([]); const prevDraftMessage = usePrevious(draftMessage); + const userWallet = useOnyx(ONYXKEYS.USER_WALLET); // The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -1018,9 +1015,6 @@ export default withOnyx({ key: ({action}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${action.reportActionID}`, initialValue: {}, }, - userWallet: { - key: ONYXKEYS.USER_WALLET, - }, linkedTransactionRouteError: { key: ({action}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID ?? -1 : -1}`, From c0777314092b71482abe90168f6d7e3db70fa4e4 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 20 Sep 2024 10:39:19 -0600 Subject: [PATCH 10/14] Fix getting wallet from onyx --- 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 dc0e43bd5214..64a34ebd60f1 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -199,7 +199,7 @@ function ReportActionItem({ const popoverAnchorRef = useRef>(null); const downloadedPreviews = useRef([]); const prevDraftMessage = usePrevious(draftMessage); - const userWallet = useOnyx(ONYXKEYS.USER_WALLET); + const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); // The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing From 63679a180b59954772c75149e489d5c23e75d90d Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 20 Sep 2024 12:32:31 -0600 Subject: [PATCH 11/14] UseOnyx to get emoji reactions --- src/pages/home/report/ReportActionItem.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 64a34ebd60f1..2d4817101409 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -86,8 +86,6 @@ type ReportActionItemOnyxProps = { /** IOU report for this action, if any */ iouReport: OnyxEntry; - emojiReactions: OnyxEntry; - /** The transaction (linked with the report action) route error */ linkedTransactionRouteError: NonNullable> | null; }; @@ -155,7 +153,6 @@ function ReportActionItem({ transactionThreadReport, linkedReportActionID, displayAsGroup, - emojiReactions, index, iouReport, isMostRecentIOUReportAction, @@ -200,6 +197,7 @@ function ReportActionItem({ const downloadedPreviews = useRef([]); const prevDraftMessage = usePrevious(draftMessage); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); + const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${action.reportActionID}`); // The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -1011,10 +1009,6 @@ export default withOnyx({ }, initialValue: {} as OnyxTypes.Report, }, - emojiReactions: { - key: ({action}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${action.reportActionID}`, - initialValue: {}, - }, linkedTransactionRouteError: { key: ({action}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID ?? -1 : -1}`, @@ -1028,7 +1022,6 @@ export default withOnyx({ prevProps.displayAsGroup === nextProps.displayAsGroup && prevProps.isMostRecentIOUReportAction === nextProps.isMostRecentIOUReportAction && prevProps.shouldDisplayNewMarker === nextProps.shouldDisplayNewMarker && - lodashIsEqual(prevProps.emojiReactions, nextProps.emojiReactions) && lodashIsEqual(prevProps.action, nextProps.action) && lodashIsEqual(prevProps.iouReport, nextProps.iouReport) && lodashIsEqual(prevProps.report.pendingFields, nextProps.report.pendingFields) && From 5a1d6e4c2800b7291746b270db4e68caf3829a9c Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 20 Sep 2024 12:39:53 -0600 Subject: [PATCH 12/14] Move linked transaction route error for useOnyx --- src/pages/home/report/ReportActionItem.tsx | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 2d4817101409..aa918706424b 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -85,9 +85,6 @@ import ReportAttachmentsContext from './ReportAttachmentsContext'; type ReportActionItemOnyxProps = { /** IOU report for this action, if any */ iouReport: OnyxEntry; - - /** The transaction (linked with the report action) route error */ - linkedTransactionRouteError: NonNullable> | null; }; type ReportActionItemProps = { @@ -163,7 +160,6 @@ function ReportActionItem({ onPress = undefined, isFirstVisibleReportAction = false, shouldUseThreadDividerLine = false, - linkedTransactionRouteError, hideThreadReplies = false, shouldDisplayContextMenu = true, parentReportActionForTransactionThread, @@ -198,6 +194,9 @@ function ReportActionItem({ const prevDraftMessage = usePrevious(draftMessage); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${action.reportActionID}`); + const [linkedTransactionRouteError] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID ?? -1 : -1}`, { + selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? null + }) // The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -1009,11 +1008,6 @@ export default withOnyx({ }, initialValue: {} as OnyxTypes.Report, }, - linkedTransactionRouteError: { - key: ({action}) => - `${ONYXKEYS.COLLECTION.TRANSACTION}${ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID ?? -1 : -1}`, - selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? null, - }, })( memo(ReportActionItem, (prevProps, nextProps) => { const prevParentReportAction = prevProps.parentReportAction; @@ -1046,7 +1040,6 @@ export default withOnyx({ lodashIsEqual(prevProps.report.fieldList, nextProps.report.fieldList) && lodashIsEqual(prevProps.transactionThreadReport, nextProps.transactionThreadReport) && lodashIsEqual(prevProps.reportActions, nextProps.reportActions) && - lodashIsEqual(prevProps.linkedTransactionRouteError, nextProps.linkedTransactionRouteError) && lodashIsEqual(prevParentReportAction, nextParentReportAction) ); }), From 140f1dcb612075e823894722abebc16a5acb563e Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 20 Sep 2024 12:48:19 -0600 Subject: [PATCH 13/14] Get iouReport with useOnyx --- src/pages/home/report/ReportActionItem.tsx | 93 +++++++++------------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index aa918706424b..19ef7a4d3e6d 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -64,7 +64,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; -import type {Errors} from '@src/types/onyx/OnyxCommon'; import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {RestrictedReadOnlyContextMenuActions} from './ContextMenu/ContextMenuActions'; @@ -82,11 +81,6 @@ import ReportActionItemSingle from './ReportActionItemSingle'; import ReportActionItemThread from './ReportActionItemThread'; import ReportAttachmentsContext from './ReportAttachmentsContext'; -type ReportActionItemOnyxProps = { - /** IOU report for this action, if any */ - iouReport: OnyxEntry; -}; - type ReportActionItemProps = { /** Report for this action */ report: OnyxTypes.Report; @@ -142,7 +136,7 @@ type ReportActionItemProps = { /** Whether context menu should be displayed */ shouldDisplayContextMenu?: boolean; -} & ReportActionItemOnyxProps; +}; function ReportActionItem({ action, @@ -151,7 +145,6 @@ function ReportActionItem({ linkedReportActionID, displayAsGroup, index, - iouReport, isMostRecentIOUReportAction, parentReportAction, shouldDisplayNewMarker, @@ -195,8 +188,11 @@ function ReportActionItem({ const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${action.reportActionID}`); const [linkedTransactionRouteError] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID ?? -1 : -1}`, { - selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? null - }) + selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? null, + }); + const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${ReportActionsUtils.getIOUReportIDFromReportActionPreview(action) ?? -1}`, { + initialValue: {} as OnyxTypes.Report + }); // The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -1000,47 +996,36 @@ function ReportActionItem({ ); } -export default withOnyx({ - iouReport: { - key: ({action}) => { - const iouReportID = ReportActionsUtils.getIOUReportIDFromReportActionPreview(action); - return `${ONYXKEYS.COLLECTION.REPORT}${iouReportID ?? -1}`; - }, - initialValue: {} as OnyxTypes.Report, - }, -})( - memo(ReportActionItem, (prevProps, nextProps) => { - const prevParentReportAction = prevProps.parentReportAction; - const nextParentReportAction = nextProps.parentReportAction; - return ( - prevProps.displayAsGroup === nextProps.displayAsGroup && - prevProps.isMostRecentIOUReportAction === nextProps.isMostRecentIOUReportAction && - prevProps.shouldDisplayNewMarker === nextProps.shouldDisplayNewMarker && - lodashIsEqual(prevProps.action, nextProps.action) && - lodashIsEqual(prevProps.iouReport, nextProps.iouReport) && - lodashIsEqual(prevProps.report.pendingFields, nextProps.report.pendingFields) && - lodashIsEqual(prevProps.report.isDeletedParentAction, nextProps.report.isDeletedParentAction) && - lodashIsEqual(prevProps.report.errorFields, nextProps.report.errorFields) && - prevProps.report?.statusNum === nextProps.report?.statusNum && - prevProps.report?.stateNum === nextProps.report?.stateNum && - prevProps.report?.parentReportID === nextProps.report?.parentReportID && - prevProps.report?.parentReportActionID === nextProps.report?.parentReportActionID && - // TaskReport's created actions render the TaskView, which updates depending on certain fields in the TaskReport - ReportUtils.isTaskReport(prevProps.report) === ReportUtils.isTaskReport(nextProps.report) && - prevProps.action.actionName === nextProps.action.actionName && - prevProps.report.reportName === nextProps.report.reportName && - prevProps.report.description === nextProps.report.description && - ReportUtils.isCompletedTaskReport(prevProps.report) === ReportUtils.isCompletedTaskReport(nextProps.report) && - prevProps.report.managerID === nextProps.report.managerID && - prevProps.shouldHideThreadDividerLine === nextProps.shouldHideThreadDividerLine && - prevProps.report?.total === nextProps.report?.total && - prevProps.report?.nonReimbursableTotal === nextProps.report?.nonReimbursableTotal && - prevProps.report?.policyAvatar === nextProps.report?.policyAvatar && - prevProps.linkedReportActionID === nextProps.linkedReportActionID && - lodashIsEqual(prevProps.report.fieldList, nextProps.report.fieldList) && - lodashIsEqual(prevProps.transactionThreadReport, nextProps.transactionThreadReport) && - lodashIsEqual(prevProps.reportActions, nextProps.reportActions) && - lodashIsEqual(prevParentReportAction, nextParentReportAction) - ); - }), -); +export default memo(ReportActionItem, (prevProps, nextProps) => { + const prevParentReportAction = prevProps.parentReportAction; + const nextParentReportAction = nextProps.parentReportAction; + return ( + prevProps.displayAsGroup === nextProps.displayAsGroup && + prevProps.isMostRecentIOUReportAction === nextProps.isMostRecentIOUReportAction && + prevProps.shouldDisplayNewMarker === nextProps.shouldDisplayNewMarker && + lodashIsEqual(prevProps.action, nextProps.action) && + lodashIsEqual(prevProps.report.pendingFields, nextProps.report.pendingFields) && + lodashIsEqual(prevProps.report.isDeletedParentAction, nextProps.report.isDeletedParentAction) && + lodashIsEqual(prevProps.report.errorFields, nextProps.report.errorFields) && + prevProps.report?.statusNum === nextProps.report?.statusNum && + prevProps.report?.stateNum === nextProps.report?.stateNum && + prevProps.report?.parentReportID === nextProps.report?.parentReportID && + prevProps.report?.parentReportActionID === nextProps.report?.parentReportActionID && + // TaskReport's created actions render the TaskView, which updates depending on certain fields in the TaskReport + ReportUtils.isTaskReport(prevProps.report) === ReportUtils.isTaskReport(nextProps.report) && + prevProps.action.actionName === nextProps.action.actionName && + prevProps.report.reportName === nextProps.report.reportName && + prevProps.report.description === nextProps.report.description && + ReportUtils.isCompletedTaskReport(prevProps.report) === ReportUtils.isCompletedTaskReport(nextProps.report) && + prevProps.report.managerID === nextProps.report.managerID && + prevProps.shouldHideThreadDividerLine === nextProps.shouldHideThreadDividerLine && + prevProps.report?.total === nextProps.report?.total && + prevProps.report?.nonReimbursableTotal === nextProps.report?.nonReimbursableTotal && + prevProps.report?.policyAvatar === nextProps.report?.policyAvatar && + prevProps.linkedReportActionID === nextProps.linkedReportActionID && + lodashIsEqual(prevProps.report.fieldList, nextProps.report.fieldList) && + lodashIsEqual(prevProps.transactionThreadReport, nextProps.transactionThreadReport) && + lodashIsEqual(prevProps.reportActions, nextProps.reportActions) && + lodashIsEqual(prevParentReportAction, nextParentReportAction) + ); +}); From 0bde07646934a0ea82ba92a6e9326e21151d7edf Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 20 Sep 2024 12:51:50 -0600 Subject: [PATCH 14/14] Prettify, remove withOnyx import --- src/pages/home/report/ReportActionItem.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 19ef7a4d3e6d..57c76c148005 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -3,7 +3,7 @@ import React, {memo, useCallback, useContext, useEffect, useMemo, useRef, useSta import type {GestureResponderEvent, TextInput} from 'react-native'; import {InteractionManager, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {useOnyx, withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {Emoji} from '@assets/emojis/types'; import {AttachmentContext} from '@components/AttachmentContext'; import Button from '@components/Button'; @@ -187,11 +187,14 @@ function ReportActionItem({ const prevDraftMessage = usePrevious(draftMessage); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${action.reportActionID}`); - const [linkedTransactionRouteError] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID ?? -1 : -1}`, { - selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? null, - }); + const [linkedTransactionRouteError] = useOnyx( + `${ONYXKEYS.COLLECTION.TRANSACTION}${ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID ?? -1 : -1}`, + { + selector: (transaction: OnyxEntry) => transaction?.errorFields?.route ?? null, + }, + ); const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${ReportActionsUtils.getIOUReportIDFromReportActionPreview(action) ?? -1}`, { - initialValue: {} as OnyxTypes.Report + initialValue: {} as OnyxTypes.Report, }); // The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here.