Files
twenty/packages/twenty-front/src/modules/activities/emails/utils/getDisplayNameFromParticipant.ts
T
Lucas Bordeau 581dfafe11 Renamed nullable utils into isDefined and isUndefinedOrNull (#4402)
* Renamed nullable utils into isDefined and isUndefinedOrNull
2024-03-11 14:28:57 +01:00

39 lines
996 B
TypeScript

import { isNonEmptyString } from '@sniptt/guards';
import { EmailThreadMessageParticipant } from '@/activities/emails/types/EmailThreadMessageParticipant';
import { isDefined } from '~/utils/isDefined';
export const getDisplayNameFromParticipant = ({
participant,
shouldUseFullName = false,
}: {
participant: EmailThreadMessageParticipant;
shouldUseFullName?: boolean;
}) => {
if (isDefined(participant.person)) {
return (
`${participant.person?.name?.firstName}` +
(shouldUseFullName ? ` ${participant.person?.name?.lastName}` : '')
);
}
if (isDefined(participant.workspaceMember)) {
return (
participant.workspaceMember?.name?.firstName +
(shouldUseFullName
? ` ${participant.workspaceMember?.name?.lastName}`
: '')
);
}
if (isNonEmptyString(participant.displayName)) {
return participant.displayName;
}
if (isNonEmptyString(participant.handle)) {
return participant.handle;
}
return 'Unknown';
};