Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: missing avatars and names above IOU preview in main chat after login #42453

Merged
merged 12 commits into from
Jun 26, 2024
7 changes: 4 additions & 3 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ 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);
Expand Down Expand Up @@ -369,7 +370,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 @@ -772,8 +772,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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to specifically set the parentReportAction default value as undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eVoloshchak Some other places we can use this function without parentReportAction param.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used in this PR?

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 @@ -6837,7 +6840,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 @@ -84,9 +84,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 @@ -110,8 +111,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 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 = 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 @@ -207,6 +207,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
Loading