"use client"; import { DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuContent, DropdownMenuTrigger, DropdownMenu, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuPortal, DropdownMenuSubContent, DropdownMenuCheckboxItem, } from "ui/dropdown-menu"; import { AvatarFallback, AvatarImage, Avatar } from "ui/avatar"; import { SidebarMenuButton, SidebarMenuItem, SidebarMenu } from "ui/sidebar"; import { ChevronsUpDown, Command, LogOutIcon, Settings2, Palette, Languages, Sun, MoonStar, ChevronRight, Settings, } from "lucide-react"; import { useTheme } from "next-themes"; import { appStore } from "@/app/store"; import { BASE_THEMES, COOKIE_KEY_LOCALE, SUPPORTED_LOCALES } from "lib/const"; import { capitalizeFirstLetter, cn, fetcher } from "lib/utils"; import { authClient } from "auth/client"; import { useTranslations } from "next-intl"; import useSWR from "swr"; import { getLocaleAction } from "@/i18n/get-locale"; import { Suspense, useCallback } from "react"; import { GithubIcon } from "ui/github-icon"; import { DiscordIcon } from "ui/discord-icon"; import { useThemeStyle } from "@/hooks/use-theme-style"; import { BasicUser } from "app-types/user"; import { getUserAvatar } from "lib/user/utils"; import { Skeleton } from "ui/skeleton"; export function AppSidebarUserInner(props: { user?: BasicUser; }) { const { data: user } = useSWR(`/api/user/details`, fetcher, { fallbackData: props.user, suspense: true, revalidateOnMount: false, revalidateOnFocus: false, shouldRetryOnError: false, refreshInterval: 1000 * 60 * 10, }); const appStoreMutate = appStore((state) => state.mutate); const t = useTranslations("Layout"); const logout = () => { authClient.signOut().finally(() => { window.location.href = "/sign-in"; }); }; if (!user) return null; return ( {user?.name?.slice(0, 1) || ""} {user?.email}
{user?.name?.slice(0, 1) || ""}
{user?.name} {user?.email}
appStoreMutate({ openChatPreferences: true })} > {t("chatPreferences")} appStoreMutate({ openShortcutsPopup: true })} > {t("keyboardShortcuts")} { window.open( "https://github.com/cgoinglove/better-chatbot/issues/new", "_blank", ); }} > {t("reportAnIssue")} { window.open("https://discord.gg/gCRu69Upnp", "_blank"); }} > {t("joinCommunity")} appStoreMutate({ openUserSettings: true })} className="cursor-pointer" data-testid="user-settings-menu-item" > {t("userSettings")} {t("signOut")}
); } function SelectTheme() { const t = useTranslations("Layout"); const { theme = "light", setTheme } = useTheme(); const { themeStyle = "default", setThemeStyle } = useThemeStyle(); return ( {`${capitalizeFirstLetter(theme)} ${capitalizeFirstLetter( themeStyle, )}`} } > {t("theme")} {capitalizeFirstLetter(theme)}
setTheme(theme === "light" ? "dark" : "light")} className="cursor-pointer border rounded-full flex items-center" >
{BASE_THEMES.map((t) => ( { e.preventDefault(); setThemeStyle(t); }} className="text-sm" > {capitalizeFirstLetter(t)} ))}
); } function SelectLanguage() { const t = useTranslations("Layout"); const { data: currentLocale } = useSWR(COOKIE_KEY_LOCALE, getLocaleAction, { fallbackData: SUPPORTED_LOCALES[0].code, revalidateOnFocus: false, }); const handleOnChange = useCallback((locale: string) => { document.cookie = `${COOKIE_KEY_LOCALE}=${locale}; path=/;`; window.location.reload(); }, []); return ( {t("language")} {t("language")} {SUPPORTED_LOCALES.map((locale) => ( locale.code !== currentLocale && handleOnChange(locale.code) } > {locale.name} ))} ); } export function AppSidebarUserSkeleton() { return ( ); } export function AppSidebarUser({ user, }: { user?: BasicUser; }) { return ( }> ); }