|
| 1 | +import { getAlphabetIcon } from '@Common/Helper' |
| 2 | +import { Tooltip } from '@Common/Tooltip' |
| 3 | +import { API_TOKEN_PREFIX } from '@Shared/constants' |
| 4 | +import { useUserEmail } from '@Shared/Providers' |
| 5 | + |
| 6 | +import { Icon } from '../Icon' |
| 7 | +import { UserIdentifierProps } from './types' |
| 8 | + |
| 9 | +const UserIdentifierTooltip = ({ |
| 10 | + children, |
| 11 | + tooltipContent, |
| 12 | +}: Pick<UserIdentifierProps, 'children' | 'tooltipContent'>) => ( |
| 13 | + <Tooltip alwaysShowTippyOnHover={!!tooltipContent} content={tooltipContent}> |
| 14 | + <div className="flexbox dc__gap-8 dc__align-items-center">{children}</div> |
| 15 | + </Tooltip> |
| 16 | +) |
| 17 | + |
| 18 | +export const UserIdentifier = ({ |
| 19 | + email, |
| 20 | + children, |
| 21 | + rootClassName, |
| 22 | + tooltipContent, |
| 23 | + isUserGroup = false, |
| 24 | +}: UserIdentifierProps) => { |
| 25 | + // HOOKS |
| 26 | + const { email: currentUserEmail } = useUserEmail() |
| 27 | + |
| 28 | + // CONSTANTS |
| 29 | + const isCurrentUser = email === currentUserEmail |
| 30 | + |
| 31 | + return ( |
| 32 | + <div className={`flexbox dc__gap-8 ${rootClassName || ''}`}> |
| 33 | + {email.startsWith(API_TOKEN_PREFIX) ? ( |
| 34 | + <UserIdentifierTooltip tooltipContent={tooltipContent}> |
| 35 | + <Icon name="ic-key" color="N700" size={20} /> |
| 36 | + <div className="flexbox dc__gap-2"> |
| 37 | + <Tooltip |
| 38 | + {...(tooltipContent |
| 39 | + ? { content: email, alwaysShowTippyOnHover: false } |
| 40 | + : { content: email })} |
| 41 | + > |
| 42 | + <span className="cn-9 fs-13 fw-4 lh-20 dc__truncate"> |
| 43 | + {isCurrentUser ? 'You' : email.split(':')?.[1] || '-'} |
| 44 | + </span> |
| 45 | + </Tooltip> |
| 46 | + {children} |
| 47 | + </div> |
| 48 | + </UserIdentifierTooltip> |
| 49 | + ) : ( |
| 50 | + <UserIdentifierTooltip tooltipContent={tooltipContent}> |
| 51 | + {isUserGroup ? ( |
| 52 | + <span className="flex p-1"> |
| 53 | + <Icon name="ic-users" color="N700" size={18} /> |
| 54 | + </span> |
| 55 | + ) : ( |
| 56 | + getAlphabetIcon(email, 'dc__no-shrink m-0-imp') |
| 57 | + )} |
| 58 | + <div className="flexbox dc__gap-2"> |
| 59 | + <Tooltip |
| 60 | + {...(tooltipContent |
| 61 | + ? { content: email, alwaysShowTippyOnHover: false } |
| 62 | + : { content: email })} |
| 63 | + > |
| 64 | + <span className="cn-9 fs-13 fw-4 lh-20 dc__truncate">{isCurrentUser ? 'You' : email}</span> |
| 65 | + </Tooltip> |
| 66 | + {children} |
| 67 | + </div> |
| 68 | + </UserIdentifierTooltip> |
| 69 | + )} |
| 70 | + </div> |
| 71 | + ) |
| 72 | +} |
0 commit comments