fix: fallback to email when user name is missing in activity list
This commit is contained in:
@@ -36,12 +36,21 @@ const truncate = (value: string | null, maxLength = 50) => {
|
|||||||
return value.length > maxLength ? `${value.slice(0, maxLength - 1)}…` : value;
|
return value.length > maxLength ? `${value.slice(0, maxLength - 1)}…` : value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getUserDisplayName = (
|
||||||
|
user: { name?: string | null; email?: string | null } | null | undefined,
|
||||||
|
): string => {
|
||||||
|
if (user?.name?.trim()) return user.name;
|
||||||
|
if (user?.email) return user.email;
|
||||||
|
return t`Member`;
|
||||||
|
};
|
||||||
|
|
||||||
const getActivityText = ({
|
const getActivityText = ({
|
||||||
type,
|
type,
|
||||||
toTitle,
|
toTitle,
|
||||||
fromList,
|
fromList,
|
||||||
toList,
|
toList,
|
||||||
memberName,
|
memberName,
|
||||||
|
memberEmail,
|
||||||
isSelf,
|
isSelf,
|
||||||
label,
|
label,
|
||||||
fromTitle,
|
fromTitle,
|
||||||
@@ -54,6 +63,7 @@ const getActivityText = ({
|
|||||||
fromList: string | null;
|
fromList: string | null;
|
||||||
toList: string | null;
|
toList: string | null;
|
||||||
memberName: string | null;
|
memberName: string | null;
|
||||||
|
memberEmail: string | null;
|
||||||
isSelf: boolean;
|
isSelf: boolean;
|
||||||
label: string | null;
|
label: string | null;
|
||||||
fromTitle?: string | null;
|
fromTitle?: string | null;
|
||||||
@@ -62,6 +72,7 @@ const getActivityText = ({
|
|||||||
dateLocale: DateFnsLocale;
|
dateLocale: DateFnsLocale;
|
||||||
mergedLabels?: string[];
|
mergedLabels?: string[];
|
||||||
}) => {
|
}) => {
|
||||||
|
const displayName = memberName ?? memberEmail ?? t`Member`;
|
||||||
const TextHighlight = ({ children }: { children: React.ReactNode }) => (
|
const TextHighlight = ({ children }: { children: React.ReactNode }) => (
|
||||||
<span className="font-medium text-light-1000 dark:text-dark-1000">
|
<span className="font-medium text-light-1000 dark:text-dark-1000">
|
||||||
{children}
|
{children}
|
||||||
@@ -139,23 +150,23 @@ const getActivityText = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "card.updated.member.added" && memberName) {
|
if (type === "card.updated.member.added" && displayName) {
|
||||||
if (isSelf) return <Trans>self-assigned the card</Trans>;
|
if (isSelf) return <Trans>self-assigned the card</Trans>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Trans>
|
<Trans>
|
||||||
assigned <TextHighlight>{truncate(memberName)}</TextHighlight> to the
|
assigned <TextHighlight>{truncate(displayName)}</TextHighlight> to the
|
||||||
card
|
card
|
||||||
</Trans>
|
</Trans>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "card.updated.member.removed" && memberName) {
|
if (type === "card.updated.member.removed" && displayName) {
|
||||||
if (isSelf) return <Trans>unassigned themselves from the card</Trans>;
|
if (isSelf) return <Trans>unassigned themselves from the card</Trans>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Trans>
|
<Trans>
|
||||||
unassigned <TextHighlight>{truncate(memberName)}</TextHighlight> from
|
unassigned <TextHighlight>{truncate(displayName)}</TextHighlight> from
|
||||||
the card
|
the card
|
||||||
</Trans>
|
</Trans>
|
||||||
);
|
);
|
||||||
@@ -455,6 +466,7 @@ const ActivityList = ({
|
|||||||
fromList: activity.fromList?.name ?? null,
|
fromList: activity.fromList?.name ?? null,
|
||||||
toList: activity.toList?.name ?? null,
|
toList: activity.toList?.name ?? null,
|
||||||
memberName: activity.member?.user?.name ?? null,
|
memberName: activity.member?.user?.name ?? null,
|
||||||
|
memberEmail: activity.member?.user?.email ?? null,
|
||||||
isSelf: activity.member?.user?.id === sessionData?.user.id,
|
isSelf: activity.member?.user?.id === sessionData?.user.id,
|
||||||
label: activity.label?.name ?? null,
|
label: activity.label?.name ?? null,
|
||||||
fromTitle: activity.fromTitle ?? null,
|
fromTitle: activity.fromTitle ?? null,
|
||||||
@@ -508,7 +520,7 @@ const ActivityList = ({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm">
|
<p className="text-sm">
|
||||||
<span className="font-medium dark:text-dark-1000">{`${activity.user?.name} `}</span>
|
<span className="font-medium dark:text-dark-1000">{`${getUserDisplayName(activity.user)} `}</span>
|
||||||
<span className="space-x-1 text-light-900 dark:text-dark-800">
|
<span className="space-x-1 text-light-900 dark:text-dark-800">
|
||||||
{activityText}
|
{activityText}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user