The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { styled } from '@linaria/react';
import { Avatar, type AvatarSize } from 'twenty-ui/primitives/data-display';
import { themeCssVariables } from 'twenty-ui/theme';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
type WelcomePersonChipSizeVariant = 'default' | 'compact';
const StyledChip = styled.div<{ sizeVariant: WelcomePersonChipSizeVariant }>`
align-items: center;
display: inline-flex;
gap: ${({ sizeVariant }) =>
sizeVariant === 'compact'
? themeCssVariables.spacing[1]
: themeCssVariables.spacing[2]};
padding: ${({ sizeVariant }) =>
sizeVariant === 'compact'
? `${themeCssVariables.spacing['0.5']} ${themeCssVariables.spacing[1]}`
: `${themeCssVariables.spacing[1]} ${themeCssVariables.spacing[2]}`};
`;
const StyledPersonName = styled.span`
color: ${themeCssVariables.font.color.primary};
max-width: min(calc(40vw / var(--t-zoom, 1)), 360px);
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
@media (max-width: 600px) {
max-width: min(calc(70vw / var(--t-zoom, 1)), 360px);
}
`;
type WelcomePersonChipProps = {
avatarSize?: AvatarSize;
sizeVariant?: WelcomePersonChipSizeVariant;
};
export const WelcomePersonChip = ({
avatarSize = 'lg',
sizeVariant = 'default',
}: WelcomePersonChipProps) => {
const currentWorkspaceMember = useAtomStateValue(currentWorkspaceMemberState);
const firstName = currentWorkspaceMember?.name?.firstName ?? '';
const lastName = currentWorkspaceMember?.name?.lastName ?? '';
const fullName = `${firstName} ${lastName}`.trim();
return (
<StyledChip sizeVariant={sizeVariant}>
<Avatar
shape="circle"
size={avatarSize}
name={fullName}
colorSeed={currentWorkspaceMember?.id}
src={getAbsoluteImageUrl(currentWorkspaceMember?.avatarUrl)}
/>
<StyledPersonName>{fullName}</StyledPersonName>
</StyledChip>
);
};