"use client"; import { useState } from "react"; import { usePathname } from "next/navigation"; import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuAction, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, } from "@/components/ui/sidebar"; import { ScrollArea } from "@/components/ui/scroll-area"; import { ArrowLeft, ClipboardList, ChevronRight, Eye, FilePenLine, LayoutDashboard, Settings, } from "lucide-react"; import { ThemeToggle } from "@/components/theme-toggle"; import { DropdownMenuAvatar, type DiscordMemberProfile, } from "@/components/dropdown-menu-avatar"; import { GuardedLink } from "@/components/guarded-link"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/utils"; export function FormAdminSidebar({ formId, formTitle, isOpen, userName, userImage, profile, responseItems, }: { formId: string; formTitle: string; isOpen: boolean; userName?: string; userImage?: string; profile?: DiscordMemberProfile | null; responseItems?: { id: string; displayName: string; queueNumber: number; }[]; }) { const pathname = usePathname(); const responseList = responseItems ?? []; const [responsesOpen, setResponsesOpen] = useState(true); const currentSection = pathname.startsWith(`/admin/form/${formId}/result`) ? "Responses" : pathname.startsWith(`/admin/form/${formId}/extra`) ? "Settings" : pathname.startsWith(`/admin/form/${formId}/preview`) ? "Preview" : "Editor"; const items = [ { href: `/admin/form/${formId}`, label: "Editor", icon: LayoutDashboard, active: pathname === `/admin/form/${formId}`, }, { href: `/admin/form/${formId}/result`, label: "Responses", icon: ClipboardList, active: pathname.startsWith(`/admin/form/${formId}/result`), }, { href: `/admin/form/${formId}/extra`, label: "Settings", icon: Settings, active: pathname.startsWith(`/admin/form/${formId}/extra`), }, { href: `/admin/form/${formId}/preview`, label: "Preview", icon: Eye, active: pathname.startsWith(`/admin/form/${formId}/preview`), }, ]; return (
{formTitle} {isOpen ? "Open" : "Closed"}
{currentSection}
All forms
Workspace {items.map(({ href, label, icon: Icon, active }) => ( {label} {label === "Responses" && responseList.length > 0 && ( setResponsesOpen((open) => !open)} aria-label={`${responsesOpen ? "Collapse" : "Expand"} responses`} aria-expanded={responsesOpen} > )} {label === "Responses" && responsesOpen && responseList.length > 0 && ( {responseList.map((response) => { const responseHref = `/admin/form/${formId}/result/${response.id}`; return ( {response.queueNumber}. {response.displayName} ); })} )} ))}
{(userName || profile) && ( )}
); }