Files
Aut.ManagementFaculty/src/components/templates/CourseDetailTemplate.tsx
T
smhk1376andCursor bd2cfa5a26
Deploy edu.mstaut.ir / deploy (push) Has been cancelled
Add rich HTML course lead/body and refresh AI course media from delivery v2.
Course detail pages can show sanitized HTML ad copy under the hero and a structured body; posters and brochures are updated for both AI workshops.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-20 00:54:30 +03:30

169 lines
5.6 KiB
TypeScript

import Link from "next/link";
import { Clock, Layers, Wallet } from "lucide-react";
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 { CourseMediaFigure } from "@/components/molecules/CourseMediaFigure";
import { DetailList, type DetailItem } from "@/components/molecules/DetailList";
import { PageHero } from "@/components/molecules/PageHero";
import { RichHtmlContent } from "@/components/molecules/RichHtmlContent";
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
import { CourseRegisterGate } from "@/components/organisms/CourseRegisterGate";
import { Badge } from "@/components/ui/badge";
import type { Course } from "@/lib/types";
import { courseCategoryHref, courseTagHref } from "@/lib/course-nav";
import { formatCoursePrice, formatLabel } from "@/lib/labels";
import { JsonLd, courseJsonLd } from "@/lib/seo/json-ld";
/** Portrait brochure delivery assets (~A4). */
const BROCHURE_HINT = { width: 1200, height: 1697 } as const;
export type CourseDetailLabels = {
submit: string;
success: string;
cta: string;
formTitle: string;
formDescription: string;
hint: string;
cancel: string;
backToCatalog: string;
detailsTitle: string;
aboutTitle: string;
duration: string;
format: string;
category: string;
price: string;
priceUnset: string;
};
export function CourseDetailTemplate({
course,
labels,
}: {
course: Course;
labels: CourseDetailLabels;
}) {
const priceLabel = formatCoursePrice(course.price);
const details: DetailItem[] = [
{ icon: Layers, label: labels.format, value: formatLabel(course.format) },
...(course.durationHours
? [
{
icon: Clock,
label: labels.duration,
value: `${course.durationHours} ساعت`,
},
]
: []),
{
icon: Wallet,
label: labels.price,
value: priceLabel ?? labels.priceUnset,
emphasis: Boolean(priceLabel),
},
];
const hasTaxonomy = course.categories.length > 0 || course.tags.length > 0;
const brochureUrl = course.brochureImageUrl?.trim() || undefined;
const leadHtml = course.leadHtml?.trim() ?? "";
const bodyHtml = course.bodyHtml?.trim() ?? "";
const heroIntro = leadHtml ? (
<RichHtmlContent html={leadHtml} tone="onPrimary" />
) : (
course.summary
);
return (
<main id="main-content">
<JsonLd data={courseJsonLd(course)} />
<PageHero
title={course.title}
intro={heroIntro}
eyebrow={course.categories[0]?.label ?? course.tags[0]?.label}
/>
<Section tone="subtle">
<Container className="grid min-w-0 gap-10 lg:grid-cols-[minmax(0,1fr)_minmax(0,22rem)] lg:items-start lg:gap-12">
<div className="min-w-0 space-y-10">
{brochureUrl ? (
<CourseMediaFigure
src={brochureUrl}
alt={`بروشور ${course.title}`}
width={BROCHURE_HINT.width}
height={BROCHURE_HINT.height}
priority
/>
) : null}
{bodyHtml || course.seoDescription ? (
<section className="space-y-4">
<Heading level={3} as="h2">
{labels.aboutTitle}
</Heading>
{bodyHtml ? (
<RichHtmlContent html={bodyHtml} />
) : (
<p className="text-base leading-7 text-foreground/90">
{course.seoDescription}
</p>
)}
</section>
) : null}
{hasTaxonomy ? (
<section className="space-y-4">
<Heading level={3} as="h2">
{labels.category}
</Heading>
<div className="flex flex-wrap gap-2">
{course.categories.map((c) => (
<Link key={c.id} href={courseCategoryHref(c.slug)}>
<Badge className="h-7 cursor-pointer px-3 text-sm font-semibold">
{c.label}
</Badge>
</Link>
))}
{course.tags.map((t) => (
<Link key={t.id} href={courseTagHref(t.slug)}>
<Badge
variant="outline"
className="h-7 cursor-pointer px-3 text-xs hover:bg-muted"
>
{t.label}
</Badge>
</Link>
))}
</div>
</section>
) : null}
</div>
<aside className="min-w-0 space-y-4 lg:sticky lg:top-28">
<SurfaceCard padded as="div">
<p className="mb-4 text-sm font-bold text-foreground">
{labels.detailsTitle}
</p>
<DetailList items={details} />
</SurfaceCard>
<CourseRegisterGate
courseSlug={course.slug}
submitLabel={labels.submit}
successLabel={labels.success}
ctaLabel={labels.cta}
formTitle={labels.formTitle}
formDescription={labels.formDescription}
hint={labels.hint}
cancelLabel={labels.cancel}
/>
<TextLink href="/professional" className="block px-1 text-sm">
{labels.backToCatalog}
</TextLink>
</aside>
</Container>
</Section>
</main>
);
}