508 lines
15 KiB
TypeScript
508 lines
15 KiB
TypeScript
"use client";
|
|
|
|
import {
|
|
BadgeCheck,
|
|
BarChart3,
|
|
Briefcase,
|
|
Check,
|
|
ChevronDown,
|
|
ChevronsUpDown,
|
|
ClipboardList,
|
|
Clock3,
|
|
FileText,
|
|
Folder,
|
|
Globe2,
|
|
HelpCircle,
|
|
LayoutDashboard,
|
|
LogOut,
|
|
Search,
|
|
Settings,
|
|
Sparkles,
|
|
Star,
|
|
User,
|
|
Users,
|
|
} from "lucide-react";
|
|
import * as React from "react";
|
|
|
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
import {
|
|
Breadcrumb,
|
|
BreadcrumbItem,
|
|
BreadcrumbLink,
|
|
BreadcrumbList,
|
|
BreadcrumbPage,
|
|
BreadcrumbSeparator,
|
|
} from "@/components/ui/breadcrumb";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Separator } from "@/components/ui/separator";
|
|
import {
|
|
Sidebar,
|
|
SidebarContent,
|
|
SidebarFooter,
|
|
SidebarGroup,
|
|
SidebarGroupContent,
|
|
SidebarGroupLabel,
|
|
SidebarHeader,
|
|
SidebarInput,
|
|
SidebarInset,
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
SidebarProvider,
|
|
SidebarRail,
|
|
SidebarTrigger,
|
|
} from "@/components/ui/sidebar";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
// Base nav item - used by simple sidebars
|
|
type NavItem = {
|
|
label: string;
|
|
icon: React.ComponentType<React.SVGProps<SVGSVGElement>>;
|
|
href: string;
|
|
isActive?: boolean;
|
|
// Optional children for submenus (Sidebar3+)
|
|
children?: NavItem[];
|
|
};
|
|
|
|
// Nav group with optional collapsible state
|
|
type NavGroup = {
|
|
title: string;
|
|
items: NavItem[];
|
|
// Optional: default collapsed state (Sidebar2+)
|
|
defaultOpen?: boolean;
|
|
};
|
|
|
|
// User data for footer (Sidebar6+)
|
|
type UserData = {
|
|
name: string;
|
|
email: string;
|
|
avatar: string;
|
|
};
|
|
|
|
// Workspace data for switcher (Sidebar7+)
|
|
type Workspace = {
|
|
id: string;
|
|
name: string;
|
|
logo: string;
|
|
plan: string;
|
|
};
|
|
|
|
// Complete sidebar data structure
|
|
type SidebarData = {
|
|
// Logo/branding (all sidebars)
|
|
logo: {
|
|
src: string;
|
|
alt: string;
|
|
title: string;
|
|
description: string;
|
|
};
|
|
// Main navigation groups (all sidebars)
|
|
navGroups: NavGroup[];
|
|
// Footer navigation group (all sidebars)
|
|
footerGroup: NavGroup;
|
|
// User data for user footer (Sidebar6+)
|
|
user?: UserData;
|
|
// Workspaces for switcher (Sidebar7+)
|
|
workspaces?: Workspace[];
|
|
// Currently active workspace (Sidebar7+)
|
|
activeWorkspace?: string;
|
|
};
|
|
|
|
// Shared sidebar data - works with all sidebar variations
|
|
const sidebarData: SidebarData = {
|
|
logo: {
|
|
src: "/block-media/shadcnblocks/block/logos/ShadcnBlocks-logo.svg",
|
|
alt: "فروشیار",
|
|
title: "فروشیار",
|
|
description: "داشبورد درآمد فروش",
|
|
},
|
|
navGroups: [
|
|
{
|
|
title: "نمای کلی",
|
|
defaultOpen: true,
|
|
items: [
|
|
{
|
|
label: "داشبورد",
|
|
icon: LayoutDashboard,
|
|
href: "#",
|
|
isActive: true,
|
|
},
|
|
{ label: "پیگیریها", icon: ClipboardList, href: "#" },
|
|
{ label: "پیشبینی فروش", icon: BarChart3, href: "#" },
|
|
],
|
|
},
|
|
{
|
|
title: "فرصتها",
|
|
defaultOpen: true,
|
|
items: [
|
|
{
|
|
label: "فرصتهای باز",
|
|
icon: Briefcase,
|
|
href: "#",
|
|
children: [
|
|
{ label: "فرصت سازمانی آفتاب", icon: FileText, href: "#" },
|
|
{ label: "فرصت رشد مهتاب", icon: FileText, href: "#" },
|
|
{ label: "فرصت پایلوت", icon: FileText, href: "#" },
|
|
],
|
|
},
|
|
{
|
|
label: "بسته شده",
|
|
icon: Folder,
|
|
href: "#",
|
|
children: [
|
|
{ label: "بردهای ۱۴۰۳", icon: FileText, href: "#" },
|
|
{ label: "بردهای ۱۴۰۲", icon: FileText, href: "#" },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: "تیم فروش",
|
|
defaultOpen: false,
|
|
items: [
|
|
{ label: "نمایندگان", icon: Users, href: "#" },
|
|
{ label: "اهداف ماهانه", icon: Clock3, href: "#" },
|
|
{ label: "تأیید تخفیف", icon: BadgeCheck, href: "#" },
|
|
{ label: "بازبینی پیشبینی", icon: Star, href: "#" },
|
|
],
|
|
},
|
|
{
|
|
title: "فضای کار",
|
|
defaultOpen: false,
|
|
items: [
|
|
{ label: "یکپارچهسازیها", icon: Globe2, href: "#" },
|
|
{ label: "اتوماسیون فروش", icon: Sparkles, href: "#" },
|
|
],
|
|
},
|
|
],
|
|
footerGroup: {
|
|
title: "پشتیبانی",
|
|
items: [
|
|
{ label: "مرکز راهنما", icon: HelpCircle, href: "#" },
|
|
{ label: "تنظیمات", icon: Settings, href: "#" },
|
|
],
|
|
},
|
|
user: {
|
|
name: "علی رضایی",
|
|
email: "ali@example.com",
|
|
avatar:
|
|
"/block-media/shadcnblocks/block/avatar-4.webp",
|
|
},
|
|
workspaces: [
|
|
{
|
|
id: "1",
|
|
name: "ShadcnBlocks",
|
|
logo: "/block-media/shadcnblocks/block/logos/ShadcnBlocks-logo.svg",
|
|
plan: "سازمانی",
|
|
},
|
|
{
|
|
id: "2",
|
|
name: "قالبهای پیشنهاد",
|
|
logo: "/block-media/shadcnblocks/block/logos/ShadcnBlocks-logo.svg",
|
|
plan: "تیم فروش SMB",
|
|
},
|
|
{
|
|
id: "3",
|
|
name: "اسکریپتهای تماس",
|
|
logo: "/block-media/shadcnblocks/block/logos/ShadcnBlocks-logo.svg",
|
|
plan: "آزمایشی",
|
|
},
|
|
],
|
|
activeWorkspace: "1",
|
|
};
|
|
|
|
// Helper to get active workspace
|
|
const getActiveWorkspace = (data: SidebarData): Workspace | undefined => {
|
|
return data.workspaces?.find((w) => w.id === data.activeWorkspace);
|
|
};
|
|
|
|
const WorkspaceSwitcher = ({
|
|
workspaces,
|
|
activeWorkspace,
|
|
}: {
|
|
workspaces: Workspace[];
|
|
activeWorkspace: Workspace;
|
|
}) => {
|
|
const [selected, setSelected] = React.useState(activeWorkspace);
|
|
|
|
return (
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<SidebarMenuButton
|
|
size="lg"
|
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
|
>
|
|
<div className="flex aspect-square size-8 items-center justify-center rounded-sm bg-primary">
|
|
<img
|
|
src={selected.logo}
|
|
alt={selected.name}
|
|
className="size-6 text-primary-foreground invert dark:invert-0"
|
|
/>
|
|
</div>
|
|
<div className="grid flex-1 text-start text-sm leading-tight">
|
|
<span className="truncate font-medium">{selected.name}</span>
|
|
<span className="truncate text-xs text-muted-foreground">
|
|
{selected.plan}
|
|
</span>
|
|
</div>
|
|
<ChevronsUpDown className="ms-auto size-4" />
|
|
</SidebarMenuButton>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
|
align="start"
|
|
sideOffset={4}
|
|
>
|
|
<DropdownMenuLabel className="text-xs text-muted-foreground">
|
|
فضاهای کاری
|
|
</DropdownMenuLabel>
|
|
{workspaces.map((workspace) => (
|
|
<DropdownMenuItem
|
|
key={workspace.id}
|
|
onClick={() => setSelected(workspace)}
|
|
className="gap-2 p-2"
|
|
>
|
|
<div className="flex size-6 items-center justify-center rounded-sm bg-primary">
|
|
<img
|
|
src={workspace.logo}
|
|
alt={workspace.name}
|
|
className="size-4 text-primary-foreground invert dark:invert-0"
|
|
/>
|
|
</div>
|
|
<span>{workspace.name}</span>
|
|
{workspace.id === selected.id && (
|
|
<Check className="ms-auto size-4" />
|
|
)}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
);
|
|
};
|
|
|
|
const SearchForm = () => {
|
|
return (
|
|
<form>
|
|
<SidebarGroup className="py-0">
|
|
<SidebarGroupContent className="relative">
|
|
<Label htmlFor="search" className="sr-only">
|
|
جستجو
|
|
</Label>
|
|
<SidebarInput id="search" placeholder="جستجوی فرصت، شرکت..." className="ps-8" />
|
|
<Search className="pointer-events-none absolute top-1/2 start-2 size-4 -translate-y-1/2 opacity-50 select-none" />
|
|
</SidebarGroupContent>
|
|
</SidebarGroup>
|
|
</form>
|
|
);
|
|
};
|
|
|
|
// Nav item with dropdown menu for children
|
|
const NavMenuItem = ({ item }: { item: NavItem }) => {
|
|
const Icon = item.icon;
|
|
const hasChildren = item.children && item.children.length > 0;
|
|
|
|
if (!hasChildren) {
|
|
return (
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton asChild isActive={item.isActive}>
|
|
<a href={item.href}>
|
|
<Icon className="size-4" />
|
|
<span>{item.label}</span>
|
|
</a>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<SidebarMenuItem>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<SidebarMenuButton isActive={item.isActive}>
|
|
<Icon className="size-4" />
|
|
<span>{item.label}</span>
|
|
<ChevronDown className="ms-auto size-4" />
|
|
</SidebarMenuButton>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
className="min-w-48 rounded-lg"
|
|
side="bottom"
|
|
align="start"
|
|
sideOffset={4}
|
|
>
|
|
{item.children!.map((child) => {
|
|
const ChildIcon = child.icon;
|
|
return (
|
|
<DropdownMenuItem key={child.label} asChild>
|
|
<a href={child.href} className="flex items-center gap-2">
|
|
<ChildIcon className="size-4" />
|
|
<span>{child.label}</span>
|
|
</a>
|
|
</DropdownMenuItem>
|
|
);
|
|
})}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</SidebarMenuItem>
|
|
);
|
|
};
|
|
|
|
const NavUser = ({ user }: { user: UserData }) => {
|
|
return (
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<SidebarMenuButton
|
|
size="lg"
|
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
|
>
|
|
<Avatar className="size-8 rounded-lg">
|
|
<AvatarImage src={user.avatar} alt={user.name} />
|
|
<AvatarFallback className="rounded-lg">
|
|
{user.name
|
|
.split(" ")
|
|
.map((n) => n[0])
|
|
.join("")}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div className="grid flex-1 text-start text-sm leading-tight">
|
|
<span className="truncate font-medium">{user.name}</span>
|
|
<span className="truncate text-xs text-muted-foreground">
|
|
{user.email}
|
|
</span>
|
|
</div>
|
|
<ChevronsUpDown className="ms-auto size-4" />
|
|
</SidebarMenuButton>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
|
side="bottom"
|
|
align="start"
|
|
sideOffset={4}
|
|
>
|
|
<DropdownMenuLabel className="p-0 font-normal">
|
|
<div className="flex items-center gap-2 px-1 py-1.5 text-start text-sm">
|
|
<Avatar className="size-8 rounded-lg">
|
|
<AvatarImage src={user.avatar} alt={user.name} />
|
|
<AvatarFallback className="rounded-lg">
|
|
{user.name
|
|
.split(" ")
|
|
.map((n) => n[0])
|
|
.join("")}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div className="grid flex-1 text-start text-sm leading-tight">
|
|
<span className="truncate font-medium">{user.name}</span>
|
|
<span className="truncate text-xs text-muted-foreground">
|
|
{user.email}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</DropdownMenuLabel>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem>
|
|
<User className="me-2 size-4" />
|
|
حساب کاربری
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem>
|
|
<LogOut className="me-2 size-4" />
|
|
خروج
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
);
|
|
};
|
|
|
|
const AppSidebar = ({ ...props }: React.ComponentProps<typeof Sidebar>) => {
|
|
const activeWorkspace = getActiveWorkspace(sidebarData);
|
|
|
|
return (
|
|
<Sidebar side="right" {...props}>
|
|
<SidebarHeader>
|
|
{sidebarData.workspaces && activeWorkspace && (
|
|
<WorkspaceSwitcher
|
|
workspaces={sidebarData.workspaces}
|
|
activeWorkspace={activeWorkspace}
|
|
/>
|
|
)}
|
|
<SearchForm />
|
|
</SidebarHeader>
|
|
<SidebarContent>
|
|
{sidebarData.navGroups.map((group) => (
|
|
<SidebarGroup key={group.title}>
|
|
<SidebarGroupLabel>{group.title}</SidebarGroupLabel>
|
|
<SidebarGroupContent>
|
|
<SidebarMenu>
|
|
{group.items.map((item) => (
|
|
<NavMenuItem key={item.label} item={item} />
|
|
))}
|
|
</SidebarMenu>
|
|
</SidebarGroupContent>
|
|
</SidebarGroup>
|
|
))}
|
|
</SidebarContent>
|
|
<SidebarFooter>
|
|
{sidebarData.user && <NavUser user={sidebarData.user} />}
|
|
</SidebarFooter>
|
|
<SidebarRail />
|
|
</Sidebar>
|
|
);
|
|
};
|
|
|
|
interface Sidebar15Props {
|
|
className?: string;
|
|
}
|
|
|
|
const Sidebar15 = ({ className }: Sidebar15Props) => {
|
|
return (
|
|
<SidebarProvider
|
|
dir="rtl"
|
|
lang="fa"
|
|
className={cn(className)}
|
|
>
|
|
<AppSidebar />
|
|
<SidebarInset>
|
|
<header className="flex h-16 shrink-0 items-center gap-2 border-b px-4">
|
|
<SidebarTrigger className="-ms-1" />
|
|
<Separator
|
|
orientation="vertical"
|
|
className="ms-2 data-[orientation=vertical]:h-4"
|
|
/>
|
|
<Breadcrumb>
|
|
<BreadcrumbList>
|
|
<BreadcrumbItem className="hidden md:block">
|
|
<BreadcrumbLink href="#">نمای کلی</BreadcrumbLink>
|
|
</BreadcrumbItem>
|
|
<BreadcrumbSeparator className="hidden md:block" />
|
|
<BreadcrumbItem>
|
|
<BreadcrumbPage>داشبورد</BreadcrumbPage>
|
|
</BreadcrumbItem>
|
|
</BreadcrumbList>
|
|
</Breadcrumb>
|
|
</header>
|
|
<div className="flex flex-1 flex-col gap-4 p-4">
|
|
<div className="min-h-[100vh] flex-1 rounded-xl bg-muted/50 md:min-h-min" />
|
|
</div>
|
|
</SidebarInset>
|
|
</SidebarProvider>
|
|
);
|
|
};
|
|
|
|
export { Sidebar15 };
|