124 lines
4.0 KiB
TypeScript
124 lines
4.0 KiB
TypeScript
"use client";
|
|
|
|
import { ChevronsUpDown, MessageSquarePlusIcon, Settings2Icon, SettingsIcon } from "lucide-react";
|
|
import { useEffect, useState } from "react";
|
|
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuGroup,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import {
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
useSidebar,
|
|
} from "@/components/ui/sidebar";
|
|
import { getStoredAuth } from "@/core/auth";
|
|
import { useI18n } from "@/core/i18n/hooks";
|
|
|
|
import { NotificationBell } from "./notification-bell";
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
import { SettingsDialog } from "./settings";
|
|
|
|
function NavMenuButtonContent({
|
|
isSidebarOpen,
|
|
t,
|
|
}: {
|
|
isSidebarOpen: boolean;
|
|
t: ReturnType<typeof useI18n>["t"];
|
|
}) {
|
|
return isSidebarOpen ? (
|
|
<div className="text-sidebar-foreground/85 flex w-full items-center gap-2 text-left text-sm">
|
|
<SettingsIcon className="size-4" />
|
|
<span>{t.workspace.settingsAndMore}</span>
|
|
<ChevronsUpDown className="text-sidebar-foreground/55 ml-auto size-4" />
|
|
</div>
|
|
) : (
|
|
<div className="flex size-full items-center justify-center">
|
|
<SettingsIcon className="text-sidebar-foreground/80 size-4" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function WorkspaceNavMenu() {
|
|
const navigate = useNavigate();
|
|
const isAdmin = getStoredAuth()?.system_role === "admin";
|
|
const [settingsOpen, setSettingsOpen] = useState(false);
|
|
const [settingsDefaultSection, setSettingsDefaultSection] = useState<
|
|
"appearance" | "memory" | "tools" | "notification" | "about"
|
|
>("appearance");
|
|
const [mounted, setMounted] = useState(false);
|
|
const { open: isSidebarOpen } = useSidebar();
|
|
const { t } = useI18n();
|
|
|
|
useEffect(() => {
|
|
setMounted(true);
|
|
}, []);
|
|
|
|
return (
|
|
<>
|
|
<SettingsDialog
|
|
open={settingsOpen}
|
|
onOpenChange={setSettingsOpen}
|
|
defaultSection={settingsDefaultSection}
|
|
/>
|
|
<SidebarMenu className="w-full">
|
|
<SidebarMenuItem>
|
|
<NotificationBell />
|
|
</SidebarMenuItem>
|
|
<SidebarMenuItem>
|
|
{mounted ? (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<SidebarMenuButton
|
|
size="lg"
|
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
|
>
|
|
<NavMenuButtonContent isSidebarOpen={isSidebarOpen} t={t} />
|
|
</SidebarMenuButton>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
|
align="end"
|
|
sideOffset={4}
|
|
>
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuItem
|
|
onClick={() => {
|
|
setSettingsDefaultSection("appearance");
|
|
setSettingsOpen(true);
|
|
}}
|
|
>
|
|
<Settings2Icon />
|
|
{t.common.settings}
|
|
</DropdownMenuItem>
|
|
{isAdmin && (
|
|
<DropdownMenuItem
|
|
onClick={() =>
|
|
navigate("/page/workspace/settings/recommended-questions")
|
|
}
|
|
>
|
|
<MessageSquarePlusIcon />
|
|
推荐问题配置
|
|
</DropdownMenuItem>
|
|
)}
|
|
</DropdownMenuGroup>
|
|
<DropdownMenuSeparator />
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
) : (
|
|
<SidebarMenuButton size="lg" className="pointer-events-none">
|
|
<NavMenuButtonContent isSidebarOpen={isSidebarOpen} t={t} />
|
|
</SidebarMenuButton>
|
|
)}
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
</>
|
|
);
|
|
}
|