Skip to content

Commit 57e5d0e

Browse files
authored
Merge pull request #42453 from nkdengineer/fix/38702
2 parents 9862fdb + a2a7393 commit 57e5d0e

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

src/components/ReportActionItem/ReportPreview.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,16 @@ function ReportPreview({
131131
const {isSmallScreenWidth} = useWindowDimensions();
132132
const [paymentType, setPaymentType] = useState<PaymentMethodType>();
133133

134-
const managerID = iouReport?.managerID ?? 0;
134+
const managerID = iouReport?.managerID ?? action.childManagerAccountID ?? 0;
135135
const {totalDisplaySpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport);
136136

137-
const iouSettled = ReportUtils.isSettled(iouReportID);
137+
const iouSettled = ReportUtils.isSettled(iouReportID) || action?.childStatusNum === CONST.REPORT.STATUS_NUM.REIMBURSED;
138+
138139
const moneyRequestComment = action?.childLastMoneyRequestComment ?? '';
139140
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport);
140141
const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport);
141142

142-
const isApproved = ReportUtils.isReportApproved(iouReport);
143+
const isApproved = ReportUtils.isReportApproved(iouReport, action);
143144
const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport, policy);
144145
const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID);
145146
const numberOfRequests = allTransactions.length;
@@ -372,7 +373,7 @@ function ReportPreview({
372373
<View style={styles.flexRow}>
373374
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
374375
<Text style={styles.textHeadlineH1}>{getDisplayAmount()}</Text>
375-
{ReportUtils.isSettled(iouReportID) && (
376+
{iouSettled && (
376377
<View style={styles.defaultCheckmarkWrapper}>
377378
<Icon
378379
src={Expensicons.Checkmark}

src/libs/ReportUtils.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,11 @@ function isReportManager(report: OnyxEntry<Report>): boolean {
770770
/**
771771
* Checks if the supplied report has been approved
772772
*/
773-
function isReportApproved(reportOrID: OnyxInputOrEntry<Report> | string | EmptyObject): boolean {
773+
function isReportApproved(reportOrID: OnyxInputOrEntry<Report> | string | EmptyObject, parentReportAction: OnyxEntry<ReportAction> = undefined): boolean {
774774
const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID;
775+
if (!report) {
776+
return parentReportAction?.childStateNum === CONST.REPORT.STATE_NUM.APPROVED && parentReportAction?.childStatusNum === CONST.REPORT.STATUS_NUM.APPROVED;
777+
}
775778
return report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED && report?.statusNum === CONST.REPORT.STATUS_NUM.APPROVED;
776779
}
777780

@@ -6905,7 +6908,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo
69056908
function getReportActionActorAccountID(reportAction: OnyxInputOrEntry<ReportAction>, iouReport: OnyxInputOrEntry<Report> | undefined): number | undefined {
69066909
switch (reportAction?.actionName) {
69076910
case CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW:
6908-
return iouReport ? iouReport.managerID : reportAction?.actorAccountID;
6911+
return !isEmptyObject(iouReport) ? iouReport.managerID : reportAction?.childManagerAccountID;
69096912

69106913
case CONST.REPORT.ACTIONS.TYPE.SUBMITTED:
69116914
return reportAction?.adminAccountID ?? reportAction?.actorAccountID;

src/pages/home/report/ReportActionItemSingle.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ function ReportActionItemSingle({
8585
const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails[actorAccountID ?? -1] ?? {};
8686
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
8787
let actorHint = (login || (displayName ?? '')).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
88-
const displayAllActors = useMemo(() => action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && iouReport, [action?.actionName, iouReport]);
88+
const displayAllActors = useMemo(() => action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW, [action?.actionName]);
8989
const isInvoiceReport = ReportUtils.isInvoiceReport(iouReport ?? {});
9090
const isWorkspaceActor = isInvoiceReport || (ReportUtils.isPolicyExpenseChat(report) && (!actorAccountID || displayAllActors));
91+
const ownerAccountID = iouReport?.ownerAccountID ?? action?.childOwnerAccountID;
9192
let avatarSource = avatar;
9293
let avatarId: number | string | undefined = actorAccountID;
9394

@@ -111,8 +112,8 @@ function ReportActionItemSingle({
111112
let secondaryAvatar: Icon;
112113
const primaryDisplayName = displayName;
113114
if (displayAllActors) {
114-
// 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
115-
const secondaryAccountId = iouReport?.ownerAccountID === actorAccountID || isInvoiceReport ? iouReport?.managerID : iouReport?.ownerAccountID;
115+
// 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
116+
const secondaryAccountId = ownerAccountID === actorAccountID || isInvoiceReport ? actorAccountID : ownerAccountID;
116117
const secondaryUserAvatar = personalDetails?.[secondaryAccountId ?? -1]?.avatar ?? FallbackAvatar;
117118
const secondaryDisplayName = ReportUtils.getDisplayNameForParticipant(secondaryAccountId);
118119

src/pages/home/report/ReportActionsListItemRenderer.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function ReportActionsListItemRenderer({
108108
childReportName: reportAction.childReportName,
109109
childManagerAccountID: reportAction.childManagerAccountID,
110110
childMoneyRequestCount: reportAction.childMoneyRequestCount,
111+
childOwnerAccountID: reportAction.childOwnerAccountID,
111112
} as ReportAction),
112113
[
113114
reportAction.reportActionID,
@@ -137,6 +138,7 @@ function ReportActionsListItemRenderer({
137138
reportAction.childReportName,
138139
reportAction.childManagerAccountID,
139140
reportAction.childMoneyRequestCount,
141+
reportAction.childOwnerAccountID,
140142
],
141143
);
142144

src/types/onyx/ReportAction.ts

+3
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ type ReportActionBase = OnyxCommon.OnyxValueWithOfflineFeedback<{
199199
/** In task reports this is account ID of the user assigned to the task */
200200
childManagerAccountID?: number;
201201

202+
/** The owner account ID of the child report action */
203+
childOwnerAccountID?: number;
204+
202205
/** The status of the child report */
203206
childStatusNum?: ValueOf<typeof CONST.REPORT.STATUS_NUM>;
204207

0 commit comments

Comments
 (0)