/
githubmirror
/
Open-Assistant
Обзор
Документация
Войти
/
githubmirror
/
Open-Assistant
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
website/src/components/UserDisplayNameCell.tsx
48 строк
1 KB
notmd
Only render auth method icon when it is available (#3258)
30 май 2023, 02:13
Не верифицирован
30 май 2023, 02:13
36e28e0
Код
Авторство
О чём код?
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> ); };