"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, } 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 } from "lucide-react"; 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 [open, setOpen] = useState(false); 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"); }); } return ( <>
{name}
)}{email}