forked from LAION-AI/Open-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserDisplayNameCell.tsx
48 lines (44 loc) · 1.39 KB
/
UserDisplayNameCell.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Flex, Link, Tooltip } from "@chakra-ui/react";
import { Discord, Google } from "@icons-pack/react-simple-icons";
import { Bot, Mail } from "lucide-react";
import NextLink from "next/link";
import { useHasAnyRole } from "src/hooks/auth/useHasAnyRole";
import { ROUTES } from "src/lib/routes";
import type { AuthMethod } from "src/types/Providers";
import { UserAvatar } from "./UserAvatar";
const AUTH_METHOD_TO_ICON: Record<AuthMethod, JSX.Element> = {
local: <Mail size="20" />,
discord: <Discord size="20" />,
google: <Google size="20" />,
system: <Bot size="20" />,
};
export const UserDisplayNameCell = ({
displayName,
avatarUrl,
userId,
authMethod,
}: {
displayName: string;
avatarUrl?: string;
userId: string;
authMethod: string;
}) => {
const isAdminOrMod = useHasAnyRole(["admin", "moderator"]);
return (
<Flex gap="2" alignItems="center">
<UserAvatar displayName={displayName} avatarUrl={avatarUrl} />
{isAdminOrMod ? (
<>
<Link as={NextLink} href={ROUTES.ADMIN_USER_DETAIL(userId)} style={{ overflow: "hidden" }}>
{displayName}
</Link>
{AUTH_METHOD_TO_ICON[authMethod] && (
<Tooltip label={`Signed in with ${authMethod}`}>{AUTH_METHOD_TO_ICON[authMethod]}</Tooltip>
)}
</>
) : (
<div style={{ overflow: "hidden" }}>{displayName}</div>
)}
</Flex>
);
};