This commit is contained in:
smhk1376 committed 2026-10-15 10:10:30 +03:30
1 parent a99af426db
commit 8886aa8640
91 files changed
+2823 -773

No files matched your search

@@ -15,73 +15,94 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
import type { Course } from "@/lib/types";
import { courseCatalogHref, courseTagHref } from "@/lib/course-nav";
import { courseCategories } from "@/lib/site-config";
import type { Course, TaxonomyRef } from "@/lib/types";
import {
courseCatalogHref,
courseCategoryHref,
courseTagHref,
} from "@/lib/course-nav";
import { formatCoursePrice, formatLabel } from "@/lib/labels";
import { cn } from "@/lib/utils";
export function CategoryCourseExplorer({
courses,
findLabel,
tagsLabel = "دسته‌بندی‌ها",
categoriesLabel = "دسته‌بندی‌ها",
tagsLabel = "تگ‌ها",
filterCategories,
filterTags,
initialTag = "",
initialCategory = "",
}: {
courses: Course[];
findLabel: string;
categoriesLabel?: string;
tagsLabel?: string;
/** From `/professional?tag=` — filters by course tag on first paint. */
filterCategories: TaxonomyRef[];
filterTags: TaxonomyRef[];
/** From `/professional?tag=` (slug). */
initialTag?: string;
/** From `/professional?category=` (slug). */
initialCategory?: string;
}) {
const router = useRouter();
const pathname = usePathname();
const [query, setQuery] = useState("");
const [category, setCategory] = useState("all");
const [tag, setTag] = useState(initialTag);
const [categorySlug, setCategorySlug] = useState(initialCategory);
const [tagSlug, setTagSlug] = useState(initialTag);
const deferredQuery = useDeferredValue(query);
const isStale = query !== deferredQuery;
const selectTag = (next: string) => {
setTag(next);
const syncUrl = (nextTag: string, nextCategory: string) => {
if (pathname !== "/professional" && !pathname.startsWith("/professional")) {
return;
}
const href = next ? courseTagHref(next) : courseCatalogHref();
router.replace(href, { scroll: false });
const params = new URLSearchParams();
if (nextTag) params.set("tag", nextTag);
if (nextCategory) params.set("category", nextCategory);
const qs = params.toString();
router.replace(qs ? `/professional?${qs}` : courseCatalogHref(), {
scroll: false,
});
};
// Distinct tags across all courses (stable order: most used first).
const tags = useMemo(() => {
const counts = new Map<string, number>();
for (const course of courses) {
for (const t of course.tags ?? []) {
counts.set(t, (counts.get(t) ?? 0) + 1);
}
}
return [...counts.entries()].sort((a, b) => b[1] - a[1]).map(([t]) => t);
}, [courses]);
const selectTag = (slug: string) => {
const next = tagSlug === slug ? "" : slug;
setTagSlug(next);
syncUrl(next, categorySlug);
};
const selectCategory = (slug: string) => {
const next = categorySlug === slug ? "" : slug;
setCategorySlug(next);
syncUrl(tagSlug, next);
};
const filtered = useMemo(() => {
return courses.filter((course) => {
const matchesCategory =
category === "all" ||
category === "best" ||
course.category === category;
const matchesTag = !tag || (course.tags ?? []).includes(tag);
!categorySlug ||
course.categories.some((c) => c.slug === categorySlug);
const matchesTag =
!tagSlug || course.tags.some((t) => t.slug === tagSlug);
const matchesQuery =
!deferredQuery ||
course.title.includes(deferredQuery) ||
course.summary.includes(deferredQuery);
return matchesCategory && matchesTag && matchesQuery;
});
}, [courses, category, tag, deferredQuery]);
}, [courses, categorySlug, tagSlug, deferredQuery]);
const resetFilters = () => {
setCategory("all");
setCategorySlug("");
setTagSlug("");
setQuery("");
selectTag("");
syncUrl("", "");
};
const activeCategory = filterCategories.find((c) => c.slug === categorySlug);
const activeTag = filterTags.find((t) => t.slug === tagSlug);
return (
<div className="space-y-8">
<form
@@ -104,31 +125,55 @@ export function CategoryCourseExplorer({
</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",
)}
{filterCategories.length > 0 ? (
<div className="space-y-3">
<span className="text-sm font-semibold text-background/80">
{categoriesLabel}
</span>
<div
className="flex flex-wrap gap-2"
role="tablist"
aria-label={categoriesLabel}
>
{item.label}
</Button>
))}
</div>
<Button
type="button"
role="tab"
size="sm"
variant={categorySlug === "" ? "default" : "ghost"}
aria-selected={categorySlug === ""}
onClick={() => {
setCategorySlug("");
syncUrl(tagSlug, "");
}}
className={cn(
categorySlug !== "" &&
"bg-background/10 text-background/85 hover:bg-background/20 hover:text-background",
)}
>
همه
</Button>
{filterCategories.map((item) => (
<Button
key={item.id}
type="button"
role="tab"
size="sm"
variant={categorySlug === item.slug ? "default" : "ghost"}
aria-selected={categorySlug === item.slug}
onClick={() => selectCategory(item.slug)}
className={cn(
categorySlug !== item.slug &&
"bg-background/10 text-background/85 hover:bg-background/20 hover:text-background",
)}
>
{item.label}
</Button>
))}
</div>
</div>
) : null}
{tags.length > 0 ? (
{filterTags.length > 0 ? (
<div className="space-y-3">
<div className="flex flex-wrap items-center gap-2">
<span className="text-sm font-semibold text-background/80">
@@ -137,75 +182,100 @@ export function CategoryCourseExplorer({
<Button
type="button"
size="sm"
variant={tag === "" ? "default" : "ghost"}
aria-selected={tag === ""}
onClick={() => selectTag("")}
variant={tagSlug === "" ? "default" : "ghost"}
aria-selected={tagSlug === ""}
onClick={() => {
setTagSlug("");
syncUrl("", categorySlug);
}}
className={cn(
tag !== "" &&
tagSlug !== "" &&
"bg-background/10 text-background/85 hover:bg-background/20 hover:text-background",
)}
>
همه
</Button>
{tags.map((item) => (
{filterTags.map((item) => (
<Button
key={item}
key={item.id}
type="button"
size="sm"
variant={tag === item ? "default" : "ghost"}
aria-selected={tag === item}
onClick={() => selectTag(tag === item ? "" : item)}
variant={tagSlug === item.slug ? "default" : "ghost"}
aria-selected={tagSlug === item.slug}
onClick={() => selectTag(item.slug)}
className={cn(
tag !== item &&
tagSlug !== item.slug &&
"bg-background/10 text-background/85 hover:bg-background/20 hover:text-background",
)}
>
{item}
{item.label}
</Button>
))}
</div>
{(tag !== "" || category !== "all") && (
<div className="flex flex-wrap items-center gap-2 text-xs text-background/60">
<span>فیلترهای فعال:</span>
{category !== "all" && (
<Badge variant="secondary" className="gap-1 py-0.5 pe-1">
{courseCategories.find((c) => c.id === category)?.label ?? category}
<button
type="button"
onClick={() => setCategory("all")}
className="rounded-full p-0.5 hover:bg-foreground/10"
aria-label="حذف فیلتر دسته‌بندی"
>
×
</button>
</Badge>
)}
{tag !== "" && (
<Badge variant="secondary" className="gap-1 py-0.5 pe-1">
{tag}
<button
type="button"
onClick={() => selectTag("")}
className="rounded-full p-0.5 hover:bg-foreground/10"
aria-label="حذف فیلتر تگ"
>
×
</button>
</Badge>
)}
<button
type="button"
onClick={resetFilters}
className="underline underline-offset-4 hover:text-background"
>
پاک‌کردن همه
</button>
</div>
)}
</div>
) : null}
{(tagSlug !== "" || categorySlug !== "") && (
<div className="flex flex-wrap items-center gap-2 text-xs text-background/60">
<span>فیلترهای فعال:</span>
{activeCategory ? (
<Badge variant="secondary" className="gap-1 py-0.5 pe-1">
{activeCategory.label}
<button
type="button"
onClick={() => {
setCategorySlug("");
syncUrl(tagSlug, "");
}}
className="rounded-full p-0.5 hover:bg-foreground/10"
aria-label="حذف فیلتر دسته"
>
×
</button>
</Badge>
) : null}
{activeTag ? (
<Badge variant="secondary" className="gap-1 py-0.5 pe-1">
{activeTag.label}
<button
type="button"
onClick={() => {
setTagSlug("");
syncUrl("", categorySlug);
}}
className="rounded-full p-0.5 hover:bg-foreground/10"
aria-label="حذف فیلتر تگ"
>
×
</button>
</Badge>
) : null}
<button
type="button"
onClick={resetFilters}
className="underline underline-offset-4 hover:text-background"
>
پاک‌کردن همه
</button>
{activeTag ? (
<Link
href={courseTagHref(activeTag.slug)}
className="sr-only"
>
{activeTag.label}
</Link>
) : null}
{activeCategory ? (
<Link
href={courseCategoryHref(activeCategory.slug)}
className="sr-only"
>
{activeCategory.label}
</Link>
) : null}
</div>
)}
{filtered.length === 0 ? (
<p className="py-10 text-center text-sm text-background/60">
دوره‌ای با این فیلترها یافت نشد.
@@ -247,19 +317,28 @@ export function CategoryCourseExplorer({
<CardDescription className="line-clamp-3 text-background/70">
{course.summary}
</CardDescription>
{course.tags && course.tags.length > 0 ? (
{(course.categories.length > 0 || course.tags.length > 0) && (
<div className="flex flex-wrap gap-1.5">
{course.tags.map((t) => (
{course.categories.map((c) => (
<Badge
key={t}
key={`cat:${c.id}`}
variant="outline"
className="border-background/25 text-[10px] text-background/80"
>
{t}
{c.label}
</Badge>
))}
{course.tags.map((t) => (
<Badge
key={`tag:${t.id}`}
variant="outline"
className="border-background/25 text-[10px] text-background/80"
>
{t.label}
</Badge>
))}
</div>
) : null}
)}
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-background/55">
<span>
{course.durationHours
@@ -286,4 +365,4 @@ export function CategoryCourseExplorer({
)}
</div>
);
}
}
+7 -6
View File
@@ -73,7 +73,7 @@ function NavDropdown({
</DropdownMenuTrigger>
<DropdownMenuContent className="z-[60] w-56 p-1" align="start">
{children.map((child) => (
<DropdownMenuItem key={child.href + child.label} className="p-0">
<DropdownMenuItem key={`nav:${child.href}:${child.label}`} className="p-0">
<Link
href={child.href}
className="w-full cursor-pointer px-1.5 py-1.5"
@@ -153,10 +153,11 @@ export function SiteHeader({
aria-label="منوی اصلی"
>
{items.map((item) => {
const itemKey = `nav:${item.href}:${item.label}`;
if (item.children && item.children.length > 0) {
return (
<NavDropdown
key={item.href + item.label}
key={itemKey}
item={item}
isDark={isDark}
/>
@@ -164,7 +165,7 @@ export function SiteHeader({
}
return item.prominent ? (
<NavLink
key={item.href + item.label}
key={itemKey}
item={item}
isDark={isDark}
className={cn(
@@ -176,7 +177,7 @@ export function SiteHeader({
/>
) : (
<NavLink
key={item.href + item.label}
key={itemKey}
item={item}
isDark={isDark}
className={cn(
@@ -260,7 +261,7 @@ export function SiteHeader({
<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}>
<li key={`nav:${item.href}:${item.label}`}>
{item.children && item.children.length > 0 ? (
<div className="py-2">
<p className="text-sm font-semibold text-background/55">
@@ -268,7 +269,7 @@ export function SiteHeader({
</p>
<ul className="mt-1 space-y-0.5 border-s border-background/20 ps-3">
{item.children.map((child) => (
<li key={child.href + child.label}>
<li key={`nav:${child.href}:${child.label}`}>
<NavLink
item={child}
isDark
+61 -40
View File
@@ -33,6 +33,7 @@ import {
} from "@/components/ui/sidebar";
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { LogoutButton } from "@/components/organisms/admin/LogoutButton";
import { isAdminEntityEnabled } from "@/lib/admin/disabled-entities";
const NAV_GROUPS = [
{
@@ -42,27 +43,39 @@ const NAV_GROUPS = [
{
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 },
{ href: "/admin/courses", label: "دوره‌ها", icon: BookOpen, entity: "courses" },
{
href: "/admin/course-categories",
label: "دسته‌بندی دوره‌ها",
icon: Tags,
entity: "course-categories",
},
{
href: "/admin/course-tags",
label: "تگ‌های دوره",
icon: Tags,
entity: "course-tags",
},
{ href: "/admin/programs", label: "برنامه‌ها", icon: GraduationCap, entity: "programs" },
{ href: "/admin/events", label: "رویدادها", icon: Calendar, entity: "events" },
{ href: "/admin/articles", label: "مقالات", icon: Newspaper, entity: "articles" },
{ href: "/admin/topics", label: "موضوعات", icon: Tags, entity: "topics" },
],
},
{
label: "جامعه",
items: [
{ href: "/admin/faculty", label: "اساتید", icon: Users },
{ href: "/admin/alumni", label: "دانش‌آموختگان", icon: MessageSquareQuote },
{ href: "/admin/faculty", label: "اساتید", icon: Users, entity: "faculty" },
{ href: "/admin/alumni", label: "دانش‌آموختگان", icon: MessageSquareQuote, entity: "alumni" },
],
},
{
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 },
{ href: "/admin/banners", label: "بنرهای کمپین", icon: Megaphone, entity: "banners" },
{ href: "/admin/stats", label: "آمار", icon: BarChart3, entity: "stats" },
{ href: "/admin/testimonials", label: "نظرات", icon: FileText, entity: "testimonials" },
{ href: "/admin/legal", label: "صفحات قانونی", icon: Scale, entity: "legal" },
],
},
{
@@ -117,35 +130,43 @@ export function AdminSidebar({ userName }: { userName: string }) {
</SidebarHeader>
<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>
))}
{NAV_GROUPS.map((group) => {
const items = group.items.filter(
(item) =>
!("entity" in item) ||
isAdminEntityEnabled(item.entity),
);
if (items.length === 0) return null;
return (
<SidebarGroup key={group.label}>
<SidebarGroupLabel>{group.label}</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{items.map((item) => {
const Icon = item.icon;
const active = isActive(
pathname,
item.href,
"exact" in item ? item.exact : false,
);
return (
<SidebarMenuItem key={item.href}>
<SidebarMenuButton
isActive={active}
tooltip={item.label}
render={<Link href={item.href} />}
>
<Icon />
<span>{item.label}</span>
</SidebarMenuButton>
</SidebarMenuItem>
);
})}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
);
})}
</SidebarContent>
<SidebarFooter className="p-3">
@@ -12,11 +12,17 @@ import {
SelectValue,
} from "@/components/ui/select";
function buildUrl(search: string, published: string, tag: string) {
function buildUrl(
search: string,
published: string,
tag: string,
category: string,
) {
const params = new URLSearchParams();
if (search.trim()) params.set("search", search.trim());
if (published && published !== "all") params.set("published", published);
if (tag && tag.trim()) params.set("tag", tag.trim());
if (category && category.trim()) params.set("category", category.trim());
const qs = params.toString();
return qs ? `/admin/courses?${qs}` : "/admin/courses";
}
@@ -25,36 +31,47 @@ export function CourseFilters({
initialSearch,
initialPublished,
initialTag,
initialCategory,
availableTags,
availableCategories,
}: {
initialSearch: string;
initialPublished: string;
initialTag: string;
availableTags: string[];
initialCategory: string;
availableTags: { id: string; slug: string; label: string }[];
availableCategories: { id: string; slug: string; label: string }[];
}) {
const router = useRouter();
const [search, setSearch] = useState(initialSearch);
const [published, setPublished] = useState(initialPublished);
const [tag, setTag] = useState(initialTag);
const hasFilters = Boolean(search.trim()) || published !== "all" || Boolean(tag.trim());
const [category, setCategory] = useState(initialCategory);
const hasFilters =
Boolean(search.trim()) ||
published !== "all" ||
Boolean(tag.trim()) ||
Boolean(category.trim());
function apply(e: React.FormEvent) {
e.preventDefault();
router.push(buildUrl(search, published, tag));
router.push(buildUrl(search, published, tag, category));
}
function clear() {
setSearch("");
setPublished("all");
setTag("");
setCategory("");
router.push("/admin/courses");
}
return (
<form onSubmit={apply} className="flex flex-wrap items-end gap-3">
{/* ... search input ... */}
<div className="w-full max-w-xs space-y-1.5">
<label htmlFor="course-search" className="text-sm font-medium">جستجو</label>
<label htmlFor="course-search" className="text-sm font-medium">
جستجو
</label>
<Input
id="course-search"
placeholder="عنوان یا اسلاگ..."
@@ -63,10 +80,14 @@ export function CourseFilters({
/>
</div>
{/* ... published select ... */}
<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")}>
<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>
@@ -78,26 +99,50 @@ export function CourseFilters({
</Select>
</div>
{/* ... tag select ... */}
<div className="w-full max-w-[12rem] space-y-1.5">
<label htmlFor="course-tag" className="text-sm font-medium">تگ</label>
<Select value={tag} onValueChange={(v) => setTag(v ?? "")}>
<label htmlFor="course-category" className="text-sm font-medium">
دسته
</label>
<Select value={category || "all"} onValueChange={(v) => setCategory(v === "all" ? "" : (v ?? ""))}>
<SelectTrigger id="course-category" className="w-full">
<SelectValue placeholder="همه" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">همه</SelectItem>
{availableCategories.map((c) => (
<SelectItem key={c.id} value={c.slug}>
{c.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="w-full max-w-[12rem] space-y-1.5">
<label htmlFor="course-tag" className="text-sm font-medium">
تگ
</label>
<Select value={tag || "all"} onValueChange={(v) => setTag(v === "all" ? "" : (v ?? ""))}>
<SelectTrigger id="course-tag" className="w-full">
<SelectValue placeholder="همه" />
</SelectTrigger>
<SelectContent>
<SelectItem value="">همه</SelectItem>
<SelectItem value="all">همه</SelectItem>
{availableTags.map((t) => (
<SelectItem key={t} value={t}>{t}</SelectItem>
<SelectItem key={t.id} value={t.slug}>
{t.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<Button type="submit">اعمال فیلتر</Button>
{hasFilters && (
<Button type="button" variant="ghost" onClick={clear}>پاک‌کردن فیلترها</Button>
)}
{hasFilters ? (
<Button type="button" variant="ghost" onClick={clear}>
پاک‌کردن فیلترها
</Button>
) : null}
</form>
);
}
}
@@ -17,19 +17,17 @@ import {
SelectValue,
} from "@/components/ui/select";
import { Badge } from "@/components/ui/badge";
import { Plus, X } from "lucide-react";
import type { AdminCourse } from "@/lib/data/admin/courses";
import type { AdminCourseCategory, AdminCourseTag } from "@/lib/data/admin/taxonomy";
import { AdminFormCard } from "@/components/organisms/admin/AdminPage";
import { ImageUploadField } from "@/components/organisms/admin/ImageUploadField";
import { courseNavTagOrder } from "@/lib/site-config";
const SUGGESTED_TAGS = courseNavTagOrder;
type Payload = {
slug: string;
title: string;
summary: string;
category: string;
categoryIds: string[];
tagIds: string[];
durationHours: number | null;
format: string;
price: number | null;
@@ -37,22 +35,28 @@ type Payload = {
posterImageUrl: string;
brochureImageUrl: string;
seoDescription: string;
tags: string[];
published: boolean;
};
interface CourseFormProps {
initial?: AdminCourse;
categories: AdminCourseCategory[];
tags: AdminCourseTag[];
}
export function CourseForm({ initial }: CourseFormProps) {
function toggleId(ids: string[], id: string): string[] {
return ids.includes(id) ? ids.filter((x) => x !== id) : [...ids, id];
}
export function CourseForm({ initial, categories, tags }: 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",
categoryIds: initial?.categoryIds ?? [],
tagIds: initial?.tagIds ?? [],
durationHours: initial?.durationHours ?? null,
format: initial?.format ?? "in-person",
price: initial?.price ?? null,
@@ -60,13 +64,11 @@ export function CourseForm({ initial }: CourseFormProps) {
posterImageUrl: initial?.posterImageUrl ?? "",
brochureImageUrl: initial?.brochureImageUrl ?? "",
seoDescription: initial?.seoDescription ?? "",
tags: initial?.tags ?? [],
published: initial?.published ?? true,
});
const [priceInput, setPriceInput] = useState(
initial?.price != null ? String(initial.price) : "",
);
const [customTagInput, setCustomTagInput] = useState("");
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
@@ -74,29 +76,6 @@ export function CourseForm({ initial }: CourseFormProps) {
setForm((f) => ({ ...f, [key]: value }));
}
function toggleTag(tag: string) {
setForm((f) => {
const exists = f.tags.includes(tag);
return {
...f,
tags: exists ? f.tags.filter((t) => t !== tag) : [...f.tags, tag],
};
});
}
function addCustomTag() {
const trimmed = customTagInput.trim();
if (!trimmed) return;
if (!form.tags.includes(trimmed)) {
set("tags", [...form.tags, trimmed]);
}
setCustomTagInput("");
}
function removeTag(tagToRemove: string) {
set("tags", form.tags.filter((t) => t !== tagToRemove));
}
function onPriceChange(raw: string) {
setPriceInput(raw);
const trimmed = raw.trim();
@@ -137,7 +116,7 @@ export function CourseForm({ initial }: CourseFormProps) {
<form onSubmit={handleSubmit}>
<AdminFormCard
title={isEdit ? "ویرایش دوره" : "ثبت دوره جدید"}
description="فیلدهای ستاره‌دار الزامی‌اند. قیمت اختیاری است."
description="فیلدهای ستاره‌دار الزامی‌اند. دسته و تگ از فهرست ادمین انتخاب می‌شوند."
footer={
<>
<Button type="submit" disabled={loading}>
@@ -152,284 +131,287 @@ export function CourseForm({ initial }: CourseFormProps) {
</>
}
>
<div className="space-y-8">
{error ? (
<p
className="mb-6 rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive"
role="alert"
>
<p className="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">
شناسه، عنوان و خلاصهٔ نمایشی دوره
<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)}
required
placeholder="ai-fluency"
/>
</div>
<div className="space-y-1.5 sm:col-span-2">
<Label htmlFor="title">عنوان *</Label>
<Input
id="title"
value={form.title}
onChange={(e) => set("title", e.target.value)}
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)}
required
rows={3}
/>
</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="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) => {
const raw = e.target.value;
set("durationHours", raw === "" ? null : Number(raw));
}}
placeholder="اختیاری"
/>
</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="خالی = بدون نمایش قیمت"
/>
</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="space-y-2">
<Label>دسته‌بندی‌ها</Label>
{categories.length === 0 ? (
<p className="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 className="flex flex-wrap gap-2">
{categories.map((item) => {
const active = form.categoryIds.includes(item.id);
return (
<Button
key={item.id}
type="button"
size="sm"
variant={active ? "default" : "outline"}
aria-pressed={active}
onClick={() => set("categoryIds", toggleId(form.categoryIds, item.id))}
className="h-8 px-3 text-xs"
>
{item.label}
</Button>
);
})}
</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="technology">هوش مصنوعی و تحول سازمان</SelectItem>
<SelectItem value="digital">برند و بازاریابی</SelectItem>
<SelectItem value="innovation">برندینگ</SelectItem>
<SelectItem value="leadership">هم‌اندیشی مدیریتی</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) => {
const raw = e.target.value;
set(
"durationHours",
raw === "" ? null : Number(raw),
);
}}
placeholder="اختیاری"
/>
</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">
برچسب‌هایی که دوره در فیلترها و دسته‌بندی سایت نمایش داده می‌شود (مثلاً کارگاه‌ها، دوره‌های سازمانی، گزیده دوره‌های برگزارشده)
</p>
</div>
<div className="space-y-3">
<div>
<Label className="text-xs text-muted-foreground">تگ‌های پیشنهادی</Label>
<div className="mt-2 flex flex-wrap gap-2">
{SUGGESTED_TAGS.map((tag) => {
const active = form.tags.includes(tag);
return (
<Button
key={tag}
)}
{form.categoryIds.length > 0 ? (
<div className="flex flex-wrap gap-1.5 pt-1">
{form.categoryIds.map((id) => {
const item = categories.find((c) => c.id === id);
return (
<Badge key={id} variant="secondary" className="gap-1 py-1 pe-1">
{item?.label ?? id}
<button
type="button"
size="sm"
variant={active ? "default" : "outline"}
aria-pressed={active}
onClick={() => toggleTag(tag)}
className="h-8 px-3 text-xs"
onClick={() =>
set(
"categoryIds",
form.categoryIds.filter((x) => x !== id),
)
}
className="rounded-full p-0.5 hover:bg-foreground/10"
aria-label="حذف دسته"
>
{tag}
</Button>
);
})}
</div>
×
</button>
</Badge>
);
})}
</div>
) : null}
</div>
<div className="flex items-end gap-2">
<div className="flex-1 space-y-1.5">
<Label htmlFor="newTag">افزودن تگ دلخواه</Label>
<Input
id="newTag"
value={customTagInput}
onChange={(e) => setCustomTagInput(e.target.value)}
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault();
addCustomTag();
}
}}
placeholder="مثلاً دوره‌های ویژه مدیران"
/>
</div>
<Button
type="button"
variant="outline"
onClick={addCustomTag}
className="shrink-0"
>
<Plus className="size-4" />
افزودن
</Button>
</div>
<div className="space-y-1.5">
<Label className="text-xs text-muted-foreground">
تگ‌های این دوره ({form.tags.length})
</Label>
{form.tags.length > 0 ? (
<div className="flex flex-wrap gap-1.5">
{form.tags.map((tag) => (
<Badge key={tag} variant="secondary" className="gap-1 py-1 pe-1">
{tag}
<button
type="button"
onClick={() => removeTag(tag)}
className="rounded-full p-0.5 transition-colors hover:bg-foreground/10"
aria-label={`حذف تگ ${tag}`}
>
<X className="size-3" />
</button>
</Badge>
))}
</div>
) : (
<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 و وضعیت انتشار
<div className="space-y-2">
<Label>تگ‌ها</Label>
{tags.length === 0 ? (
<p className="text-xs text-muted-foreground">
هنوز تگی تعریف نشده. از «تگ‌های دوره» اضافه کنید.
</p>
) : (
<div className="flex flex-wrap gap-2">
{tags.map((item) => {
const active = form.tagIds.includes(item.id);
return (
<Button
key={item.id}
type="button"
size="sm"
variant={active ? "default" : "outline"}
aria-pressed={active}
onClick={() => set("tagIds", toggleId(form.tagIds, item.id))}
className="h-8 px-3 text-xs"
>
{item.label}
</Button>
);
})}
</div>
)}
{form.tagIds.length > 0 ? (
<div className="flex flex-wrap gap-1.5 pt-1">
{form.tagIds.map((id) => {
const item = tags.find((t) => t.id === id);
return (
<Badge key={id} variant="secondary" className="gap-1 py-1 pe-1">
{item?.label ?? id}
<button
type="button"
onClick={() =>
set(
"tagIds",
form.tagIds.filter((x) => x !== id),
)
}
className="rounded-full p-0.5 hover:bg-foreground/10"
aria-label="حذف تگ"
>
×
</button>
</Badge>
);
})}
</div>
) : null}
</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)}
required
/>
</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="posterImageUrl">پوستر (نمایش در لیست دوره‌ها)</Label>
<ImageUploadField
id="posterImageUrl"
value={form.posterImageUrl}
onChange={(url) => set("posterImageUrl", url)}
folder="courses"
disabled={loading}
/>
</div>
<div className="space-y-1.5 sm:col-span-2">
<Label htmlFor="brochureImageUrl">بروشور (نمایش در صفحه جزئیات)</Label>
<ImageUploadField
id="brochureImageUrl"
value={form.brochureImageUrl}
onChange={(url) => set("brochureImageUrl", url)}
folder="courses"
disabled={loading}
/>
</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 className="space-y-1.5 sm:col-span-2">
<Label>پوستر</Label>
<ImageUploadField
id="posterImageUrl"
value={form.posterImageUrl}
onChange={(url) => set("posterImageUrl", url)}
folder="courses"
/>
</div>
</section>
<div className="space-y-1.5 sm:col-span-2">
<Label>بروشور</Label>
<ImageUploadField
id="brochureImageUrl"
value={form.brochureImageUrl}
onChange={(url) => set("brochureImageUrl", url)}
folder="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={3}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="published">وضعیت انتشار</Label>
<Select
value={form.published ? "true" : "false"}
onValueChange={(v) => set("published", v === "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>
);
}
}
@@ -9,7 +9,7 @@ import {
} 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 { formatCoursePrice, formatLabel } from "@/lib/labels";
import { PublishToggle } from "@/components/organisms/admin/courses/PublishToggle";
import { DeleteCourseDialog } from "@/components/organisms/admin/courses/DeleteCourseDialog";
@@ -44,18 +44,32 @@ export function CourseTable({ courses }: { courses: AdminCourse[] }) {
<TableRow key={course.id}>
<TableCell className="font-medium">
<div>{course.title}</div>
{course.tags && course.tags.length > 0 ? (
{course.tags.length > 0 ? (
<div className="mt-1 flex flex-wrap gap-1">
{course.tags.map((tag) => (
<Badge key={tag} variant="outline" className="text-[10px] px-1.5 py-0">
{tag}
<Badge
key={`tag:${tag.id}`}
variant="outline"
className="px-1.5 py-0 text-[10px]"
>
{tag.label}
</Badge>
))}
</div>
) : null}
</TableCell>
<TableCell>
<Badge variant="secondary">{categoryLabel(course.category)}</Badge>
<div className="flex flex-wrap gap-1">
{course.categories.length > 0 ? (
course.categories.map((cat) => (
<Badge key={`cat:${cat.id}`} variant="secondary">
{cat.label}
</Badge>
))
) : (
<span className="text-muted-foreground">—</span>
)}
</div>
</TableCell>
<TableCell className="text-muted-foreground">
{formatLabel(course.format)}
@@ -94,4 +108,4 @@ export function CourseTable({ courses }: { courses: AdminCourse[] }) {
</Table>
</div>
);
}
}