Compare commits

...

15 Commits

Author SHA1 Message Date
b64c6cf612 feat(admin): add collapsible desktop sidebar
Some checks failed
Frontend CI/CD / build (push) Has been cancelled
Frontend CI/CD / deploy (push) Has been cancelled
2026-06-15 21:53:39 +03:30
958400a8c1 feat(admin-dashboard): link top content lists 2026-06-15 21:50:42 +03:30
da8d82955e fix(admin-dashboard): refine filter reset controls 2026-06-15 21:46:20 +03:30
021bee9444 fix(admin-dashboard): prevent mobile chart overflow 2026-06-15 21:34:59 +03:30
ecd4a57da9 fix(admin-dashboard): align RTL chart axes
Some checks failed
Frontend CI/CD / build (push) Has been cancelled
Frontend CI/CD / deploy (push) Has been cancelled
2026-06-15 18:11:29 +03:30
f30d53df7e refactor(admin): simplify grouped navigation
Some checks failed
Frontend CI/CD / build (push) Has been cancelled
Frontend CI/CD / deploy (push) Has been cancelled
2026-06-15 17:43:17 +03:30
4edf8a0736 fix(admin-dashboard): tighten mobile layout 2026-06-15 17:40:31 +03:30
4fb44fcb4c fix(admin-dashboard): improve blog engagement visuals 2026-06-15 17:38:11 +03:30
268dd26d9a feat(admin-dashboard): add full result drilldown modals 2026-06-15 17:35:45 +03:30
6ba8f6ec8b feat(admin-dashboard): sync tabs and filters with URL 2026-06-15 17:32:03 +03:30
e3ddb733ee fix(admin-dashboard): polish filters and date pickers 2026-06-15 17:29:58 +03:30
9f07c0740d fix(admin-dashboard): make charts RTL-safe 2026-06-15 17:28:55 +03:30
83321c1d39 fix(admin): refresh analytics dashboard layout
Some checks failed
Frontend CI/CD / build (push) Has been cancelled
Frontend CI/CD / deploy (push) Has been cancelled
2026-06-15 16:18:13 +03:30
6c3a7ed5f4 feat(admin): add analytics dashboard UI
Some checks failed
Frontend CI/CD / build (push) Has been cancelled
Frontend CI/CD / deploy (push) Has been cancelled
2026-06-14 09:52:41 +03:30
5c15727516 feat(admin): wire analytics dashboard route 2026-06-14 09:52:14 +03:30
6 changed files with 1738 additions and 108 deletions

View File

@@ -0,0 +1,5 @@
import AdminDashboard from "@/views/AdminDashboard";
export default function AdminDashboardPage() {
return <AdminDashboard />;
}

View File

@@ -1,5 +1,5 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
export default function AdminPage() { export default function AdminPage() {
redirect("/admin/users"); redirect("/admin/dashboard");
} }

View File

