From 46e87ba4659fa14216161e82e47f03e9ceaa48d6 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 27 Mar 2024 12:07:15 +0100 Subject: [PATCH 1/5] integrate getReportActionActorAccountID --- src/libs/ReportUtils.ts | 14 ++++++++++++++ src/pages/home/report/ReportActionItemSingle.tsx | 3 ++- src/types/onyx/ReportAction.ts | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0bb3b1101b7c..41988cd5bfbb 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5517,6 +5517,19 @@ function hasActionsWithErrors(reportID: string): boolean { return Object.values(reportActions ?? {}).some((action) => !isEmptyObject(action.errors)); } +function getReportActionActorAccountID(reportAction: OnyxEntry, iouReport: OnyxEntry | undefined): number | undefined { + switch (reportAction?.actionName) { + case CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW: + return iouReport ? iouReport.managerID : reportAction?.actorAccountID; + + case CONST.REPORT.ACTIONS.TYPE.SUBMITTED: + return reportAction?.adminAccountID ?? reportAction?.actorAccountID; + + default: + return reportAction?.actorAccountID; + } +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -5735,6 +5748,7 @@ export { shouldCreateNewMoneyRequestReport, isTrackExpenseReport, hasActionsWithErrors, + getReportActionActorAccountID, }; export type { diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 696cd7a7d850..98dfbdc56c89 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -78,7 +78,8 @@ function ReportActionItemSingle({ const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); const personalDetails = usePersonalDetails() ?? CONST.EMPTY_OBJECT; - const actorAccountID = action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && iouReport ? iouReport.managerID : action?.actorAccountID; + const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport); + let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID); const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {}; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index 86383a8d0047..c35923849888 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -226,6 +226,9 @@ type ReportActionBase = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Flag for checking if data is from optimistic data */ isOptimisticAction?: boolean; + + /** The admins's ID */ + adminAccountID?: number; }>; type ReportAction = ReportActionBase & OriginalMessage; From 8c2ac0db81fce3e6a76964a1dbd11920498c0450 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 4 Apr 2024 15:17:02 +0200 Subject: [PATCH 2/5] pass adminAccountID to ReportActionItem --- .../report/ReportActionsListItemRenderer.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pages/home/report/ReportActionsListItemRenderer.tsx b/src/pages/home/report/ReportActionsListItemRenderer.tsx index 263415d90c39..879f567762dd 100644 --- a/src/pages/home/report/ReportActionsListItemRenderer.tsx +++ b/src/pages/home/report/ReportActionsListItemRenderer.tsx @@ -83,6 +83,7 @@ function ReportActionsListItemRenderer({ error: reportAction.error, created: reportAction.created, actorAccountID: reportAction.actorAccountID, + adminAccountID: reportAction.adminAccountID, childVisibleActionCount: reportAction.childVisibleActionCount, childOldestFourAccountIDs: reportAction.childOldestFourAccountIDs, childType: reportAction.childType, @@ -98,25 +99,26 @@ function ReportActionsListItemRenderer({ childMoneyRequestCount: reportAction.childMoneyRequestCount, } as ReportAction), [ + reportAction.reportActionID, + reportAction.message, + reportAction.pendingAction, reportAction.actionName, - reportAction.childCommenterCount, - reportAction.childLastVisibleActionCreated, - reportAction.childReportID, - reportAction.created, - reportAction.error, reportAction.errors, - reportAction.linkMetadata, - reportAction.message, reportAction.originalMessage, - reportAction.pendingAction, - reportAction.reportActionID, + reportAction.childCommenterCount, + reportAction.linkMetadata, + reportAction.childReportID, + reportAction.childLastVisibleActionCreated, reportAction.whisperedToAccountIDs, + reportAction.error, + reportAction.created, reportAction.actorAccountID, + reportAction.adminAccountID, reportAction.childVisibleActionCount, reportAction.childOldestFourAccountIDs, + reportAction.childType, reportAction.person, reportAction.isOptimisticAction, - reportAction.childType, reportAction.delegateAccountID, reportAction.previousMessage, reportAction.attachmentInfo, From ade097f81c04addeba519c044e33d2b5f8664727 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 4 Apr 2024 16:50:35 +0200 Subject: [PATCH 3/5] fix group message splitting --- src/libs/ReportActionsUtils.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index bf1a9f994c37..cd198841c1cf 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -130,6 +130,10 @@ function isReportPreviewAction(reportAction: OnyxEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; } +function isReportSubmitAction(reportAction: OnyxEntry): boolean { + return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED; +} + function isModifiedExpenseAction(reportAction: OnyxEntry | ReportAction | Record): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE; } @@ -435,6 +439,18 @@ function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] | return false; } + if (isReportSubmitAction(currentAction)) { + const currentActionAdminAccountID = currentAction.adminAccountID; + + return currentActionAdminAccountID === previousAction.actorAccountID || currentActionAdminAccountID === previousAction.adminAccountID; + } + + if (isReportSubmitAction(previousAction)) { + return typeof previousAction.adminAccountID === 'number' + ? currentAction.actorAccountID === previousAction.adminAccountID + : currentAction.actorAccountID === previousAction.actorAccountID; + } + return currentAction.actorAccountID === previousAction.actorAccountID; } From 177ff3570d8d04ad8995d3f5a1aff527b7f9c62e Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 4 Apr 2024 16:51:01 +0200 Subject: [PATCH 4/5] set adminAccountID to optimistic submit --- src/libs/ReportUtils.ts | 17 +++++++++++++++-- src/libs/actions/IOU.ts | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c472a58ee13f..7e99d5d414cf 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -206,7 +206,19 @@ type OptimisticApprovedReportAction = Pick< type OptimisticSubmittedReportAction = Pick< ReportAction, - 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' + | 'actionName' + | 'actorAccountID' + | 'adminAccountID' + | 'automatic' + | 'avatar' + | 'isAttachment' + | 'originalMessage' + | 'message' + | 'person' + | 'reportActionID' + | 'shouldShow' + | 'created' + | 'pendingAction' >; type OptimisticHoldReportAction = Pick< @@ -3545,7 +3557,7 @@ function buildOptimisticMovedReportAction(fromPolicyID: string, toPolicyID: stri * Builds an optimistic SUBMITTED report action with a randomly generated reportActionID. * */ -function buildOptimisticSubmittedReportAction(amount: number, currency: string, expenseReportID: string): OptimisticSubmittedReportAction { +function buildOptimisticSubmittedReportAction(amount: number, currency: string, expenseReportID: string, adminAccountID: number | undefined): OptimisticSubmittedReportAction { const originalMessage = { amount, currency, @@ -3555,6 +3567,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, return { actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED, actorAccountID: currentUserAccountID, + adminAccountID, automatic: false, avatar: getCurrentUserAvatarOrDefault(), isAttachment: false, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 5c92cd87a2bc..a0b8711433d9 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4778,12 +4778,13 @@ function approveMoneyRequest(expenseReport: OnyxTypes.Report | EmptyObject, full function submitReport(expenseReport: OnyxTypes.Report) { const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null; - const optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction(expenseReport?.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID); const parentReport = ReportUtils.getReport(expenseReport.parentReportID); const policy = getPolicy(expenseReport.policyID); const isCurrentUserManager = currentUserPersonalDetails.accountID === expenseReport.managerID; const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED); const isSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); + const adminAccountID = policy.role === CONST.POLICY.ROLE.ADMIN ? currentUserPersonalDetails.accountID : undefined; + const optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction(expenseReport?.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, adminAccountID); const optimisticData: OnyxUpdate[] = !isSubmitAndClosePolicy ? [ From cc0e6448b0aba76eaec56441d46a1fba6c7fac78 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 4 Apr 2024 19:03:59 +0200 Subject: [PATCH 5/5] rename isReportActionSubmitted --- src/libs/ReportActionsUtils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index cd198841c1cf..858618090700 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -130,7 +130,7 @@ function isReportPreviewAction(reportAction: OnyxEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; } -function isReportSubmitAction(reportAction: OnyxEntry): boolean { +function isReportActionSubmitted(reportAction: OnyxEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED; } @@ -439,13 +439,13 @@ function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] | return false; } - if (isReportSubmitAction(currentAction)) { + if (isReportActionSubmitted(currentAction)) { const currentActionAdminAccountID = currentAction.adminAccountID; return currentActionAdminAccountID === previousAction.actorAccountID || currentActionAdminAccountID === previousAction.adminAccountID; } - if (isReportSubmitAction(previousAction)) { + if (isReportActionSubmitted(previousAction)) { return typeof previousAction.adminAccountID === 'number' ? currentAction.actorAccountID === previousAction.adminAccountID : currentAction.actorAccountID === previousAction.actorAccountID;