"use client";
import { Badge } from "@/components/ui/badge";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
// import type { Workspace } from "@/lib/db";
import { cn } from "@/lib/utils";
import {
Activity,
BookOpen,
Code,
Crown,
Loader2,
LucideIcon,
Settings,
ShieldHalf,
} from "lucide-react";
import Link from "next/link";
import { useSelectedLayoutSegments } from "next/navigation";
import { useRouter } from "next/navigation";
import React, { useEffect, useState, useTransition } from "react";
import { WorkspaceSwitcher } from "./team-switcher";
import { UserButton } from "./user-button";
import service from "@/lib/http/service";
import { StaffsInfo, StaffsInfoWithoutId, queryStaffList } from "@/lib/http/staff";
type Props = {
workspace: & {
apis: {
id: string;
name: string;
}[];
};
className?: string;
};
type NavItem = {
disabled?: boolean;
tooltip?: string;
icon: LucideIcon;
href: string;
external?: boolean;
label: string;
active?: boolean;
tag?: React.ReactNode;
};
const Tag: React.FC<{ label: string }> = ({ label }) => (
{label}
);
export const DesktopSidebar: React.FC = ({ workspace, className }) => {
const segments = useSelectedLayoutSegments();
const navigation: NavItem[] = [
{
icon: Code,
href: "/manage/overview",
label: "首页",
active: segments.length === 1 && segments.at(0) === "overview",
},
{
icon: Settings,
href: "/manage/staffs",
label: "我的员工",
active: segments.at(0) === "staffs",
},
{
icon: ShieldHalf,
label: "预览效果",
href: "/preview",
active: segments.some((s) => s === "preview"),
// tag: ,
},
{
icon: Activity,
href: "/manage/billing",
label: "账单",
active: segments.at(0) === "billing",
tag: ,
},
];
const navigationDebug: NavItem[] = [
{
icon: Code,
href: "/manage/overview",
label: "首页",
active: segments.length === 1 && segments.at(0) === "overview",
},
{
icon: Code,
href: "/manage/new",
label: "创建员工",
active: segments.at(0) === "new",
},
{
icon: Code,
href: "/manage/plans",
label: "计费",
active: segments.at(0) === "plans",
},
{
icon: Code,
href: "/manage/repository",
label: "知识库列表",
active: segments.at(0) === "repository",
},
{
icon: Code,
href: "/manage/repository/new",
label: "知识库创建",
active: segments.at(0) === "repository",
},
// {
// icon: Code,
// href: "/manage/apis",
// label: "APIs",
// active: segments.at(0) === "apis",
// },
{
icon: Settings,
href: "/manage/staffs",
label: "我的员工",
active: segments.at(0) === "staffs",
},
{
icon: ShieldHalf,
label: "Authorization",
href: "/manage/authorization/roles",
active: segments.some((s) => s === "authorization"),
tag: ,
},
{
icon: ShieldHalf,
label: "预览效果",
href: "/preview",
active: segments.some((s) => s === "preview"),
// tag: ,
},
{
icon: ShieldHalf,
label: "数据分析",
href: "/manage/analysis",
active: segments.some((s) => s === "analysis"),
tag: ,
},
{
icon: Activity,
href: "/manage/billing",
label: "账单",
active: segments.at(0) === "billing",
tag: ,
},
{
icon: Activity,
href: "/manage/billing/success",
label: "支付成功",
active: segments.at(0) === "billing",
},
];
const [clientReady, setClientReady] = useState(false);
const [staffsList, setStaffsList] = useState([]);
// if (workspace.features.successPage) {
// navigation.push({
// icon: Crown,
// href: "/app/success",
// label: "Success",
// active: segments.at(0) === "success",
// tag: (
//
// internal
//
// ),
// });
// }
const firstOfNextMonth = new Date();
firstOfNextMonth.setUTCMonth(firstOfNextMonth.getUTCMonth() + 1);
firstOfNextMonth.setDate(1);
useEffect(() => {
// console.log("------------email", infoRef.current, userData.auth_token)
async function initFunc() {
// await service.post('/api/v1/customer/list/staff', {
// // email: infoRef.current.email
// }, {
// headers: {
// // 'Authorization': token
// }
// }).then(function (result: any) {
// console.log("result:", result)
// if (result && result.header.code != 0) {
// // toast.error(result.header.message)
// return
// }
// }).catch((err: any) => {
// });
const data = await queryStaffList({})
setStaffsList(data.data.list)
}
initFunc()
setClientReady(true);
}, []);
return (
);
};
const NavLink: React.FC<{ item: NavItem }> = ({ item }) => {
const [isPending, startTransition] = useTransition();
const router = useRouter();
const link = (
{
if (!item.external) {
startTransition(() => {
router.push(item.href);
});
}
}}
target={item.external ? "_blank" : undefined}
className={cn(
"group flex gap-x-2 rounded-md px-2 py-1 text-sm font-medium leading-6 items-center hover:bg-gray-200 dark:hover:bg-gray-800 justify-between",
{
"bg-gray-200 dark:bg-gray-800": item.active,
"text-content-subtle pointer-events-none": item.disabled,
},
)}
>
{isPending ? (
) : (
)}
{item.label}
{item.tag}
);
if (item.tooltip) {
return (
{link}
{item.tooltip}
);
}
return link;
};