Skip to content

Commit 3404e9c

Browse files
committed
feat: add UserIdentifier component
1 parent 794725a commit 3404e9c

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './types'
2+
export * from './UserIdentifier'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ReactNode } from 'react'
2+
3+
export interface UserIdentifierProps {
4+
email: string
5+
children?: ReactNode
6+
isUserGroup?: boolean
7+
rootClassName?: string
8+
/**
9+
* @description - If given, would show tooltip on div containing avatar, email and children
10+
*/
11+
tooltipContent?: string
12+
}

src/Shared/Components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@ export * from './ThemeSwitcher'
9494
export * from './ToggleResolveScopedVariables'
9595
export * from './UnsavedChanges'
9696
export * from './UnsavedChangesDialog'
97+
export * from './UserIdentifier'
9798
export * from './VirtualizedList'
9899
export * from './WorkflowOptionsModal'

0 commit comments

Comments
 (0)