# Introduction Avoid having multiple `isDefined` definition across our pacakges Also avoid importing `isDefined` from `twenty-ui` which exposes a huge barrel for a such little util function ## In a nutshell Removed own `isDefined.ts` definition from `twenty-ui` `twenty-front` and `twenty-server` to move it to `twenty-shared`. Updated imports for each packages, and added explicit dependencies to `twenty-shared` if not already in place Related PR https://github.com/twentyhq/twenty/pull/9941
39 lines
992 B
TypeScript
39 lines
992 B
TypeScript
import { isNonEmptyString } from '@sniptt/guards';
|
|
|
|
import { EmailThreadMessageParticipant } from '@/activities/emails/types/EmailThreadMessageParticipant';
|
|
import { isDefined } from 'twenty-shared';
|
|
|
|
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';
|
|
};
|