Enhance Next.js configuration and dependencies for improved functionality and localization support. Added support for internationalization with next-intl, updated global styles, and integrated new fonts. Removed default home page and updated README with project details and setup instructions.
This commit is contained in:
1 parent
2911dea00b
commit
44f4fa98e2
320 files changed
+31666
-220
No files matched your search
@@ -0,0 +1,108 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { X } from "lucide-react";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { DotCta } from "@/components/atoms/DotCta";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { Program } from "@/lib/types";
|
||||
|
||||
export function AcademicsOverlay({
|
||||
open,
|
||||
onClose,
|
||||
title,
|
||||
executiveLabel,
|
||||
exploreLabel,
|
||||
standardPrograms,
|
||||
executivePrograms,
|
||||
}: {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
title: string;
|
||||
executiveLabel: string;
|
||||
exploreLabel: string;
|
||||
standardPrograms: Program[];
|
||||
executivePrograms: Program[];
|
||||
}) {
|
||||
if (!open) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-[70] overflow-y-auto bg-card text-foreground"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={title}
|
||||
>
|
||||
<Container className="py-8">
|
||||
<div className="mb-8 flex items-center justify-between gap-4">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={onClose}
|
||||
className="px-0 font-semibold hover:bg-transparent hover:text-primary"
|
||||
>
|
||||
بازگشت به منو
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onClose}
|
||||
aria-label="بستن"
|
||||
>
|
||||
<X className="size-5" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<h2 className="mb-10 max-w-3xl text-start text-3xl font-bold tracking-tight sm:text-4xl">
|
||||
{title}
|
||||
</h2>
|
||||
|
||||
<ul className="grid gap-x-10 gap-y-8 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{standardPrograms.map((program) => (
|
||||
<li key={program.id}>
|
||||
<Link
|
||||
href={program.href}
|
||||
onClick={onClose}
|
||||
className="group block"
|
||||
>
|
||||
<span className="text-base font-extrabold leading-snug group-hover:text-primary">
|
||||
{program.title}
|
||||
</span>
|
||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
||||
{program.blurb}
|
||||
</p>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<h3 className="mt-14 mb-6 text-lg font-extrabold text-primary">
|
||||
{executiveLabel}
|
||||
</h3>
|
||||
<ul className="grid gap-x-10 gap-y-8 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{executivePrograms.map((program) => (
|
||||
<li key={program.id}>
|
||||
<Link
|
||||
href={program.href}
|
||||
onClick={onClose}
|
||||
className="group block"
|
||||
>
|
||||
<span className="text-base font-extrabold leading-snug group-hover:text-primary">
|
||||
{program.title}
|
||||
</span>
|
||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
||||
{program.blurb}
|
||||
</p>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<div className="mt-12">
|
||||
<DotCta href="/programs">{exploreLabel}</DotCta>
|
||||
</div>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { X } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { CampaignBanner } from "@/lib/types";
|
||||
|
||||
const STORAGE_PREFIX = "aut-banner:v1:";
|
||||
|
||||
export function CampaignBanners({ banners }: { banners: CampaignBanner[] }) {
|
||||
const [hidden, setHidden] = useState<Record<string, boolean>>({});
|
||||
const [ready, setReady] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const frame = requestAnimationFrame(() => {
|
||||
const next: Record<string, boolean> = {};
|
||||
for (const banner of banners) {
|
||||
try {
|
||||
next[banner.id] =
|
||||
localStorage.getItem(`${STORAGE_PREFIX}${banner.version}`) === "1";
|
||||
} catch {
|
||||
next[banner.id] = false;
|
||||
}
|
||||
}
|
||||
setHidden(next);
|
||||
setReady(true);
|
||||
});
|
||||
return () => cancelAnimationFrame(frame);
|
||||
}, [banners]);
|
||||
|
||||
function dismiss(banner: CampaignBanner) {
|
||||
try {
|
||||
localStorage.setItem(`${STORAGE_PREFIX}${banner.version}`, "1");
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
setHidden((prev) => ({ ...prev, [banner.id]: true }));
|
||||
}
|
||||
|
||||
if (!ready) return null;
|
||||
|
||||
const visible = banners.filter((b) => !hidden[b.id]);
|
||||
if (visible.length === 0) return null;
|
||||
|
||||
const banner = visible[0];
|
||||
|
||||
return (
|
||||
<div className="bg-chart-3 text-background">
|
||||
<Container className="flex items-center justify-between gap-4 py-3">
|
||||
<p className="min-w-0 flex-1 text-sm leading-relaxed">
|
||||
<span className="text-background/90">{banner.text}</span>{" "}
|
||||
<Link
|
||||
href={banner.href}
|
||||
className="font-bold text-background underline-offset-4 hover:underline"
|
||||
>
|
||||
{banner.cta}
|
||||
</Link>
|
||||
</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="بستن بنر"
|
||||
className="shrink-0 text-background/70 hover:bg-background/10 hover:text-background"
|
||||
onClick={() => dismiss(banner)}
|
||||
>
|
||||
<X className="size-4" />
|
||||
</Button>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
"use client";
|
||||
|
||||
import { useDeferredValue, useMemo, useState } from "react";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import type { Course } from "@/lib/types";
|
||||
import { courseCategories } from "@/lib/site-config";
|
||||
import { formatCoursePrice, formatLabel } from "@/lib/labels";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function CategoryCourseExplorer({
|
||||
courses,
|
||||
findLabel,
|
||||
}: {
|
||||
courses: Course[];
|
||||
findLabel: string;
|
||||
}) {
|
||||
const [query, setQuery] = useState("");
|
||||
const [category, setCategory] = useState("all");
|
||||
const deferredQuery = useDeferredValue(query);
|
||||
const isStale = query !== deferredQuery;
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
return courses.filter((course) => {
|
||||
const matchesCategory =
|
||||
category === "all" ||
|
||||
category === "best" ||
|
||||
course.category === category;
|
||||
const matchesQuery =
|
||||
!deferredQuery ||
|
||||
course.title.includes(deferredQuery) ||
|
||||
course.summary.includes(deferredQuery);
|
||||
return matchesCategory && matchesQuery;
|
||||
});
|
||||
}, [courses, category, deferredQuery]);
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<form
|
||||
className="flex flex-col gap-3 sm:flex-row"
|
||||
onSubmit={(e) => e.preventDefault()}
|
||||
role="search"
|
||||
>
|
||||
<Label className="sr-only" htmlFor="course-search">
|
||||
{findLabel}
|
||||
</Label>
|
||||
<Input
|
||||
id="course-search"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
placeholder={findLabel}
|
||||
className="h-11 flex-1 border-border bg-background text-foreground placeholder:text-muted-foreground"
|
||||
/>
|
||||
<Button type="submit" className="h-11">
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<div
|
||||
className="flex flex-wrap gap-2"
|
||||
role="tablist"
|
||||
aria-label="دستهبندی دورهها"
|
||||
>
|
||||
{courseCategories.map((item) => (
|
||||
<Button
|
||||
key={item.id}
|
||||
type="button"
|
||||
role="tab"
|
||||
size="sm"
|
||||
variant={category === item.id ? "default" : "ghost"}
|
||||
aria-selected={category === item.id}
|
||||
onClick={() => setCategory(item.id)}
|
||||
className={cn(
|
||||
category !== item.id &&
|
||||
"bg-background/10 text-background/85 hover:bg-background/20 hover:text-background",
|
||||
)}
|
||||
>
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"grid gap-5 transition-opacity sm:grid-cols-2 lg:grid-cols-3",
|
||||
isStale && "opacity-70",
|
||||
)}
|
||||
>
|
||||
{filtered.map((course) => {
|
||||
const priceLabel = formatCoursePrice(course.price);
|
||||
return (
|
||||
<Card
|
||||
key={course.id}
|
||||
className="gap-0 overflow-hidden bg-background/5 py-0 text-background ring-background/10"
|
||||
>
|
||||
<div className="relative aspect-[16/10] overflow-hidden">
|
||||
<Image
|
||||
src={course.imageUrl}
|
||||
alt={course.title}
|
||||
fill
|
||||
className="object-cover"
|
||||
sizes="(max-width:768px) 100vw, 33vw"
|
||||
/>
|
||||
</div>
|
||||
<CardHeader className="gap-1 px-4 pt-4">
|
||||
<CardTitle className="text-base text-background">
|
||||
<Link
|
||||
href={course.registrationUrl}
|
||||
className="transition-opacity hover:opacity-90"
|
||||
>
|
||||
{course.title}
|
||||
</Link>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3 px-4 pb-4">
|
||||
<CardDescription className="line-clamp-3 text-background/70">
|
||||
{course.summary}
|
||||
</CardDescription>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-background/55">
|
||||
<span>
|
||||
{course.durationHours} ساعت · {formatLabel(course.format)}
|
||||
</span>
|
||||
{priceLabel ? (
|
||||
<span className="font-semibold text-background/90">
|
||||
{priceLabel}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<Link
|
||||
href={course.registrationUrl}
|
||||
className="inline-flex text-sm font-semibold text-background underline-offset-4 hover:underline"
|
||||
>
|
||||
جزئیات و ثبتنام
|
||||
</Link>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
|
||||
export function ContactInterestForm({
|
||||
submitLabel,
|
||||
successLabel,
|
||||
courseSlug,
|
||||
}: {
|
||||
submitLabel: string;
|
||||
successLabel: string;
|
||||
courseSlug?: string;
|
||||
}) {
|
||||
const [form, setForm] = useState({ fullName: "", email: "", phone: "", message: "" });
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [sent, setSent] = useState(false);
|
||||
|
||||
function set<K extends keyof typeof form>(key: K, value: string) {
|
||||
setForm((f) => ({ ...f, [key]: value }));
|
||||
}
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
setError("");
|
||||
try {
|
||||
const res = await fetch("/api/registrations", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ ...form, courseSlug }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در ثبت درخواست");
|
||||
return;
|
||||
}
|
||||
setSent(true);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (sent) {
|
||||
return (
|
||||
<p className="rounded-lg border border-primary/25 bg-primary/5 p-4 text-sm text-chart-2">
|
||||
{successLabel}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="space-y-4" onSubmit={handleSubmit}>
|
||||
{error && (
|
||||
<p className="rounded-lg bg-destructive/10 p-3 text-sm text-red-600" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="name">نام و نام خانوادگی</Label>
|
||||
<Input
|
||||
id="name"
|
||||
value={form.fullName}
|
||||
onChange={(e) => set("fullName", e.target.value)}
|
||||
required
|
||||
className="h-11"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="email">ایمیل</Label>
|
||||
<Input
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
value={form.email}
|
||||
onChange={(e) => set("email", e.target.value)}
|
||||
required
|
||||
className="h-11"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="phone">تلفن</Label>
|
||||
<Input
|
||||
id="phone"
|
||||
value={form.phone}
|
||||
onChange={(e) => set("phone", e.target.value)}
|
||||
className="h-11"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="message">پیام</Label>
|
||||
<Textarea
|
||||
id="message"
|
||||
value={form.message}
|
||||
onChange={(e) => set("message", e.target.value)}
|
||||
rows={4}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" disabled={loading}>
|
||||
{loading ? "در حال ارسال..." : submitLabel}
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { ContactInterestForm } from "@/components/organisms/ContactInterestForm";
|
||||
|
||||
type CourseRegisterGateProps = {
|
||||
courseSlug: string;
|
||||
submitLabel: string;
|
||||
successLabel: string;
|
||||
ctaLabel: string;
|
||||
formTitle: string;
|
||||
formDescription: string;
|
||||
hint: string;
|
||||
cancelLabel: string;
|
||||
};
|
||||
|
||||
export function CourseRegisterGate({
|
||||
courseSlug,
|
||||
submitLabel,
|
||||
successLabel,
|
||||
ctaLabel,
|
||||
formTitle,
|
||||
formDescription,
|
||||
hint,
|
||||
cancelLabel,
|
||||
}: CourseRegisterGateProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
if (!open) {
|
||||
return (
|
||||
<div className="space-y-4 rounded-2xl bg-card p-6 shadow-sm ring-1 ring-border">
|
||||
<div className="space-y-2">
|
||||
<h2 className="text-lg font-bold tracking-tight">{formTitle}</h2>
|
||||
<p className="text-sm leading-7 text-muted-foreground">{hint}</p>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
size="lg"
|
||||
className="w-full font-bold"
|
||||
onClick={() => setOpen(true)}
|
||||
>
|
||||
{ctaLabel}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="rounded-2xl border-border/70 shadow-lg" id="register-form">
|
||||
<CardHeader className="space-y-1">
|
||||
<CardTitle>{formTitle}</CardTitle>
|
||||
<CardDescription>{formDescription}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<ContactInterestForm
|
||||
courseSlug={courseSlug}
|
||||
submitLabel={submitLabel}
|
||||
successLabel={successLabel}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
className="w-full"
|
||||
onClick={() => setOpen(false)}
|
||||
>
|
||||
{cancelLabel}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
"use client";
|
||||
|
||||
import useEmblaCarousel from "embla-carousel-react";
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||
import { useCallback } from "react";
|
||||
import { DotCta } from "@/components/atoms/DotCta";
|
||||
import { ProgramCard } from "@/components/molecules/Cards";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { Program } from "@/lib/types";
|
||||
|
||||
export function ProgramCarousel({
|
||||
title,
|
||||
programs,
|
||||
keepExploringLabel,
|
||||
hideTitle = false,
|
||||
}: {
|
||||
title: string;
|
||||
programs: Program[];
|
||||
keepExploringLabel: string;
|
||||
hideTitle?: boolean;
|
||||
}) {
|
||||
const [emblaRef, emblaApi] = useEmblaCarousel({
|
||||
align: "start",
|
||||
direction: "rtl",
|
||||
loop: false,
|
||||
});
|
||||
|
||||
const scrollPrev = useCallback(() => emblaApi?.scrollPrev(), [emblaApi]);
|
||||
const scrollNext = useCallback(() => emblaApi?.scrollNext(), [emblaApi]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-5 flex items-end justify-between gap-4">
|
||||
{!hideTitle && title ? (
|
||||
<h2 className="text-2xl font-bold tracking-tight sm:text-3xl">
|
||||
{title}
|
||||
</h2>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
aria-label="قبلی"
|
||||
onClick={scrollPrev}
|
||||
>
|
||||
<ChevronRight className="size-4" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
aria-label="بعدی"
|
||||
onClick={scrollNext}
|
||||
>
|
||||
<ChevronLeft className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="overflow-hidden" ref={emblaRef}>
|
||||
<div className="flex gap-5">
|
||||
{programs.map((program) => (
|
||||
<div
|
||||
key={program.id}
|
||||
className="min-w-0 shrink-0 basis-[88%] sm:basis-[42%] lg:basis-[30%]"
|
||||
>
|
||||
<ProgramCard program={program} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-7">
|
||||
<DotCta href="/programs">{keepExploringLabel}</DotCta>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { Search, X } from "lucide-react";
|
||||
import { useDeferredValue, useEffect, useMemo, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import type { Course, Program } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function SearchOverlay({
|
||||
courses,
|
||||
programs,
|
||||
label,
|
||||
}: {
|
||||
courses: Course[];
|
||||
programs: Program[];
|
||||
label: string;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [query, setQuery] = useState("");
|
||||
const deferredQuery = useDeferredValue(query);
|
||||
const isStale = query !== deferredQuery;
|
||||
|
||||
useEffect(() => {
|
||||
function onKey(e: KeyboardEvent) {
|
||||
if (e.key === "Escape") setOpen(false);
|
||||
}
|
||||
if (open) window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [open]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const previousOverflow = document.body.style.overflow;
|
||||
const previousPadding = document.body.style.paddingInlineEnd;
|
||||
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
||||
document.body.style.overflow = "hidden";
|
||||
if (scrollbarWidth > 0) document.body.style.paddingInlineEnd = `${scrollbarWidth}px`;
|
||||
return () => {
|
||||
document.body.style.overflow = previousOverflow;
|
||||
document.body.style.paddingInlineEnd = previousPadding;
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
const results = useMemo(() => {
|
||||
const q = deferredQuery.trim();
|
||||
if (!q) {
|
||||
return { programs: programs.slice(0, 4), courses: courses.slice(0, 4) };
|
||||
}
|
||||
return {
|
||||
programs: programs.filter(
|
||||
(p) => p.title.includes(q) || p.blurb.includes(q),
|
||||
),
|
||||
courses: courses.filter(
|
||||
(c) => c.title.includes(q) || c.summary.includes(q),
|
||||
),
|
||||
};
|
||||
}, [deferredQuery, programs, courses]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label={label}
|
||||
onClick={() => setOpen(true)}
|
||||
className="size-11 text-inherit hover:bg-foreground/5"
|
||||
>
|
||||
<Search />
|
||||
</Button>
|
||||
|
||||
{open ? createPortal(
|
||||
<div
|
||||
className="fixed inset-0 z-[100] overflow-y-auto bg-background text-foreground"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={label}
|
||||
>
|
||||
<div className="border-b border-border bg-card">
|
||||
<div className="mx-auto flex max-w-4xl items-center justify-between px-4 py-5 sm:px-6">
|
||||
<p className="text-sm font-semibold text-muted-foreground">{label}</p>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="text-foreground hover:bg-muted"
|
||||
aria-label="بستن جستجو"
|
||||
onClick={() => setOpen(false)}
|
||||
>
|
||||
<X />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mx-auto flex max-w-4xl flex-col gap-8 px-4 py-8 sm:px-6 sm:py-12">
|
||||
<Input
|
||||
autoFocus
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
placeholder="جستجوی برنامه یا دوره…"
|
||||
className="h-14 rounded-xl border-border bg-card px-4 text-lg text-foreground shadow-sm placeholder:text-muted-foreground focus-visible:border-primary focus-visible:ring-primary/20 sm:text-xl"
|
||||
/>
|
||||
<div
|
||||
className={cn(
|
||||
"grid gap-8 transition-opacity sm:grid-cols-2",
|
||||
isStale && "opacity-70",
|
||||
)}
|
||||
>
|
||||
<ResultGroup
|
||||
title="برنامهها"
|
||||
items={results.programs.map((p) => ({
|
||||
href: p.href,
|
||||
title: p.title,
|
||||
subtitle: p.tagline,
|
||||
}))}
|
||||
onNavigate={() => setOpen(false)}
|
||||
/>
|
||||
<ResultGroup
|
||||
title="دورهها"
|
||||
items={results.courses.map((c) => ({
|
||||
href: c.registrationUrl,
|
||||
title: c.title,
|
||||
subtitle: c.summary,
|
||||
}))}
|
||||
onNavigate={() => setOpen(false)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
, document.body) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ResultGroup({
|
||||
title,
|
||||
items,
|
||||
onNavigate,
|
||||
}: {
|
||||
title: string;
|
||||
items: { href: string; title: string; subtitle?: string }[];
|
||||
onNavigate: () => void;
|
||||
}) {
|
||||
return (
|
||||
<div>
|
||||
<p className="mb-3 text-xs font-bold text-muted-foreground">{title}</p>
|
||||
<ul className="space-y-3">
|
||||
{items.length === 0 ? (
|
||||
<li className="text-sm text-muted-foreground">موردی یافت نشد</li>
|
||||
) : (
|
||||
items.map((item) => (
|
||||
<li key={item.href + item.title}>
|
||||
<Link
|
||||
href={item.href}
|
||||
onClick={onNavigate}
|
||||
className="block rounded-xl bg-card p-4 shadow-sm ring-1 ring-border transition-[background-color,box-shadow] hover:bg-muted hover:shadow-md"
|
||||
>
|
||||
<span className="font-semibold">{item.title}</span>
|
||||
{item.subtitle ? (
|
||||
<span className="mt-1 line-clamp-2 block text-xs leading-6 text-muted-foreground">
|
||||
{item.subtitle}
|
||||
</span>
|
||||
) : null}
|
||||
</Link>
|
||||
</li>
|
||||
))
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import Link from "next/link";
|
||||
import { BrandLogo } from "@/components/atoms/BrandLogo";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
siteAddress,
|
||||
siteShortName,
|
||||
siteUniversity,
|
||||
} from "@/lib/site-config";
|
||||
|
||||
export function SiteFooter({
|
||||
copyright,
|
||||
links,
|
||||
linksTitle = "دسترسی سریع",
|
||||
}: {
|
||||
copyright: string;
|
||||
links: { label: string; href: string }[];
|
||||
linksTitle?: string;
|
||||
variant?: "home" | "professional";
|
||||
}) {
|
||||
return (
|
||||
<footer className="border-t border-border bg-chart-3 pb-[env(safe-area-inset-bottom)] text-background">
|
||||
<Container className="py-12 sm:py-14">
|
||||
<div className="grid gap-10 sm:grid-cols-2 lg:grid-cols-3 lg:gap-12">
|
||||
<div className="max-w-sm space-y-4">
|
||||
<BrandLogo
|
||||
title={siteShortName}
|
||||
subtitle={siteUniversity}
|
||||
onDark
|
||||
/>
|
||||
<p className="text-sm leading-7 text-background/65">
|
||||
{siteAddress.line}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<nav aria-label="لینکهای پاورقی" className="space-y-4">
|
||||
<p className="text-xs font-semibold tracking-wide text-background/55">
|
||||
{linksTitle}
|
||||
</p>
|
||||
<ul className="flex flex-col gap-2.5 text-sm font-medium">
|
||||
{links.map((link) => (
|
||||
<li key={link.href}>
|
||||
<Link
|
||||
href={link.href}
|
||||
className="text-background/80 transition-colors hover:text-background"
|
||||
>
|
||||
{link.label}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div className="space-y-4 sm:max-w-xs lg:justify-self-end lg:text-end">
|
||||
<p className="text-xs font-semibold tracking-wide text-background/55">
|
||||
تماس
|
||||
</p>
|
||||
<div className="space-y-1.5 text-sm text-background/75">
|
||||
<p dir="ltr">
|
||||
<a
|
||||
href={`tel:${siteAddress.phone}`}
|
||||
className="transition-colors hover:text-background"
|
||||
>
|
||||
{siteAddress.phone}
|
||||
</a>
|
||||
</p>
|
||||
<p dir="ltr">
|
||||
<a
|
||||
href={`mailto:${siteAddress.email}`}
|
||||
className="transition-colors hover:text-background"
|
||||
>
|
||||
{siteAddress.email}
|
||||
</a>
|
||||
</p>
|
||||
<p className="pt-1">
|
||||
<a
|
||||
href={siteAddress.mapUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="font-medium text-background/90 transition-colors hover:text-background"
|
||||
>
|
||||
موقعیت روی نقشه
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Separator className="my-8 bg-background/10" />
|
||||
|
||||
<p className="text-xs text-background/45">{copyright}</p>
|
||||
</Container>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
"use client";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import Link from "next/link";
|
||||
import { Menu, X } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { BrandLogo } from "@/components/atoms/BrandLogo";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { SearchOverlay } from "@/components/organisms/SearchOverlay";
|
||||
import type { Course, NavItem, Program } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const AcademicsOverlay = dynamic(
|
||||
() =>
|
||||
import("@/components/organisms/AcademicsOverlay").then(
|
||||
(m) => m.AcademicsOverlay,
|
||||
),
|
||||
{ ssr: false },
|
||||
);
|
||||
|
||||
export function SiteHeader({
|
||||
items,
|
||||
searchLabel,
|
||||
brandHref = "/",
|
||||
brandTitle,
|
||||
brandSubtitle,
|
||||
academicsLabel,
|
||||
programSelectorTitle,
|
||||
executiveLabel,
|
||||
exploreLabel,
|
||||
variant = "home",
|
||||
courses = [],
|
||||
programs = [],
|
||||
}: {
|
||||
items: NavItem[];
|
||||
searchLabel: string;
|
||||
brandHref?: string;
|
||||
brandTitle: string;
|
||||
brandSubtitle?: string;
|
||||
academicsLabel: string;
|
||||
programSelectorTitle: string;
|
||||
executiveLabel: string;
|
||||
exploreLabel: string;
|
||||
variant?: "home" | "professional";
|
||||
courses?: Course[];
|
||||
programs?: Program[];
|
||||
}) {
|
||||
const [mobileOpen, setMobileOpen] = useState(false);
|
||||
const [academicsOpen, setAcademicsOpen] = useState(false);
|
||||
const isDark = variant === "professional";
|
||||
const standardPrograms = programs.filter((p) => p.group === "standard");
|
||||
const executivePrograms = programs.filter((p) => p.group === "executive");
|
||||
|
||||
useEffect(() => {
|
||||
if (!mobileOpen) return;
|
||||
const prev = document.body.style.overflow;
|
||||
document.body.style.overflow = "hidden";
|
||||
return () => {
|
||||
document.body.style.overflow = prev;
|
||||
};
|
||||
}, [mobileOpen]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<header
|
||||
className={cn(
|
||||
"site-header sticky top-0 z-50 pt-[env(safe-area-inset-top)] shadow-sm backdrop-blur-xl",
|
||||
isDark
|
||||
? "border-b border-background/10 bg-chart-3/95 text-background"
|
||||
: "border-b border-border bg-card/95 text-foreground",
|
||||
)}
|
||||
>
|
||||
<Container className="flex h-[4.5rem] items-center justify-start gap-3 sm:h-20 sm:gap-5" dir="rtl">
|
||||
<BrandLogo
|
||||
href={brandHref}
|
||||
title={brandTitle}
|
||||
subtitle={brandSubtitle}
|
||||
onDark={isDark}
|
||||
/>
|
||||
|
||||
<nav
|
||||
className="hidden min-w-0 flex-1 items-center justify-start gap-0.5 xl:flex"
|
||||
aria-label="منوی اصلی"
|
||||
>
|
||||
{items.map((item) => (
|
||||
<Link
|
||||
key={item.href + item.label}
|
||||
href={item.href}
|
||||
className={cn(
|
||||
"rounded-lg px-2.5 py-2 text-sm font-semibold transition-colors",
|
||||
isDark
|
||||
? "text-background/80 hover:text-background"
|
||||
: "text-foreground/75 hover:bg-muted hover:text-primary",
|
||||
)}
|
||||
>
|
||||
{item.label}
|
||||
</Link>
|
||||
))}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className={cn(
|
||||
"ms-2 h-9 border-primary/20 font-bold text-primary hover:bg-primary hover:text-primary-foreground",
|
||||
isDark &&
|
||||
"border-background/50 bg-transparent text-background hover:bg-background hover:text-foreground",
|
||||
)}
|
||||
onClick={() => setAcademicsOpen(true)}
|
||||
>
|
||||
{academicsLabel}
|
||||
</Button>
|
||||
</nav>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"ms-auto flex shrink-0 items-center gap-0.5 xl:ms-0",
|
||||
isDark && "text-background",
|
||||
)}
|
||||
>
|
||||
<SearchOverlay
|
||||
courses={courses}
|
||||
programs={programs}
|
||||
label={searchLabel}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="xl:hidden"
|
||||
aria-label={mobileOpen ? "بستن منو" : "باز کردن منو"}
|
||||
aria-expanded={mobileOpen}
|
||||
onClick={() => setMobileOpen((v) => !v)}
|
||||
>
|
||||
{mobileOpen ? (
|
||||
<X className="size-5" />
|
||||
) : (
|
||||
<Menu className="size-5" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</Container>
|
||||
</header>
|
||||
|
||||
{mobileOpen ? (
|
||||
<div
|
||||
className="fixed inset-0 z-[60] flex flex-col bg-chart-3 text-background pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)] xl:hidden"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label="منوی اصلی"
|
||||
>
|
||||
<Container className="flex h-16 items-center justify-between gap-3">
|
||||
<BrandLogo
|
||||
href={brandHref}
|
||||
title={brandTitle}
|
||||
subtitle={brandSubtitle}
|
||||
onDark
|
||||
compact
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="text-background hover:bg-background/10"
|
||||
aria-label="بستن منو"
|
||||
onClick={() => setMobileOpen(false)}
|
||||
>
|
||||
<X className="size-5" />
|
||||
</Button>
|
||||
</Container>
|
||||
<Separator className="bg-background/10" />
|
||||
<Container className="flex-1 overflow-y-auto py-6">
|
||||
<ul className="space-y-1 text-start">
|
||||
{items.map((item) => (
|
||||
<li key={item.href + item.label}>
|
||||
<Link
|
||||
href={item.href}
|
||||
className="block py-3.5 text-lg font-bold transition-colors hover:text-background/70"
|
||||
onClick={() => setMobileOpen(false)}
|
||||
>
|
||||
{item.label}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="mt-8 w-full border-background/80 bg-transparent py-3.5 text-background hover:bg-background hover:text-foreground"
|
||||
onClick={() => {
|
||||
setMobileOpen(false);
|
||||
setAcademicsOpen(true);
|
||||
}}
|
||||
>
|
||||
{academicsLabel}
|
||||
</Button>
|
||||
</Container>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{academicsOpen ? (
|
||||
<AcademicsOverlay
|
||||
open={academicsOpen}
|
||||
onClose={() => setAcademicsOpen(false)}
|
||||
title={programSelectorTitle}
|
||||
executiveLabel={executiveLabel}
|
||||
exploreLabel={exploreLabel}
|
||||
standardPrograms={standardPrograms}
|
||||
executivePrograms={executivePrograms}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import type { ReactNode } from "react";
|
||||
import Link from "next/link";
|
||||
import { ArrowRight } from "lucide-react";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function AdminPageHeader({
|
||||
title,
|
||||
description,
|
||||
actions,
|
||||
backHref,
|
||||
backLabel = "بازگشت",
|
||||
}: {
|
||||
title: string;
|
||||
description?: ReactNode;
|
||||
actions?: ReactNode;
|
||||
backHref?: string;
|
||||
backLabel?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-col gap-4 border-b border-border pb-6 sm:flex-row sm:items-end sm:justify-between">
|
||||
<div className="min-w-0 space-y-2">
|
||||
{backHref ? (
|
||||
<Link
|
||||
href={backHref}
|
||||
className={cn(
|
||||
buttonVariants({ variant: "ghost", size: "sm" }),
|
||||
"-ms-2 h-8 gap-1.5 px-2 text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
<ArrowRight className="size-3.5" />
|
||||
{backLabel}
|
||||
</Link>
|
||||
) : null}
|
||||
<div className="space-y-1">
|
||||
<h1 className="text-2xl font-bold tracking-tight text-foreground">
|
||||
{title}
|
||||
</h1>
|
||||
{description ? (
|
||||
<div className="text-sm text-muted-foreground">{description}</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{actions ? (
|
||||
<div className="flex shrink-0 flex-wrap items-center gap-2">{actions}</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function AdminToolbarCard({
|
||||
title = "فیلترها",
|
||||
description,
|
||||
children,
|
||||
}: {
|
||||
title?: string;
|
||||
description?: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Card size="sm" className="shadow-none">
|
||||
<CardHeader className="border-b [.border-b]:pb-3">
|
||||
<CardTitle className="text-sm font-semibold">{title}</CardTitle>
|
||||
{description ? <CardDescription>{description}</CardDescription> : null}
|
||||
</CardHeader>
|
||||
<CardContent className="pt-4">{children}</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function AdminTableCard({
|
||||
title = "فهرست",
|
||||
description,
|
||||
children,
|
||||
}: {
|
||||
title?: string;
|
||||
description?: ReactNode;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Card className="gap-0 overflow-hidden py-0 shadow-none">
|
||||
<CardHeader className="border-b py-4 [.border-b]:pb-4">
|
||||
<CardTitle className="text-base">{title}</CardTitle>
|
||||
{description ? <CardDescription>{description}</CardDescription> : null}
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">{children}</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function AdminFormCard({
|
||||
title = "جزئیات",
|
||||
description,
|
||||
children,
|
||||
footer,
|
||||
}: {
|
||||
title?: string;
|
||||
description?: string;
|
||||
children: ReactNode;
|
||||
footer?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Card className="max-w-3xl shadow-none">
|
||||
<CardHeader className="border-b [.border-b]:pb-4">
|
||||
<CardTitle>{title}</CardTitle>
|
||||
{description ? <CardDescription>{description}</CardDescription> : null}
|
||||
</CardHeader>
|
||||
<CardContent className="pt-6">{children}</CardContent>
|
||||
{footer ? (
|
||||
<CardFooter className="justify-start gap-2 border-t bg-muted/30">
|
||||
{footer}
|
||||
</CardFooter>
|
||||
) : null}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function AdminPage({
|
||||
children,
|
||||
className,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
}) {
|
||||
return <div className={cn("space-y-6", className)}>{children}</div>;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
import {
|
||||
SidebarInset,
|
||||
SidebarProvider,
|
||||
SidebarTrigger,
|
||||
} from "@/components/ui/sidebar";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { AdminSidebar } from "@/components/organisms/admin/AdminSidebar";
|
||||
|
||||
export function AdminShell({
|
||||
userName,
|
||||
children,
|
||||
}: {
|
||||
userName: string;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<SidebarProvider
|
||||
dir="rtl"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": "16.5rem",
|
||||
"--header-height": "3.5rem",
|
||||
} as React.CSSProperties
|
||||
}
|
||||
>
|
||||
<AdminSidebar userName={userName} />
|
||||
<SidebarInset className="bg-muted/30 md:peer-data-[variant=inset]:ms-2 md:peer-data-[variant=inset]:me-0 md:peer-data-[variant=inset]:peer-data-[state=collapsed]:me-2">
|
||||
<header className="sticky top-0 z-20 flex h-(--header-height) shrink-0 items-center gap-2 border-b bg-background/95 px-4 backdrop-blur supports-backdrop-filter:bg-background/80">
|
||||
<SidebarTrigger className="-ms-1" />
|
||||
<Separator orientation="vertical" className="me-1 data-[orientation=vertical]:h-4" />
|
||||
<div className="flex min-w-0 flex-1 items-center justify-between gap-3">
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<span className="relative size-6 shrink-0 overflow-hidden rounded-full bg-chart-3 ring-1 ring-border md:hidden">
|
||||
<Image
|
||||
src="/brand/amirkabir.png"
|
||||
alt=""
|
||||
fill
|
||||
sizes="24px"
|
||||
className="object-cover"
|
||||
/>
|
||||
</span>
|
||||
<p className="truncate text-sm font-medium text-muted-foreground">
|
||||
مدیریت محتوا
|
||||
</p>
|
||||
</div>
|
||||
<span className="hidden truncate text-sm text-muted-foreground sm:inline">
|
||||
{userName}
|
||||
</span>
|
||||
</div>
|
||||
</header>
|
||||
<div className="mx-auto w-full max-w-7xl flex-1 px-4 py-6 md:px-8 md:py-8">
|
||||
{children}
|
||||
</div>
|
||||
</SidebarInset>
|
||||
</SidebarProvider>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
"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,
|
||||
SidebarSeparator,
|
||||
} from "@/components/ui/sidebar";
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
||||
import { LogoutButton } from "@/components/organisms/admin/LogoutButton";
|
||||
|
||||
const NAV_GROUPS = [
|
||||
{
|
||||
label: "نمای کلی",
|
||||
items: [{ href: "/admin", label: "داشبورد", icon: LayoutDashboard, exact: true }],
|
||||
},
|
||||
{
|
||||
label: "محتوا",
|
||||
items: [
|
||||
{ href: "/admin/courses", label: "دورهها", icon: BookOpen },
|
||||
{ href: "/admin/programs", label: "برنامهها", icon: GraduationCap },
|
||||
{ href: "/admin/events", label: "رویدادها", icon: Calendar },
|
||||
{ href: "/admin/articles", label: "مقالات", icon: Newspaper },
|
||||
{ href: "/admin/topics", label: "موضوعات", icon: Tags },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "جامعه",
|
||||
items: [
|
||||
{ href: "/admin/faculty", label: "اساتید", icon: Users },
|
||||
{ href: "/admin/alumni", label: "دانشآموختگان", icon: MessageSquareQuote },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "سایت",
|
||||
items: [
|
||||
{ href: "/admin/banners", label: "بنرهای کمپین", icon: Megaphone },
|
||||
{ href: "/admin/stats", label: "آمار", icon: BarChart3 },
|
||||
{ href: "/admin/testimonials", label: "نظرات", icon: FileText },
|
||||
{ href: "/admin/legal", label: "صفحات قانونی", icon: Scale },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "درخواستها",
|
||||
items: [{ href: "/admin/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="gap-3 p-3">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton
|
||||
size="lg"
|
||||
render={<Link href="/admin" />}
|
||||
className="data-active:bg-sidebar-accent"
|
||||
>
|
||||
<span className="relative size-8 shrink-0 overflow-hidden rounded-lg bg-chart-3 ring-1 ring-sidebar-border">
|
||||
<Image
|
||||
src="/brand/amirkabir.png"
|
||||
alt=""
|
||||
fill
|
||||
sizes="32px"
|
||||
className="object-cover"
|
||||
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>
|
||||
|
||||
<SidebarSeparator />
|
||||
|
||||
<SidebarContent>
|
||||
{NAV_GROUPS.map((group) => (
|
||||
<SidebarGroup key={group.label}>
|
||||
<SidebarGroupLabel>{group.label}</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{group.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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
export const LEAD_STATUS_LABELS: Record<string, string> = {
|
||||
new: "جدید",
|
||||
contacted: "تماس گرفته شد",
|
||||
enrolled: "ثبتنام شد",
|
||||
rejected: "رد شد",
|
||||
};
|
||||
|
||||
const STATUS_VARIANTS: Record<string, "default" | "secondary" | "outline" | "destructive"> = {
|
||||
new: "default",
|
||||
contacted: "secondary",
|
||||
enrolled: "outline",
|
||||
rejected: "destructive",
|
||||
};
|
||||
|
||||
export interface LeadForDashboard {
|
||||
id: string;
|
||||
full_name: string;
|
||||
email: string;
|
||||
course_slug: string | null;
|
||||
status: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export function LeadsList({ leads }: { leads: LeadForDashboard[] }) {
|
||||
const router = useRouter();
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function changeStatus(id: string, status: string) {
|
||||
setError("");
|
||||
const res = await fetch(`/api/admin/registrations/${id}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در تغییر وضعیت");
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
if (leads.length === 0) {
|
||||
return <p className="text-sm text-muted-foreground">درخواستی ثبت نشده است.</p>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{error && (
|
||||
<p className="text-sm text-red-600" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-right text-sm">
|
||||
<thead>
|
||||
<tr className="border-b text-muted-foreground">
|
||||
<th className="py-2 pe-4 font-medium">نام</th>
|
||||
<th className="py-2 pe-4 font-medium">ایمیل</th>
|
||||
<th className="py-2 pe-4 font-medium">دوره</th>
|
||||
<th className="py-2 pe-4 font-medium">وضعیت</th>
|
||||
<th className="py-2 font-medium">تغییر وضعیت</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{leads.map((lead) => (
|
||||
<tr key={lead.id} className="border-b">
|
||||
<td className="py-3 pe-4">{lead.full_name}</td>
|
||||
<td className="py-3 pe-4 text-muted-foreground">{lead.email}</td>
|
||||
<td className="py-3 pe-4 text-muted-foreground">
|
||||
{lead.course_slug ?? "—"}
|
||||
</td>
|
||||
<td className="py-3 pe-4">
|
||||
<Badge variant={STATUS_VARIANTS[lead.status] ?? "secondary"}>
|
||||
{LEAD_STATUS_LABELS[lead.status] ?? lead.status}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="py-3">
|
||||
<Select
|
||||
value={lead.status}
|
||||
onValueChange={(v) => v && changeStatus(lead.id, v)}
|
||||
>
|
||||
<SelectTrigger className="w-40">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="new">جدید</SelectItem>
|
||||
<SelectItem value="contacted">تماس گرفته شد</SelectItem>
|
||||
<SelectItem value="enrolled">ثبتنام شد</SelectItem>
|
||||
<SelectItem value="rejected">رد شد</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function LogoutButton() {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function handleLogout() {
|
||||
setLoading(true);
|
||||
try {
|
||||
await fetch("/api/admin/logout", { method: "POST" });
|
||||
} catch {
|
||||
// ignore network errors — still navigate to login
|
||||
} finally {
|
||||
router.push("/admin/login");
|
||||
router.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Button variant="ghost" size="sm" onClick={handleLogout} disabled={loading}>
|
||||
{loading ? "…" : "خروج"}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
|
||||
function buildUrl(search: string, published: string) {
|
||||
const params = new URLSearchParams();
|
||||
if (search.trim()) params.set("search", search.trim());
|
||||
if (published && published !== "all") params.set("published", published);
|
||||
const qs = params.toString();
|
||||
return qs ? `/admin/courses?${qs}` : "/admin/courses";
|
||||
}
|
||||
|
||||
export function CourseFilters({
|
||||
initialSearch,
|
||||
initialPublished,
|
||||
}: {
|
||||
initialSearch: string;
|
||||
initialPublished: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [search, setSearch] = useState(initialSearch);
|
||||
const [published, setPublished] = useState(initialPublished);
|
||||
const hasFilters = Boolean(initialSearch.trim()) || initialPublished !== "all";
|
||||
|
||||
function apply(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
router.push(buildUrl(search, published));
|
||||
}
|
||||
|
||||
function clear() {
|
||||
setSearch("");
|
||||
setPublished("all");
|
||||
router.push("/admin/courses");
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
onSubmit={apply}
|
||||
className="flex flex-wrap items-end gap-3"
|
||||
>
|
||||
<div className="w-full max-w-xs space-y-1.5">
|
||||
<label htmlFor="course-search" className="text-sm font-medium">
|
||||
جستجو
|
||||
</label>
|
||||
<Input
|
||||
id="course-search"
|
||||
placeholder="عنوان یا اسلاگ دوره..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full max-w-[12rem] space-y-1.5">
|
||||
<label htmlFor="course-published" className="text-sm font-medium">
|
||||
وضعیت انتشار
|
||||
</label>
|
||||
<Select value={published} onValueChange={(v) => setPublished(v ?? "all")}>
|
||||
<SelectTrigger id="course-published" className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">همه</SelectItem>
|
||||
<SelectItem value="true">منتشرشده</SelectItem>
|
||||
<SelectItem value="false">پیشنویس</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<Button type="submit">اعمال فیلتر</Button>
|
||||
{hasFilters && (
|
||||
<Button type="button" variant="ghost" onClick={clear}>
|
||||
پاککردن فیلترها
|
||||
</Button>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { cn } from "@/lib/utils";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import type { AdminCourse } from "@/lib/data/admin/courses";
|
||||
import { AdminFormCard } from "@/components/organisms/admin/AdminPage";
|
||||
|
||||
type Payload = {
|
||||
slug: string;
|
||||
title: string;
|
||||
summary: string;
|
||||
category: string;
|
||||
durationHours: number;
|
||||
format: string;
|
||||
price: number | null;
|
||||
registrationUrl: string;
|
||||
imageUrl: string;
|
||||
seoDescription: string;
|
||||
published: boolean;
|
||||
};
|
||||
|
||||
interface CourseFormProps {
|
||||
initial?: AdminCourse;
|
||||
}
|
||||
|
||||
export function CourseForm({ initial }: CourseFormProps) {
|
||||
const router = useRouter();
|
||||
const isEdit = Boolean(initial);
|
||||
const [form, setForm] = useState<Payload>({
|
||||
slug: initial?.slug ?? "",
|
||||
title: initial?.title ?? "",
|
||||
summary: initial?.summary ?? "",
|
||||
category: initial?.category ?? "leadership",
|
||||
durationHours: initial?.durationHours ?? 16,
|
||||
format: initial?.format ?? "online",
|
||||
price: initial?.price ?? null,
|
||||
registrationUrl: initial?.registrationUrl ?? "/register/",
|
||||
imageUrl: initial?.imageUrl ?? "",
|
||||
seoDescription: initial?.seoDescription ?? "",
|
||||
published: initial?.published ?? true,
|
||||
});
|
||||
const [priceInput, setPriceInput] = useState(
|
||||
initial?.price != null ? String(initial.price) : "",
|
||||
);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
function set<K extends keyof Payload>(key: K, value: Payload[K]) {
|
||||
setForm((f) => ({ ...f, [key]: value }));
|
||||
}
|
||||
|
||||
function onPriceChange(raw: string) {
|
||||
setPriceInput(raw);
|
||||
const trimmed = raw.trim();
|
||||
if (trimmed === "") {
|
||||
set("price", null);
|
||||
return;
|
||||
}
|
||||
const n = Number(trimmed.replace(/,/g, ""));
|
||||
set("price", Number.isFinite(n) ? Math.round(n) : null);
|
||||
}
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
setError("");
|
||||
try {
|
||||
const res = await fetch(
|
||||
isEdit ? `/api/admin/courses/${initial!.id}` : "/api/admin/courses",
|
||||
{
|
||||
method: isEdit ? "PATCH" : "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(form),
|
||||
},
|
||||
);
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در ذخیره دوره");
|
||||
return;
|
||||
}
|
||||
router.push("/admin/courses");
|
||||
router.refresh();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<AdminFormCard
|
||||
title={isEdit ? "ویرایش دوره" : "ثبت دوره جدید"}
|
||||
description="فیلدهای ستارهدار الزامیاند. قیمت اختیاری است."
|
||||
footer={
|
||||
<>
|
||||
<Button type="submit" disabled={loading}>
|
||||
{loading ? "در حال ذخیره..." : isEdit ? "ذخیره تغییرات" : "ایجاد دوره"}
|
||||
</Button>
|
||||
<Link
|
||||
href="/admin/courses"
|
||||
className={cn(buttonVariants({ variant: "outline" }))}
|
||||
>
|
||||
انصراف
|
||||
</Link>
|
||||
</>
|
||||
}
|
||||
>
|
||||
{error ? (
|
||||
<p
|
||||
className="mb-6 rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive"
|
||||
role="alert"
|
||||
>
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="space-y-8">
|
||||
<section className="space-y-4">
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold text-foreground">اطلاعات اصلی</h2>
|
||||
<p className="mt-0.5 text-xs text-muted-foreground">
|
||||
شناسه، عنوان و خلاصهٔ نمایشی دوره
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="slug">اسلاگ</Label>
|
||||
<Input
|
||||
id="slug"
|
||||
value={form.slug}
|
||||
onChange={(e) => set("slug", e.target.value)}
|
||||
placeholder="ai-for-managers"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="title">عنوان</Label>
|
||||
<Input
|
||||
id="title"
|
||||
value={form.title}
|
||||
onChange={(e) => set("title", e.target.value)}
|
||||
placeholder="هوش مصنوعی برای مدیران"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5 sm:col-span-2">
|
||||
<Label htmlFor="summary">خلاصه</Label>
|
||||
<Textarea
|
||||
id="summary"
|
||||
value={form.summary}
|
||||
onChange={(e) => set("summary", e.target.value)}
|
||||
rows={3}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<Separator />
|
||||
|
||||
<section className="space-y-4">
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold text-foreground">برگزاری و قیمت</h2>
|
||||
<p className="mt-0.5 text-xs text-muted-foreground">
|
||||
دسته، قالب، مدت و هزینهٔ اختیاری
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-3">
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="category">دستهبندی</Label>
|
||||
<Select value={form.category} onValueChange={(v) => v && set("category", v)}>
|
||||
<SelectTrigger id="category" className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="leadership">رهبری</SelectItem>
|
||||
<SelectItem value="technology">فناوری</SelectItem>
|
||||
<SelectItem value="innovation">نوآوری</SelectItem>
|
||||
<SelectItem value="energy">انرژی</SelectItem>
|
||||
<SelectItem value="design">طراحی</SelectItem>
|
||||
<SelectItem value="digital">دیجیتال</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="format">قالب برگزاری</Label>
|
||||
<Select value={form.format} onValueChange={(v) => v && set("format", v)}>
|
||||
<SelectTrigger id="format" className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="online">آنلاین</SelectItem>
|
||||
<SelectItem value="blended">ترکیبی</SelectItem>
|
||||
<SelectItem value="in-person">حضوری</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="durationHours">مدت (ساعت)</Label>
|
||||
<Input
|
||||
id="durationHours"
|
||||
type="number"
|
||||
min={1}
|
||||
value={form.durationHours}
|
||||
onChange={(e) => set("durationHours", Number(e.target.value))}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5 sm:col-span-3">
|
||||
<Label htmlFor="price">قیمت (تومان)</Label>
|
||||
<Input
|
||||
id="price"
|
||||
type="number"
|
||||
min={0}
|
||||
inputMode="numeric"
|
||||
value={priceInput}
|
||||
onChange={(e) => onPriceChange(e.target.value)}
|
||||
placeholder="خالی = بدون نمایش قیمت"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
اگر خالی بماند، قیمت در سایت نمایش داده نمیشود.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<Separator />
|
||||
|
||||
<section className="space-y-4">
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold text-foreground">رسانه و انتشار</h2>
|
||||
<p className="mt-0.5 text-xs text-muted-foreground">
|
||||
لینک ثبتنام، تصویر، SEO و وضعیت انتشار
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-1.5 sm:col-span-2">
|
||||
<Label htmlFor="registrationUrl">لینک ثبتنام</Label>
|
||||
<Input
|
||||
id="registrationUrl"
|
||||
value={form.registrationUrl}
|
||||
onChange={(e) => set("registrationUrl", e.target.value)}
|
||||
placeholder="/register/ai-for-managers"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5 sm:col-span-2">
|
||||
<Label htmlFor="imageUrl">آدرس تصویر</Label>
|
||||
<Input
|
||||
id="imageUrl"
|
||||
value={form.imageUrl}
|
||||
onChange={(e) => set("imageUrl", e.target.value)}
|
||||
placeholder="/images/courses/..."
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5 sm:col-span-2">
|
||||
<Label htmlFor="seoDescription">توضیح SEO</Label>
|
||||
<Textarea
|
||||
id="seoDescription"
|
||||
value={form.seoDescription}
|
||||
onChange={(e) => set("seoDescription", e.target.value)}
|
||||
rows={2}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="published">وضعیت انتشار</Label>
|
||||
<Select
|
||||
value={form.published ? "true" : "false"}
|
||||
onValueChange={(v) => set("published", (v ?? "true") === "true")}
|
||||
>
|
||||
<SelectTrigger id="published" className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="true">منتشرشده</SelectItem>
|
||||
<SelectItem value="false">پیشنویس</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</AdminFormCard>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import Link from "next/link";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import type { AdminCourse } from "@/lib/data/admin/courses";
|
||||
import { categoryLabel, formatCoursePrice, formatLabel } from "@/lib/labels";
|
||||
import { PublishToggle } from "@/components/organisms/admin/courses/PublishToggle";
|
||||
import { DeleteCourseDialog } from "@/components/organisms/admin/courses/DeleteCourseDialog";
|
||||
|
||||
export function CourseTable({ courses }: { courses: AdminCourse[] }) {
|
||||
if (courses.length === 0) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center px-6 py-14 text-center">
|
||||
<p className="text-sm font-medium text-foreground">دورهای یافت نشد</p>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
فیلتر را تغییر دهید یا دوره جدیدی بسازید.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>عنوان</TableHead>
|
||||
<TableHead>دسته</TableHead>
|
||||
<TableHead>قالب</TableHead>
|
||||
<TableHead>مدت (ساعت)</TableHead>
|
||||
<TableHead>قیمت</TableHead>
|
||||
<TableHead>انتشار</TableHead>
|
||||
<TableHead>عملیات</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{courses.map((course) => (
|
||||
<TableRow key={course.id}>
|
||||
<TableCell className="font-medium">{course.title}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="secondary">{categoryLabel(course.category)}</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{formatLabel(course.format)}
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{course.durationHours ?? "—"}
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{formatCoursePrice(course.price) ?? "—"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<PublishToggle id={course.id} published={course.published} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-2">
|
||||
<Link
|
||||
href={`/admin/courses/${course.id}/edit`}
|
||||
className="text-sm text-primary hover:underline"
|
||||
>
|
||||
ویرایش
|
||||
</Link>
|
||||
{course.published && (
|
||||
<Link
|
||||
href={`/register/${course.slug}`}
|
||||
className="text-sm text-muted-foreground hover:underline"
|
||||
>
|
||||
پیشنمایش
|
||||
</Link>
|
||||
)}
|
||||
<DeleteCourseDialog id={course.id} title={course.title} />
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
|
||||
export function DeleteCourseDialog({ id, title }: { id: string; title: string }) {
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function handleDelete() {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
try {
|
||||
const res = await fetch(`/api/admin/courses/${id}`, { method: "DELETE" });
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در حذف دوره");
|
||||
return;
|
||||
}
|
||||
setOpen(false);
|
||||
router.refresh();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger render={<Button variant="ghost" size="sm" />}>
|
||||
حذف
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>حذف دوره</DialogTitle>
|
||||
<DialogDescription>
|
||||
دوره «{title}» برای همیشه حذف میشود. این عمل قابل بازگشت نیست.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => setOpen(false)}>
|
||||
انصراف
|
||||
</Button>
|
||||
<Button type="button" variant="destructive" onClick={handleDelete} disabled={loading}>
|
||||
{loading ? "در حال حذف..." : "حذف دوره"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function PublishToggle({ id, published }: { id: string; published: boolean }) {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function toggle() {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
try {
|
||||
const res = await fetch(`/api/admin/courses/${id}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ published: !published }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در ذخیره وضعیت");
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant={published ? "outline" : "ghost"}
|
||||
onClick={toggle}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? "..." : published ? "منتشرشده" : "پیشنویس"}
|
||||
</Button>
|
||||
{error && <p className="mt-1 max-w-40 text-xs text-red-600">{error}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
|
||||
export function GenericDeleteDialog({
|
||||
apiPath,
|
||||
id,
|
||||
noun,
|
||||
subject,
|
||||
}: {
|
||||
apiPath: string;
|
||||
id: string;
|
||||
noun: string;
|
||||
subject: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function handleDelete() {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
try {
|
||||
const res = await fetch(`${apiPath}/${id}`, { method: "DELETE" });
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در حذف");
|
||||
return;
|
||||
}
|
||||
setOpen(false);
|
||||
router.refresh();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger render={<Button variant="ghost" size="sm" />}>
|
||||
حذف
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>حذف {noun}</DialogTitle>
|
||||
<DialogDescription>
|
||||
«{subject}» برای همیشه حذف میشود. این عمل قابل بازگشت نیست.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => setOpen(false)}>
|
||||
انصراف
|
||||
</Button>
|
||||
<Button type="button" variant="destructive" onClick={handleDelete} disabled={loading}>
|
||||
{loading ? "در حال حذف..." : `حذف ${noun}`}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
|
||||
function buildUrl(entity: string, search: string, published: string) {
|
||||
const params = new URLSearchParams();
|
||||
if (search.trim()) params.set("search", search.trim());
|
||||
if (published && published !== "all") params.set("published", published);
|
||||
const qs = params.toString();
|
||||
return qs ? `/admin/${entity}?${qs}` : `/admin/${entity}`;
|
||||
}
|
||||
|
||||
export function GenericFilters({
|
||||
entity,
|
||||
searchHint,
|
||||
hasPublished,
|
||||
initialSearch,
|
||||
initialPublished,
|
||||
}: {
|
||||
entity: string;
|
||||
searchHint: string;
|
||||
hasPublished: boolean;
|
||||
initialSearch: string;
|
||||
initialPublished: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [search, setSearch] = useState(initialSearch);
|
||||
const [published, setPublished] = useState(initialPublished);
|
||||
const hasFilters = Boolean(initialSearch.trim()) || initialPublished !== "all";
|
||||
|
||||
function apply(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
router.push(buildUrl(entity, search, published));
|
||||
}
|
||||
|
||||
function clear() {
|
||||
setSearch("");
|
||||
setPublished("all");
|
||||
router.push(`/admin/${entity}`);
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={apply} className="flex flex-wrap items-end gap-3">
|
||||
<div className="w-full max-w-xs space-y-1.5">
|
||||
<label htmlFor={`${entity}-search`} className="text-sm font-medium">
|
||||
جستجو
|
||||
</label>
|
||||
<Input
|
||||
id={`${entity}-search`}
|
||||
placeholder={searchHint}
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{hasPublished && (
|
||||
<div className="w-full max-w-[12rem] space-y-1.5">
|
||||
<label htmlFor={`${entity}-published`} className="text-sm font-medium">
|
||||
وضعیت انتشار
|
||||
</label>
|
||||
<Select value={published} onValueChange={(v) => setPublished(v ?? "all")}>
|
||||
<SelectTrigger id={`${entity}-published`} className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">همه</SelectItem>
|
||||
<SelectItem value="true">منتشرشده</SelectItem>
|
||||
<SelectItem value="false">پیشنویس</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
<Button type="submit">اعمال فیلتر</Button>
|
||||
{hasFilters && (
|
||||
<Button type="button" variant="ghost" onClick={clear}>
|
||||
پاککردن فیلترها
|
||||
</Button>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { cn } from "@/lib/utils";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
type AdminFieldSpec,
|
||||
type GenericFormSpec,
|
||||
} from "@/lib/admin/entities";
|
||||
import { AdminFormCard } from "@/components/organisms/admin/AdminPage";
|
||||
|
||||
function defaultValue(field: AdminFieldSpec): unknown {
|
||||
if (field.type === "stringList") return [];
|
||||
if (field.type === "boolean") return Boolean(field.defaultValue ?? false);
|
||||
return field.defaultValue ?? "";
|
||||
}
|
||||
|
||||
function finalValue(field: AdminFieldSpec, value: unknown): unknown {
|
||||
if (field.type === "stringList") {
|
||||
return (value as string[]).map((s) => s.trim()).filter(Boolean);
|
||||
}
|
||||
if (field.type === "number") return Number(value);
|
||||
if (field.type === "boolean") return value;
|
||||
// optional empty text/date becomes null (e.g. event endDate, program tagline)
|
||||
if (!field.required && value === "") return null;
|
||||
return value;
|
||||
}
|
||||
|
||||
export function GenericForm({
|
||||
spec,
|
||||
initial,
|
||||
}: {
|
||||
spec: GenericFormSpec;
|
||||
initial?: unknown;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const data = (initial ?? {}) as Record<string, unknown>;
|
||||
const isEdit = Boolean(initial);
|
||||
const editId = data[spec.idColumn];
|
||||
|
||||
const [form, setForm] = useState<Record<string, unknown>>(() => {
|
||||
const state: Record<string, unknown> = {};
|
||||
for (const field of spec.fields) {
|
||||
state[field.name] = data[field.name] !== undefined ? data[field.name] : defaultValue(field);
|
||||
}
|
||||
return state;
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
function set(name: string, value: unknown) {
|
||||
setForm((f) => ({ ...f, [name]: value }));
|
||||
}
|
||||
|
||||
function setListItem(name: string, index: number, value: string) {
|
||||
setForm((f) => {
|
||||
const list = [...((f[name] as string[]) ?? [])];
|
||||
list[index] = value;
|
||||
return { ...f, [name]: list };
|
||||
});
|
||||
}
|
||||
|
||||
function addListItem(name: string) {
|
||||
setForm((f) => ({ ...f, [name]: [...((f[name] as string[]) ?? []), ""] }));
|
||||
}
|
||||
|
||||
function removeListItem(name: string, index: number) {
|
||||
setForm((f) => ({
|
||||
...f,
|
||||
[name]: ((f[name] as string[]) ?? []).filter((_, i) => i !== index),
|
||||
}));
|
||||
}
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
setError("");
|
||||
|
||||
const payload: Record<string, unknown> = {};
|
||||
for (const field of spec.fields) {
|
||||
payload[field.name] = finalValue(field, form[field.name]);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(isEdit ? `${spec.apiPath}/${editId}` : spec.apiPath, {
|
||||
method: isEdit ? "PATCH" : "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در ذخیره");
|
||||
return;
|
||||
}
|
||||
router.push(`/admin/${spec.key}`);
|
||||
router.refresh();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
function renderControl(field: AdminFieldSpec) {
|
||||
const value = form[field.name];
|
||||
|
||||
switch (field.type) {
|
||||
case "textarea":
|
||||
return (
|
||||
<Textarea
|
||||
value={String(value ?? "")}
|
||||
onChange={(e) => set(field.name, e.target.value)}
|
||||
rows={4}
|
||||
required={field.required}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
case "number":
|
||||
return (
|
||||
<Input
|
||||
type="number"
|
||||
value={Number(value ?? 0)}
|
||||
onChange={(e) => set(field.name, Number(e.target.value))}
|
||||
required={field.required}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
case "date":
|
||||
return (
|
||||
<Input
|
||||
type="date"
|
||||
value={String(value ?? "")}
|
||||
onChange={(e) => set(field.name, e.target.value)}
|
||||
required={field.required}
|
||||
/>
|
||||
);
|
||||
case "select":
|
||||
return (
|
||||
<Select value={String(value ?? "")} onValueChange={(v) => v && set(field.name, v)}>
|
||||
<SelectTrigger id={field.name} className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{(field.options ?? []).map((opt) => (
|
||||
<SelectItem key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
case "boolean": {
|
||||
const options = field.options ?? [
|
||||
{ value: "true", label: "بله" },
|
||||
{ value: "false", label: "خیر" },
|
||||
];
|
||||
return (
|
||||
<Select
|
||||
value={Boolean(value) ? "true" : "false"}
|
||||
onValueChange={(v) => set(field.name, v === "true")}
|
||||
>
|
||||
<SelectTrigger id={field.name} className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{options.map((opt) => (
|
||||
<SelectItem key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
case "stringList":
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{((value as string[]) ?? []).map((item, index) => (
|
||||
<div key={index} className="flex gap-2">
|
||||
<Input
|
||||
value={item}
|
||||
onChange={(e) => setListItem(field.name, index, e.target.value)}
|
||||
placeholder={field.placeholder ?? "مورد…"}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => removeListItem(field.name, index)}
|
||||
>
|
||||
حذف
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
<Button type="button" variant="outline" size="sm" onClick={() => addListItem(field.name)}>
|
||||
+ افزودن مورد
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
default:
|
||||
return (
|
||||
<Input
|
||||
value={String(value ?? "")}
|
||||
onChange={(e) => set(field.name, e.target.value)}
|
||||
required={field.required}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<AdminFormCard
|
||||
title={isEdit ? `ویرایش ${spec.noun}` : `ثبت ${spec.noun} جدید`}
|
||||
description="پس از ذخیره، فهرست بهروز میشود."
|
||||
footer={
|
||||
<>
|
||||
<Button type="submit" disabled={loading}>
|
||||
{loading
|
||||
? "در حال ذخیره..."
|
||||
: isEdit
|
||||
? "ذخیره تغییرات"
|
||||
: `ایجاد ${spec.noun}`}
|
||||
</Button>
|
||||
<Link
|
||||
href={`/admin/${spec.key}`}
|
||||
className={cn(buttonVariants({ variant: "outline" }))}
|
||||
>
|
||||
انصراف
|
||||
</Link>
|
||||
</>
|
||||
}
|
||||
>
|
||||
{error ? (
|
||||
<p
|
||||
className="mb-6 rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive"
|
||||
role="alert"
|
||||
>
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="grid gap-5 sm:grid-cols-2">
|
||||
{spec.fields.map((field) => (
|
||||
<div
|
||||
key={field.name}
|
||||
className={field.full ? "space-y-1.5 sm:col-span-2" : "space-y-1.5"}
|
||||
>
|
||||
<Label htmlFor={field.name}>{field.label}</Label>
|
||||
{renderControl(field)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</AdminFormCard>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import Link from "next/link";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import type { AdminEntitySpec } from "@/lib/admin/entities";
|
||||
import { PublishToggle } from "@/components/organisms/admin/generic/PublishToggle";
|
||||
import { GenericDeleteDialog } from "@/components/organisms/admin/generic/GenericDeleteDialog";
|
||||
|
||||
function truncate(value: unknown, max = 60): string {
|
||||
const text = String(value ?? "—");
|
||||
return text.length > max ? `${text.slice(0, max)}…` : text;
|
||||
}
|
||||
|
||||
export function GenericTable({ spec, rows }: { spec: AdminEntitySpec; rows: unknown[] }) {
|
||||
if (rows.length === 0) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center px-6 py-14 text-center">
|
||||
<p className="text-sm font-medium text-foreground">موردی یافت نشد</p>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
هنوز محتوایی برای این بخش ثبت نشده است.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{spec.columns.map((col) => (
|
||||
<TableHead key={col.name}>{col.label}</TableHead>
|
||||
))}
|
||||
<TableHead>عملیات</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map((row) => {
|
||||
const r = row as Record<string, unknown>;
|
||||
const id = String(r[spec.idColumn] ?? "");
|
||||
const preview = spec.preview && r.published ? spec.preview(r) : null;
|
||||
return (
|
||||
<TableRow key={String(id)}>
|
||||
{spec.columns.map((col, i) => {
|
||||
const value = r[col.name];
|
||||
if (col.variant === "badge") {
|
||||
const label = col.map ? (col.map[String(value)] ?? String(value)) : String(value);
|
||||
const isPublish = col.name === "published";
|
||||
return (
|
||||
<TableCell key={col.name}>
|
||||
<Badge variant={isPublish || label === "پیشنویس" ? "outline" : "secondary"}>
|
||||
{value === null || value === undefined || value === "" ? "—" : label}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<TableCell
|
||||
key={col.name}
|
||||
className={i === 0 ? "font-medium" : "text-muted-foreground"}
|
||||
>
|
||||
<span title={String(value ?? "")}>{truncate(value)}</span>
|
||||
</TableCell>
|
||||
);
|
||||
})}
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-3">
|
||||
{spec.hasPublished && (
|
||||
<PublishToggle apiPath={spec.apiPath} id={id} published={Boolean(r.published)} />
|
||||
)}
|
||||
<Link
|
||||
href={`/admin/${spec.key}/${id}/edit`}
|
||||
className="text-sm text-primary hover:underline"
|
||||
>
|
||||
ویرایش
|
||||
</Link>
|
||||
{preview && (
|
||||
<Link
|
||||
href={preview}
|
||||
className="text-sm text-muted-foreground hover:underline"
|
||||
>
|
||||
پیشنمایش
|
||||
</Link>
|
||||
)}
|
||||
<GenericDeleteDialog apiPath={spec.apiPath} id={id} noun={spec.noun} subject={String(r[spec.columns[0].name] ?? "")} />
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function PublishToggle({
|
||||
apiPath,
|
||||
id,
|
||||
published,
|
||||
}: {
|
||||
apiPath: string;
|
||||
id: string;
|
||||
published: boolean;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function toggle() {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
try {
|
||||
const res = await fetch(`${apiPath}/${id}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ published: !published }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در ذخیره وضعیت");
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant={published ? "outline" : "ghost"}
|
||||
onClick={toggle}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? "..." : published ? "منتشرشده" : "پیشنویس"}
|
||||
</Button>
|
||||
{error && <p className="mt-1 max-w-40 text-xs text-red-600">{error}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
|
||||
function buildUrl(search: string, status: string) {
|
||||
const params = new URLSearchParams();
|
||||
if (search.trim()) params.set("search", search.trim());
|
||||
if (status && status !== "all") params.set("status", status);
|
||||
const qs = params.toString();
|
||||
return qs ? `/admin/registrations?${qs}` : "/admin/registrations";
|
||||
}
|
||||
|
||||
export function RegistrationFilters({
|
||||
initialSearch,
|
||||
initialStatus,
|
||||
}: {
|
||||
initialSearch: string;
|
||||
initialStatus: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [search, setSearch] = useState(initialSearch);
|
||||
const [status, setStatus] = useState(initialStatus);
|
||||
const hasFilters = Boolean(initialSearch.trim()) || initialStatus !== "all";
|
||||
|
||||
function apply(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
router.push(buildUrl(search, status));
|
||||
}
|
||||
|
||||
function clear() {
|
||||
setSearch("");
|
||||
setStatus("all");
|
||||
router.push("/admin/registrations");
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={apply} className="flex flex-wrap items-end gap-3">
|
||||
<div className="w-full max-w-xs space-y-1.5">
|
||||
<label htmlFor="reg-search" className="text-sm font-medium">
|
||||
جستجو
|
||||
</label>
|
||||
<Input
|
||||
id="reg-search"
|
||||
placeholder="نام، ایمیل یا اسلاگ دوره..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full max-w-[12rem] space-y-1.5">
|
||||
<label htmlFor="reg-status" className="text-sm font-medium">
|
||||
وضعیت
|
||||
</label>
|
||||
<Select value={status} onValueChange={(v) => setStatus(v ?? "all")}>
|
||||
<SelectTrigger id="reg-status" className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">همه</SelectItem>
|
||||
<SelectItem value="new">جدید</SelectItem>
|
||||
<SelectItem value="contacted">تماس گرفته شد</SelectItem>
|
||||
<SelectItem value="enrolled">ثبتنام شد</SelectItem>
|
||||
<SelectItem value="rejected">رد شد</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<Button type="submit">اعمال فیلتر</Button>
|
||||
{hasFilters && (
|
||||
<Button type="button" variant="ghost" onClick={clear}>
|
||||
پاککردن فیلترها
|
||||
</Button>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import type { AdminRegistration } from "@/lib/data/admin/registrations";
|
||||
import { LEAD_STATUS_LABELS } from "@/components/organisms/admin/LeadsList";
|
||||
|
||||
function statusVariant(status: string): "default" | "secondary" | "outline" | "destructive" {
|
||||
switch (status) {
|
||||
case "new":
|
||||
return "default";
|
||||
case "contacted":
|
||||
return "secondary";
|
||||
case "enrolled":
|
||||
return "outline";
|
||||
case "rejected":
|
||||
return "destructive";
|
||||
default:
|
||||
return "secondary";
|
||||
}
|
||||
}
|
||||
|
||||
function faDate(value: string): string {
|
||||
return new Date(value).toLocaleDateString("fa-IR");
|
||||
}
|
||||
|
||||
export function RegistrationsTable({ rows }: { rows: AdminRegistration[] }) {
|
||||
const router = useRouter();
|
||||
const [busyId, setBusyId] = useState<string | null>(null);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function changeStatus(id: string, status: string) {
|
||||
setBusyId(id);
|
||||
setError("");
|
||||
try {
|
||||
const res = await fetch(`/api/admin/registrations/${id}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در تغییر وضعیت");
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
} finally {
|
||||
setBusyId(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteLead(id: string) {
|
||||
setBusyId(id);
|
||||
setError("");
|
||||
try {
|
||||
const res = await fetch(`/api/admin/registrations/${id}`, { method: "DELETE" });
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
setError(data.error || "خطا در حذف لید");
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
} finally {
|
||||
setBusyId(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (rows.length === 0) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center px-6 py-14 text-center">
|
||||
<p className="text-sm font-medium text-foreground">درخواستی یافت نشد</p>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
فیلتر را تغییر دهید یا منتظر درخواست جدید بمانید.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-0">
|
||||
{error ? (
|
||||
<p className="border-b border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
<div className="overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>نام</TableHead>
|
||||
<TableHead>ایمیل</TableHead>
|
||||
<TableHead>تلفن</TableHead>
|
||||
<TableHead>دوره</TableHead>
|
||||
<TableHead>وضعیت</TableHead>
|
||||
<TableHead>تغییر وضعیت</TableHead>
|
||||
<TableHead>تاریخ</TableHead>
|
||||
<TableHead>عملیات</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map((lead) => (
|
||||
<TableRow key={lead.id}>
|
||||
<TableCell className="font-medium">{lead.full_name}</TableCell>
|
||||
<TableCell className="text-muted-foreground">{lead.email}</TableCell>
|
||||
<TableCell className="text-muted-foreground">{lead.phone ?? "—"}</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{lead.course_slug ?? "—"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={statusVariant(lead.status)}>
|
||||
{LEAD_STATUS_LABELS[lead.status] ?? lead.status}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Select value={lead.status} onValueChange={(v) => v && changeStatus(lead.id, v)}>
|
||||
<SelectTrigger className="w-40" disabled={busyId === lead.id}>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="new">جدید</SelectItem>
|
||||
<SelectItem value="contacted">تماس گرفته شد</SelectItem>
|
||||
<SelectItem value="enrolled">ثبتنام شد</SelectItem>
|
||||
<SelectItem value="rejected">رد شد</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">{faDate(lead.created_at)}</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={busyId === lead.id}
|
||||
onClick={() => deleteLead(lead.id)}
|
||||
>
|
||||
حذف
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user