"use client"; import { createApiClient } from "@app/api"; import { Avatar, AvatarFallback } from "@app/components/ui/avatar"; import { Button } from "@app/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from "@app/components/ui/command"; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "@app/components/ui/dropdown-menu"; import { Popover, PopoverContent, PopoverTrigger } from "@app/components/ui/popover"; import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@app/components/ui/select"; import { useEnvContext } from "@app/hooks/useEnvContext"; import { useToast } from "@app/hooks/useToast"; import { cn, formatAxiosError } from "@app/lib/utils"; import { ListOrgsResponse } from "@server/routers/org"; import { Check, ChevronsUpDown, Laptop, LogOut, Moon, Plus, Sun, User } from "lucide-react"; import { useTheme } from "next-themes"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; type HeaderProps = { name?: string; email: string; orgId: string; orgs: ListOrgsResponse["orgs"]; }; export default function Header({ email, orgId, name, orgs }: HeaderProps) { const { toast } = useToast(); const { setTheme, theme } = useTheme(); const [open, setOpen] = useState(false); const [userTheme, setUserTheme] = useState<"light" | "dark" | "system">( theme as "light" | "dark" | "system" ); const router = useRouter(); const api = createApiClient(useEnvContext()); function getInitials() { if (name) { const [firstName, lastName] = name.split(" "); return `${firstName[0]}${lastName[0]}`; } return email.substring(0, 2).toUpperCase(); } function logout() { api.post("/auth/logout") .catch((e) => { console.error("Error logging out", e); toast({ title: "Error logging out", description: formatAxiosError(e, "Error logging out") }); }) .then(() => { router.push("/auth/login"); }); } function handleThemeChange(theme: "light" | "dark" | "system") { setUserTheme(theme); setTheme(theme); } return ( <>
Signed in as
{email}