diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 135e9eece17d0..69917ce35c6bf 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 isReportActionSubmitted(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; } @@ -450,6 +454,18 @@ function isConsecutiveActionMadeByPreviousActor(reportActions: ReportAction[] | return false; } + if (isReportActionSubmitted(currentAction)) { + const currentActionAdminAccountID = currentAction.adminAccountID; + + return currentActionAdminAccountID === previousAction.actorAccountID || currentActionAdminAccountID === previousAction.adminAccountID; + } + + if (isReportActionSubmitted(previousAction)) { + return typeof previousAction.adminAccountID === 'number' + ? currentAction.actorAccountID === previousAction.adminAccountID + : currentAction.actorAccountID === previousAction.actorAccountID; + } + return currentAction.actorAccountID === previousAction.actorAccountID; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e49c2f25ccc4f..e91ae06730079 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -209,7 +209,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< @@ -3559,7 +3571,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, @@ -3569,6 +3581,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, return { actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED, actorAccountID: currentUserAccountID, + adminAccountID, automatic: false, avatar: getCurrentUserAvatarOrDefault(), isAttachment: false, @@ -5726,6 +5739,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; + } +} + /** * @returns the object to update `report.hasOutstandingChildRequest` */ @@ -5977,6 +6003,7 @@ export { isGroupChat, isTrackExpenseReport, hasActionsWithErrors, + getReportActionActorAccountID, getGroupChatName, getOutstandingChildRequest, }; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c2d462bbc4a86..cad7f1e87270c 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4969,11 +4969,12 @@ 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 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 optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, isSubmitAndClosePolicy ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.SUBMITTED); const optimisticData: OnyxUpdate[] = !isSubmitAndClosePolicy diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 23d97680e9d35..1e0dc432b3fc6 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/pages/home/report/ReportActionsListItemRenderer.tsx b/src/pages/home/report/ReportActionsListItemRenderer.tsx index 263415d90c390..879f567762dd5 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, diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index 6133f35afa470..dade2052e0528 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;