Deploy edu.mstaut.ir / deploy (push) Has been cancelled
Production already has migrations through 008; 009 only updates four seed labels by id. Faculty sync remains upsert-by-email/name and does not wipe curated data. Co-authored-by: Cursor <cursoragent@cursor.com>
192 lines
6.6 KiB
TypeScript
192 lines
6.6 KiB
TypeScript
"use client";
|
|
|
|
import Image from "next/image";
|
|
import Link from "next/link";
|
|
import { usePathname } from "next/navigation";
|
|
import {
|
|
BookOpen,
|
|
Calendar,
|
|
FileText,
|
|
GraduationCap,
|
|
LayoutDashboard,
|
|
Megaphone,
|
|
MessageSquareQuote,
|
|
Newspaper,
|
|
Scale,
|
|
Tags,
|
|
Users,
|
|
ClipboardList,
|
|
BarChart3,
|
|
} from "lucide-react";
|
|
import {
|
|
Sidebar,
|
|
SidebarContent,
|
|
SidebarFooter,
|
|
SidebarGroup,
|
|
SidebarGroupContent,
|
|
SidebarGroupLabel,
|
|
SidebarHeader,
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
SidebarRail,
|
|
} from "@/components/ui/sidebar";
|
|
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
|
import { LogoutButton } from "@/components/organisms/admin/LogoutButton";
|
|
import { isAdminEntityEnabled } from "@/lib/admin/disabled-entities";
|
|
|
|
const NAV_GROUPS = [
|
|
{
|
|
label: "نمای کلی",
|
|
items: [{ href: "/mstcontroller", label: "داشبورد", icon: LayoutDashboard, exact: true }],
|
|
},
|
|
{
|
|
label: "محتوا",
|
|
items: [
|
|
{ href: "/mstcontroller/courses", label: "دوره ها", icon: BookOpen, entity: "courses" },
|
|
{
|
|
href: "/mstcontroller/course-categories",
|
|
label: "دسته بندی دوره ها",
|
|
icon: Tags,
|
|
entity: "course-categories",
|
|
},
|
|
{
|
|
href: "/mstcontroller/course-tags",
|
|
label: "تگ های دوره",
|
|
icon: Tags,
|
|
entity: "course-tags",
|
|
},
|
|
{ href: "/mstcontroller/programs", label: "برنامه ها", icon: GraduationCap, entity: "programs" },
|
|
{ href: "/mstcontroller/events", label: "رویدادها", icon: Calendar, entity: "events" },
|
|
{ href: "/mstcontroller/articles", label: "مقالات", icon: Newspaper, entity: "articles" },
|
|
{ href: "/mstcontroller/topics", label: "موضوعات", icon: Tags, entity: "topics" },
|
|
],
|
|
},
|
|
{
|
|
label: "جامعه",
|
|
items: [
|
|
{ href: "/mstcontroller/faculty", label: "اساتید", icon: Users, entity: "faculty" },
|
|
{ href: "/mstcontroller/alumni", label: "دانش آموختگان", icon: MessageSquareQuote, entity: "alumni" },
|
|
],
|
|
},
|
|
{
|
|
label: "سایت",
|
|
items: [
|
|
{ href: "/mstcontroller/banners", label: "بنرهای کمپین", icon: Megaphone, entity: "banners" },
|
|
{ href: "/mstcontroller/stats", label: "آمار", icon: BarChart3, entity: "stats" },
|
|
{ href: "/mstcontroller/testimonials", label: "نظرات", icon: FileText, entity: "testimonials" },
|
|
{ href: "/mstcontroller/legal", label: "صفحات قانونی", icon: Scale, entity: "legal" },
|
|
],
|
|
},
|
|
{
|
|
label: "درخواست ها",
|
|
items: [{ href: "/mstcontroller/registrations", label: "برگ ثبت نام", icon: ClipboardList }],
|
|
},
|
|
] as const;
|
|
|
|
function isActive(pathname: string, href: string, exact?: boolean) {
|
|
if (exact) return pathname === href;
|
|
return pathname === href || pathname.startsWith(`${href}/`);
|
|
}
|
|
|
|
export function AdminSidebar({ userName }: { userName: string }) {
|
|
const pathname = usePathname();
|
|
const initials = userName
|
|
.split(/\s+/)
|
|
.filter(Boolean)
|
|
.slice(0, 2)
|
|
.map((part) => part[0])
|
|
.join("");
|
|
|
|
return (
|
|
<Sidebar side="right" collapsible="icon" variant="inset">
|
|
<SidebarHeader className="h-(--header-height) shrink-0 justify-center gap-0 border-b border-sidebar-border p-0 px-3">
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton
|
|
size="lg"
|
|
render={<Link href="/mstcontroller" />}
|
|
className="data-active:bg-sidebar-accent"
|
|
>
|
|
<span className="relative size-8 shrink-0">
|
|
<Image
|
|
src="/brand/mst-faculty.png"
|
|
alt=""
|
|
fill
|
|
sizes="32px"
|
|
className="object-contain brightness-0"
|
|
priority
|
|
/>
|
|
</span>
|
|
<div className="grid flex-1 text-start text-sm leading-tight">
|
|
<span className="truncate font-semibold">پنل مدیریت</span>
|
|
<span className="truncate text-xs text-muted-foreground">
|
|
آموزش آزاد دانشگاه صنعتی امیرکبیر
|
|
</span>
|
|
</div>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
</SidebarHeader>
|
|
|
|
<SidebarContent>
|
|
{NAV_GROUPS.map((group) => {
|
|
const items = group.items.filter(
|
|
(item) =>
|
|
!("entity" in item) ||
|
|
isAdminEntityEnabled(item.entity),
|
|
);
|
|
if (items.length === 0) return null;
|
|
return (
|
|
<SidebarGroup key={group.label}>
|
|
<SidebarGroupLabel>{group.label}</SidebarGroupLabel>
|
|
<SidebarGroupContent>
|
|
<SidebarMenu>
|
|
{items.map((item) => {
|
|
const Icon = item.icon;
|
|
const active = isActive(
|
|
pathname,
|
|
item.href,
|
|
"exact" in item ? item.exact : false,
|
|
);
|
|
return (
|
|
<SidebarMenuItem key={item.href}>
|
|
<SidebarMenuButton
|
|
isActive={active}
|
|
tooltip={item.label}
|
|
render={<Link href={item.href} />}
|
|
>
|
|
<Icon />
|
|
<span>{item.label}</span>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
);
|
|
})}
|
|
</SidebarMenu>
|
|
</SidebarGroupContent>
|
|
</SidebarGroup>
|
|
);
|
|
})}
|
|
</SidebarContent>
|
|
|
|
<SidebarFooter className="p-3">
|
|
<div className="flex items-center gap-2 rounded-lg border border-sidebar-border bg-sidebar px-2 py-2 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:border-0 group-data-[collapsible=icon]:p-0">
|
|
<Avatar className="size-8">
|
|
<AvatarFallback className="bg-sidebar-accent text-xs font-semibold">
|
|
{initials || "اد"}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div className="min-w-0 flex-1 group-data-[collapsible=icon]:hidden">
|
|
<p className="truncate text-sm font-medium">{userName}</p>
|
|
<p className="truncate text-xs text-muted-foreground">مدیر محتوا</p>
|
|
</div>
|
|
<div className="group-data-[collapsible=icon]:hidden">
|
|
<LogoutButton />
|
|
</div>
|
|
</div>
|
|
</SidebarFooter>
|
|
<SidebarRail />
|
|
</Sidebar>
|
|
);
|
|
}
|