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: Copilot not correctly displayed in report action #54348

Merged
merged 7 commits into from
Jan 6, 2025
Merged
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
30 changes: 17 additions & 13 deletions src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ const showUserDetails = (accountID: string) => {
Navigation.navigate(ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute()));
};

const showWorkspaceDetails = (reportID: string) => {
const showWorkspaceDetails = (reportID: string | undefined) => {
if (!reportID) {
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID, Navigation.getReportRHPActiveRoute()));
};

Expand All @@ -84,14 +87,16 @@ function ReportActionItemSingle({
const {translate} = useLocalize();
const personalDetails = usePersonalDetails();
const policy = usePolicy(report?.policyID);
const delegatePersonalDetails = personalDetails?.[action?.delegateAccountID ?? ''];
const delegatePersonalDetails = action?.delegateAccountID ? personalDetails?.[action?.delegateAccountID] : undefined;
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}`);
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`,
);

let displayName = ReportUtils.getDisplayNameForParticipant(actorAccountID);
const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails?.[actorAccountID ?? -1] ?? {};
const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails?.[actorAccountID ?? CONST.DEFAULT_NUMBER_ID] ?? {};
const accountOwnerDetails = getPersonalDetailByEmail(login ?? '');
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
let actorHint = (login || (displayName ?? '')).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
Expand All @@ -102,13 +107,12 @@ function ReportActionItemSingle({

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

if (isWorkspaceActor) {
displayName = ReportUtils.getPolicyName(report, undefined, policy);
actorHint = displayName;
avatarSource = ReportUtils.getWorkspaceIcon(report, policy).source;
avatarId = report?.policyID;
} else if (action?.delegateAccountID && personalDetails?.[action?.delegateAccountID]) {
} else if (delegatePersonalDetails) {
displayName = delegatePersonalDetails?.displayName ?? '';
avatarSource = delegatePersonalDetails?.avatar;
avatarId = delegatePersonalDetails?.accountID;
Expand Down Expand Up @@ -149,7 +153,7 @@ function ReportActionItemSingle({

secondaryAvatar = reportIcons.at(avatarIconIndex) ?? {name: '', source: '', type: CONST.ICON_TYPE_AVATAR};
} else if (ReportUtils.isInvoiceReport(iouReport)) {
const secondaryAccountId = iouReport?.managerID ?? -1;
const secondaryAccountId = iouReport?.managerID ?? CONST.DEFAULT_NUMBER_ID;
const secondaryUserAvatar = personalDetails?.[secondaryAccountId ?? -1]?.avatar ?? FallbackAvatar;
const secondaryDisplayName = ReportUtils.getDisplayNameForParticipant(secondaryAccountId);

Expand Down Expand Up @@ -186,7 +190,7 @@ function ReportActionItemSingle({

const showActorDetails = useCallback(() => {
if (isWorkspaceActor) {
showWorkspaceDetails(reportID ?? '');
showWorkspaceDetails(reportID);
} else {
// Show participants page IOU report preview
if (iouReportID && displayAllActors) {
Expand All @@ -199,8 +203,8 @@ function ReportActionItemSingle({

const shouldDisableDetailPage = useMemo(
() =>
CONST.RESTRICTED_ACCOUNT_IDS.includes(actorAccountID ?? -1) ||
(!isWorkspaceActor && ReportUtils.isOptimisticPersonalDetail(action?.delegateAccountID ? Number(action.delegateAccountID) : actorAccountID ?? -1)),
CONST.RESTRICTED_ACCOUNT_IDS.includes(actorAccountID ?? CONST.DEFAULT_NUMBER_ID) ||
(!isWorkspaceActor && ReportUtils.isOptimisticPersonalDetail(action?.delegateAccountID ? Number(action.delegateAccountID) : actorAccountID ?? CONST.DEFAULT_NUMBER_ID)),
[action, isWorkspaceActor, actorAccountID],
);

Expand All @@ -226,8 +230,8 @@ function ReportActionItemSingle({
}
return (
<UserDetailsTooltip
accountID={Number(icon.id ?? -1)}
delegateAccountID={Number(action?.delegateAccountID ?? -1)}
accountID={Number(delegatePersonalDetails && !isWorkspaceActor ? actorAccountID : icon.id ?? CONST.DEFAULT_NUMBER_ID)}
delegateAccountID={action?.delegateAccountID}
icon={icon}
>
<View>
Expand Down Expand Up @@ -277,7 +281,7 @@ function ReportActionItemSingle({
<ReportActionItemFragment
// eslint-disable-next-line react/no-array-index-key
key={`person-${action?.reportActionID}-${index}`}
accountID={Number(icon.id) ?? -1}
accountID={Number(delegatePersonalDetails && !isWorkspaceActor ? actorAccountID : icon.id ?? CONST.DEFAULT_NUMBER_ID)}
fragment={{...fragment, type: fragment.type ?? '', text: fragment.text ?? ''}}
delegateAccountID={action?.delegateAccountID}
isSingleLine
Expand Down
Loading