Skip to content

Commit

Permalink
Merge pull request #42453 from nkdengineer/fix/38702
Browse files Browse the repository at this point in the history
  • Loading branch information
youssef-lr authored Jun 26, 2024
2 parents 9862fdb + a2a7393 commit 57e5d0e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,16 @@ function ReportPreview({
const {isSmallScreenWidth} = useWindowDimensions();
const [paymentType, setPaymentType] = useState<PaymentMethodType>();

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;
Expand Down Expand Up @@ -372,7 +373,7 @@ function ReportPreview({
<View style={styles.flexRow}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={styles.textHeadlineH1}>{getDisplayAmount()}</Text>
{ReportUtils.isSettled(iouReportID) && (
{iouSettled && (
<View style={styles.defaultCheckmarkWrapper}>
<Icon
src={Expensicons.Checkmark}
Expand Down
7 changes: 5 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,11 @@ function isReportManager(report: OnyxEntry<Report>): boolean {
/**
* Checks if the supplied report has been approved
*/
function isReportApproved(reportOrID: OnyxInputOrEntry<Report> | string | EmptyObject): boolean {
function isReportApproved(reportOrID: OnyxInputOrEntry<Report> | string | EmptyObject, parentReportAction: OnyxEntry<ReportAction> = 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;
}

Expand Down Expand Up @@ -6905,7 +6908,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo
function getReportActionActorAccountID(reportAction: OnyxInputOrEntry<ReportAction>, iouReport: OnyxInputOrEntry<Report> | 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;
Expand Down
7 changes: 4 additions & 3 deletions src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function ReportActionsListItemRenderer({
childReportName: reportAction.childReportName,
childManagerAccountID: reportAction.childManagerAccountID,
childMoneyRequestCount: reportAction.childMoneyRequestCount,
childOwnerAccountID: reportAction.childOwnerAccountID,
} as ReportAction),
[
reportAction.reportActionID,
Expand Down Expand Up @@ -137,6 +138,7 @@ function ReportActionsListItemRenderer({
reportAction.childReportName,
reportAction.childManagerAccountID,
reportAction.childMoneyRequestCount,
reportAction.childOwnerAccountID,
],
);

Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/ReportAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof CONST.REPORT.STATUS_NUM>;

Expand Down

0 comments on commit 57e5d0e

Please sign in to comment.