Skip to content

Commit

Permalink
Merge pull request Expensify#51180 from Expensify/georgia-fixTooltip
Browse files Browse the repository at this point in the history
fix owner tooltip for expense reports
  • Loading branch information
Beamanator authored Oct 30, 2024
2 parents 6cd5c64 + 69ad164 commit dad3f63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
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 @@ -8039,10 +8039,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 @@ -8051,7 +8058,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)}
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

0 comments on commit dad3f63

Please sign in to comment.