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,43 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { getLegalPage } from "@/lib/data/site";
|
||||
|
||||
type Props = { params: Promise<{ slug: string }> };
|
||||
|
||||
const ALLOWED = new Set(["privacy", "accessibility", "press", "careers"]);
|
||||
|
||||
export async function generateStaticParams() {
|
||||
return [...ALLOWED].map((slug) => ({ slug }));
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const page = await getLegalPage(slug);
|
||||
if (!page) return { title: "صفحه یافت نشد" };
|
||||
return { title: page.title, description: page.body[0] };
|
||||
}
|
||||
|
||||
export default async function LegalSlugPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
if (!ALLOWED.has(slug)) notFound();
|
||||
const page = await getLegalPage(slug);
|
||||
if (!page) notFound();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={page.title} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container narrow className="space-y-5 rounded-2xl bg-card p-6 shadow-sm ring-1 ring-border sm:p-10">
|
||||
{page.body.map((paragraph) => (
|
||||
<p key={paragraph} className="leading-8 text-foreground/90">
|
||||
{paragraph}
|
||||
</p>
|
||||
))}
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { getTopics } from "@/lib/data/site";
|
||||
import { aboutFocusAreas, siteMission } from "@/lib/site-config";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return { title: t("aboutTitle"), description: siteMission };
|
||||
}
|
||||
|
||||
export default async function AboutPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const topics = await getTopics();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("aboutTitle")} intro={siteMission} />
|
||||
<Section className="relative overflow-hidden">
|
||||
<Container>
|
||||
<p className="text-xs font-bold text-primary">مسیرهای اثرگذاری</p><Heading level={2} className="mt-2 text-3xl sm:text-4xl">حوزههای تمرکز</Heading>
|
||||
<div className="mt-8 grid gap-4 sm:grid-cols-2">
|
||||
{aboutFocusAreas.map((area) => (
|
||||
<SurfaceCard key={area.title}>
|
||||
<Heading as="h3" level={4}>
|
||||
{area.title}
|
||||
</Heading>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
{area.description}
|
||||
</p>
|
||||
</SurfaceCard>
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</Section>
|
||||
<Section tone="muted">
|
||||
<Container>
|
||||
<p className="text-xs font-bold text-primary">نگاه میانرشتهای</p><Heading level={2} className="mt-2 text-3xl sm:text-4xl">تقاطع مدیریت و فناوری</Heading>
|
||||
<div className="mt-6 grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{topics.map((topic) => (
|
||||
<SurfaceCard key={topic.id} padded="sm" className="h-full">
|
||||
<Link href={topic.href} className="block">
|
||||
<span className="font-semibold hover:text-primary">
|
||||
{topic.title}
|
||||
</span>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
{topic.description}
|
||||
</p>
|
||||
</Link>
|
||||
</SurfaceCard>
|
||||
))}
|
||||
</div>
|
||||
<Link href="/programs" className={cn(buttonVariants(), "mt-8")}>
|
||||
کشف برنامهها
|
||||
</Link>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { Metadata } from "next";
|
||||
import Image from "next/image";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { BadgeLabel } from "@/components/atoms/BadgeLabel";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { getAlumniStories } from "@/lib/data/site";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return { title: t("alumniTitle"), description: t("alumniIntro") };
|
||||
}
|
||||
|
||||
export default async function AlumniPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const stories = await getAlumniStories();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("alumniTitle")} intro={t("alumniIntro")} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container>
|
||||
<div className="grid gap-8 md:grid-cols-3">
|
||||
{stories.map((story) => (
|
||||
<SurfaceCard
|
||||
key={story.id}
|
||||
id={story.id}
|
||||
padded={false}
|
||||
className="group scroll-mt-24 overflow-hidden rounded-2xl"
|
||||
>
|
||||
<div className="relative aspect-[16/10]">
|
||||
<Image
|
||||
src={story.imageUrl}
|
||||
alt={story.name}
|
||||
fill
|
||||
className="object-cover transition-transform duration-500 group-hover:scale-[1.03]"
|
||||
sizes="(max-width:768px) 100vw, 33vw"
|
||||
/>
|
||||
</div>
|
||||
<div className="p-5">
|
||||
<BadgeLabel>{story.program}</BadgeLabel>
|
||||
<Heading as="h2" level={4} className="mt-3">
|
||||
{story.title}
|
||||
</Heading>
|
||||
<p className="mt-2 text-sm leading-7 text-muted-foreground">
|
||||
{story.excerpt}
|
||||
</p>
|
||||
<p className="mt-4 text-sm font-semibold">{story.name}</p>
|
||||
</div>
|
||||
</SurfaceCard>
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { ContactInterestForm } from "@/components/organisms/ContactInterestForm";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { siteAddress } from "@/lib/site-config";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return { title: t("contactTitle"), description: t("contactIntro") };
|
||||
}
|
||||
|
||||
export default async function ContactPage() {
|
||||
const t = await getTranslations("pages");
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("contactTitle")} intro={t("contactIntro")} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container className="grid gap-10 lg:grid-cols-2">
|
||||
<div className="space-y-5 lg:pt-4">
|
||||
<Heading level={2}>اطلاعات تماس</Heading>
|
||||
<div className="space-y-3 text-sm leading-7 text-muted-foreground">
|
||||
<p>
|
||||
<span className="font-semibold text-foreground">آدرس: </span>
|
||||
{siteAddress.line}
|
||||
</p>
|
||||
<p dir="ltr">
|
||||
<span className="font-semibold text-foreground">تلفن: </span>
|
||||
{siteAddress.phone}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-semibold text-foreground">ایمیل: </span>
|
||||
<a
|
||||
href={`mailto:${siteAddress.email}`}
|
||||
className="text-primary hover:underline"
|
||||
>
|
||||
{siteAddress.email}
|
||||
</a>
|
||||
</p>
|
||||
<a
|
||||
href={siteAddress.mapUrl}
|
||||
className="inline-block text-primary hover:underline"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
مشاهده روی نقشه
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<Card className="rounded-2xl border-border/70 shadow-lg">
|
||||
<CardHeader>
|
||||
<CardTitle>ارسال پیام</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ContactInterestForm
|
||||
submitLabel={t("submit")}
|
||||
successLabel={t("registerSuccess")}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { DotCta } from "@/components/atoms/DotCta";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export default function MainError({
|
||||
error,
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string };
|
||||
reset: () => void;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
console.error(error);
|
||||
}, [error]);
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex min-h-[50vh] w-full max-w-7xl flex-col items-start justify-center px-5 py-20 sm:px-8 lg:px-12">
|
||||
<p className="text-sm font-semibold text-primary">خطا</p>
|
||||
<h1 className="mt-3 text-2xl font-bold tracking-tight sm:text-3xl">
|
||||
بارگذاری صفحه ناموفق بود
|
||||
</h1>
|
||||
<p className="mt-3 max-w-md text-base leading-relaxed text-muted-foreground">
|
||||
لطفاً دوباره تلاش کنید. اگر مشکل ادامه داشت، چند لحظه بعد بازگردید.
|
||||
</p>
|
||||
<div className="mt-8 flex flex-wrap gap-4">
|
||||
<Button type="button" onClick={reset}>
|
||||
تلاش مجدد
|
||||
</Button>
|
||||
<DotCta href="/">بازگشت به خانه</DotCta>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { TextLink } from "@/components/atoms/TextLink";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { getEventById } from "@/lib/data/events";
|
||||
|
||||
type Props = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { id } = await params;
|
||||
const event = await getEventById(id);
|
||||
if (!event) return { title: "رویداد یافت نشد" };
|
||||
return { title: event.title, description: event.summary };
|
||||
}
|
||||
|
||||
export default async function EventDetailPage({ params }: Props) {
|
||||
const { id } = await params;
|
||||
const event = await getEventById(id);
|
||||
if (!event) notFound();
|
||||
|
||||
const start = new Date(event.startDate).toLocaleDateString("fa-IR", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
const end = event.endDate
|
||||
? new Date(event.endDate).toLocaleDateString("fa-IR", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
})
|
||||
: null;
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={event.title} intro={event.summary} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container narrow className="space-y-5 rounded-2xl bg-card p-6 shadow-sm ring-1 ring-border sm:p-10">
|
||||
<p className="text-sm">
|
||||
<span className="font-semibold">زمان: </span>
|
||||
{start}
|
||||
{end ? ` تا ${end}` : ""}
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
<span className="font-semibold">مکان: </span>
|
||||
{event.location}
|
||||
</p>
|
||||
<Heading level={3}>درباره رویداد</Heading>
|
||||
<p className="leading-8 text-foreground/90">{event.summary}</p>
|
||||
<TextLink href="/events">بازگشت به رویدادها</TextLink>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { EventCard } from "@/components/molecules/Cards";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { getEvents } from "@/lib/data/events";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return { title: t("eventsTitle"), description: t("eventsIntro") };
|
||||
}
|
||||
|
||||
export default async function EventsPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const events = await getEvents();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("eventsTitle")} intro={t("eventsIntro")} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container>
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{events.map((event) => (
|
||||
<EventCard key={event.id} {...event} variant="list" />
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import type { Metadata } from "next";
|
||||
import Image from "next/image";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { getFaculty } from "@/lib/data/site";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return { title: t("facultyTitle"), description: t("facultyIntro") };
|
||||
}
|
||||
|
||||
export default async function FacultyPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const members = await getFaculty();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("facultyTitle")} intro={t("facultyIntro")} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container>
|
||||
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{members.map((member) => (
|
||||
<SurfaceCard key={member.id} className="group rounded-2xl">
|
||||
<div className="relative mb-5 aspect-[4/3] overflow-hidden rounded-xl bg-muted">
|
||||
<Image
|
||||
src={member.imageUrl}
|
||||
alt={member.name}
|
||||
fill
|
||||
className="object-cover transition-transform duration-500 group-hover:scale-[1.03]"
|
||||
sizes="(max-width:768px) 100vw, 33vw"
|
||||
/>
|
||||
</div>
|
||||
<Heading as="h2" level={4}>
|
||||
{member.name}
|
||||
</Heading>
|
||||
<p className="mt-1 text-sm text-primary">{member.title}</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
{member.focus}
|
||||
</p>
|
||||
<p className="mt-3 text-sm leading-7 text-muted-foreground">
|
||||
{member.bio}
|
||||
</p>
|
||||
</SurfaceCard>
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import type { Metadata } from "next";
|
||||
import Image from "next/image";
|
||||
import { notFound } from "next/navigation";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { BadgeLabel } from "@/components/atoms/BadgeLabel";
|
||||
import { MetamorphField } from "@/components/atoms/MetamorphField";
|
||||
import { TextLink } from "@/components/atoms/TextLink";
|
||||
import { getArticleById } from "@/lib/data/articles";
|
||||
import { JsonLd } from "@/lib/seo/json-ld";
|
||||
|
||||
type Props = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { id } = await params;
|
||||
const article = await getArticleById(id);
|
||||
if (!article) return { title: "مقاله یافت نشد" };
|
||||
return { title: article.title, description: article.excerpt };
|
||||
}
|
||||
|
||||
export default async function InsightDetailPage({ params }: Props) {
|
||||
const { id } = await params;
|
||||
const article = await getArticleById(id);
|
||||
if (!article) notFound();
|
||||
|
||||
const date = new Date(article.publishedAt).toLocaleDateString("fa-IR");
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<JsonLd
|
||||
data={{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Article",
|
||||
headline: article.title,
|
||||
description: article.excerpt,
|
||||
datePublished: article.publishedAt,
|
||||
author: { "@type": "Person", name: article.author },
|
||||
image: article.imageUrl,
|
||||
}}
|
||||
/>
|
||||
<Section tone="dark" className="relative overflow-hidden pb-16 pt-16 sm:pb-20 sm:pt-20">
|
||||
<MetamorphField tone="dark" density="sparse" className="opacity-35" />
|
||||
<Container narrow className="relative z-[1]">
|
||||
<BadgeLabel>{article.category}</BadgeLabel>
|
||||
<Heading as="h1" level={1} className="mt-4 text-background">
|
||||
{article.title}
|
||||
</Heading>
|
||||
<p className="mt-3 text-sm text-background/60">
|
||||
{article.author} · {date}
|
||||
</p>
|
||||
</Container>
|
||||
</Section>
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40 pt-10">
|
||||
<Container narrow>
|
||||
<div className="relative mb-10 aspect-[16/9] overflow-hidden rounded-2xl bg-muted shadow-xl">
|
||||
<Image
|
||||
src={article.imageUrl}
|
||||
alt={article.title}
|
||||
fill
|
||||
className="object-cover"
|
||||
sizes="(max-width:768px) 100vw, 800px"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
<p className="text-lg leading-9 text-foreground/90">{article.body}</p>
|
||||
<TextLink href="/insights" className="mt-10 inline-block">
|
||||
بازگشت به مقالات
|
||||
</TextLink>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { ArticleCard } from "@/components/molecules/Cards";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { getArticles } from "@/lib/data/articles";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return { title: t("insightsTitle"), description: t("insightsIntro") };
|
||||
}
|
||||
|
||||
export default async function InsightsPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const articles = await getArticles();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("insightsTitle")} intro={t("insightsIntro")} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container>
|
||||
<div className="mx-auto max-w-5xl">
|
||||
{articles.map((article) => (
|
||||
<ArticleCard
|
||||
key={article.id}
|
||||
title={article.title}
|
||||
category={article.category}
|
||||
excerpt={article.excerpt}
|
||||
imageUrl={article.imageUrl}
|
||||
href={article.href}
|
||||
variant="list"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { CampaignBanners } from "@/components/organisms/CampaignBanners";
|
||||
import { SiteFooter } from "@/components/organisms/SiteFooter";
|
||||
import { SiteHeader } from "@/components/organisms/SiteHeader";
|
||||
import { getCourses } from "@/lib/data/courses";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
import { getCampaignBanners } from "@/lib/data/site";
|
||||
import { homeNav, siteShortName } from "@/lib/site-config";
|
||||
|
||||
export default async function MainLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const t = await getTranslations();
|
||||
const year = new Date().getFullYear();
|
||||
const [courses, programs, banners] = await Promise.all([
|
||||
getCourses(),
|
||||
getPrograms(),
|
||||
getCampaignBanners(),
|
||||
]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SiteHeader
|
||||
items={homeNav}
|
||||
searchLabel={t("nav.search")}
|
||||
brandTitle={siteShortName}
|
||||
brandSubtitle={t("nav.brandSubtitle")}
|
||||
academicsLabel={t("nav.academics")}
|
||||
programSelectorTitle={t("home.programSelectorTitle")}
|
||||
executiveLabel={t("home.executiveLabel")}
|
||||
exploreLabel={t("home.exploreOurPrograms")}
|
||||
variant="home"
|
||||
courses={courses}
|
||||
programs={programs}
|
||||
/>
|
||||
<CampaignBanners banners={banners} />
|
||||
<div className="flex-1">{children}</div>
|
||||
<SiteFooter
|
||||
copyright={t("footer.copyright", { year })}
|
||||
linksTitle={t("footer.links")}
|
||||
links={[
|
||||
{ label: t("footer.press"), href: "/press" },
|
||||
{ label: t("footer.careers"), href: "/careers" },
|
||||
{ label: t("footer.accessibility"), href: "/accessibility" },
|
||||
{ label: t("footer.privacy"), href: "/privacy" },
|
||||
]}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import {
|
||||
HomeEvents,
|
||||
HomeHero,
|
||||
HomeIdeas,
|
||||
HomeRest,
|
||||
type HomeLabels,
|
||||
} from "@/components/templates/HomeTemplate";
|
||||
import { getArticles, getFeaturedArticle } from "@/lib/data/articles";
|
||||
import { getEvents } from "@/lib/data/events";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
import { getSiteStats, getTopics } from "@/lib/data/site";
|
||||
|
||||
async function getLabels(): Promise<HomeLabels> {
|
||||
const t = await getTranslations();
|
||||
return {
|
||||
executiveLabel: t("home.executiveLabel"),
|
||||
exploreOurPrograms: t("home.exploreOurPrograms"),
|
||||
ideasTitle: t("home.ideasTitle"),
|
||||
eventsTitle: t("home.eventsTitle"),
|
||||
seeAllEvents: t("nav.seeAllEvents"),
|
||||
intersectionsTitle: t("home.intersectionsTitle"),
|
||||
intersectionsSubtitle: t("home.intersectionsSubtitle"),
|
||||
moreThanDegree: t("home.moreThanDegree"),
|
||||
moreThanDegreeBody: t("home.moreThanDegreeBody"),
|
||||
keepExploring: t("home.keepExploring"),
|
||||
hireTitle: t("home.hireTitle"),
|
||||
hireBody: t("home.hireBody"),
|
||||
registerCta: t("nav.registerCta"),
|
||||
missionTitle: t("home.missionTitle"),
|
||||
findUsTitle: t("home.findUsTitle"),
|
||||
ideasEyebrow: t("home.ideasEyebrow"),
|
||||
linksTitle: t("footer.links"),
|
||||
};
|
||||
}
|
||||
|
||||
async function HeroSection() {
|
||||
const [featured, labels] = await Promise.all([
|
||||
getFeaturedArticle(),
|
||||
getLabels(),
|
||||
]);
|
||||
if (!featured) return null;
|
||||
return <HomeHero featured={featured} eyebrow={labels.ideasEyebrow} />;
|
||||
}
|
||||
|
||||
async function IdeasSection() {
|
||||
const [articles, labels] = await Promise.all([getArticles(), getLabels()]);
|
||||
return <HomeIdeas articles={articles} title={labels.ideasTitle} />;
|
||||
}
|
||||
|
||||
async function EventsSection() {
|
||||
const [events, labels] = await Promise.all([getEvents(), getLabels()]);
|
||||
return (
|
||||
<HomeEvents
|
||||
events={events}
|
||||
title={labels.eventsTitle}
|
||||
seeAllLabel={labels.seeAllEvents}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
async function RestSection() {
|
||||
const [programs, intersections, stats, labels] = await Promise.all([
|
||||
getPrograms(),
|
||||
getTopics(),
|
||||
getSiteStats(),
|
||||
getLabels(),
|
||||
]);
|
||||
const carouselPrograms = programs.filter((p) =>
|
||||
[
|
||||
"management-core",
|
||||
"evening-management",
|
||||
"executive",
|
||||
"leadership-fellows",
|
||||
"business-analytics",
|
||||
"finance",
|
||||
].includes(p.slug),
|
||||
);
|
||||
return (
|
||||
<HomeRest
|
||||
labels={labels}
|
||||
carouselPrograms={carouselPrograms}
|
||||
intersections={intersections}
|
||||
stats={stats}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default function HomePage() {
|
||||
return (
|
||||
<main id="main-content">
|
||||
<HeroSection />
|
||||
<IdeasSection />
|
||||
<EventsSection />
|
||||
<RestSection />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { TextLink } from "@/components/atoms/TextLink";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { getCourses } from "@/lib/data/courses";
|
||||
import { getProgramBySlug } from "@/lib/data/programs";
|
||||
|
||||
type Props = { params: Promise<{ slug: string }> };
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const program = await getProgramBySlug(slug);
|
||||
if (!program) return { title: "برنامه یافت نشد" };
|
||||
return {
|
||||
title: program.title,
|
||||
description: program.blurb,
|
||||
};
|
||||
}
|
||||
|
||||
export default async function ProgramDetailPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const [program, courses, t] = await Promise.all([
|
||||
getProgramBySlug(slug),
|
||||
getCourses(),
|
||||
getTranslations("pages"),
|
||||
]);
|
||||
if (!program) notFound();
|
||||
|
||||
const related = courses.slice(0, 3);
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero
|
||||
title={program.title}
|
||||
intro={program.blurb}
|
||||
eyebrow={program.tagline}
|
||||
/>
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container className="grid gap-10 lg:grid-cols-[2fr_1fr]">
|
||||
<div>
|
||||
<p className="text-base leading-8 text-foreground/90">{program.body}</p>
|
||||
<Heading level={2} className="mt-10">
|
||||
{t("highlights")}
|
||||
</Heading>
|
||||
<ul className="mt-4 list-disc space-y-2 ps-5 text-sm leading-7">
|
||||
{program.highlights.map((item) => (
|
||||
<li key={item}>{item}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<aside className="h-fit space-y-4 rounded-2xl bg-card p-6 shadow-sm ring-1 ring-border">
|
||||
<p className="text-sm">
|
||||
<span className="font-semibold">مخاطب: </span>
|
||||
{program.audience}
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
<span className="font-semibold">مدت: </span>
|
||||
{program.durationLabel}
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
<span className="font-semibold">فرمت: </span>
|
||||
{program.formatLabel}
|
||||
</p>
|
||||
<Link
|
||||
href="/professional"
|
||||
className={cn(buttonVariants(), "w-full")}
|
||||
>
|
||||
مشاهده دورهها
|
||||
</Link>
|
||||
<TextLink href="/programs" className="block text-sm">
|
||||
{t("backToPrograms")}
|
||||
</TextLink>
|
||||
</aside>
|
||||
</Container>
|
||||
</Section>
|
||||
<Section tone="muted">
|
||||
<Container>
|
||||
<Heading level={2}>{t("relatedCourses")}</Heading>
|
||||
<ul className="mt-6 grid gap-4 sm:grid-cols-3">
|
||||
{related.map((course) => (
|
||||
<li key={course.id}>
|
||||
<SurfaceCard padded="sm" as="div" className="h-full">
|
||||
<Link
|
||||
href={course.registrationUrl}
|
||||
className="font-semibold hover:text-primary"
|
||||
>
|
||||
{course.title}
|
||||
</Link>
|
||||
<p className="mt-2 line-clamp-3 text-sm text-muted-foreground">
|
||||
{course.summary}
|
||||
</p>
|
||||
</SurfaceCard>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { BadgeLabel } from "@/components/atoms/BadgeLabel";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return {
|
||||
title: t("programsTitle"),
|
||||
description: t("programsIntro"),
|
||||
};
|
||||
}
|
||||
|
||||
export default async function ProgramsPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const programs = await getPrograms();
|
||||
const standard = programs.filter((p) => p.group === "standard");
|
||||
const executive = programs.filter((p) => p.group === "executive");
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("programsTitle")} intro={t("programsIntro")} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container className="space-y-10">
|
||||
<ProgramGroup title={t("standardGroup")} items={standard} />
|
||||
<ProgramGroup title={t("executiveGroup")} items={executive} />
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function ProgramGroup({
|
||||
title,
|
||||
items,
|
||||
}: {
|
||||
title: string;
|
||||
items: Awaited<ReturnType<typeof getPrograms>>;
|
||||
}) {
|
||||
return (
|
||||
<div>
|
||||
<Heading level={2} className="mb-6">
|
||||
{title}
|
||||
</Heading>
|
||||
<div className="grid gap-5 md:grid-cols-2">
|
||||
{items.map((program) => (
|
||||
<SurfaceCard key={program.id} className="flex flex-col rounded-2xl p-6 sm:p-7">
|
||||
<BadgeLabel className="w-fit">{program.tagline}</BadgeLabel>
|
||||
<Heading as="h3" level={3} className="mt-3">
|
||||
<Link href={program.href} className="hover:text-primary">
|
||||
{program.title}
|
||||
</Link>
|
||||
</Heading>
|
||||
<p className="mt-2 flex-1 text-sm leading-relaxed text-muted-foreground">
|
||||
{program.blurb}
|
||||
</p>
|
||||
<dl className="mt-4 grid grid-cols-2 gap-2 text-xs text-muted-foreground">
|
||||
<div>
|
||||
<dt className="font-semibold text-foreground">مخاطب</dt>
|
||||
<dd>{program.audience}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="font-semibold text-foreground">مدت</dt>
|
||||
<dd>{program.durationLabel}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="font-semibold text-foreground">فرمت</dt>
|
||||
<dd>{program.formatLabel}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<Link
|
||||
href={program.href}
|
||||
className={cn(buttonVariants({ variant: "outline" }), "mt-5 w-fit")}
|
||||
>
|
||||
جزئیات برنامه
|
||||
</Link>
|
||||
</SurfaceCard>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { CourseDetailTemplate } from "@/components/templates/CourseDetailTemplate";
|
||||
import { getCourseById } from "@/lib/data/courses";
|
||||
|
||||
type Props = { params: Promise<{ slug: string }> };
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const course = await getCourseById(slug);
|
||||
if (!course) return { title: "دوره یافت نشد" };
|
||||
return {
|
||||
title: course.title,
|
||||
description: course.seoDescription || course.summary,
|
||||
};
|
||||
}
|
||||
|
||||
export default async function CourseRegisterPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const [course, t] = await Promise.all([
|
||||
getCourseById(slug),
|
||||
getTranslations("pages"),
|
||||
]);
|
||||
if (!course) notFound();
|
||||
|
||||
return (
|
||||
<CourseDetailTemplate
|
||||
course={course}
|
||||
labels={{
|
||||
submit: t("submit"),
|
||||
success: t("registerSuccess"),
|
||||
cta: t("registerCtaRequest"),
|
||||
formTitle: t("registerFormTitle"),
|
||||
formDescription: t("registerFormDescription"),
|
||||
hint: t("registerFormHint"),
|
||||
cancel: t("registerFormCancel"),
|
||||
backToCatalog: t("backToCourses"),
|
||||
detailsTitle: t("courseDetailsTitle"),
|
||||
aboutTitle: t("courseAboutTitle"),
|
||||
duration: t("courseDuration"),
|
||||
format: t("courseFormat"),
|
||||
category: t("courseCategory"),
|
||||
price: t("coursePrice"),
|
||||
priceUnset: t("coursePriceUnset"),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { TextLink } from "@/components/atoms/TextLink";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { getTopicBySlug } from "@/lib/data/site";
|
||||
|
||||
type Props = { params: Promise<{ slug: string }> };
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const topic = await getTopicBySlug(slug);
|
||||
if (!topic) return { title: "موضوع یافت نشد" };
|
||||
return { title: topic.title, description: topic.description };
|
||||
}
|
||||
|
||||
export default async function TopicPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const topic = await getTopicBySlug(slug);
|
||||
if (!topic) notFound();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero
|
||||
title={topic.title}
|
||||
intro={topic.description}
|
||||
imageUrl={topic.imageUrl}
|
||||
/>
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container className="grid gap-10 lg:grid-cols-[2fr_1fr]">
|
||||
<div>
|
||||
<p className="text-base leading-8">{topic.body}</p>
|
||||
<ul className="mt-8 list-disc space-y-2 ps-5 text-sm">
|
||||
{topic.highlights.map((h) => (
|
||||
<li key={h}>{h}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<aside className="h-fit space-y-4 rounded-2xl bg-card p-6 shadow-sm ring-1 ring-border">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
دورههای مرتبط با این موضوع را در فهرست دورههای کوتاه ببینید.
|
||||
</p>
|
||||
<Link href="/professional" className={cn(buttonVariants())}>
|
||||
مشاهده دورهها
|
||||
</Link>
|
||||
<Separator />
|
||||
<TextLink href="/" className="block text-sm">
|
||||
بازگشت به خانه
|
||||
</TextLink>
|
||||
</aside>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { valuesContent } from "@/lib/site-config";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return { title: t("valuesTitle"), description: valuesContent.intro };
|
||||
}
|
||||
|
||||
export default async function ValuesPage() {
|
||||
const t = await getTranslations("pages");
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("valuesTitle")} intro={valuesContent.intro} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container>
|
||||
<div className="grid gap-5 sm:grid-cols-2">
|
||||
{valuesContent.items.map((item) => (
|
||||
<Card key={item.title} className="rounded-2xl border-border/70 shadow-sm transition-[box-shadow,border-color] hover:border-primary/20 hover:shadow-md">
|
||||
<CardHeader>
|
||||
<CardTitle>{item.title}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm leading-7 text-muted-foreground">
|
||||
{item.text}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { ENTITIES } from "@/lib/admin/entities";
|
||||
import { GenericForm } from "@/components/organisms/admin/generic/GenericForm";
|
||||
import {
|
||||
AdminPage,
|
||||
AdminPageHeader,
|
||||
} from "@/components/organisms/admin/AdminPage";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminEntityEditPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ entity: string; id: string }>;
|
||||
}) {
|
||||
const { entity, id } = await params;
|
||||
const spec = ENTITIES[entity];
|
||||
if (!spec) notFound();
|
||||
|
||||
const row = (await spec.get(id)) as Record<string, unknown>;
|
||||
if (!row) notFound();
|
||||
|
||||
return (
|
||||
<AdminPage>
|
||||
<AdminPageHeader
|
||||
title={`ویرایش ${spec.noun}`}
|
||||
description={String(row[spec.columns[0].name] ?? "")}
|
||||
backHref={`/admin/${entity}`}
|
||||
backLabel={`بازگشت به ${spec.navLabel}`}
|
||||
/>
|
||||
<GenericForm
|
||||
spec={{
|
||||
key: spec.key,
|
||||
noun: spec.noun,
|
||||
apiPath: spec.apiPath,
|
||||
idColumn: spec.idColumn,
|
||||
fields: spec.fields,
|
||||
}}
|
||||
initial={row}
|
||||
/>
|
||||
</AdminPage>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { ENTITIES } from "@/lib/admin/entities";
|
||||
import { GenericForm } from "@/components/organisms/admin/generic/GenericForm";
|
||||
import {
|
||||
AdminPage,
|
||||
AdminPageHeader,
|
||||
} from "@/components/organisms/admin/AdminPage";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminEntityCreatePage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ entity: string }>;
|
||||
}) {
|
||||
const { entity } = await params;
|
||||
const spec = ENTITIES[entity];
|
||||
if (!spec) notFound();
|
||||
|
||||
return (
|
||||
<AdminPage>
|
||||
<AdminPageHeader
|
||||
title={`${spec.noun} جدید`}
|
||||
description={
|
||||
spec.hasPublished
|
||||
? "پس از ثبت، در صورت «منتشرشده» بودن در سایت عمومی نمایش داده میشود."
|
||||
: undefined
|
||||
}
|
||||
backHref={`/admin/${entity}`}
|
||||
backLabel={`بازگشت به ${spec.navLabel}`}
|
||||
/>
|
||||
<GenericForm
|
||||
spec={{
|
||||
key: spec.key,
|
||||
noun: spec.noun,
|
||||
apiPath: spec.apiPath,
|
||||
idColumn: spec.idColumn,
|
||||
fields: spec.fields,
|
||||
}}
|
||||
/>
|
||||
</AdminPage>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { ENTITIES } from "@/lib/admin/entities";
|
||||
import { GenericFilters } from "@/components/organisms/admin/generic/GenericFilters";
|
||||
import { GenericTable } from "@/components/organisms/admin/generic/GenericTable";
|
||||
import {
|
||||
AdminPage,
|
||||
AdminPageHeader,
|
||||
AdminTableCard,
|
||||
AdminToolbarCard,
|
||||
} from "@/components/organisms/admin/AdminPage";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminEntityListPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ entity: string }>;
|
||||
searchParams: Promise<{ search?: string; published?: string }>;
|
||||
}) {
|
||||
const { entity } = await params;
|
||||
const spec = ENTITIES[entity];
|
||||
if (!spec) notFound();
|
||||
|
||||
const { search = "", published: publishedRaw } = await searchParams;
|
||||
const published =
|
||||
publishedRaw === "true" ? true : publishedRaw === "false" ? false : undefined;
|
||||
|
||||
const rows = await spec.list({ search, published });
|
||||
|
||||
return (
|
||||
<AdminPage>
|
||||
<AdminPageHeader
|
||||
title={spec.navLabel}
|
||||
description={`${rows.length} مورد${search ? ` مطابق فیلتر «${search}»` : ""}`}
|
||||
actions={
|
||||
<Link href={`/admin/${entity}/new`} className={cn(buttonVariants())}>
|
||||
+ {spec.noun} جدید
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
|
||||
<AdminToolbarCard description={spec.searchHint}>
|
||||
<GenericFilters
|
||||
entity={entity}
|
||||
searchHint={spec.searchHint}
|
||||
hasPublished={spec.hasPublished}
|
||||
initialSearch={search}
|
||||
initialPublished={publishedRaw ?? "all"}
|
||||
/>
|
||||
</AdminToolbarCard>
|
||||
|
||||
<AdminTableCard title={`فهرست ${spec.navLabel}`}>
|
||||
<GenericTable spec={spec} rows={rows} />
|
||||
</AdminTableCard>
|
||||
</AdminPage>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { getAdminCourseById } from "@/lib/data/admin/courses";
|
||||
import { CourseForm } from "@/components/organisms/admin/courses/CourseForm";
|
||||
import {
|
||||
AdminPage,
|
||||
AdminPageHeader,
|
||||
} from "@/components/organisms/admin/AdminPage";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function EditCoursePage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
}) {
|
||||
const { id } = await params;
|
||||
const course = await getAdminCourseById(id);
|
||||
if (!course) notFound();
|
||||
|
||||
return (
|
||||
<AdminPage>
|
||||
<AdminPageHeader
|
||||
title="ویرایش دوره"
|
||||
description={course.title}
|
||||
backHref="/admin/courses"
|
||||
backLabel="بازگشت به دورهها"
|
||||
/>
|
||||
<CourseForm initial={course} />
|
||||
</AdminPage>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { CourseForm } from "@/components/organisms/admin/courses/CourseForm";
|
||||
import {
|
||||
AdminPage,
|
||||
AdminPageHeader,
|
||||
} from "@/components/organisms/admin/AdminPage";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default function NewCoursePage() {
|
||||
return (
|
||||
<AdminPage>
|
||||
<AdminPageHeader
|
||||
title="دوره جدید"
|
||||
description="دوره پس از ثبت، در صورت «منتشرشده» بودن در سایت عمومی نمایش داده میشود."
|
||||
backHref="/admin/courses"
|
||||
backLabel="بازگشت به دورهها"
|
||||
/>
|
||||
<CourseForm />
|
||||
</AdminPage>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import Link from "next/link";
|
||||
import { listAdminCourses } from "@/lib/data/admin/courses";
|
||||
import { CourseTable } from "@/components/organisms/admin/courses/CourseTable";
|
||||
import { CourseFilters } from "@/components/organisms/admin/courses/CourseFilters";
|
||||
import {
|
||||
AdminPage,
|
||||
AdminPageHeader,
|
||||
AdminTableCard,
|
||||
AdminToolbarCard,
|
||||
} from "@/components/organisms/admin/AdminPage";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminCoursesPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ search?: string; published?: string }>;
|
||||
}) {
|
||||
const { search = "", published: publishedRaw } = await searchParams;
|
||||
const published =
|
||||
publishedRaw === "true" ? true : publishedRaw === "false" ? false : undefined;
|
||||
|
||||
const courses = await listAdminCourses({ search, published });
|
||||
|
||||
return (
|
||||
<AdminPage>
|
||||
<AdminPageHeader
|
||||
title="دورهها"
|
||||
description={`${courses.length} دوره${search ? ` مطابق فیلتر «${search}»` : ""}`}
|
||||
actions={
|
||||
<Link href="/admin/courses/new" className={cn(buttonVariants())}>
|
||||
+ دوره جدید
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
|
||||
<AdminToolbarCard description="جستجو بر اساس عنوان یا اسلاگ و فیلتر وضعیت انتشار">
|
||||
<CourseFilters
|
||||
initialSearch={search}
|
||||
initialPublished={publishedRaw ?? "all"}
|
||||
/>
|
||||
</AdminToolbarCard>
|
||||
|
||||
<AdminTableCard
|
||||
title="فهرست دورهها"
|
||||
description="مدیریت، انتشار و پیشنمایش دورههای کوتاه"
|
||||
>
|
||||
<CourseTable courses={courses} />
|
||||
</AdminTableCard>
|
||||
</AdminPage>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { verifySession } from "@/lib/auth/admin";
|
||||
import { AdminShell } from "@/components/organisms/admin/AdminShell";
|
||||
|
||||
// Authoritative admin guard + shell.
|
||||
// - Verifies the session against the database for every /admin page
|
||||
// (login lives outside this route group, see src/app/admin/login).
|
||||
// - Proxy only does a fast cookie-presence redirect; this is the real check.
|
||||
|
||||
export default async function AdminGuardLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const session = await verifySession();
|
||||
if (!session) {
|
||||
redirect("/admin/login");
|
||||
}
|
||||
|
||||
return <AdminShell userName={session.name}>{children}</AdminShell>;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import Link from "next/link";
|
||||
import {
|
||||
BookOpen,
|
||||
Calendar,
|
||||
GraduationCap,
|
||||
Newspaper,
|
||||
Plus,
|
||||
Users,
|
||||
MessageSquareQuote,
|
||||
} from "lucide-react";
|
||||
import { query } from "@/lib/db";
|
||||
import {
|
||||
Card,
|
||||
CardAction,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { LeadsList, type LeadForDashboard } from "@/components/organisms/admin/LeadsList";
|
||||
import {
|
||||
AdminPage,
|
||||
AdminPageHeader,
|
||||
} from "@/components/organisms/admin/AdminPage";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
interface CountRow {
|
||||
entity: string;
|
||||
n: number;
|
||||
}
|
||||
|
||||
const getCounts = async (): Promise<Record<string, number>> => {
|
||||
const res = await query<CountRow>(
|
||||
`SELECT 'courses' AS entity, count(*)::int AS n FROM courses
|
||||
UNION ALL SELECT 'programs', count(*) FROM programs
|
||||
UNION ALL SELECT 'events', count(*) FROM events
|
||||
UNION ALL SELECT 'articles', count(*) FROM articles
|
||||
UNION ALL SELECT 'faculty', count(*) FROM faculty_members
|
||||
UNION ALL SELECT 'alumni', count(*) FROM alumni_stories`,
|
||||
);
|
||||
return Object.fromEntries(res.rows.map((r) => [r.entity, r.n]));
|
||||
};
|
||||
|
||||
const countCards = [
|
||||
{ key: "courses", label: "دورهها", href: "/admin/courses", icon: BookOpen },
|
||||
{ key: "programs", label: "برنامهها", href: "/admin/programs", icon: GraduationCap },
|
||||
{ key: "events", label: "رویدادها", href: "/admin/events", icon: Calendar },
|
||||
{ key: "articles", label: "مقالات", href: "/admin/articles", icon: Newspaper },
|
||||
{ key: "faculty", label: "اساتید", href: "/admin/faculty", icon: Users },
|
||||
{ key: "alumni", label: "دانشآموختگان", href: "/admin/alumni", icon: MessageSquareQuote },
|
||||
] as const;
|
||||
|
||||
export default async function AdminDashboardPage() {
|
||||
const [counts, leadsRes] = await Promise.all([
|
||||
getCounts(),
|
||||
query<LeadForDashboard>(
|
||||
`SELECT id, full_name, email, course_slug, status, created_at
|
||||
FROM registration_leads ORDER BY created_at DESC LIMIT 5`,
|
||||
),
|
||||
]);
|
||||
|
||||
return (
|
||||
<AdminPage className="space-y-8">
|
||||
<AdminPageHeader
|
||||
title="داشبورد"
|
||||
description="نمای کلی محتوای مدیریتشدنی و درخواستهای تازه"
|
||||
actions={
|
||||
<Link href="/admin/courses/new" className={cn(buttonVariants())}>
|
||||
<Plus className="size-4" />
|
||||
دوره جدید
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-sm font-semibold text-muted-foreground">آمار محتوا</h2>
|
||||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-6">
|
||||
{countCards.map(({ key, label, href, icon: Icon }) => (
|
||||
<Link key={key} href={href} className="group">
|
||||
<Card className="h-full shadow-none transition-colors group-hover:bg-muted/40">
|
||||
<CardHeader className="gap-3 pb-2">
|
||||
<div className="flex size-9 items-center justify-center rounded-lg bg-primary/10 text-primary">
|
||||
<Icon className="size-4" />
|
||||
</div>
|
||||
<CardDescription>{label}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-3xl font-bold tabular-nums tracking-tight">
|
||||
{counts[key] ?? 0}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<Card className="shadow-none">
|
||||
<CardHeader className="border-b [.border-b]:pb-4">
|
||||
<CardTitle>درخواستهای اخیر ثبتنام</CardTitle>
|
||||
<CardDescription>۵ درخواست آخر از برگ ثبتنام</CardDescription>
|
||||
<CardAction>
|
||||
<Link
|
||||
href="/admin/registrations"
|
||||
className={cn(buttonVariants({ variant: "outline", size: "sm" }))}
|
||||
>
|
||||
مشاهده همه
|
||||
</Link>
|
||||
</CardAction>
|
||||
</CardHeader>
|
||||
<CardContent className="pt-6">
|
||||
<LeadsList leads={leadsRes.rows} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</AdminPage>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { listAdminRegistrations } from "@/lib/data/admin/registrations";
|
||||
import { RegistrationFilters } from "@/components/organisms/admin/registrations/RegistrationFilters";
|
||||
import { RegistrationsTable } from "@/components/organisms/admin/registrations/RegistrationsTable";
|
||||
import { LEAD_STATUS_LABELS } from "@/components/organisms/admin/LeadsList";
|
||||
import {
|
||||
AdminPage,
|
||||
AdminPageHeader,
|
||||
AdminTableCard,
|
||||
AdminToolbarCard,
|
||||
} from "@/components/organisms/admin/AdminPage";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminRegistrationsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ search?: string; status?: string }>;
|
||||
}) {
|
||||
const { search = "", status = "" } = await searchParams;
|
||||
const rows = await listAdminRegistrations({ search, status });
|
||||
|
||||
const parts = [
|
||||
`${rows.length} درخواست`,
|
||||
search ? `جستجو: «${search}»` : null,
|
||||
status && LEAD_STATUS_LABELS[status]
|
||||
? `وضعیت: ${LEAD_STATUS_LABELS[status]}`
|
||||
: null,
|
||||
].filter(Boolean);
|
||||
|
||||
return (
|
||||
<AdminPage>
|
||||
<AdminPageHeader title="برگ ثبتنام" description={parts.join(" · ")} />
|
||||
|
||||
<AdminToolbarCard description="جستجو بر اساس نام، ایمیل یا اسلاگ دوره">
|
||||
<RegistrationFilters
|
||||
initialSearch={search}
|
||||
initialStatus={status || "all"}
|
||||
/>
|
||||
</AdminToolbarCard>
|
||||
|
||||
<AdminTableCard title="درخواستها" description="پیگیری و تغییر وضعیت لیدها">
|
||||
<RegistrationsTable rows={rows} />
|
||||
</AdminTableCard>
|
||||
</AdminPage>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
"use client";
|
||||
|
||||
import { useState, FormEvent, Suspense } from "react";
|
||||
import Image from "next/image";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
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";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
function LoginForm() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const redirect = searchParams.get("redirect") || "/admin";
|
||||
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function handleSubmit(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
setError("");
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await fetch("/api/admin/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ email, password }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
setError(data.error || "خطای احراز هویت");
|
||||
return;
|
||||
}
|
||||
router.push(redirect);
|
||||
router.refresh();
|
||||
} catch {
|
||||
setError("خطای شبکه");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div dir="rtl" className="flex min-h-svh items-center justify-center bg-muted/40 px-4 py-12">
|
||||
<Card className="w-full max-w-md shadow-sm">
|
||||
<CardHeader className="space-y-3 text-center">
|
||||
<div className="mx-auto relative size-14 overflow-hidden rounded-full bg-chart-3 ring-1 ring-border shadow-sm">
|
||||
<Image
|
||||
src="/brand/amirkabir.png"
|
||||
alt="دانشگاه صنعتی امیرکبیر"
|
||||
fill
|
||||
sizes="56px"
|
||||
className="object-cover"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
<CardTitle className="text-2xl font-bold tracking-tight">
|
||||
ورود به پنل ادمین
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
آموزش آزاد دانشگاه صنعتی امیرکبیر
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{error ? (
|
||||
<div
|
||||
className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive"
|
||||
role="alert"
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">ایمیل</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="admin@example.com"
|
||||
required
|
||||
autoComplete="email"
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="password">رمز عبور</Label>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="••••••••"
|
||||
required
|
||||
autoComplete="current-password"
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" className="w-full" disabled={loading}>
|
||||
{loading ? "در حال ورود..." : "ورود"}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AdminLoginPage() {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="flex min-h-svh items-center justify-center text-sm text-muted-foreground">
|
||||
در حال بارگذاری...
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<LoginForm />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToAlumniStory, type AlumniStoryRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { alumniPatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const ALUMNI_COLUMNS: Record<string, string> = {
|
||||
title: "title",
|
||||
excerpt: "excerpt",
|
||||
name: "name",
|
||||
program: "program",
|
||||
imageUrl: "image_url",
|
||||
href: "href",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/alumni/[id] — update alumni story (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = alumniPatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("alumni_stories", "id", ALUMNI_COLUMNS, parsed.data as Record<string, unknown>);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<AlumniStoryRow>(spec.sql, [...spec.params, id]);
|
||||
if (res.rows.length === 0) return errorResponse("داستان دانشآموخته یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
data: { ...rowToAlumniStory(row), published: row.published },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("admin update alumni error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/alumni/[id] — delete alumni story (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM alumni_stories WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("داستان دانشآموخته یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete alumni error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToAlumniStory, type AlumniStoryRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { alumniCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/alumni — create alumni story (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = alumniCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = makeId();
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"alumni_stories",
|
||||
["id", "title", "excerpt", "name", "program", "image_url", "href", "published"],
|
||||
[id, d.title, d.excerpt, d.name, d.program, d.imageUrl, d.href, d.published],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<AlumniStoryRow>(`SELECT * FROM alumni_stories WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToAlumniStory(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("admin create alumni error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToArticle, type ArticleRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { articlePatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const ARTICLE_COLUMNS: Record<string, string> = {
|
||||
title: "title",
|
||||
category: "category",
|
||||
excerpt: "excerpt",
|
||||
imageUrl: "image_url",
|
||||
href: "href",
|
||||
featured: "featured",
|
||||
body: "body",
|
||||
publishedAt: "published_at",
|
||||
author: "author",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/articles/[id] — update article (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = articlePatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const sets: string[] = [];
|
||||
const values: unknown[] = [];
|
||||
for (const [key, column] of Object.entries(ARTICLE_COLUMNS)) {
|
||||
const v = parsed.data[key as keyof typeof parsed.data];
|
||||
if (v !== undefined) {
|
||||
values.push(v);
|
||||
sets.push(`${column} = $${values.length}`);
|
||||
}
|
||||
}
|
||||
if (sets.length === 0) {
|
||||
return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
}
|
||||
values.push(id);
|
||||
|
||||
try {
|
||||
const res = await query<ArticleRow>(
|
||||
`UPDATE articles SET ${sets.join(", ")} WHERE id = $${values.length} RETURNING *`,
|
||||
values,
|
||||
);
|
||||
if (res.rows.length === 0) return errorResponse("مقاله یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
revalidateSite();
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
data: { ...rowToArticle(row), published: row.published },
|
||||
});
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err) && err.constraint === "articles_one_featured") {
|
||||
return errorResponse("فقط یک مقالهٔ ویژهٔ منتشرشده مجاز است", 409);
|
||||
}
|
||||
console.error("admin update article error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/articles/[id] — delete article (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM articles WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("مقاله یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete article error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToArticle, type ArticleRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { articleCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/articles — create article (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = articleCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = randomUUID();
|
||||
|
||||
try {
|
||||
await query(
|
||||
`INSERT INTO articles
|
||||
(id, title, category, excerpt, image_url, href, featured, body, published_at, author, published)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)`,
|
||||
[
|
||||
id, d.title, d.category, d.excerpt, d.imageUrl, d.href,
|
||||
d.featured, d.body, d.publishedAt, d.author, d.published,
|
||||
],
|
||||
);
|
||||
const res = await query<ArticleRow>(`SELECT * FROM articles WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
revalidateSite();
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToArticle(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err) && err.constraint === "articles_one_featured") {
|
||||
return errorResponse("فقط یک مقالهٔ ویژهٔ منتشرشده مجاز است", 409);
|
||||
}
|
||||
console.error("admin create article error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToCampaignBanner, type CampaignBannerRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { bannerPatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const BANNER_COLUMNS: Record<string, string> = {
|
||||
version: "version",
|
||||
text: "text",
|
||||
href: "href",
|
||||
cta: "cta",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/banners/[id] — update banner (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = bannerPatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("campaign_banners", "id", BANNER_COLUMNS, parsed.data as Record<string, unknown>);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<CampaignBannerRow>(spec.sql, [...spec.params, id]);
|
||||
if (res.rows.length === 0) return errorResponse("بنر یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
data: { ...rowToCampaignBanner(row), published: row.published },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("admin update banner error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/banners/[id] — delete banner (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM campaign_banners WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("بنر یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete banner error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToCampaignBanner, type CampaignBannerRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { bannerCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/banners — create campaign banner (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = bannerCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = makeId();
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"campaign_banners",
|
||||
["id", "version", "text", "href", "cta", "published"],
|
||||
[id, d.version, d.text, d.href, d.cta, d.published],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<CampaignBannerRow>(`SELECT * FROM campaign_banners WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToCampaignBanner(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("admin create banner error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToCourse, type CourseRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { coursePatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { getAdminCourseById } from "@/lib/data/admin/courses";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// GET /api/admin/courses/[id] — single course (admin only; includes unpublished)
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const course = await getAdminCourseById(id);
|
||||
if (!course) return errorResponse("دوره یافت نشد", 404);
|
||||
return NextResponse.json({ ok: true, data: course });
|
||||
} catch (err) {
|
||||
console.error("admin get course error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
const COURSE_COLUMNS: Record<string, string> = {
|
||||
slug: "slug",
|
||||
title: "title",
|
||||
summary: "summary",
|
||||
category: "category",
|
||||
durationHours: "duration_hours",
|
||||
format: "format",
|
||||
price: "price",
|
||||
registrationUrl: "registration_url",
|
||||
imageUrl: "image_url",
|
||||
seoDescription: "seo_description",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/courses/[id] — update course (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = coursePatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const sets: string[] = [];
|
||||
const values: unknown[] = [];
|
||||
for (const [key, column] of Object.entries(COURSE_COLUMNS)) {
|
||||
const v = parsed.data[key as keyof typeof parsed.data];
|
||||
if (v !== undefined) {
|
||||
values.push(v);
|
||||
sets.push(`${column} = $${values.length}`);
|
||||
}
|
||||
}
|
||||
if (sets.length === 0) {
|
||||
return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
}
|
||||
values.push(id);
|
||||
|
||||
try {
|
||||
const res = await query<CourseRow>(
|
||||
`UPDATE courses SET ${sets.join(", ")} WHERE id = $${values.length} RETURNING *`,
|
||||
values,
|
||||
);
|
||||
if (res.rows.length === 0) return errorResponse("دوره یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true, data: { ...rowToCourse(row), published: row.published } });
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err) && err.constraint === "courses_slug_key") {
|
||||
return errorResponse("این slug قبلاً استفاده شده است", 409);
|
||||
}
|
||||
console.error("admin update course error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/courses/[id] — delete course (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM courses WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("دوره یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete course error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToCourse, type CourseRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { courseCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { listAdminCourses } from "@/lib/data/admin/courses";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// GET /api/admin/courses — list courses (admin only; includes unpublished)
|
||||
// Query: ?search=<text>&published=true|false
|
||||
export async function GET(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
try {
|
||||
const { searchParams } = request.nextUrl;
|
||||
const publishedRaw = searchParams.get("published");
|
||||
const published =
|
||||
publishedRaw === "true" ? true : publishedRaw === "false" ? false : null;
|
||||
const data = await listAdminCourses({
|
||||
search: searchParams.get("search") ?? undefined,
|
||||
published: published ?? undefined,
|
||||
});
|
||||
return NextResponse.json({ ok: true, data });
|
||||
} catch (err) {
|
||||
console.error("admin list courses error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/admin/courses — create course (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = courseCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = randomUUID();
|
||||
|
||||
try {
|
||||
await query(
|
||||
`INSERT INTO courses
|
||||
(id, slug, title, summary, category, duration_hours, format, price,
|
||||
registration_url, image_url, seo_description, published)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)`,
|
||||
[
|
||||
id, d.slug, d.title, d.summary, d.category, d.durationHours, d.format,
|
||||
d.price ?? null, d.registrationUrl, d.imageUrl, d.seoDescription, d.published,
|
||||
],
|
||||
);
|
||||
const res = await query<CourseRow>(`SELECT * FROM courses WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
revalidateSite();
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToCourse(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err) && err.constraint === "courses_slug_key") {
|
||||
return errorResponse("این slug قبلاً استفاده شده است", 409);
|
||||
}
|
||||
console.error("admin create course error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToEvent, type EventRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { eventPatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const EVENT_COLUMNS: Record<string, string> = {
|
||||
title: "title",
|
||||
startDate: "start_date",
|
||||
endDate: "end_date",
|
||||
location: "location",
|
||||
href: "href",
|
||||
summary: "summary",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/events/[id] — update event (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = eventPatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("events", "id", EVENT_COLUMNS, parsed.data as Record<string, unknown>);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<EventRow>(spec.sql, [...spec.params, id]);
|
||||
if (res.rows.length === 0) return errorResponse("رویداد یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({ ok: true, data: { ...rowToEvent(row), published: row.published } });
|
||||
} catch (err) {
|
||||
console.error("admin update event error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/events/[id] — delete event (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM events WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("رویداد یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete event error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToEvent, type EventRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { eventCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/events — create event (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = eventCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = makeId();
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"events",
|
||||
["id", "title", "start_date", "end_date", "location", "href", "summary", "published"],
|
||||
[id, d.title, d.startDate, d.endDate, d.location, d.href, d.summary, d.published],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<EventRow>(`SELECT * FROM events WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToEvent(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("admin create event error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToFacultyMember, type FacultyMemberRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { facultyPatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const FACULTY_COLUMNS: Record<string, string> = {
|
||||
name: "name",
|
||||
title: "title",
|
||||
focus: "focus",
|
||||
bio: "bio",
|
||||
imageUrl: "image_url",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/faculty/[id] — update faculty member (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = facultyPatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("faculty_members", "id", FACULTY_COLUMNS, parsed.data as Record<string, unknown>);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<FacultyMemberRow>(spec.sql, [...spec.params, id]);
|
||||
if (res.rows.length === 0) return errorResponse("عضو هیئت علمی یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
data: { ...rowToFacultyMember(row), published: row.published },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("admin update faculty error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/faculty/[id] — delete faculty member (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM faculty_members WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("عضو هیئت علمی یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete faculty error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToFacultyMember, type FacultyMemberRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { facultyCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/faculty — create faculty member (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = facultyCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = makeId();
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"faculty_members",
|
||||
["id", "name", "title", "focus", "bio", "image_url", "published"],
|
||||
[id, d.name, d.title, d.focus, d.bio, d.imageUrl, d.published],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<FacultyMemberRow>(`SELECT * FROM faculty_members WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToFacultyMember(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("admin create faculty error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToLegalPage, type LegalPageRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { legalPatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const LEGAL_COLUMNS: Record<string, string> = {
|
||||
title: "title",
|
||||
body: "body",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/legal/[slug] — update legal page (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ slug: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { slug } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = legalPatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const data: Record<string, unknown> = { ...parsed.data };
|
||||
if (data.body !== undefined) {
|
||||
data.body = JSON.stringify(data.body);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("legal_pages", "slug", LEGAL_COLUMNS, data);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<LegalPageRow>(spec.sql, [...spec.params, slug]);
|
||||
if (res.rows.length === 0) return errorResponse("صفحهٔ حقوقی یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
data: { ...rowToLegalPage(row), published: row.published },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("admin update legal error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/legal/[slug] — delete legal page (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ slug: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { slug } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM legal_pages WHERE slug = $1 RETURNING slug`, [slug]);
|
||||
if (res.rows.length === 0) return errorResponse("صفحهٔ حقوقی یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete legal error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToLegalPage, type LegalPageRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { legalCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/legal — create legal page (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = legalCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"legal_pages",
|
||||
["slug", "title", "body", "published"],
|
||||
[d.slug, d.title, JSON.stringify(d.body), d.published],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<LegalPageRow>(`SELECT * FROM legal_pages WHERE slug = $1`, [d.slug]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToLegalPage(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err)) {
|
||||
return errorResponse("این slug قبلاً استفاده شده است", 409);
|
||||
}
|
||||
console.error("admin create legal error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { verifyPassword, createSession, setSessionCookie } from "@/lib/auth/admin";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { email, password } = await request.json();
|
||||
if (!email || !password) {
|
||||
return NextResponse.json({ error: "ایمیل و رمز الزامی است" }, { status: 400 });
|
||||
}
|
||||
|
||||
const res = await query(
|
||||
`SELECT id, email, password_hash, name, role FROM admin_users WHERE email = $1 LIMIT 1`,
|
||||
[email],
|
||||
);
|
||||
if (res.rows.length === 0) {
|
||||
return NextResponse.json({ error: "کاربر یافت نشد" }, { status: 401 });
|
||||
}
|
||||
|
||||
const user = res.rows[0];
|
||||
const ok = await verifyPassword(password, user.password_hash);
|
||||
if (!ok) {
|
||||
return NextResponse.json({ error: "رمز نادرست است" }, { status: 401 });
|
||||
}
|
||||
|
||||
const cookieValue = await createSession(user.id);
|
||||
await setSessionCookie(cookieValue);
|
||||
|
||||
return NextResponse.json({ ok: true, user: { id: user.id, email: user.email, name: user.name, role: user.role } });
|
||||
} catch (error) {
|
||||
console.error("admin login error:", error);
|
||||
return NextResponse.json({ error: "خطای سرور" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { destroySession, clearSessionCookie } from "@/lib/auth/admin";
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
await destroySession();
|
||||
await clearSessionCookie();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (error) {
|
||||
console.error("admin logout error:", error);
|
||||
return NextResponse.json({ error: "خطای سرور" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToProgram, type ProgramRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { programPatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const PROGRAM_COLUMNS: Record<string, string> = {
|
||||
slug: "slug",
|
||||
title: "title",
|
||||
blurb: "blurb",
|
||||
group: "group_key",
|
||||
href: "href",
|
||||
tagline: "tagline",
|
||||
audience: "audience",
|
||||
durationLabel: "duration_label",
|
||||
formatLabel: "format_label",
|
||||
highlights: "highlights",
|
||||
body: "body",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/programs/[id] — update program (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = programPatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const data: Record<string, unknown> = { ...parsed.data };
|
||||
if (data.highlights !== undefined) {
|
||||
data.highlights = JSON.stringify(data.highlights);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("programs", "id", PROGRAM_COLUMNS, data);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<ProgramRow>(spec.sql, [...spec.params, id]);
|
||||
if (res.rows.length === 0) return errorResponse("برنامه یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({ ok: true, data: { ...rowToProgram(row), published: row.published } });
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err) && err.constraint === "programs_slug_key") {
|
||||
return errorResponse("این slug قبلاً استفاده شده است", 409);
|
||||
}
|
||||
console.error("admin update program error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/programs/[id] — delete program (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM programs WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("برنامه یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete program error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToProgram, type ProgramRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { programCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/programs — create program (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = programCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = makeId();
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"programs",
|
||||
["id", "slug", "title", "blurb", "group_key", "href", "tagline", "audience", "duration_label", "format_label", "highlights", "body", "published"],
|
||||
[id, d.slug, d.title, d.blurb, d.group, d.href, d.tagline ?? null, d.audience, d.durationLabel, d.formatLabel, JSON.stringify(d.highlights), d.body, d.published],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<ProgramRow>(`SELECT * FROM programs WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToProgram(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err) && err.constraint === "programs_slug_key") {
|
||||
return errorResponse("این slug قبلاً استفاده شده است", 409);
|
||||
}
|
||||
console.error("admin create program error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { registrationStatusSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { parseJsonBody } from "@/lib/api/crud";
|
||||
import type { RegistrationLeadRow } from "@/app/api/admin/registrations/route";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// PATCH /api/admin/registrations/[id] — change lead status (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = registrationStatusSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await query<RegistrationLeadRow>(
|
||||
`UPDATE registration_leads SET status = $1 WHERE id = $2 RETURNING *`,
|
||||
[parsed.data.status, id],
|
||||
);
|
||||
if (res.rows.length === 0) return errorResponse("لید ثبتنام یافت نشد", 404);
|
||||
return NextResponse.json({ ok: true, data: res.rows[0] });
|
||||
} catch (err) {
|
||||
console.error("admin update registration error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/registrations/[id] — delete a lead (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(
|
||||
`DELETE FROM registration_leads WHERE id = $1 RETURNING id`,
|
||||
[id],
|
||||
);
|
||||
if (res.rows.length === 0) return errorResponse("لید ثبتنام یافت نشد", 404);
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete registration error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { listAdminRegistrations } from "@/lib/data/admin/registrations";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export interface RegistrationLeadRow {
|
||||
id: string;
|
||||
course_id: string | null;
|
||||
course_slug: string | null;
|
||||
full_name: string;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
message: string | null;
|
||||
source: string;
|
||||
status: "new" | "contacted" | "enrolled" | "rejected";
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
// GET /api/admin/registrations — list registration leads (admin only)
|
||||
// Query: ?search=<text>&status=new|contacted|enrolled|rejected
|
||||
export async function GET(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
try {
|
||||
const { searchParams } = request.nextUrl;
|
||||
const data = await listAdminRegistrations({
|
||||
search: searchParams.get("search") ?? undefined,
|
||||
status: searchParams.get("status") ?? undefined,
|
||||
});
|
||||
return NextResponse.json({ ok: true, data });
|
||||
} catch (err) {
|
||||
console.error("admin list registrations error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToSiteStat, type SiteStatRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { statPatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const STAT_COLUMNS: Record<string, string> = {
|
||||
value: "value",
|
||||
label: "label",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/stats/[id] — update stat (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = statPatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("site_stats", "id", STAT_COLUMNS, parsed.data as Record<string, unknown>);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<SiteStatRow>(spec.sql, [...spec.params, id]);
|
||||
if (res.rows.length === 0) return errorResponse("آمار یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({ ok: true, data: { ...rowToSiteStat(row), published: row.published } });
|
||||
} catch (err) {
|
||||
console.error("admin update stat error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/stats/[id] — delete stat (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM site_stats WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("آمار یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete stat error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToSiteStat, type SiteStatRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { statCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/stats — create site stat (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = statCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = makeId();
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"site_stats",
|
||||
["id", "value", "label", "published"],
|
||||
[id, d.value, d.label, d.published],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<SiteStatRow>(`SELECT * FROM site_stats WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToSiteStat(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("admin create stat error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToTestimonial, type TestimonialRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { testimonialPatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const TESTIMONIAL_COLUMNS: Record<string, string> = {
|
||||
quote: "quote",
|
||||
name: "name",
|
||||
role: "role",
|
||||
courseTitle: "course_title",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/testimonials/[id] — update testimonial (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = testimonialPatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("testimonials", "id", TESTIMONIAL_COLUMNS, parsed.data as Record<string, unknown>);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<TestimonialRow>(spec.sql, [...spec.params, id]);
|
||||
if (res.rows.length === 0) return errorResponse("بازخورد یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
data: { ...rowToTestimonial(row), published: row.published },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("admin update testimonial error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/testimonials/[id] — delete testimonial (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM testimonials WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("بازخورد یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete testimonial error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToTestimonial, type TestimonialRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { testimonialCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/testimonials — create testimonial (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = testimonialCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = makeId();
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"testimonials",
|
||||
["id", "quote", "name", "role", "course_title", "published"],
|
||||
[id, d.quote, d.name, d.role, d.courseTitle, d.published],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<TestimonialRow>(`SELECT * FROM testimonials WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToTestimonial(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("admin create testimonial error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToIntersectionTopic, type IntersectionTopicRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { topicPatchSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const TOPIC_COLUMNS: Record<string, string> = {
|
||||
slug: "slug",
|
||||
title: "title",
|
||||
description: "description",
|
||||
href: "href",
|
||||
imageUrl: "image_url",
|
||||
body: "body",
|
||||
highlights: "highlights",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/topics/[id] — update topic (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = topicPatchSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const data: Record<string, unknown> = { ...parsed.data };
|
||||
if (data.highlights !== undefined) {
|
||||
data.highlights = JSON.stringify(data.highlights);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("intersection_topics", "id", TOPIC_COLUMNS, data);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<IntersectionTopicRow>(spec.sql, [...spec.params, id]);
|
||||
if (res.rows.length === 0) return errorResponse("موضوع یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
data: { ...rowToIntersectionTopic(row), published: row.published },
|
||||
});
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err) && err.constraint === "intersection_topics_slug_key") {
|
||||
return errorResponse("این slug قبلاً استفاده شده است", 409);
|
||||
}
|
||||
console.error("admin update topic error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/topics/[id] — delete topic (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM intersection_topics WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("موضوع یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete topic error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToIntersectionTopic, type IntersectionTopicRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { topicCreateSchema } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/topics — create topic (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = topicCreateSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = makeId();
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"intersection_topics",
|
||||
["id", "slug", "title", "description", "href", "image_url", "body", "highlights", "published"],
|
||||
[id, d.slug, d.title, d.description, d.href, d.imageUrl, d.body, JSON.stringify(d.highlights), d.published],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<IntersectionTopicRow>(`SELECT * FROM intersection_topics WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToIntersectionTopic(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err) && err.constraint === "intersection_topics_slug_key") {
|
||||
return errorResponse("این slug قبلاً استفاده شده است", 409);
|
||||
}
|
||||
console.error("admin create topic error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getArticleById } from "@/lib/data/articles";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const article = await getArticleById(id);
|
||||
if (!article) {
|
||||
return NextResponse.json({ error: "Article not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ data: article });
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getArticles } from "@/lib/data/articles";
|
||||
|
||||
export async function GET() {
|
||||
const data = await getArticles();
|
||||
return NextResponse.json({ data });
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getCourseById } from "@/lib/data/courses";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const course = await getCourseById(id);
|
||||
if (!course) {
|
||||
return NextResponse.json({ error: "Course not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ data: course });
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getCourses } from "@/lib/data/courses";
|
||||
|
||||
export async function GET() {
|
||||
const data = await getCourses();
|
||||
return NextResponse.json({ data });
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getEventById } from "@/lib/data/events";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const event = await getEventById(id);
|
||||
if (!event) {
|
||||
return NextResponse.json({ error: "Event not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ data: event });
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getEvents } from "@/lib/data/events";
|
||||
|
||||
export async function GET() {
|
||||
const data = await getEvents();
|
||||
return NextResponse.json({ data });
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getProgramBySlug } from "@/lib/data/programs";
|
||||
|
||||
type Params = { params: Promise<{ slug: string }> };
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
const { slug } = await params;
|
||||
const program = await getProgramBySlug(slug);
|
||||
if (!program) {
|
||||
return NextResponse.json({ error: "Program not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ data: program });
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
|
||||
export async function GET() {
|
||||
const data = await getPrograms();
|
||||
return NextResponse.json({ data });
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { publicRegistrationSchema } from "@/lib/validation/public";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/registrations — create a registration lead (public).
|
||||
// Used by ContactInterestForm on /register/[slug] and /contact.
|
||||
export async function POST(request: NextRequest) {
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return errorResponse("بدنهٔ درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = publicRegistrationSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const d = parsed.data;
|
||||
const courseSlug = d.courseSlug?.trim() || null;
|
||||
|
||||
try {
|
||||
const course = courseSlug
|
||||
? await query<{ id: string }>(
|
||||
"SELECT id FROM courses WHERE slug = $1 AND published = true LIMIT 1",
|
||||
[courseSlug],
|
||||
)
|
||||
: null;
|
||||
|
||||
await query(
|
||||
`INSERT INTO registration_leads
|
||||
(course_id, course_slug, full_name, email, phone, message, source)
|
||||
VALUES ($1, $2, $3, $4, NULLIF($5, ''), NULLIF($6, ''), 'register_page')`,
|
||||
[
|
||||
course?.rows[0]?.id ?? null,
|
||||
courseSlug,
|
||||
d.fullName,
|
||||
d.email,
|
||||
d.phone,
|
||||
d.message,
|
||||
],
|
||||
);
|
||||
return NextResponse.json({ ok: true }, { status: 201 });
|
||||
} catch (err) {
|
||||
console.error("create registration lead error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
+285
-14
@@ -1,26 +1,297 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
@import "shadcn/tailwind.css";
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
}
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
/*
|
||||
AUT Open Education — shadcn/ui theme only
|
||||
Brand identity via CSS variables (primary / accent / muted). No ds-* or --brand-*.
|
||||
*/
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
--font-sans: var(--font-iransans);
|
||||
--font-heading: var(--font-iransans);
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-ring: var(--ring);
|
||||
--color-input: var(--input);
|
||||
--color-border: var(--border);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-card: var(--card);
|
||||
--radius-sm: 0.375rem;
|
||||
--radius-md: 0.625rem;
|
||||
--radius-lg: 0.875rem;
|
||||
--radius-xl: 1.125rem;
|
||||
--radius-2xl: 1.25rem;
|
||||
--radius-3xl: 1.5rem;
|
||||
--radius-4xl: 1.75rem;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
:root {
|
||||
/* AUT red + gold mapped into standard shadcn tokens */
|
||||
--background: #ffffff;
|
||||
--foreground: #1a1a1a;
|
||||
--card: #ffffff;
|
||||
--card-foreground: #1a1a1a;
|
||||
--popover: #ffffff;
|
||||
--popover-foreground: #1a1a1a;
|
||||
--primary: #a31f34;
|
||||
--primary-foreground: #ffffff;
|
||||
--secondary: #f0efeb;
|
||||
--secondary-foreground: #1a1a1a;
|
||||
--muted: #f7f6f3;
|
||||
--muted-foreground: #5c5c5c;
|
||||
--accent: #d9dee5;
|
||||
--accent-foreground: #16202c;
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: #ebe9e4;
|
||||
--input: #ebe9e4;
|
||||
--ring: #a31f34;
|
||||
--radius: 0.625rem;
|
||||
|
||||
--chart-1: #a31f34;
|
||||
--chart-2: #0c2d5a;
|
||||
--chart-3: #061525;
|
||||
--chart-4: #9aa5b1;
|
||||
--chart-5: #5c5c5c;
|
||||
--sidebar: #ffffff;
|
||||
--sidebar-foreground: #1a1a1a;
|
||||
--sidebar-primary: #a31f34;
|
||||
--sidebar-primary-foreground: #ffffff;
|
||||
--sidebar-accent: #f0efeb;
|
||||
--sidebar-accent-foreground: #1a1a1a;
|
||||
--sidebar-border: #e2e0db;
|
||||
--sidebar-ring: #a31f34;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #f7f6f3;
|
||||
--card: #141414;
|
||||
--card-foreground: #f7f6f3;
|
||||
--popover: #141414;
|
||||
--popover-foreground: #f7f6f3;
|
||||
--primary: #c43a4e;
|
||||
--primary-foreground: #ffffff;
|
||||
--secondary: #1f1f1f;
|
||||
--secondary-foreground: #f7f6f3;
|
||||
--muted: #1a1a1a;
|
||||
--muted-foreground: #a3a3a3;
|
||||
--accent: #c7ced8;
|
||||
--accent-foreground: #111827;
|
||||
--border: #2a2a2a;
|
||||
--input: #2a2a2a;
|
||||
--ring: #c43a4e;
|
||||
--sidebar: #141414;
|
||||
--sidebar-foreground: #f7f6f3;
|
||||
--sidebar-primary: #c43a4e;
|
||||
--sidebar-primary-foreground: #ffffff;
|
||||
--sidebar-accent: #1f1f1f;
|
||||
--sidebar-accent-foreground: #f7f6f3;
|
||||
--sidebar-border: #2a2a2a;
|
||||
--sidebar-ring: #c43a4e;
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border outline-ring/50;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground antialiased;
|
||||
font-size: 16px;
|
||||
line-height: 1.65;
|
||||
text-align: start;
|
||||
}
|
||||
html {
|
||||
@apply font-sans scroll-smooth;
|
||||
scroll-padding-top: 6rem;
|
||||
}
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
/* Metamorphism dots + lines — soft presence, not noise */
|
||||
@keyframes metamorph-line-pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.35;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes metamorph-dot-breathe {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.55;
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
transform: scale(1.35);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes metamorph-field-drift {
|
||||
0%,
|
||||
100% {
|
||||
transform: translate3d(0, 0, 0);
|
||||
}
|
||||
50% {
|
||||
transform: translate3d(1.2%, -0.8%, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes metamorph-dash-flow {
|
||||
from { stroke-dashoffset: 24; }
|
||||
to { stroke-dashoffset: 0; }
|
||||
}
|
||||
|
||||
@keyframes section-reveal {
|
||||
from { opacity: 0; transform: translateY(2rem); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
.metamorph-field__mesh {
|
||||
animation: metamorph-field-drift 18s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.metamorph-field__line {
|
||||
stroke-dasharray: 4 8;
|
||||
animation:
|
||||
metamorph-line-pulse 7s ease-in-out infinite,
|
||||
metamorph-dash-flow 8s linear infinite;
|
||||
}
|
||||
|
||||
.page-hero::after,
|
||||
.home-hero::after {
|
||||
position: absolute;
|
||||
inset-inline: 0;
|
||||
bottom: 0;
|
||||
height: 1px;
|
||||
content: "";
|
||||
background: linear-gradient(90deg, transparent, var(--accent), transparent);
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.site-header::before {
|
||||
position: absolute;
|
||||
inset-inline: 0;
|
||||
top: 0;
|
||||
height: 2px;
|
||||
content: "";
|
||||
background: linear-gradient(90deg, var(--primary), var(--accent), var(--primary));
|
||||
}
|
||||
|
||||
.site-header nav a {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.site-header nav a::after {
|
||||
position: absolute;
|
||||
inset-inline-start: 50%;
|
||||
bottom: 0.15rem;
|
||||
width: 0.3rem;
|
||||
height: 0.3rem;
|
||||
border-radius: 999px;
|
||||
content: "";
|
||||
background: var(--primary);
|
||||
opacity: 0;
|
||||
transform: translateX(50%) scale(0);
|
||||
transition: opacity 200ms ease, transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
|
||||
.site-header nav a:hover::after,
|
||||
.site-header nav a:focus-visible::after {
|
||||
opacity: 1;
|
||||
transform: translateX(50%) scale(1);
|
||||
}
|
||||
|
||||
.motion-section[data-tone="muted"] {
|
||||
background-image: radial-gradient(color-mix(in oklab, var(--foreground) 9%, transparent) 0.7px, transparent 0.7px);
|
||||
background-size: 22px 22px;
|
||||
}
|
||||
|
||||
.motion-section[data-tone="dark"] {
|
||||
background-image:
|
||||
radial-gradient(circle at 10% 20%, color-mix(in oklab, var(--primary) 30%, transparent), transparent 28%),
|
||||
radial-gradient(circle at 90% 80%, color-mix(in oklab, var(--accent) 10%, transparent), transparent 25%);
|
||||
}
|
||||
|
||||
@supports (animation-timeline: view()) {
|
||||
.motion-section {
|
||||
animation: section-reveal both cubic-bezier(0.22, 1, 0.36, 1);
|
||||
animation-timeline: view();
|
||||
animation-range: entry 5% cover 28%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
[data-slot="card"] img {
|
||||
transition: transform 500ms cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
[data-slot="card"]:hover img {
|
||||
transform: scale(1.025);
|
||||
}
|
||||
}
|
||||
|
||||
.metamorph-field__dot {
|
||||
transform-box: fill-box;
|
||||
transform-origin: center;
|
||||
animation: metamorph-dot-breathe 6s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
html {
|
||||
scroll-behavior: auto;
|
||||
}
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
animation-duration: 0.01ms !important;
|
||||
animation-iteration-count: 1 !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
}
|
||||
.metamorph-field__mesh,
|
||||
.metamorph-field__line,
|
||||
.metamorph-field__dot {
|
||||
animation: none !important;
|
||||
}
|
||||
.metamorph-field animate {
|
||||
display: none;
|
||||
}
|
||||
.motion-section {
|
||||
animation: none !important;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
+98
-18
@@ -1,29 +1,109 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import localFont from "next/font/local";
|
||||
import { NextIntlClientProvider } from "next-intl";
|
||||
import { getLocale, getMessages, getTranslations } from "next-intl/server";
|
||||
import { JsonLd, organizationJsonLd } from "@/lib/seo/json-ld";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
const iranSans = localFont({
|
||||
src: [
|
||||
{
|
||||
path: "../fonts/iransans/IRANSansUltraLight.woff2",
|
||||
weight: "200",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../fonts/iransans/IRANSansLight.woff2",
|
||||
weight: "300",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../fonts/iransans/IRANSans.woff2",
|
||||
weight: "400",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../fonts/iransans/IRANSansMedium.woff2",
|
||||
weight: "500",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../fonts/iransans/IRANSansBold.woff2",
|
||||
weight: "600",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../fonts/iransans/IRANSansBold.woff2",
|
||||
weight: "700",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../fonts/iransans/IRANSansBold.woff2",
|
||||
weight: "800",
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
path: "../fonts/iransans/IRANSansBold.woff2",
|
||||
weight: "900",
|
||||
style: "normal",
|
||||
},
|
||||
],
|
||||
variable: "--font-iransans",
|
||||
display: "optional",
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("meta");
|
||||
return {
|
||||
metadataBase: new URL("https://openedu.aut.ac.ir"),
|
||||
title: {
|
||||
default: t("homeTitle"),
|
||||
template: `%s | ${t("homeTitle")}`,
|
||||
},
|
||||
description: t("homeDescription"),
|
||||
icons: {
|
||||
icon: [{ url: "/brand/amirkabir.png", type: "image/png" }],
|
||||
apple: [{ url: "/brand/amirkabir.png", type: "image/png" }],
|
||||
shortcut: "/brand/amirkabir.png",
|
||||
},
|
||||
openGraph: {
|
||||
type: "website",
|
||||
locale: "fa_IR",
|
||||
siteName: t("homeTitle"),
|
||||
title: t("homeTitle"),
|
||||
description: t("homeDescription"),
|
||||
images: [{ url: "/brand/amirkabir.png", alt: "دانشگاه صنعتی امیرکبیر" }],
|
||||
},
|
||||
alternates: {
|
||||
canonical: "/",
|
||||
languages: { fa: "/" },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
};
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const locale = await getLocale();
|
||||
const messages = await getMessages();
|
||||
const t = await getTranslations("nav");
|
||||
|
||||
export default function RootLayout({ children }: LayoutProps<"/">) {
|
||||
return (
|
||||
<html
|
||||
lang="en"
|
||||
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
|
||||
>
|
||||
<body className="min-h-full flex flex-col">{children}</body>
|
||||
<html lang={locale} dir="rtl" className={`${iranSans.variable} h-full`}>
|
||||
<body className="flex min-h-full flex-col font-sans">
|
||||
<NextIntlClientProvider messages={messages}>
|
||||
<a
|
||||
href="#main-content"
|
||||
className="sr-only focus:not-sr-only focus:absolute focus:start-4 focus:top-4 focus:z-[100] focus:bg-card focus:px-3 focus:py-2"
|
||||
>
|
||||
{t("skipToContent")}
|
||||
</a>
|
||||
<JsonLd data={organizationJsonLd()} />
|
||||
{children}
|
||||
</NextIntlClientProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
import Image from "next/image";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className="flex flex-col flex-1 items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
||||
<main className="flex flex-1 w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
||||
<Image
|
||||
className="dark:invert h-5 w-[100px]"
|
||||
src="/next.svg"
|
||||
alt="Next.js logo"
|
||||
width={100}
|
||||
height={20}
|
||||
priority
|
||||
/>
|
||||
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
|
||||
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
|
||||
To get started, edit the{" "}
|
||||
<code className="rounded bg-black/[.06] px-1.5 py-0.5 font-mono text-[0.9em] dark:bg-white/[.08]">
|
||||
page.tsx
|
||||
</code>{" "}
|
||||
file.
|
||||
</h1>
|
||||
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
||||
Looking for a starting point or more instructions? Head over to{" "}
|
||||
<a
|
||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Templates
|
||||
</a>{" "}
|
||||
or the{" "}
|
||||
<a
|
||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Learning
|
||||
</a>{" "}
|
||||
center.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
className="dark:invert h-[14px] w-4"
|
||||
src="/vercel.svg"
|
||||
alt="Vercel logomark"
|
||||
width={16}
|
||||
height={14}
|
||||
/>
|
||||
Deploy Now
|
||||
</a>
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
|
||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Documentation
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { DotCta } from "@/components/atoms/DotCta";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export default function ProfessionalError({
|
||||
error,
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string };
|
||||
reset: () => void;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
console.error(error);
|
||||
}, [error]);
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex min-h-[50vh] w-full max-w-7xl flex-col items-start justify-center bg-chart-3 px-5 py-20 text-background sm:px-8 lg:px-12">
|
||||
<p className="text-sm font-semibold text-accent">خطا</p>
|
||||
<h1 className="mt-3 text-2xl font-bold tracking-tight text-background sm:text-3xl">
|
||||
بارگذاری صفحه ناموفق بود
|
||||
</h1>
|
||||
<p className="mt-3 max-w-md text-background/70">لطفاً دوباره تلاش کنید.</p>
|
||||
<div className="mt-8 flex flex-wrap gap-4">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="border-background/60 bg-transparent text-background hover:bg-background hover:text-foreground"
|
||||
onClick={reset}
|
||||
>
|
||||
تلاش مجدد
|
||||
</Button>
|
||||
<DotCta href="/professional" onDark>
|
||||
بازگشت
|
||||
</DotCta>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { SiteFooter } from "@/components/organisms/SiteFooter";
|
||||
import { SiteHeader } from "@/components/organisms/SiteHeader";
|
||||
import { getCourses } from "@/lib/data/courses";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
import { professionalNav, siteShortName } from "@/lib/site-config";
|
||||
|
||||
export default async function ProfessionalLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const t = await getTranslations();
|
||||
const year = new Date().getFullYear();
|
||||
const [courses, programs] = await Promise.all([getCourses(), getPrograms()]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SiteHeader
|
||||
items={professionalNav}
|
||||
searchLabel={t("nav.search")}
|
||||
brandTitle={siteShortName}
|
||||
brandSubtitle={t("nav.brandSubtitle")}
|
||||
brandHref="/professional"
|
||||
academicsLabel={t("nav.academics")}
|
||||
programSelectorTitle={t("home.programSelectorTitle")}
|
||||
executiveLabel={t("home.executiveLabel")}
|
||||
exploreLabel={t("home.exploreOurPrograms")}
|
||||
variant="professional"
|
||||
courses={courses}
|
||||
programs={programs}
|
||||
/>
|
||||
<div className="flex-1">{children}</div>
|
||||
<SiteFooter
|
||||
variant="professional"
|
||||
copyright={t("footer.copyright", { year })}
|
||||
linksTitle={t("footer.links")}
|
||||
links={[
|
||||
{ label: t("footer.press"), href: "/press" },
|
||||
{ label: t("footer.careers"), href: "/careers" },
|
||||
{ label: t("footer.accessibility"), href: "/accessibility" },
|
||||
{ label: t("footer.privacy"), href: "/privacy" },
|
||||
]}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { ProfessionalLandingTemplate } from "@/components/templates/ProfessionalLandingTemplate";
|
||||
import { getCourses } from "@/lib/data/courses";
|
||||
import { getSiteStats, getTestimonials } from "@/lib/data/site";
|
||||
import { courseJsonLd, JsonLd } from "@/lib/seo/json-ld";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("meta");
|
||||
return {
|
||||
title: t("professionalTitle"),
|
||||
description: t("professionalDescription"),
|
||||
openGraph: {
|
||||
title: t("professionalTitle"),
|
||||
description: t("professionalDescription"),
|
||||
},
|
||||
alternates: {
|
||||
canonical: "/professional",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default async function ProfessionalPage() {
|
||||
const t = await getTranslations();
|
||||
const [courses, stats, testimonials] = await Promise.all([
|
||||
getCourses(),
|
||||
getSiteStats(),
|
||||
getTestimonials(),
|
||||
]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{courses.slice(0, 3).map((course) => (
|
||||
<JsonLd key={course.id} data={courseJsonLd(course)} />
|
||||
))}
|
||||
<ProfessionalLandingTemplate
|
||||
labels={{
|
||||
pathways: t("professional.pathways"),
|
||||
exploreCourses: t("nav.exploreCourses"),
|
||||
heroTitle: t("professional.heroTitle"),
|
||||
heroBody: t("professional.heroBody"),
|
||||
findProgram: t("professional.findProgram"),
|
||||
offeredBy: t("professional.offeredBy"),
|
||||
dppTitle: t("professional.dppTitle"),
|
||||
dppBody: t("professional.dppBody"),
|
||||
statsTitle: t("professional.statsTitle"),
|
||||
rankTitle: t("professional.rankTitle"),
|
||||
testimonialsTitle: t("professional.testimonialsTitle"),
|
||||
}}
|
||||
courses={courses}
|
||||
stats={stats}
|
||||
testimonials={testimonials}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user