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 owner tooltip for expense reports #51180

Merged
merged 8 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,7 @@ function getIcons(
if (isChatThread(report)) {
const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];

const actorAccountID = getReportActionActorAccountID(parentReportAction, report);
const actorAccountID = getReportActionActorAccountID(parentReportAction, report, report);
const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[actorAccountID ?? -1], '', false);
const actorIcon = {
id: actorAccountID,
Expand Down Expand Up @@ -8034,10 +8034,17 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo
return (isChatThread(report) && !!getReportNotificationPreference(report)) || isUserCreatedPolicyRoom(report) || isNonAdminOrOwnerOfPolicyExpenseChat(report, policy);
}

function getReportActionActorAccountID(reportAction: OnyxInputOrEntry<ReportAction>, iouReport: OnyxInputOrEntry<Report> | undefined): number | undefined {
function getReportActionActorAccountID(
reportAction: OnyxInputOrEntry<ReportAction>,
iouReport: OnyxInputOrEntry<Report> | undefined,
report: OnyxInputOrEntry<Report> | undefined,
): number | undefined {
switch (reportAction?.actionName) {
case CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW:
return !isEmptyObject(iouReport) ? iouReport.managerID : reportAction?.childManagerAccountID;
case CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW: {
const ownerAccountID = iouReport?.ownerAccountID ?? reportAction?.childOwnerAccountID;
const actorAccountID = iouReport?.managerID ?? reportAction?.childManagerAccountID;
return isPolicyExpenseChat(report) ? ownerAccountID : actorAccountID;
}

case CONST.REPORT.ACTIONS.TYPE.SUBMITTED:
return reportAction?.adminAccountID ?? reportAction?.actorAccountID;
Expand All @@ -8046,7 +8053,6 @@ function getReportActionActorAccountID(reportAction: OnyxInputOrEntry<ReportActi
return reportAction?.actorAccountID;
}
}

function createDraftWorkspaceAndNavigateToConfirmationScreen(transactionID: string, actionName: IOUAction): void {
const isCategorizing = actionName === CONST.IOU.ACTION.CATEGORIZE;
const {expenseChatReportID, policyID, policyName} = PolicyActions.createDraftWorkspace();
Expand Down
17 changes: 6 additions & 11 deletions src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ function ReportActionItemSingle({
const personalDetails = usePersonalDetails() ?? CONST.EMPTY_OBJECT;
const policy = usePolicy(report?.policyID);
const delegatePersonalDetails = personalDetails[action?.delegateAccountID ?? ''];
const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport);
const ownerAccountID = iouReport?.ownerAccountID ?? action?.childOwnerAccountID;
const isReportPreviewAction = action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW;
const actorAccountID = ReportUtils.getReportActionActorAccountID(action, iouReport, report);
const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`);

let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID);
Expand All @@ -94,20 +96,13 @@ function ReportActionItemSingle({
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
let actorHint = (login || (displayName ?? '')).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
const isTripRoom = ReportUtils.isTripRoom(report);
const isReportPreviewAction = action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW;
const displayAllActors = isReportPreviewAction && !isTripRoom && !ReportUtils.isPolicyExpenseChat(report);
const isInvoiceReport = ReportUtils.isInvoiceReport(iouReport ?? null);
const isWorkspaceActor = isInvoiceReport || (ReportUtils.isPolicyExpenseChat(report) && (!actorAccountID || displayAllActors));
const ownerAccountID = iouReport?.ownerAccountID ?? action?.childOwnerAccountID;

let avatarSource = avatar;
let avatarId: number | string | undefined = actorAccountID;

if (isReportPreviewAction && ReportUtils.isPolicyExpenseChat(report)) {
avatarId = ownerAccountID;
avatarSource = personalDetails[ownerAccountID ?? -1]?.avatar;
displayName = ReportUtils.getDisplayNameForParticipant(ownerAccountID);
actorHint = displayName;
}
if (isWorkspaceActor) {
displayName = ReportUtils.getPolicyName(report, undefined, policy);
actorHint = displayName;
Expand Down Expand Up @@ -220,7 +215,7 @@ function ReportActionItemSingle({
}
return (
<UserDetailsTooltip
accountID={Number(actorAccountID ?? -1)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Using icon to keep a single source of truth in UserDetailsTooltip makes sense to me but I think we should still fix the actorAccountID value. The status is still broken (showing the status of the approver for both accounts)

Screenshot 2024-10-21 at 9 04 58 PM

accountID={Number(icon.id ?? -1)}
delegateAccountID={Number(action?.delegateAccountID ?? -1)}
icon={icon}
>
Expand Down Expand Up @@ -271,7 +266,7 @@ function ReportActionItemSingle({
<ReportActionItemFragment
// eslint-disable-next-line react/no-array-index-key
key={`person-${action?.reportActionID}-${index}`}
accountID={actorAccountID ?? -1}
accountID={Number(icon.id) ?? -1}
fragment={{...fragment, type: fragment.type ?? '', text: fragment.text ?? ''}}
delegateAccountID={action?.delegateAccountID}
isSingleLine
Expand Down
Loading