diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index fd2427a4ddc3..06083365bc96 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -131,15 +131,16 @@ function ReportPreview({ const {isSmallScreenWidth} = useWindowDimensions(); const [paymentType, setPaymentType] = useState(); - const managerID = iouReport?.managerID ?? 0; + const managerID = iouReport?.managerID ?? action.childManagerAccountID ?? 0; const {totalDisplaySpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport); - const iouSettled = ReportUtils.isSettled(iouReportID); + const iouSettled = ReportUtils.isSettled(iouReportID) || action?.childStatusNum === CONST.REPORT.STATUS_NUM.REIMBURSED; + const moneyRequestComment = action?.childLastMoneyRequestComment ?? ''; const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport); - const isApproved = ReportUtils.isReportApproved(iouReport); + const isApproved = ReportUtils.isReportApproved(iouReport, action); const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport, policy); const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID); const numberOfRequests = allTransactions.length; @@ -372,7 +373,7 @@ function ReportPreview({ {getDisplayAmount()} - {ReportUtils.isSettled(iouReportID) && ( + {iouSettled && ( ): boolean { /** * Checks if the supplied report has been approved */ -function isReportApproved(reportOrID: OnyxInputOrEntry | string | EmptyObject): boolean { +function isReportApproved(reportOrID: OnyxInputOrEntry | string | EmptyObject, parentReportAction: OnyxEntry = undefined): boolean { const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID; + if (!report) { + return parentReportAction?.childStateNum === CONST.REPORT.STATE_NUM.APPROVED && parentReportAction?.childStatusNum === CONST.REPORT.STATUS_NUM.APPROVED; + } return report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED && report?.statusNum === CONST.REPORT.STATUS_NUM.APPROVED; } @@ -6905,7 +6908,7 @@ function canLeaveChat(report: OnyxEntry, policy: OnyxEntry): boo function getReportActionActorAccountID(reportAction: OnyxInputOrEntry, iouReport: OnyxInputOrEntry | undefined): number | undefined { switch (reportAction?.actionName) { case CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW: - return iouReport ? iouReport.managerID : reportAction?.actorAccountID; + return !isEmptyObject(iouReport) ? iouReport.managerID : reportAction?.childManagerAccountID; case CONST.REPORT.ACTIONS.TYPE.SUBMITTED: return reportAction?.adminAccountID ?? reportAction?.actorAccountID; diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index ac2228bf272a..e5794148dc46 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -85,9 +85,10 @@ function ReportActionItemSingle({ const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {}; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing let actorHint = (login || (displayName ?? '')).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''); - const displayAllActors = useMemo(() => action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && iouReport, [action?.actionName, iouReport]); + const displayAllActors = useMemo(() => action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW, [action?.actionName]); const isInvoiceReport = ReportUtils.isInvoiceReport(iouReport ?? {}); const isWorkspaceActor = isInvoiceReport || (ReportUtils.isPolicyExpenseChat(report) && (!actorAccountID || displayAllActors)); + const ownerAccountID = iouReport?.ownerAccountID ?? action?.childOwnerAccountID; let avatarSource = avatar; let avatarId: number | string | undefined = actorAccountID; @@ -111,8 +112,8 @@ function ReportActionItemSingle({ let secondaryAvatar: Icon; const primaryDisplayName = displayName; if (displayAllActors) { - // The ownerAccountID and actorAccountID can be the same if the user submits an expense back from the IOU's original creator, in that case we need to use managerID to avoid displaying the same user twice - const secondaryAccountId = iouReport?.ownerAccountID === actorAccountID || isInvoiceReport ? iouReport?.managerID : iouReport?.ownerAccountID; + // The ownerAccountID and actorAccountID can be the same if a user submits an expense back from the IOU's original creator, in that case we need to use managerID to avoid displaying the same user twice + const secondaryAccountId = ownerAccountID === actorAccountID || isInvoiceReport ? actorAccountID : ownerAccountID; const secondaryUserAvatar = personalDetails?.[secondaryAccountId ?? -1]?.avatar ?? FallbackAvatar; const secondaryDisplayName = ReportUtils.getDisplayNameForParticipant(secondaryAccountId); diff --git a/src/pages/home/report/ReportActionsListItemRenderer.tsx b/src/pages/home/report/ReportActionsListItemRenderer.tsx index c095f3fa0cb0..e433ff00e1a1 100644 --- a/src/pages/home/report/ReportActionsListItemRenderer.tsx +++ b/src/pages/home/report/ReportActionsListItemRenderer.tsx @@ -108,6 +108,7 @@ function ReportActionsListItemRenderer({ childReportName: reportAction.childReportName, childManagerAccountID: reportAction.childManagerAccountID, childMoneyRequestCount: reportAction.childMoneyRequestCount, + childOwnerAccountID: reportAction.childOwnerAccountID, } as ReportAction), [ reportAction.reportActionID, @@ -137,6 +138,7 @@ function ReportActionsListItemRenderer({ reportAction.childReportName, reportAction.childManagerAccountID, reportAction.childMoneyRequestCount, + reportAction.childOwnerAccountID, ], ); diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index 8c8386b239a5..4762690db3c1 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -199,6 +199,9 @@ type ReportActionBase = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** In task reports this is account ID of the user assigned to the task */ childManagerAccountID?: number; + /** The owner account ID of the child report action */ + childOwnerAccountID?: number; + /** The status of the child report */ childStatusNum?: ValueOf;