@@ -416,6 +416,60 @@ class ApiClient {
}); });
} }
async getAdminDashboard(params?: {
date_from?: string;
date_to?: string;
event_id?: number;
granularity?: 'auto' | 'day' | 'week' | 'month';
}) {
const query = new URLSearchParams();
if (params?.date_from) query.set('date_from', params.date_from);
if (params?.date_to) query.set('date_to', params.date_to);
if (params?.event_id != null) query.set('event_id', String(params.event_id));
if (params?.granularity) query.set('granularity', params.granularity);
return this.request<Types.AdminDashboardAnalyticsSchema>(
`/api/analytics/admin/dashboard${query.toString() ? `?${query.toString()}` : ''}`,
);
}
async getAdminUserAnalytics(params?: { date_from?: string; date_to?: string }) {
const query = new URLSearchParams();
if (params?.date_from) query.set('date_from', params.date_from);
if (params?.date_to) query.set('date_to', params.date_to);
return this.request<Types.UserAnalyticsSchema>(
`/api/analytics/admin/users${query.toString() ? `?${query.toString()}` : ''}`,
);
}
async getAdminEventAnalytics(params?: { date_from?: string; date_to?: string; event_id?: number }) {
const query = new URLSearchParams();
if (params?.date_from) query.set('date_from', params.date_from);
if (params?.date_to) query.set('date_to', params.date_to);
if (params?.event_id != null) query.set('event_id', String(params.event_id));
return this.request<Types.EventAnalyticsSchema>(
`/api/analytics/admin/events${query.toString() ? `?${query.toString()}` : ''}`,
);
}
async getAdminBlogAnalytics(params?: { date_from?: string; date_to?: string }) {
const query = new URLSearchParams();
if (params?.date_from) query.set('date_from', params.date_from);
if (params?.date_to) query.set('date_to', params.date_to);
return this.request<Types.BlogAnalyticsSchema>(
`/api/analytics/admin/blog${query.toString() ? `?${query.toString()}` : ''}`,
);
}
async getAdminDashboardEventOptions(params?: { search?: string; limit?: number; offset?: number }) {
const query = new URLSearchParams();
if (params?.search) query.set('search', params.search);
if (params?.limit != null) query.set('limit', String(params.limit));
if (params?.offset != null) query.set('offset', String(params.offset));
return this.request<Types.AnalyticsEventOptionsSchema>(
`/api/analytics/admin/events/options${query.toString() ? `?${query.toString()}` : ''}`,
);
}
// ============= Blog Endpoints ============= // ============= Blog Endpoints =============
async getPosts(params?: { async getPosts(params?: {

View File

@@ -753,6 +753,197 @@ export interface PaginatedResponse<T> {
previous?: string; previous?: string;
} }
// Admin analytics
export interface AnalyticsPointSchema {
label: string;
value: number;
}
export interface AnalyticsPointGroupSchema {
items: AnalyticsPointSchema[];
top_items: AnalyticsPointSchema[];
other_count: number;
total_count: number;
}
export interface AnalyticsTrendPointSchema {
date: string;
label: string;
value: number;
}
export interface AnalyticsRegistrationStatusSchema {
status: string;
label: string;
value: number;
}
export interface AnalyticsTopEventSchema {
id: number;
title: string;
slug: string;
attendees: number;
capacity?: number | null;
fill_rate?: number | null;
revenue: number;
}
export interface AnalyticsPostPopularitySchema {
id: number;
title: string;
slug: string;
likes: number;
saves: number;
comments: number;
}
export interface AnalyticsPostPopularityGroupSchema {
items: AnalyticsPostPopularitySchema[];
top_items: AnalyticsPostPopularitySchema[];
other_count: number;
total_count: number;
}
export interface AnalyticsTopPostSchema extends AnalyticsPostPopularitySchema {
score: number;
}
export interface AdminDashboardAnalyticsSchema {
filters: {
date_from?: string | null;
date_to?: string | null;
event_id?: number | null;
granularity: 'day' | 'week' | 'month';
};
summary: {
total_users: number;
verified_users: number;
total_events: number;
total_registrations: number;
total_revenue: number;
total_discount: number;
published_posts: number;
total_likes: number;
total_saves: number;
total_comments: number;
};
users: {
signup_trend: AnalyticsTrendPointSchema[];
by_major: AnalyticsPointSchema[];
by_university: AnalyticsPointSchema[];
by_year: AnalyticsPointSchema[];
};
events: {
registration_status: AnalyticsRegistrationStatusSchema[];
by_major: AnalyticsPointSchema[];
by_university: AnalyticsPointSchema[];
top_events: AnalyticsTopEventSchema[];
registration_trend: AnalyticsTrendPointSchema[];
};
revenue: {
trend: AnalyticsTrendPointSchema[];
by_event: AnalyticsPointSchema[];
payment_status: AnalyticsRegistrationStatusSchema[];
total_paid: number;
total_discount: number;
total_base: number;
};
blog: {
totals: {
posts: number;
likes: number;
saves: number;
comments: number;
};
post_popularity: AnalyticsPostPopularitySchema[];
top_posts: AnalyticsTopPostSchema[];
activity_trend: Array<{ date: string; likes: number; saves: number; comments: number }>;
by_category: AnalyticsPointSchema[];
by_tag: AnalyticsPointSchema[];
};
achievements: {
distinct_participants: number;
learning_hours: number;
published_content: number;
community_engagement: number;
};
}
export interface AnalyticsEventOptionsSchema {
count: number;
results: Array<{
value: string;
label: string;
description?: string | null;
}>;
}
export interface UserAnalyticsSchema {
filters: {
date_from?: string | null;
date_to?: string | null;
granularity: 'day' | 'week' | 'month';
};
summary: {
total_users: number;
verified_users: number;
unverified_users: number;
profile_completion_rate: number;
};
signup_trend: AnalyticsTrendPointSchema[];
by_major: AnalyticsPointGroupSchema;
by_university: AnalyticsPointGroupSchema;
by_year: AnalyticsPointGroupSchema;
}
export interface EventAnalyticsSchema {
filters: {
date_from?: string | null;
date_to?: string | null;
event_id?: number | null;
};
summary: {
total_events: number;
total_registrations: number;
distinct_participants: number;
total_revenue: number;
total_discount: number;
total_base: number;
learning_hours: number;
};
registration_status: AnalyticsRegistrationStatusSchema[];
payment_status: AnalyticsRegistrationStatusSchema[];
attendee_by_major: AnalyticsPointGroupSchema;
attendee_by_university: AnalyticsPointGroupSchema;
registration_trend: AnalyticsTrendPointSchema[];
revenue_trend: AnalyticsTrendPointSchema[];
revenue_by_event: AnalyticsPointGroupSchema;
top_events: {
top_items: AnalyticsTopEventSchema[];
other_count: number;
total_count: number;
};
}
export interface BlogAnalyticsSchema {
filters: {
date_from?: string | null;
date_to?: string | null;
};
summary: {
published_posts: number;
total_likes: number;
total_saves: number;
total_comments: number;
community_engagement: number;
};
activity_trend: Array<{ date: string; likes: number; saves: number; comments: number }>;
post_popularity: AnalyticsPostPopularityGroupSchema;
top_posts: AnalyticsTopPostSchema[];
by_category: AnalyticsPointGroupSchema;
by_tag: AnalyticsPointGroupSchema;
}
// payment // payment
export interface CreatePaymentOut { export interface CreatePaymentOut {
start_pay_url: string; start_pay_url: string;

1369
src/views/AdminDashboard.tsx Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,15 @@
"use client"; "use client";
import type { ReactNode } from "react"; import type { ReactNode } from "react";
import { useEffect, useMemo, useState } from "react"; import { useMemo, useState } from "react";
import { import {
Building2, Building2,
CalendarDays, CalendarDays,
ChevronDown,
FileText, FileText,
FolderTree, FolderTree,
GraduationCap, GraduationCap,
LayoutDashboard,
Menu,
PanelRightClose, PanelRightClose,
PanelRightOpen, PanelRightOpen,
ShieldCheck, ShieldCheck,
@@ -19,10 +20,17 @@ import {
import { Navigate, NavLink, useLocation } from "@/lib/router"; import { Navigate, NavLink, useLocation } from "@/lib/router";
import { useAuth } from "@/contexts/AuthContext"; import { useAuth } from "@/contexts/AuthContext";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"; import { Sheet, SheetClose, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
const navGroups = [ const navGroups = [
{
key: "dashboard",
label: "داشبورد",
items: [
{ to: "/admin/dashboard", label: "داشبورد", icon: LayoutDashboard, visibility: "staff" },
],
},
{ {
key: "users", key: "users",
label: "کاربران", label: "کاربران",
@@ -57,30 +65,12 @@ type NavItem = (typeof navGroups)[number]["items"][number];
export default function AdminLayout({ children }: { children: ReactNode }) { export default function AdminLayout({ children }: { children: ReactNode }) {
const location = useLocation(); const location = useLocation();
const { user, isAuthenticated, loading } = useAuth(); const { user, isAuthenticated, loading } = useAuth();
const [collapsed, setCollapsed] = useState(false); const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
const [openGroups, setOpenGroups] = useState<Record<string, boolean>>({
users: true,
events: true,
blog: true,
});
const canAccessAdmin = useMemo( const canAccessAdmin = useMemo(
() => isAuthenticated && Boolean(user?.is_staff || user?.is_superuser || user?.can_access_blog_admin), () => isAuthenticated && Boolean(user?.is_staff || user?.is_superuser || user?.can_access_blog_admin),
[isAuthenticated, user?.can_access_blog_admin, user?.is_staff, user?.is_superuser], [isAuthenticated, user?.can_access_blog_admin, user?.is_staff, user?.is_superuser],
); );
useEffect(() => {
const saved = window.localStorage.getItem("admin-sidebar-collapsed");
if (saved) setCollapsed(saved === "true");
}, []);
const toggleCollapsed = () => {
setCollapsed((current) => {
const next = !current;
window.localStorage.setItem("admin-sidebar-collapsed", String(next));
return next;
});
};
if (loading) { if (loading) {
return ( return (
<div className="min-h-screen flex items-center justify-center text-muted-foreground" dir="rtl"> <div className="min-h-screen flex items-center justify-center text-muted-foreground" dir="rtl">
@@ -103,7 +93,6 @@ export default function AdminLayout({ children }: { children: ReactNode }) {
const visibleGroups = navGroups const visibleGroups = navGroups
.map((group) => ({ ...group, items: group.items.filter(canSeeItem) })) .map((group) => ({ ...group, items: group.items.filter(canSeeItem) }))
.filter((group) => group.items.length > 0); .filter((group) => group.items.length > 0);
const visibleNavItems = visibleGroups.flatMap((group) => group.items);
const isItemActive = (to: string) => { const isItemActive = (to: string) => {
if (location.pathname === to) return true; if (location.pathname === to) return true;
@@ -121,107 +110,129 @@ export default function AdminLayout({ children }: { children: ReactNode }) {
<div className="flex min-h-screen"> <div className="flex min-h-screen">
<aside <aside
className={cn( className={cn(
"sticky top-0 hidden h-screen shrink-0 border-l bg-background/95 shadow-sm backdrop-blur transition-[width] duration-300 ease-in-out lg:flex lg:flex-col", "sticky top-0 hidden h-screen shrink-0 border-l bg-background/95 shadow-sm backdrop-blur transition-[width] duration-300 lg:flex lg:flex-col",
collapsed ? "w-20" : "w-72", sidebarCollapsed ? "w-20" : "w-72",
)} )}
> >
<div className="flex items-center justify-between gap-2 border-b p-4"> <div className={cn("border-b p-4", sidebarCollapsed ? "text-center" : "text-right")}>
{!collapsed ? ( <div className={cn("flex items-center gap-2", sidebarCollapsed ? "justify-center" : "justify-start")}>
<div className="text-right"> <Button
<h1 className="text-lg font-bold">پنل مدیریت</h1> type="button"
<p className="text-xs text-muted-foreground">انجمن علمی مهندسی کامپیوتر</p> variant="ghost"
</div> size="icon"
) : null} className="h-9 w-9 shrink-0 rounded-2xl"
<Button variant="ghost" size="icon" onClick={toggleCollapsed} aria-label="باز و بسته کردن منوی مدیریت"> onClick={() => setSidebarCollapsed((value) => !value)}
{collapsed ? <PanelRightOpen className="h-5 w-5" /> : <PanelRightClose className="h-5 w-5" />} aria-label={sidebarCollapsed ? "باز کردن منوی مدیریت" : "جمع کردن منوی مدیریت"}
</Button> title={sidebarCollapsed ? "باز کردن منو" : "جمع کردن منو"}
>
{sidebarCollapsed ? <PanelRightOpen className="h-4 w-4" /> : <PanelRightClose className="h-4 w-4" />}
</Button>
{!sidebarCollapsed ? (
<div className="min-w-0">
<h1 className="text-lg font-bold">پنل مدیریت</h1>
<p className="text-xs text-muted-foreground">انجمن علمی مهندسی کامپیوتر</p>
</div>
) : null}
</div>
</div> </div>
<nav className="flex-1 space-y-3 p-3"> <nav className="flex-1 space-y-3 p-3">
{visibleGroups.map((group) => ( {visibleGroups.map((group) => (
<Collapsible <div key={group.key} className="space-y-2">
key={group.key} <p
open={collapsed ? true : openGroups[group.key]} className={cn(
onOpenChange={(open) => setOpenGroups((current) => ({ ...current, [group.key]: open }))} "px-3 py-2 text-xs font-semibold text-muted-foreground transition-opacity",
> sidebarCollapsed && "sr-only",
{!collapsed ? ( )}
<CollapsibleTrigger className="mb-1 flex w-full items-center justify-between rounded-xl px-3 py-2 text-xs font-semibold text-muted-foreground hover:bg-muted/70"> >
<span>{group.label}</span> {group.label}
<ChevronDown </p>
className={cn("h-4 w-4 transition-transform", openGroups[group.key] ? "rotate-180" : "")} {group.items.map((item) => {
/> const Icon = item.icon;
</CollapsibleTrigger> const active = isItemActive(item.to);
) : null} return (
<CollapsibleContent className="space-y-2"> <NavLink
{group.items.map((item) => { key={item.to}
const Icon = item.icon; to={item.to}
const active = isItemActive(item.to); title={sidebarCollapsed ? item.label : undefined}
return ( className={cn(
<NavLink "flex items-center rounded-2xl px-3 py-3 text-sm transition",
key={item.to} sidebarCollapsed ? "justify-center" : "gap-3",
to={item.to} active
title={collapsed ? item.label : undefined} ? "bg-primary text-primary-foreground shadow"
className={cn( : "text-muted-foreground hover:bg-muted hover:text-foreground",
"flex items-center gap-3 rounded-2xl px-3 py-3 text-sm transition", )}
collapsed ? "justify-center" : "justify-start", >
active <Icon className="h-5 w-5 shrink-0" />
? "bg-primary text-primary-foreground shadow" <span className={cn("font-medium", sidebarCollapsed && "sr-only")}>{item.label}</span>
: "text-muted-foreground hover:bg-muted hover:text-foreground", </NavLink>
)} );
> })}
<Icon className="h-5 w-5 shrink-0" /> </div>
{!collapsed ? <span className="font-medium">{item.label}</span> : null}
</NavLink>
);
})}
</CollapsibleContent>
</Collapsible>
))} ))}
</nav> </nav>
</aside> </aside>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<div className="border-b bg-background/90 lg:hidden"> <div className="border-b bg-background/90 lg:hidden">
<div className="px-4 py-3 text-right"> <div className="flex items-center justify-between gap-3 px-4 py-3">
<h1 className="text-lg font-bold">پنل مدیریت</h1> <div className="text-right">
<p className="text-xs text-muted-foreground">مدیریت بخشهای سامانه</p> <h1 className="text-lg font-bold">پنل مدیریت</h1>
<p className="text-xs text-muted-foreground">مدیریت بخشهای سامانه</p>
</div>
<Sheet>
<SheetTrigger asChild>
<Button variant="outline" size="sm" className="gap-2 rounded-2xl">
<Menu className="h-4 w-4" />
منو
</Button>
</SheetTrigger>
<SheetContent
side="bottom"
className="max-h-[82vh] overflow-y-auto rounded-t-[2rem] border-t p-4 pb-[calc(env(safe-area-inset-bottom)+1rem)]"
dir="rtl"
>
<SheetHeader className="mt-6 text-right">
<SheetTitle>بخشهای پنل مدیریت</SheetTitle>
</SheetHeader>
<nav className="mt-5 space-y-5">
{visibleGroups.map((group) => (
<div key={group.key} className="space-y-2">
<p className="px-2 text-xs font-semibold text-muted-foreground">{group.label}</p>
<div className="grid gap-2 sm:grid-cols-2">
{group.items.map((item) => {
const Icon = item.icon;
const active = isItemActive(item.to);
return (
<SheetClose asChild key={item.to}>
<NavLink
to={item.to}
className={cn(
"flex items-center gap-3 rounded-2xl border px-3 py-3 text-sm transition",
active
? "border-primary bg-primary text-primary-foreground shadow"
: "bg-background text-muted-foreground hover:bg-muted hover:text-foreground",
)}
aria-current={active ? "page" : undefined}
>
<Icon className="h-5 w-5 shrink-0" />
<span className="font-medium">{item.label}</span>
</NavLink>
</SheetClose>
);
})}
</div>
</div>
))}
</nav>
</SheetContent>
</Sheet>
</div> </div>
</div> </div>
<div className="container mx-auto min-w-0 px-3 pb-28 pt-4 sm:px-4 lg:py-6"> <div className="container mx-auto min-w-0 px-3 pb-8 pt-4 sm:px-4 lg:py-6">
{children} {children}
</div> </div>
</div> </div>
</div> </div>
<div
className="fixed inset-x-0 z-50 px-4 lg:hidden"
style={{ bottom: "calc(env(safe-area-inset-bottom) + 0.9rem)" }}
>
<nav
aria-label="Admin mobile navigation"
className="mx-auto flex w-full max-w-sm items-center justify-between rounded-[1.75rem] border border-white/20 bg-background/70 px-2 py-2 shadow-[0_18px_60px_rgba(15,23,42,0.18)] backdrop-blur-2xl dark:border-white/10 dark:bg-slate-950/65"
dir="rtl"
>
{visibleNavItems.map((item) => {
const Icon = item.icon;
const active = isItemActive(item.to);
return (
<NavLink
key={item.to}
to={item.to}
className={cn(
"flex min-w-0 flex-1 flex-col items-center justify-center gap-1 rounded-2xl px-2 py-2 text-[10px] font-medium transition-all",
active
? "bg-primary text-primary-foreground shadow-sm"
: "text-muted-foreground hover:bg-white/30 hover:text-foreground dark:hover:bg-white/10",
)}
aria-current={active ? "page" : undefined}
>
<Icon className={cn("h-5 w-5", active ? "scale-105" : "")} />
<span className="max-w-full truncate">{item.label}</span>
</NavLink>
);
})}
</nav>
</div>
</div> </div>
); );
} }