From 79578049766b7bfc8e709f2c7608c5af49de977b Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 14 May 2024 12:21:28 +0700 Subject: [PATCH 1/6] Use report preview action to display data in ReportPreview --- src/components/ReportActionItem/ReportPreview.tsx | 7 ++++--- src/libs/ReportUtils.ts | 7 +++++-- src/pages/home/report/ReportActionItemSingle.tsx | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 9c5821329e1c6..c44f41f156244 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -117,10 +117,11 @@ function ReportPreview({ [transactions, iouReportID, action], ); - const managerID = iouReport?.managerID ?? 0; + const managerID = iouReport?.managerID ?? action.actorAccountID ?? 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 numberOfRequests = ReportActionUtils.getNumberOfMoneyRequests(action); const moneyRequestComment = action?.childLastMoneyRequestComment ?? ''; const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport); @@ -297,7 +298,7 @@ function ReportPreview({ {getDisplayAmount()} - {ReportUtils.isSettled(iouReportID) && ( + {iouSettled && ( ): boolean { /** * Checks if the supplied report has been approved */ -function isReportApproved(reportOrID: OnyxEntry | string | EmptyObject): boolean { +function isReportApproved(reportOrID: OnyxEntry | string | EmptyObject, parentReportAction: OnyxEntry = null): 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; } @@ -6556,7 +6559,7 @@ function canLeaveChat(report: OnyxEntry, policy: OnyxEntry): boo function getReportActionActorAccountID(reportAction: OnyxEntry, iouReport: OnyxEntry | 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?.actorAccountID; 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 234147a30bd50..6070bd7c0e6ec 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -84,9 +84,11 @@ 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 participantAccountIDs = ReportUtils.getVisibleChatMemberAccountIDs(report.reportID); + const ownerAccountID = iouReport?.ownerAccountID ?? (participantAccountIDs ?? []).find((accountID) => accountID !== actorAccountID); let avatarSource = UserUtils.getAvatar(avatar ?? '', actorAccountID); if (isWorkspaceActor) { @@ -108,7 +110,7 @@ function ReportActionItemSingle({ const primaryDisplayName = displayName; if (displayAllActors) { // The ownerAccountID and actorAccountID can be the same if the 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 = iouReport?.ownerAccountID === actorAccountID || isInvoiceReport ? iouReport?.managerID : iouReport?.ownerAccountID; + const secondaryAccountId = ownerAccountID === actorAccountID || isInvoiceReport ? actorAccountID : ownerAccountID; const secondaryUserAvatar = personalDetails?.[secondaryAccountId ?? -1]?.avatar ?? ''; const secondaryDisplayName = ReportUtils.getDisplayNameForParticipant(secondaryAccountId); From 0f7a6ed7f636d446a04474feded296573f701179 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 22 May 2024 12:18:40 +0700 Subject: [PATCH 2/6] fix: add fallback report action child owner account id --- src/components/ReportActionItem/ReportPreview.tsx | 2 +- src/libs/ReportUtils.ts | 2 +- src/pages/home/report/ReportActionItemSingle.tsx | 3 +-- src/types/onyx/ReportAction.ts | 1 + 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 787c9083ba10a..85194b34d069f 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -118,7 +118,7 @@ function ReportPreview({ [transactions, iouReportID, action], ); - const managerID = iouReport?.managerID ?? action.actorAccountID ?? 0; + const managerID = iouReport?.managerID ?? action.childManagerAccountID ?? 0; const {totalDisplaySpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport); const iouSettled = ReportUtils.isSettled(iouReportID) || action?.childStatusNum === CONST.REPORT.STATUS_NUM.REIMBURSED; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 951082ffd3f8b..21219471397f8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6576,7 +6576,7 @@ function canLeaveChat(report: OnyxEntry, policy: OnyxEntry): boo function getReportActionActorAccountID(reportAction: OnyxEntry, iouReport: OnyxEntry | undefined): number | undefined { switch (reportAction?.actionName) { case CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW: - return !isEmptyObject(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 3bba1da28ed67..cc0f68c8aef78 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -87,8 +87,7 @@ function ReportActionItemSingle({ 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 participantAccountIDs = ReportUtils.getVisibleChatMemberAccountIDs(report.reportID); - const ownerAccountID = iouReport?.ownerAccountID ?? (participantAccountIDs ?? []).find((accountID) => accountID !== actorAccountID); + const ownerAccountID = iouReport?.ownerAccountID ?? action?.childOwnerAccountID; let avatarSource = UserUtils.getAvatar(avatar ?? '', actorAccountID); if (isWorkspaceActor) { diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index d7333feb86505..d370cf51837ed 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -176,6 +176,7 @@ type ReportActionBase = OnyxCommon.OnyxValueWithOfflineFeedback<{ childVisibleActionCount?: number; parentReportID?: string; childManagerAccountID?: number; + childOwnerAccountID?: number; /** The status of the child report */ childStatusNum?: ValueOf; From 1dd2daf53d1874fb9ab4a255057d070c2c02345a Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 22 May 2024 12:33:22 +0700 Subject: [PATCH 3/6] fix lint --- 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 21219471397f8..5027847dfa384 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -790,7 +790,7 @@ function isReportManager(report: OnyxEntry): boolean { function isReportApproved(reportOrID: OnyxEntry | string | EmptyObject, parentReportAction: OnyxEntry = null): 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 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; } From 32f869d0678a3b5c25a90eb3a89bd4e4055722a0 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 12 Jun 2024 10:58:15 +0700 Subject: [PATCH 4/6] fix lint --- src/pages/home/report/ReportActionsListItemRenderer.tsx | 2 ++ src/types/onyx/ReportAction.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/pages/home/report/ReportActionsListItemRenderer.tsx b/src/pages/home/report/ReportActionsListItemRenderer.tsx index 18118e48f7cbb..a86520dd72444 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 bb100ed27af60..94533d7f524df 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -206,6 +206,8 @@ 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 */ From e311c1019dd62b130a47383515b47c54456e3791 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 19 Jun 2024 23:08:59 +0700 Subject: [PATCH 5/6] Update src/pages/home/report/ReportActionItemSingle.tsx Co-authored-by: Eugene Voloshchak --- src/pages/home/report/ReportActionItemSingle.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 0ee1472a6bb9d..6045f23a5ea09 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -111,7 +111,7 @@ function ReportActionItemSingle({ let secondaryAvatar: Icon; const primaryDisplayName = displayName; if (displayAllActors) { - // The ownerAccountID and actorAccountID can be the same if the 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 + // 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); From a2a739379748a4bdf72409ab7541376a66765ac1 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Sat, 22 Jun 2024 15:34:05 +0700 Subject: [PATCH 6/6] pass action to isReportApproved --- src/components/ReportActionItem/ReportPreview.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index f2ac6bb42252f..06083365bc96b 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -140,7 +140,7 @@ function ReportPreview({ 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;