Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b84409ed7 | ||
|
|
1641edfd01 |
No files matched your search
+4
-3
@@ -2,6 +2,7 @@
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.npm-cache
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
@@ -24,9 +25,9 @@
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# admin-uploaded images (keep folder via .gitkeep)
|
||||
/public/uploads/*
|
||||
!/public/uploads/.gitkeep
|
||||
# admin-uploaded images (served by GET /uploads/[...path], not public/)
|
||||
/uploads/
|
||||
/public/uploads/
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
|
||||
+5
-2
@@ -36,8 +36,11 @@ COPY --from=builder /app/public ./public
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
# Writable dir for admin image uploads (mount a volume in compose for persistence)
|
||||
RUN mkdir -p ./public/uploads && chown -R nextjs:nodejs ./public/uploads
|
||||
# Writable dir for admin image uploads (mount a volume in compose for persistence).
|
||||
# Keep this outside public/: Next standalone does not serve runtime public files.
|
||||
RUN rm -rf ./public/uploads \
|
||||
&& mkdir -p ./uploads \
|
||||
&& chown -R nextjs:nodejs ./uploads
|
||||
|
||||
USER nextjs
|
||||
|
||||
|
||||
+5
-2
@@ -18,8 +18,11 @@ COPY --chown=nextjs:nodejs . ./
|
||||
# Next warns/breaks if a legacy root-level ./static exists alongside ./public
|
||||
RUN rm -rf ./static
|
||||
|
||||
# Writable dir for admin image uploads (mount a volume in compose for persistence)
|
||||
RUN mkdir -p ./public/uploads && chown -R nextjs:nodejs ./public/uploads
|
||||
# Writable dir for admin image uploads (mount a volume in compose for persistence).
|
||||
# Keep this outside public/: Next standalone does not serve runtime public files.
|
||||
RUN rm -rf ./public/uploads \
|
||||
&& mkdir -p ./uploads \
|
||||
&& chown -R nextjs:nodejs ./uploads
|
||||
|
||||
USER nextjs
|
||||
EXPOSE 3000
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Catalog pin + manual order for current courses.
|
||||
-- Archive grouping still uses tag-archive; featured never lifts an archive course.
|
||||
ALTER TABLE courses
|
||||
ADD COLUMN IF NOT EXISTS featured BOOLEAN NOT NULL DEFAULT false,
|
||||
ADD COLUMN IF NOT EXISTS sort_order INT NOT NULL DEFAULT 0;
|
||||
+2
-1
@@ -122,7 +122,8 @@ async function main() {
|
||||
await upsert("courses", courses.map(courseToRow), [
|
||||
"id", "slug", "title", "summary", "duration_hours", "format", "price",
|
||||
"registration_url", "poster_image_url", "brochure_image_url", "image_url",
|
||||
"lead_html", "body_html", "seo_description", "published",
|
||||
"lead_html", "body_html", "seo_description", "published", "featured",
|
||||
"sort_order",
|
||||
]);
|
||||
const courseIds = courses.map((c) => c.id);
|
||||
await client.query(
|
||||
|
||||
+2
-2
@@ -13,11 +13,11 @@ services:
|
||||
- HOSTNAME=0.0.0.0
|
||||
- NEXT_PUBLIC_SITE_URL=${NEXT_PUBLIC_SITE_URL:-https://edu.mstaut.ir}
|
||||
- DATABASE_URL=${DATABASE_URL:?Set DATABASE_URL in a protected environment file}
|
||||
- UPLOAD_DIR=/app/public/uploads
|
||||
- UPLOAD_DIR=/app/uploads
|
||||
# Nginx Proxy Manager: edu.mstaut.ir → http://aut-management-faculty:3000
|
||||
# DB: same Docker network as container `insaight-postgres` (not the public IP).
|
||||
volumes:
|
||||
- uploads_data:/app/public/uploads
|
||||
- uploads_data:/app/uploads
|
||||
expose:
|
||||
- "3000"
|
||||
networks:
|
||||
|
||||
@@ -47,6 +47,8 @@
|
||||
|---|---|
|
||||
| `course.categories` | many-to-many با `course_categories` (موضوع؛ ادمین) |
|
||||
| `course.tags` | many-to-many با `course_tags` (نوع/منو؛ ادمین) |
|
||||
| `course.featured` | تیک ویژه؛ چند دورهٔ جاری میتوانند ویژه باشند (محدودیت تکویژهٔ مقاله اینجا نیست) |
|
||||
| `course.sortOrder` | عدد ترتیب؛ کوچکتر جلوتر (مثل دسته/تگ) |
|
||||
| `program.group` | `standard` یا `executive` برای selector هوم |
|
||||
| `event.endDate` | اگر null باشد رویداد تکروزه است |
|
||||
| `article.featured` | حداکثر یک مقاله featured در هوم |
|
||||
@@ -58,6 +60,8 @@
|
||||
- هیچ مبلغ/ظرفیت واقعی محاسبه نمیشود تا DB وصل شود.
|
||||
- منوی صفحهٔ اصلی فقط **یک** دراپداون دوره دارد؛ لیبل ریشه = `courseNavParentTag`؛ فرزندان = تگهای `show_in_nav`. فیلتر پایدار با **slug**: `/professional?tag=` و `/professional?category=` (مستند: `docs/LINKS.md`).
|
||||
- دسته و تگ فقط از ادمین تعریف میشوند (`/admin/course-categories`، `/admin/course-tags`)؛ هر دوره میتواند چند دسته و چند تگ داشته باشد.
|
||||
- ترتیب لیست عمومی دوره: غیرآرشیو، سپس `featured`، سپس `sort_order` صعودی، سپس عنوان. هوم و جستجو همین ترتیب را میگیرند؛ هوم آرشیو را نشان نمیدهد.
|
||||
- تگ `archive` (گزیدهٔ برگزارشده) در کتالوگ بلوک جدا و ظاهر ملایمتر است؛ `featured` دورهٔ آرشیو را به بلوک جاری بالا نمیآورد.
|
||||
|
||||
## Locale / Format Rules
|
||||
- زبان UI: فارسی؛ `dir="rtl"`؛ اعداد نمایشی میتوانند فارسیسازی شوند در لایهٔ UI.
|
||||
|
||||
+7
-1
@@ -76,7 +76,7 @@ node scripts/test-db-connection.mjs
|
||||
|
||||
| جدول | نکته |
|
||||
|---|---|
|
||||
| `courses` | `category`/`format` با CHECK؛ `slug` UNIQUE؛ `price` اختیاری (تومان، NULL = مخفی در UI) |
|
||||
| `courses` | `format` با CHECK؛ `slug` UNIQUE؛ `price` اختیاری؛ `featured` + `sort_order` (migration 011) |
|
||||
| `programs` | `group_key` (بهجای reserve واژهٔ `group`)؛ `highlights` JSONB |
|
||||
| `events` | `start_date`/`end_date` DATE؛ `end_date` NULL = تکروزه |
|
||||
| `articles` | `featured` + ایندکس جزئی `articles_one_featured` (حداکثر یک مقالهٔ published با `featured=true`) |
|
||||
@@ -98,6 +98,12 @@ node scripts/test-db-connection.mjs
|
||||
- `idx_programs_title` / `idx_courses_title` روی `(published, title)`.
|
||||
- `courses.slug`, `programs.slug`, `intersection_topics.slug` از 001 UNIQUE هستند و ایندکس جزئی `articles_one_featured` از 001 موجود است — تکرار نشدهاند.
|
||||
|
||||
## اولویت کاتالوگ (011)
|
||||
|
||||
- Migration: `db/migrations/011_course_priority.sql`.
|
||||
- `courses.featured BOOLEAN NOT NULL DEFAULT false` و `courses.sort_order INT NOT NULL DEFAULT 0`.
|
||||
- لیست عمومی: غیرآرشیو (`tag-archive`) سپس ویژه سپس `sort_order` سپس عنوان. آرشیو با تگ جدا میشود، نه با ستون جدید.
|
||||
|
||||
## Admin (فاز E — 2026-09-22)
|
||||
|
||||
- مکانیزم: `admin_users` (رمز با scrypt در `password_hash`، هرگز plaintext) + `admin_sessions` (توکن تصادفی؛ `token_hash` در DB ذخیره میشود؛ cookie فقط `admin_session` HttpOnly/SameSite=Lax).
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
| فیلتر با تگ | `/professional?tag=<slug>` |
|
||||
| فیلتر با دسته | `/professional?category=<slug>` |
|
||||
| هر دو فیلتر | `/professional?tag=<slug>&category=<slug>` |
|
||||
| گزیدهٔ برگزارشده | `/professional?tag=archive` (در لیست کامل، بلوک جدا زیر دورههای جاری) |
|
||||
|
||||
### تگ پدر (لیبل منو)
|
||||
|
||||
|
||||
@@ -30,3 +30,4 @@
|
||||
| 2026-09-24 | D23 — پایان H: حذف کامل وابستگی runtime به mock برای محتوای با تیبل: `intersections`، `stats`، `testimonials` از DB میآیند (`getTopics`، `getSiteStats`، `getTestimonials` در `lib/data/site.ts`؛ `HomeRest` با prop `stats`)؛ هویت/ناو استاتیکِ بدونتیبل به ماژول مستقل `src/lib/site-config.ts` منتقل شد؛ `src/lib/mock/site.ts` فقط برای seed باقی ماند (کامنت هدر دارد)؛ ایندکسها با `db/migrations/002_indexes.sql` (leads/articles/events/programs/courses)؛ اسکریپت `scripts/smoke.mjs` (۴ API عمومی + login + create/delete stat) | معیار پذیرش C/H: runtime هیچ import مستقیمی از mock ندارد؛ config بدون تیبل نباید «دادهٔ mock» تلقی شود؛ smoke خواندنی + یک write ادمین میسنجد |
|
||||
| 2026-10-12 | D25 — تاکسونومی دوره دو لایهٔ ادمینمحور: `course_categories` (موضوع) + `course_tags` (نوع/منو) با junction many-to-many؛ حذف `courses.category` enum و `courses.tags` text[]؛ لینک پایدار با slug (`?tag=` / `?category=`)؛ CRUD در `/admin/course-categories` و `/admin/course-tags` | دسته و تگ باید پویا و قابل تعریف در ادمین باشند؛ لیبل فارسی جدا از slug است |
|
||||
| 2026-10-11 | D24 — آپلود تصویر ادمین: `POST /api/admin/upload` (multipart، فقط ادمین) فایل را در `public/uploads/{folder}/` مینویسد و مسیر عمومی `/uploads/...` برمیگرداند؛ UI با `ImageUploadField` در `CourseForm` و فیلد نوع `image` در `GenericForm`/`entities` (articles/topics/faculty/alumni)؛ persistence در Docker با volume `uploads_data` و env `UPLOAD_DIR` | ورود دستی URL اشتباه بود؛ ادمین باید فایل بارگذاری کند؛ ستونهای DB همچنان path/URL میمانند |
|
||||
| 2026-10-22 | D26 — اولویت کاتالوگ: `courses.featured` + `courses.sort_order` (migration 011)؛ ترتیب عمومی غیرآرشیو → ویژه → ترتیب → عنوان؛ تگ `archive` در کتالوگ بلوک جدا با کارت ملایمتر است و از هوم حذف میماند | چند دورهٔ جاری باید جلو بیایند و گزیدهٔ برگزارشده از لیست جاری جدا دیده شود |
|
||||
@@ -1,11 +1,10 @@
|
||||
# Active Context
|
||||
|
||||
## Current Goal
|
||||
چکلیست UI در `docs/Todo.Md` پیاده شد؛ سه آیتم blocked منتظر کاربر.
|
||||
اولویت نمایش دورهها (ویژه + ترتیب) و جداسازی گزیدهٔ برگزارشده در کتالوگ.
|
||||
|
||||
## Current Work
|
||||
- انجامشده: هدر/ناو/فوتر، فونت Vazirmatn، هوم، سرچ/کارت دورهها، اسکیما اساتید (`profile_url` + `course_faculty_links`)
|
||||
- لوگو دانشکده اعمال شد (`/brand/mst-faculty.png` + favicon)
|
||||
- انجامشده: `featured`/`sort_order` روی `courses`، ادمین، Badge ویژه، بلوک آرشیو جدا در `/professional`
|
||||
- Blocked: پالت رنگی mst (۱۱)، seed اساتید پس از دسترسی (۱۷c)
|
||||
|
||||
## Current Blockers
|
||||
@@ -13,5 +12,6 @@
|
||||
- دسترسی به شبکه اساتید mst برای کپی داده
|
||||
|
||||
## Next Steps
|
||||
1. دریافت پالت و بهروزرسانی توکنهای `globals.css`
|
||||
2. پس از دسترسی mst: seed اساتید با `profileUrl`
|
||||
1. در ادمین، دورههای مهم جاری را ویژه/مرتب کنید
|
||||
2. دریافت پالت و بهروزرسانی توکنهای `globals.css`
|
||||
3. پس از دسترسی mst: seed اساتید با `profileUrl`
|
||||
@@ -39,10 +39,12 @@
|
||||
|
||||
- [x] منوی هوم: یک دراپداون از تگها؛ `courseNavParentTag`؛ لینک پایدار
|
||||
- [x] D25 تاکسونومی ادمینمحور: دسته + تگ many-to-many؛ migration 007؛ CRUD ادمین؛ فیلتر `?tag=`/`?category=` با slug
|
||||
- [x] D26 اولویت کاتالوگ: `featured` + `sort_order` (migration 011)؛ بلوک جدا برای تگ `archive`
|
||||
|
||||
## Next
|
||||
- [x] فاز H باقیمانده — ایندکسها، docs/README نهایی، حذف وابستگی runtime به mock، smoke script
|
||||
- [x] Todo UI سایت (هدر/هوم/دورهها/فونت/اسکیما اساتید) — جزئیات در `docs/Todo.Md`
|
||||
- [x] D26 اولویت دوره + جداسازی گزیدهٔ برگزارشده
|
||||
- [ ] محتوای واقعی از پنل ادمین (طبق دستور کاربر بعداً)
|
||||
- [x] لوگوی دانشکده (نشان بدون متن کناری + favicon)
|
||||
- [ ] Todo blocked: پالت mst، seed اساتید از شبکه دانشکده
|
||||
|
||||
@@ -7,6 +7,10 @@ const nextConfig: NextConfig = {
|
||||
output: "standalone",
|
||||
// Babel React Compiler is heavy in Docker/CI; keep it for local `next dev`.
|
||||
reactCompiler: process.env.DISABLE_REACT_COMPILER !== "1",
|
||||
// VPS deploy sets SKIP_TYPECHECK=1. `npm run build` locally still typechecks.
|
||||
typescript: {
|
||||
ignoreBuildErrors: process.env.SKIP_TYPECHECK === "1",
|
||||
},
|
||||
experimental: {
|
||||
optimizePackageImports: ["lucide-react"],
|
||||
},
|
||||
|
||||
Whitespace-only changes.
@@ -44,8 +44,8 @@ docker run --rm --network "$NETWORK" --env-file "$ENV_FILE" \
|
||||
# Check the database and a minimal page set before switching the public upstream.
|
||||
CANDIDATE="edu-candidate-${REVISION:0:12}"
|
||||
docker run -d --name "$CANDIDATE" --network "$NETWORK" --env-file "$ENV_FILE" \
|
||||
-e UPLOAD_DIR=/app/public/uploads \
|
||||
-v "$UPLOAD_VOLUME:/app/public/uploads" \
|
||||
-e UPLOAD_DIR=/app/uploads \
|
||||
-v "$UPLOAD_VOLUME:/app/uploads" \
|
||||
"$IMAGE"
|
||||
cleanup_candidate() { docker rm -f "$CANDIDATE" >/dev/null 2>&1 || true; }
|
||||
trap cleanup_candidate EXIT
|
||||
@@ -101,8 +101,8 @@ rollback() {
|
||||
trap rollback ERR
|
||||
docker run -d --name "$CONTAINER" --restart unless-stopped \
|
||||
--network "$NETWORK" --env-file "$ENV_FILE" \
|
||||
-e UPLOAD_DIR=/app/public/uploads \
|
||||
-v "$UPLOAD_VOLUME:/app/public/uploads" \
|
||||
-e UPLOAD_DIR=/app/uploads \
|
||||
-v "$UPLOAD_VOLUME:/app/uploads" \
|
||||
-p 127.0.0.1:3000:3000 "$IMAGE"
|
||||
READY=false
|
||||
for attempt in $(seq 1 20); do
|
||||
|
||||
@@ -149,17 +149,15 @@ async function main() {
|
||||
}
|
||||
|
||||
const sequences = await client.query(`
|
||||
SELECT sequencename, last_value, is_called
|
||||
SELECT sequencename, last_value
|
||||
FROM pg_sequences
|
||||
WHERE schemaname = 'public'
|
||||
ORDER BY sequencename
|
||||
`);
|
||||
for (const seq of sequences.rows) {
|
||||
const called = seq.is_called === true;
|
||||
if (seq.last_value == null) continue;
|
||||
const seqName = String(seq.sequencename).replaceAll("'", "''");
|
||||
lines.push(
|
||||
`SELECT setval('${seqName}', ${Number(seq.last_value)}, ${called});`,
|
||||
);
|
||||
lines.push(`SELECT setval('${seqName}', ${Number(seq.last_value)}, true);`);
|
||||
}
|
||||
|
||||
lines.push("", "COMMIT;", "");
|
||||
|
||||
@@ -13,14 +13,23 @@ export NODE_OPTIONS="${NODE_OPTIONS:---max-old-space-size=3072}"
|
||||
|
||||
echo "Building Next.js at $ROOT (Node 22 container)…"
|
||||
# No BuildKit cache mounts — stock docker on the VPS does not support type=cache.
|
||||
# A normal host directory works. .next/cache stays on the checkout between deploys
|
||||
# so webpack can reuse it. Do not delete it here.
|
||||
NPM_CACHE=/var/cache/edu-npm
|
||||
if ! mkdir -p "$NPM_CACHE" 2>/dev/null; then
|
||||
NPM_CACHE="$ROOT/.npm-cache"
|
||||
mkdir -p "$NPM_CACHE"
|
||||
fi
|
||||
docker run --rm \
|
||||
-e DISABLE_REACT_COMPILER=1 \
|
||||
-e NEXT_TELEMETRY_DISABLED=1 \
|
||||
-e NEXT_PUBLIC_SITE_URL \
|
||||
-e NODE_OPTIONS \
|
||||
-e SKIP_TYPECHECK=1 \
|
||||
-v "$ROOT:/app" -w /app \
|
||||
-v "$NPM_CACHE:/root/.npm" \
|
||||
node:22-alpine \
|
||||
sh -ec 'npm ci --no-audit --no-fund && npm run build'
|
||||
sh /app/scripts/vps-next-build.sh
|
||||
|
||||
bash scripts/assemble-prebuilt.sh "$ROOT/prebuilt"
|
||||
rm -rf "$ROOT/prebuilt/static"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
# Runs inside node:22-alpine with the repo mounted at /app.
|
||||
# npm cache is a host directory mounted at /root/.npm (BuildKit cache mounts
|
||||
# are unavailable on the VPS Docker).
|
||||
set -eu
|
||||
cd /app
|
||||
|
||||
lock=$(sha256sum package-lock.json | awk 'NR==1 { print $1 }')
|
||||
node_ver=$(node -v)
|
||||
stamp="node_modules/.install-stamp"
|
||||
want="$lock $node_ver"
|
||||
|
||||
if [ -d node_modules/next ] && [ -f "$stamp" ] && [ "$(cat "$stamp")" = "$want" ]; then
|
||||
echo "Dependencies unchanged ($node_ver); skipping npm ci"
|
||||
else
|
||||
echo "Installing dependencies ($node_ver)…"
|
||||
npm ci --no-audit --no-fund --prefer-offline --cache /root/.npm
|
||||
printf '%s\n' "$want" > "$stamp"
|
||||
fi
|
||||
|
||||
npm run build
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Metadata } from "next";
|
||||
import Image from "next/image";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
@@ -41,7 +41,7 @@ export default async function AlumniPage() {
|
||||
className="scroll-mt-24"
|
||||
>
|
||||
<div className="relative aspect-[16/10] bg-muted">
|
||||
<Image
|
||||
<CmsImage
|
||||
src={story.imageUrl}
|
||||
alt={story.name}
|
||||
fill
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Metadata } from "next";
|
||||
import Image from "next/image";
|
||||
import { notFound } from "next/navigation";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { TextLink } from "@/components/atoms/TextLink";
|
||||
@@ -56,7 +56,7 @@ export default async function InsightDetailPage({ params }: Props) {
|
||||
<Section tone="subtle">
|
||||
<Container narrow>
|
||||
<div className="relative mb-10 aspect-[16/9] overflow-hidden rounded-2xl bg-muted ring-1 ring-foreground/10">
|
||||
<Image
|
||||
<CmsImage
|
||||
src={article.imageUrl}
|
||||
alt={article.title}
|
||||
fill
|
||||
|
||||
@@ -47,6 +47,8 @@ const COURSE_COLUMNS: Record<string, string> = {
|
||||
bodyHtml: "body_html",
|
||||
seoDescription: "seo_description",
|
||||
published: "published",
|
||||
featured: "featured",
|
||||
sortOrder: "sort_order",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/courses/[id] — update course (admin only)
|
||||
|
||||
@@ -65,8 +65,8 @@ export async function POST(request: NextRequest) {
|
||||
`INSERT INTO courses
|
||||
(id, slug, title, summary, duration_hours, format, price,
|
||||
registration_url, poster_image_url, brochure_image_url, image_url,
|
||||
lead_html, body_html, seo_description, published)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)`,
|
||||
lead_html, body_html, seo_description, published, featured, sort_order)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17)`,
|
||||
[
|
||||
id,
|
||||
d.slug,
|
||||
@@ -83,6 +83,8 @@ export async function POST(request: NextRequest) {
|
||||
d.bodyHtml,
|
||||
d.seoDescription,
|
||||
d.published,
|
||||
d.featured,
|
||||
d.sortOrder,
|
||||
],
|
||||
);
|
||||
await setCourseCategories(id, d.categoryIds ?? []);
|
||||
|
||||
@@ -2,6 +2,8 @@ import type { Metadata, Viewport } from "next";
|
||||
import { Vazirmatn } from "next/font/google";
|
||||
import { NextIntlClientProvider } from "next-intl";
|
||||
import { getLocale, getMessages, getTranslations } from "next-intl/server";
|
||||
import { Suspense } from "react";
|
||||
import { GlobalActionLoadingOverlay } from "@/components/molecules/GlobalActionLoadingOverlay";
|
||||
import { getSiteOrigin } from "@/lib/seo/metadata";
|
||||
import { JsonLd, organizationJsonLd } from "@/lib/seo/json-ld";
|
||||
import "./globals.css";
|
||||
@@ -78,6 +80,9 @@ export default async function RootLayout({
|
||||
className={`${vazirmatn.className} flex min-h-full min-w-0 flex-col font-sans`}
|
||||
>
|
||||
<NextIntlClientProvider messages={messages}>
|
||||
<Suspense fallback={null}>
|
||||
<GlobalActionLoadingOverlay />
|
||||
</Suspense>
|
||||
<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"
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
import { useState, FormEvent, Suspense } from "react";
|
||||
import Image from "next/image";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
@@ -17,7 +18,7 @@ import {
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
function LoginForm() {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const redirect = searchParams.get("redirect") || "/mstcontroller";
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { readFile, stat } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
mimeForUploadExt,
|
||||
resolveStoredUploadPath,
|
||||
} from "@/lib/uploads/image";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
type RouteParams = { params: Promise<{ path: string[] }> };
|
||||
|
||||
async function lookupUpload(segments: string[]) {
|
||||
const absolutePath = resolveStoredUploadPath(segments);
|
||||
if (!absolutePath) return null;
|
||||
|
||||
try {
|
||||
const info = await stat(absolutePath);
|
||||
if (!info.isFile()) return null;
|
||||
const mime = mimeForUploadExt(path.extname(absolutePath));
|
||||
if (!mime) return null;
|
||||
return { absolutePath, info, mime };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function headersFor(file: { info: { size: number }; mime: string }) {
|
||||
return {
|
||||
"Content-Type": file.mime,
|
||||
"Content-Length": String(file.info.size),
|
||||
"Cache-Control": "public, max-age=31536000, immutable",
|
||||
};
|
||||
}
|
||||
|
||||
export async function GET(_request: Request, { params }: RouteParams) {
|
||||
const { path: segments } = await params;
|
||||
const file = await lookupUpload(segments);
|
||||
if (!file) {
|
||||
return new NextResponse("Not found", { status: 404 });
|
||||
}
|
||||
const buffer = await readFile(file.absolutePath);
|
||||
return new NextResponse(buffer, {
|
||||
status: 200,
|
||||
headers: headersFor(file),
|
||||
});
|
||||
}
|
||||
|
||||
export async function HEAD(_request: Request, { params }: RouteParams) {
|
||||
const { path: segments } = await params;
|
||||
const file = await lookupUpload(segments);
|
||||
if (!file) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
return new NextResponse(null, {
|
||||
status: 200,
|
||||
headers: headersFor(file),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import Image, { type ImageProps } from "next/image";
|
||||
import { isRuntimeUploadSrc } from "@/lib/uploads/types";
|
||||
|
||||
/**
|
||||
* next/image optimizer reads from `public/` at build time. Runtime uploads
|
||||
* live outside that tree, so skip optimization for `/uploads/...`.
|
||||
*/
|
||||
export function CmsImage({ src, unoptimized, ...props }: ImageProps) {
|
||||
const skipOptimize =
|
||||
unoptimized ??
|
||||
(typeof src === "string" && isRuntimeUploadSrc(src));
|
||||
|
||||
return <Image src={src} unoptimized={skipOptimize} {...props} />;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
import { ArrowUpLeft, MapPin, Wifi } from "lucide-react";
|
||||
import {
|
||||
Card,
|
||||
@@ -65,7 +65,7 @@ export function ArticleCard({
|
||||
return (
|
||||
<article className="group grid overflow-hidden border-b border-border py-7 first:pt-0 last:border-b-0 sm:grid-cols-[14rem_1fr] sm:gap-8 lg:grid-cols-[19rem_1fr] lg:py-9">
|
||||
<Link href={href} className="relative aspect-[16/10] overflow-hidden rounded-xl bg-muted sm:aspect-auto sm:min-h-44">
|
||||
<Image src={imageUrl} alt={title} fill placeholder="blur" blurDataURL={blurDataURL} className="object-cover transition-transform duration-500 group-hover:scale-[1.025]" sizes="(max-width:640px) 100vw, 304px" />
|
||||
<CmsImage src={imageUrl} alt={title} fill placeholder="blur" blurDataURL={blurDataURL} className="object-cover transition-transform duration-500 group-hover:scale-[1.025]" sizes="(max-width:640px) 100vw, 304px" />
|
||||
</Link>
|
||||
<div className="flex min-w-0 flex-col justify-center pt-5 sm:pt-0">
|
||||
<p className="text-xs font-bold text-accent">{category}</p>
|
||||
@@ -101,7 +101,7 @@ export function ArticleCard({
|
||||
featured ? "aspect-[16/10]" : "aspect-[4/3]",
|
||||
)}
|
||||
>
|
||||
<Image
|
||||
<CmsImage
|
||||
src={imageUrl}
|
||||
alt={title}
|
||||
fill
|
||||
@@ -236,7 +236,7 @@ export function IntersectionCard({
|
||||
className="group relative block min-h-[16rem] overflow-hidden rounded-2xl bg-primary shadow-sm sm:min-h-[18rem]"
|
||||
>
|
||||
<div className="absolute inset-0 overflow-hidden">
|
||||
<Image
|
||||
<CmsImage
|
||||
src={imageUrl}
|
||||
alt={title}
|
||||
fill
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Image from "next/image";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
|
||||
/** Card media: banner image when set; otherwise course title on themed surface. */
|
||||
export function CourseCardBanner({
|
||||
@@ -13,7 +13,7 @@ export function CourseCardBanner({
|
||||
return (
|
||||
<div className="pointer-events-none relative aspect-video overflow-hidden bg-primary-foreground/10">
|
||||
{hasBanner ? (
|
||||
<Image
|
||||
<CmsImage
|
||||
src={bannerUrl!}
|
||||
alt=""
|
||||
fill
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
import Link from "next/link";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { CourseCardBanner } from "@/components/molecules/CourseCardBanner";
|
||||
import type { Course } from "@/lib/types";
|
||||
import { formatCoursePrice, formatLabel } from "@/lib/labels";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function CourseCatalogCard({
|
||||
course,
|
||||
variant,
|
||||
categorySlug,
|
||||
tagSlug,
|
||||
categoryHref,
|
||||
tagHref,
|
||||
}: {
|
||||
course: Course;
|
||||
variant: "current" | "archive";
|
||||
categorySlug: string;
|
||||
tagSlug: string;
|
||||
categoryHref: (slug: string) => string;
|
||||
tagHref: (slug: string) => string;
|
||||
}) {
|
||||
const priceLabel = formatCoursePrice(course.price);
|
||||
const isArchive = variant === "archive";
|
||||
const showFeatured = !isArchive && Boolean(course.featured);
|
||||
|
||||
return (
|
||||
<Card
|
||||
className={cn(
|
||||
"group relative gap-0 overflow-hidden py-0 text-primary-foreground transition-colors",
|
||||
isArchive
|
||||
? "bg-primary-foreground/[0.03] opacity-80 ring-primary-foreground/5 hover:ring-primary-foreground/20"
|
||||
: "bg-primary-foreground/5 ring-primary-foreground/10 hover:ring-primary-foreground/30",
|
||||
)}
|
||||
>
|
||||
<Link
|
||||
href={course.registrationUrl}
|
||||
className="absolute inset-0 z-0"
|
||||
aria-label={course.title}
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<CourseCardBanner title={course.title} bannerUrl={course.posterImageUrl} />
|
||||
<CardHeader className="pointer-events-none relative z-[1] gap-1 px-4 pt-4">
|
||||
{showFeatured ? (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="w-fit border-secondary bg-secondary/20 text-[10px] font-semibold text-secondary"
|
||||
>
|
||||
ویژه
|
||||
</Badge>
|
||||
) : null}
|
||||
<CardTitle className="text-base text-primary-foreground">
|
||||
{course.title}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="pointer-events-none relative z-[1] space-y-3 px-4 pb-4">
|
||||
<CardDescription className="line-clamp-3 text-primary-foreground/70">
|
||||
{course.summary}
|
||||
</CardDescription>
|
||||
{course.categories.length > 0 || course.tags.length > 0 ? (
|
||||
<div className="pointer-events-auto flex flex-wrap gap-1.5">
|
||||
{course.categories.map((c) => {
|
||||
const href = categoryHref(c.slug);
|
||||
const active = categorySlug === c.slug;
|
||||
return (
|
||||
<Link
|
||||
key={`cat:${c.id}`}
|
||||
href={href}
|
||||
className="relative z-[2]"
|
||||
aria-current={active ? "true" : undefined}
|
||||
>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"cursor-pointer border-primary-foreground/25 text-[11px] font-semibold text-primary-foreground/90 hover:bg-primary-foreground/15",
|
||||
active && "border-secondary bg-secondary/25 text-secondary",
|
||||
)}
|
||||
>
|
||||
{c.label}
|
||||
</Badge>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
{course.tags.map((t) => {
|
||||
const href = tagHref(t.slug);
|
||||
const active = tagSlug === t.slug;
|
||||
return (
|
||||
<Link
|
||||
key={`tag:${t.id}`}
|
||||
href={href}
|
||||
className="relative z-[2]"
|
||||
aria-current={active ? "true" : undefined}
|
||||
>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"cursor-pointer border-primary-foreground/25 text-[10px] text-primary-foreground/75 hover:bg-primary-foreground/15",
|
||||
active && "border-secondary bg-secondary/25 text-secondary",
|
||||
)}
|
||||
>
|
||||
{t.label}
|
||||
</Badge>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-primary-foreground/55">
|
||||
<span>
|
||||
{course.durationHours
|
||||
? `${course.durationHours} ساعت · ${formatLabel(course.format)}`
|
||||
: formatLabel(course.format)}
|
||||
</span>
|
||||
{priceLabel ? (
|
||||
<span className="font-semibold text-primary-foreground/90">
|
||||
{priceLabel}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="inline-flex text-sm font-semibold text-primary-foreground underline-offset-4 group-hover:underline">
|
||||
{isArchive ? "مشاهده جزئیات" : "جزئیات و ثبت نام"}
|
||||
</span>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import Image from "next/image";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ export function CourseMediaFigure({
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<Image
|
||||
<CmsImage
|
||||
src={src}
|
||||
alt={alt}
|
||||
width={width}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Image from "next/image";
|
||||
import { ExternalLink, GraduationCap } from "lucide-react";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
@@ -25,7 +25,7 @@ export function FacultyMemberCard({ member }: { member: FacultyMember }) {
|
||||
<SurfaceCard className="group flex h-full flex-col rounded-2xl">
|
||||
<div className="relative mb-5 aspect-[4/3] overflow-hidden rounded-xl bg-muted">
|
||||
{photo ? (
|
||||
<Image
|
||||
<CmsImage
|
||||
src={member.imageUrl}
|
||||
alt={member.name}
|
||||
fill
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
"use client";
|
||||
|
||||
import { usePathname, useSearchParams } from "next/navigation";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
GLOBAL_ACTION_LOADING_START,
|
||||
GLOBAL_ACTION_LOADING_STOP,
|
||||
} from "@/lib/global-action-loading";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const MIN_VISIBLE_MS = 320;
|
||||
const STALL_MS = 25_000;
|
||||
|
||||
function routeKey(pathname: string, search: string) {
|
||||
return `${pathname}?${search}`;
|
||||
}
|
||||
|
||||
function isModifiedPointer(event: MouseEvent) {
|
||||
return (
|
||||
event.button !== 0 ||
|
||||
event.metaKey ||
|
||||
event.ctrlKey ||
|
||||
event.shiftKey ||
|
||||
event.altKey
|
||||
);
|
||||
}
|
||||
|
||||
function isOptedOut(element: Element) {
|
||||
return Boolean(element.closest("[data-no-action-loading]"));
|
||||
}
|
||||
|
||||
function isInternalAnchor(anchor: HTMLAnchorElement) {
|
||||
if (anchor.target === "_blank" || anchor.hasAttribute("download")) {
|
||||
return false;
|
||||
}
|
||||
const href = anchor.getAttribute("href");
|
||||
if (!href || href.startsWith("#") || href.startsWith("mailto:") || href.startsWith("tel:")) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
const url = new URL(href, window.location.href);
|
||||
return url.origin === window.location.origin;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function GlobalActionLoadingOverlay() {
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const search = searchParams.toString();
|
||||
const currentRouteKey = routeKey(pathname, search);
|
||||
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
const activeRef = useRef(false);
|
||||
const startedAtRef = useRef(0);
|
||||
const inflightRef = useRef(0);
|
||||
const prevRouteKeyRef = useRef<string | null>(null);
|
||||
const finishTimerRef = useRef<number | null>(null);
|
||||
const hideTimerRef = useRef<number | null>(null);
|
||||
const stallTimerRef = useRef<number | null>(null);
|
||||
|
||||
const clearTimers = useCallback(() => {
|
||||
if (finishTimerRef.current != null) {
|
||||
window.clearTimeout(finishTimerRef.current);
|
||||
finishTimerRef.current = null;
|
||||
}
|
||||
if (hideTimerRef.current != null) {
|
||||
window.clearTimeout(hideTimerRef.current);
|
||||
hideTimerRef.current = null;
|
||||
}
|
||||
if (stallTimerRef.current != null) {
|
||||
window.clearTimeout(stallTimerRef.current);
|
||||
stallTimerRef.current = null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const hide = useCallback(() => {
|
||||
activeRef.current = false;
|
||||
inflightRef.current = 0;
|
||||
clearTimers();
|
||||
setVisible(false);
|
||||
}, [clearTimers]);
|
||||
|
||||
const scheduleFinish = useCallback(() => {
|
||||
if (!activeRef.current) {
|
||||
return;
|
||||
}
|
||||
if (inflightRef.current > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const elapsed = Date.now() - startedAtRef.current;
|
||||
const delay = Math.max(MIN_VISIBLE_MS - elapsed, 0);
|
||||
|
||||
if (finishTimerRef.current != null) {
|
||||
window.clearTimeout(finishTimerRef.current);
|
||||
}
|
||||
|
||||
finishTimerRef.current = window.setTimeout(() => {
|
||||
if (!activeRef.current || inflightRef.current > 0) {
|
||||
return;
|
||||
}
|
||||
activeRef.current = false;
|
||||
hideTimerRef.current = window.setTimeout(() => setVisible(false), 180);
|
||||
}, delay);
|
||||
}, []);
|
||||
|
||||
const start = useCallback(() => {
|
||||
clearTimers();
|
||||
activeRef.current = true;
|
||||
startedAtRef.current = Date.now();
|
||||
inflightRef.current = 0;
|
||||
setVisible(true);
|
||||
|
||||
stallTimerRef.current = window.setTimeout(() => {
|
||||
if (activeRef.current) {
|
||||
hide();
|
||||
}
|
||||
}, STALL_MS);
|
||||
}, [clearTimers, hide]);
|
||||
|
||||
useEffect(() => {
|
||||
if (prevRouteKeyRef.current === null) {
|
||||
prevRouteKeyRef.current = currentRouteKey;
|
||||
return;
|
||||
}
|
||||
if (prevRouteKeyRef.current !== currentRouteKey) {
|
||||
prevRouteKeyRef.current = currentRouteKey;
|
||||
if (activeRef.current) {
|
||||
scheduleFinish();
|
||||
}
|
||||
}
|
||||
}, [currentRouteKey, scheduleFinish]);
|
||||
|
||||
useEffect(() => {
|
||||
const originalFetch = window.fetch.bind(window);
|
||||
|
||||
window.fetch = async (...args) => {
|
||||
if (activeRef.current) {
|
||||
inflightRef.current += 1;
|
||||
}
|
||||
try {
|
||||
return await originalFetch(...args);
|
||||
} finally {
|
||||
if (activeRef.current && inflightRef.current > 0) {
|
||||
inflightRef.current -= 1;
|
||||
if (inflightRef.current === 0) {
|
||||
scheduleFinish();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return () => {
|
||||
window.fetch = originalFetch;
|
||||
};
|
||||
}, [scheduleFinish]);
|
||||
|
||||
useEffect(() => {
|
||||
const onActionClick = (event: MouseEvent) => {
|
||||
if (event.defaultPrevented || isModifiedPointer(event)) {
|
||||
return;
|
||||
}
|
||||
const target = event.target;
|
||||
if (!(target instanceof Element) || isOptedOut(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const anchor = target.closest("a");
|
||||
if (anchor && isInternalAnchor(anchor)) {
|
||||
const href = anchor.getAttribute("href");
|
||||
if (!href) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const url = new URL(href, window.location.href);
|
||||
const targetKey = routeKey(url.pathname, url.searchParams.toString());
|
||||
if (targetKey !== currentRouteKey) {
|
||||
start();
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const button = target.closest('[data-slot="button"], button, input[type="submit"]');
|
||||
if (button instanceof HTMLElement && !button.hasAttribute("disabled")) {
|
||||
if (button.closest("a")) {
|
||||
return;
|
||||
}
|
||||
start();
|
||||
window.setTimeout(() => {
|
||||
if (activeRef.current && inflightRef.current === 0) {
|
||||
scheduleFinish();
|
||||
}
|
||||
}, 64);
|
||||
}
|
||||
};
|
||||
|
||||
const onSubmit = (event: Event) => {
|
||||
const form = event.target;
|
||||
if (!(form instanceof HTMLFormElement) || isOptedOut(form)) {
|
||||
return;
|
||||
}
|
||||
start();
|
||||
};
|
||||
|
||||
const onManualStart = () => start();
|
||||
const onManualStop = () => hide();
|
||||
|
||||
document.addEventListener("click", onActionClick, true);
|
||||
document.addEventListener("submit", onSubmit, true);
|
||||
window.addEventListener(GLOBAL_ACTION_LOADING_START, onManualStart);
|
||||
window.addEventListener(GLOBAL_ACTION_LOADING_STOP, onManualStop);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("click", onActionClick, true);
|
||||
document.removeEventListener("submit", onSubmit, true);
|
||||
window.removeEventListener(GLOBAL_ACTION_LOADING_START, onManualStart);
|
||||
window.removeEventListener(GLOBAL_ACTION_LOADING_STOP, onManualStop);
|
||||
};
|
||||
}, [currentRouteKey, hide, scheduleFinish, start]);
|
||||
|
||||
useEffect(() => () => clearTimers(), [clearTimers]);
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-hidden={!visible}
|
||||
aria-busy={visible}
|
||||
className={cn(
|
||||
"pointer-events-none fixed inset-0 z-[200] bg-background/40 backdrop-blur-[1px] transition-opacity duration-200 motion-reduce:transition-none",
|
||||
visible ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ReactNode } from "react";
|
||||
import Image from "next/image";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { MetamorphField } from "@/components/atoms/MetamorphField";
|
||||
@@ -35,7 +35,7 @@ export function PageHero({
|
||||
: "py-16 sm:py-24",
|
||||
)}
|
||||
>
|
||||
<Image
|
||||
<CmsImage
|
||||
src={imageUrl ?? "/brand/neural-learning-wave.webp"}
|
||||
alt=""
|
||||
fill
|
||||
|
||||
@@ -7,22 +7,20 @@ import { Search, X } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { CourseCardBanner } from "@/components/molecules/CourseCardBanner";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { CourseCatalogCard } from "@/components/molecules/CourseCatalogCard";
|
||||
import type { Course, TaxonomyRef } from "@/lib/types";
|
||||
import {
|
||||
ARCHIVE_SECTION_LABEL,
|
||||
ARCHIVE_TAG_SLUG,
|
||||
isArchiveCourse,
|
||||
} from "@/lib/course-catalog";
|
||||
import {
|
||||
courseCatalogHref,
|
||||
courseCategoryHref,
|
||||
courseTagHref,
|
||||
} from "@/lib/course-nav";
|
||||
import { formatCoursePrice, formatLabel } from "@/lib/labels";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const categoryChipClass =
|
||||
@@ -119,6 +117,20 @@ export function CategoryCourseExplorer({
|
||||
});
|
||||
}, [courses, categorySlug, tagSlug, deferredQuery]);
|
||||
|
||||
const { currentCourses, archiveCourses } = useMemo(() => {
|
||||
const current: Course[] = [];
|
||||
const archive: Course[] = [];
|
||||
for (const course of filtered) {
|
||||
if (isArchiveCourse(course)) archive.push(course);
|
||||
else current.push(course);
|
||||
}
|
||||
return { currentCourses: current, archiveCourses: archive };
|
||||
}, [filtered]);
|
||||
|
||||
const archiveLabel =
|
||||
filterTags.find((tag) => tag.slug === ARCHIVE_TAG_SLUG)?.label ??
|
||||
ARCHIVE_SECTION_LABEL;
|
||||
|
||||
const hasFilters = tagSlug !== "" || categorySlug !== "" || query !== "";
|
||||
|
||||
const resetFilters = () => {
|
||||
@@ -337,108 +349,78 @@ export function CategoryCourseExplorer({
|
||||
دوره ای با این فیلتر ها یافت نشد.
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-10">
|
||||
{currentCourses.length > 0 ? (
|
||||
<CourseCatalogGrid
|
||||
courses={currentCourses}
|
||||
variant="current"
|
||||
isStale={isStale}
|
||||
categorySlug={categorySlug}
|
||||
tagSlug={tagSlug}
|
||||
categoryHref={categoryHref}
|
||||
tagHref={tagHref}
|
||||
/>
|
||||
) : null}
|
||||
{currentCourses.length > 0 && archiveCourses.length > 0 ? (
|
||||
<Separator className="bg-primary-foreground/15" />
|
||||
) : null}
|
||||
{archiveCourses.length > 0 ? (
|
||||
<div className="space-y-5">
|
||||
<Heading level={4} as="h2">
|
||||
{archiveLabel}
|
||||
</Heading>
|
||||
<CourseCatalogGrid
|
||||
courses={archiveCourses}
|
||||
variant="archive"
|
||||
isStale={isStale}
|
||||
categorySlug={categorySlug}
|
||||
tagSlug={tagSlug}
|
||||
categoryHref={categoryHref}
|
||||
tagHref={tagHref}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CourseCatalogGrid({
|
||||
courses,
|
||||
variant,
|
||||
isStale,
|
||||
categorySlug,
|
||||
tagSlug,
|
||||
categoryHref,
|
||||
tagHref,
|
||||
}: {
|
||||
courses: Course[];
|
||||
variant: "current" | "archive";
|
||||
isStale: boolean;
|
||||
categorySlug: string;
|
||||
tagSlug: string;
|
||||
categoryHref: (slug: string) => string;
|
||||
tagHref: (slug: string) => string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"grid gap-5 transition-opacity sm:grid-cols-2 lg:grid-cols-3",
|
||||
isStale && "opacity-70",
|
||||
)}
|
||||
>
|
||||
{filtered.map((course) => {
|
||||
const priceLabel = formatCoursePrice(course.price);
|
||||
return (
|
||||
<Card
|
||||
{courses.map((course) => (
|
||||
<CourseCatalogCard
|
||||
key={course.id}
|
||||
className="group relative gap-0 overflow-hidden bg-primary-foreground/5 py-0 text-primary-foreground ring-primary-foreground/10 transition-colors hover:ring-primary-foreground/30"
|
||||
>
|
||||
{/* Full-card hit target sits under content; badges use pointer-events-auto */}
|
||||
<Link
|
||||
href={course.registrationUrl}
|
||||
className="absolute inset-0 z-0"
|
||||
aria-label={course.title}
|
||||
tabIndex={-1}
|
||||
course={course}
|
||||
variant={variant}
|
||||
categorySlug={categorySlug}
|
||||
tagSlug={tagSlug}
|
||||
categoryHref={categoryHref}
|
||||
tagHref={tagHref}
|
||||
/>
|
||||
<CourseCardBanner
|
||||
title={course.title}
|
||||
bannerUrl={course.posterImageUrl}
|
||||
/>
|
||||
<CardHeader className="pointer-events-none relative z-[1] gap-1 px-4 pt-4">
|
||||
<CardTitle className="text-base text-primary-foreground">
|
||||
{course.title}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="pointer-events-none relative z-[1] space-y-3 px-4 pb-4">
|
||||
<CardDescription className="line-clamp-3 text-primary-foreground/70">
|
||||
{course.summary}
|
||||
</CardDescription>
|
||||
{(course.categories.length > 0 || course.tags.length > 0) && (
|
||||
<div className="pointer-events-auto flex flex-wrap gap-1.5">
|
||||
{course.categories.map((c) => {
|
||||
const href = categoryHref(c.slug);
|
||||
const active = categorySlug === c.slug;
|
||||
return (
|
||||
<Link
|
||||
key={`cat:${c.id}`}
|
||||
href={href}
|
||||
className="relative z-[2]"
|
||||
aria-current={active ? "true" : undefined}
|
||||
>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"cursor-pointer border-primary-foreground/25 text-[11px] font-semibold text-primary-foreground/90 hover:bg-primary-foreground/15",
|
||||
active && "border-secondary bg-secondary/25 text-secondary",
|
||||
)}
|
||||
>
|
||||
{c.label}
|
||||
</Badge>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
{course.tags.map((t) => {
|
||||
const href = tagHref(t.slug);
|
||||
const active = tagSlug === t.slug;
|
||||
return (
|
||||
<Link
|
||||
key={`tag:${t.id}`}
|
||||
href={href}
|
||||
className="relative z-[2]"
|
||||
aria-current={active ? "true" : undefined}
|
||||
>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"cursor-pointer border-primary-foreground/25 text-[10px] text-primary-foreground/75 hover:bg-primary-foreground/15",
|
||||
active && "border-secondary bg-secondary/25 text-secondary",
|
||||
)}
|
||||
>
|
||||
{t.label}
|
||||
</Badge>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-primary-foreground/55">
|
||||
<span>
|
||||
{course.durationHours
|
||||
? `${course.durationHours} ساعت · ${formatLabel(course.format)}`
|
||||
: formatLabel(course.format)}
|
||||
</span>
|
||||
{priceLabel ? (
|
||||
<span className="font-semibold text-primary-foreground/90">
|
||||
{priceLabel}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="inline-flex text-sm font-semibold text-primary-foreground underline-offset-4 group-hover:underline">
|
||||
جزئیات و ثبت نام
|
||||
</span>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -64,6 +64,7 @@ export function SearchOverlay({
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
data-no-action-loading
|
||||
aria-label={label}
|
||||
onClick={() => setOpen(true)}
|
||||
className="size-11 text-inherit hover:bg-foreground/5"
|
||||
@@ -85,6 +86,7 @@ export function SearchOverlay({
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
data-no-action-loading
|
||||
className="text-foreground hover:bg-muted"
|
||||
aria-label="بستن جستجو"
|
||||
onClick={() => setOpen(false)}
|
||||
|
||||
@@ -52,6 +52,7 @@ function NavDropdown({
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
data-no-action-loading
|
||||
className={cn(
|
||||
"inline-flex cursor-pointer items-center gap-1 rounded-lg px-3 py-2 text-sm font-semibold transition-colors outline-none",
|
||||
isDark
|
||||
@@ -187,6 +188,7 @@ export function SiteHeader({
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="xl:hidden"
|
||||
data-no-action-loading
|
||||
aria-label={mobileOpen ? "بستن منو" : "باز کردن منو"}
|
||||
aria-expanded={mobileOpen}
|
||||
onClick={() => setMobileOpen((v) => !v)}
|
||||
@@ -222,6 +224,7 @@ export function SiteHeader({
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="text-primary-foreground hover:bg-primary-foreground/10"
|
||||
data-no-action-loading
|
||||
aria-label="بستن منو"
|
||||
onClick={() => setMobileOpen(false)}
|
||||
>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { useState, useTransition } from "react";
|
||||
import { RefreshCw } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -17,7 +17,7 @@ type SyncPayload = {
|
||||
};
|
||||
|
||||
export function FacultySyncButton() {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [pending, startTransition] = useTransition();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
import Image from "next/image";
|
||||
import { ImageIcon, Loader2, Trash2, Upload } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { UploadFolder } from "@/lib/uploads/types";
|
||||
|
||||
@@ -75,11 +75,10 @@ export function ImageUploadField({
|
||||
{value ? (
|
||||
<div className="overflow-hidden rounded-xl border border-border bg-muted/40">
|
||||
<div className="relative aspect-[16/9] w-full max-w-md bg-muted">
|
||||
<Image
|
||||
<CmsImage
|
||||
src={value}
|
||||
alt="پیش نمایش تصویر"
|
||||
fill
|
||||
unoptimized
|
||||
className="object-cover"
|
||||
sizes="(max-width: 768px) 100vw, 28rem"
|
||||
/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
@@ -29,7 +29,7 @@ export interface LeadForDashboard {
|
||||
}
|
||||
|
||||
export function LeadsList({ leads }: { leads: LeadForDashboard[] }) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function changeStatus(id: string, status: string) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function LogoutButton() {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function handleLogout() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -42,7 +42,7 @@ export function CourseFilters({
|
||||
availableTags: { id: string; slug: string; label: string }[];
|
||||
availableCategories: { id: string; slug: string; label: string }[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [search, setSearch] = useState(initialSearch);
|
||||
const [published, setPublished] = useState(initialPublished);
|
||||
const [tag, setTag] = useState(initialTag);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import Link from "next/link";
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -41,6 +41,8 @@ type Payload = {
|
||||
bodyHtml: string;
|
||||
seoDescription: string;
|
||||
published: boolean;
|
||||
featured: boolean;
|
||||
sortOrder: number;
|
||||
};
|
||||
|
||||
interface CourseFormProps {
|
||||
@@ -60,7 +62,7 @@ export function CourseForm({
|
||||
tags,
|
||||
faculty,
|
||||
}: CourseFormProps) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const isEdit = Boolean(initial);
|
||||
const [form, setForm] = useState<Payload>({
|
||||
slug: initial?.slug ?? "",
|
||||
@@ -79,6 +81,8 @@ export function CourseForm({
|
||||
bodyHtml: initial?.bodyHtml ?? "",
|
||||
seoDescription: initial?.seoDescription ?? "",
|
||||
published: initial?.published ?? true,
|
||||
featured: initial?.featured ?? false,
|
||||
sortOrder: initial?.sortOrder ?? 0,
|
||||
});
|
||||
const [priceInput, setPriceInput] = useState(
|
||||
initial?.price != null ? String(initial.price) : "",
|
||||
@@ -505,6 +509,33 @@ export function CourseForm({
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="featured">نمایش در کاتالوگ</Label>
|
||||
<Select
|
||||
value={form.featured ? "true" : "false"}
|
||||
onValueChange={(v) => set("featured", v === "true")}
|
||||
>
|
||||
<SelectTrigger id="featured" className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="true">ویژه (بالای لیست جاری)</SelectItem>
|
||||
<SelectItem value="false">عادی</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="sortOrder">ترتیب</Label>
|
||||
<Input
|
||||
id="sortOrder"
|
||||
type="number"
|
||||
value={String(form.sortOrder)}
|
||||
onChange={(e) => set("sortOrder", Number(e.target.value) || 0)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
عدد کوچکتر جلوتر است. روی دورهٔ آرشیو فقط داخل بلوک گزیده اثر دارد.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -35,6 +35,8 @@ export function CourseTable({ courses }: { courses: AdminCourse[] }) {
|
||||
<TableHead>قالب</TableHead>
|
||||
<TableHead>مدت (ساعت)</TableHead>
|
||||
<TableHead>قیمت</TableHead>
|
||||
<TableHead>ویژه</TableHead>
|
||||
<TableHead>ترتیب</TableHead>
|
||||
<TableHead>انتشار</TableHead>
|
||||
<TableHead>عملیات</TableHead>
|
||||
</TableRow>
|
||||
@@ -80,6 +82,16 @@ export function CourseTable({ courses }: { courses: AdminCourse[] }) {
|
||||
<TableCell className="text-muted-foreground">
|
||||
{formatCoursePrice(course.price) ?? "—"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{course.featured ? (
|
||||
<Badge variant="secondary">ویژه</Badge>
|
||||
) : (
|
||||
<span className="text-muted-foreground">—</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{course.sortOrder ?? 0}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<PublishToggle id={course.id} published={course.published} />
|
||||
</TableCell>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from "@/components/ui/dialog";
|
||||
|
||||
export function DeleteCourseDialog({ id, title }: { id: string; title: string }) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function PublishToggle({ id, published }: { id: string; published: boolean }) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
@@ -24,7 +24,7 @@ export function GenericDeleteDialog({
|
||||
noun: string;
|
||||
subject: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -33,7 +33,7 @@ export function GenericFilters({
|
||||
initialSearch: string;
|
||||
initialPublished: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [search, setSearch] = useState(initialSearch);
|
||||
const [published, setPublished] = useState(initialPublished);
|
||||
const hasFilters = Boolean(initialSearch.trim()) || initialPublished !== "all";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import Link from "next/link";
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -48,7 +48,7 @@ export function GenericForm({
|
||||
spec: GenericFormSpec;
|
||||
initial?: unknown;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const data = (initial ?? {}) as Record<string, unknown>;
|
||||
const isEdit = Boolean(initial);
|
||||
const editId = data[spec.idColumn];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function PublishToggle({
|
||||
@@ -13,7 +13,7 @@ export function PublishToggle({
|
||||
id: string;
|
||||
published: boolean;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -27,7 +27,7 @@ export function RegistrationFilters({
|
||||
initialSearch: string;
|
||||
initialStatus: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [search, setSearch] = useState(initialSearch);
|
||||
const [status, setStatus] = useState(initialStatus);
|
||||
const hasFilters = Boolean(initialSearch.trim()) || initialStatus !== "all";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAppRouter } from "@/hooks/use-app-router";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -42,7 +42,7 @@ function faDate(value: string): string {
|
||||
}
|
||||
|
||||
export function RegistrationsTable({ rows }: { rows: AdminRegistration[] }) {
|
||||
const router = useRouter();
|
||||
const router = useAppRouter();
|
||||
const [busyId, setBusyId] = useState<string | null>(null);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import { cn } from "@/lib/utils";
|
||||
import { CourseCardBanner } from "@/components/molecules/CourseCardBanner";
|
||||
import { HeroFeatured } from "@/components/molecules/HeroFeatured";
|
||||
import { SectionHeader } from "@/components/molecules/SectionHeader";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import type { Article, Course } from "@/lib/types";
|
||||
import { formatCoursePrice, formatLabel } from "@/lib/labels";
|
||||
import { homeContent } from "@/lib/site-config";
|
||||
@@ -142,6 +143,14 @@ export function HomeCourseSearch({
|
||||
bannerUrl={course.posterImageUrl}
|
||||
/>
|
||||
<CardHeader className="pointer-events-none relative z-[1] gap-1 px-4 pt-4">
|
||||
{course.featured ? (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="w-fit border-secondary bg-secondary/20 text-[10px] font-semibold text-secondary"
|
||||
>
|
||||
ویژه
|
||||
</Badge>
|
||||
) : null}
|
||||
<CardTitle className="text-base text-primary-foreground">
|
||||
{course.title}
|
||||
</CardTitle>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMemo } from "react";
|
||||
import { startActionLoading } from "@/lib/global-action-loading";
|
||||
|
||||
export function useAppRouter() {
|
||||
const router = useRouter();
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
...router,
|
||||
push: (...args: Parameters<typeof router.push>) => {
|
||||
startActionLoading();
|
||||
return router.push(...args);
|
||||
},
|
||||
replace: (...args: Parameters<typeof router.replace>) => {
|
||||
startActionLoading();
|
||||
return router.replace(...args);
|
||||
},
|
||||
refresh: () => {
|
||||
startActionLoading();
|
||||
return router.refresh();
|
||||
},
|
||||
}),
|
||||
[router],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { Course } from "@/lib/types";
|
||||
|
||||
export const ARCHIVE_TAG_ID = "tag-archive";
|
||||
export const ARCHIVE_TAG_SLUG = "archive";
|
||||
export const ARCHIVE_SECTION_LABEL = "گزیده دوره های برگزار شده";
|
||||
|
||||
export function isArchiveCourse(course: Pick<Course, "tags">): boolean {
|
||||
return course.tags.some(
|
||||
(tag) => tag.slug === ARCHIVE_TAG_SLUG || tag.id === ARCHIVE_TAG_ID,
|
||||
);
|
||||
}
|
||||
+12
-7
@@ -2,32 +2,37 @@ import { query } from "@/lib/db";
|
||||
import type { Course } from "@/lib/types";
|
||||
import { rowToCourse, type CourseRow } from "@/lib/db/mappers";
|
||||
import { COURSE_WITH_TAXONOMY_SELECT } from "@/lib/data/course-taxonomy-sql";
|
||||
import { ARCHIVE_TAG_ID } from "@/lib/course-catalog";
|
||||
|
||||
/** Past offerings tagged `tag-archive` — lowest catalog priority; excluded from home. */
|
||||
const ARCHIVE_TAG_ID = "tag-archive";
|
||||
|
||||
/** Past offerings tagged `tag-archive` — catalog block of their own; excluded from home. */
|
||||
const isArchiveCourseSql = `EXISTS (
|
||||
SELECT 1 FROM course_tag_links ctl
|
||||
WHERE ctl.course_id = c.id AND ctl.tag_id = '${ARCHIVE_TAG_ID}'
|
||||
)`;
|
||||
|
||||
const catalogOrderSql = `CASE WHEN ${isArchiveCourseSql} THEN 1 ELSE 0 END ASC,
|
||||
CASE WHEN c.featured THEN 0 ELSE 1 END ASC,
|
||||
c.sort_order ASC,
|
||||
c.title ASC`;
|
||||
|
||||
export async function getCourses(): Promise<Course[]> {
|
||||
const res = await query<CourseRow>(
|
||||
`${COURSE_WITH_TAXONOMY_SELECT}
|
||||
WHERE c.published = true
|
||||
ORDER BY CASE WHEN ${isArchiveCourseSql} THEN 1 ELSE 0 END ASC,
|
||||
c.title ASC`,
|
||||
ORDER BY ${catalogOrderSql}`,
|
||||
);
|
||||
return res.rows.map(rowToCourse);
|
||||
}
|
||||
|
||||
/** Latest published courses for home preview (newest first; archive excluded). */
|
||||
/** Priority-ordered published courses for home preview (archive excluded). */
|
||||
export async function getLatestCourses(limit = 6): Promise<Course[]> {
|
||||
const res = await query<CourseRow>(
|
||||
`${COURSE_WITH_TAXONOMY_SELECT}
|
||||
WHERE c.published = true
|
||||
AND NOT ${isArchiveCourseSql}
|
||||
ORDER BY c.created_at DESC, c.title ASC
|
||||
ORDER BY CASE WHEN c.featured THEN 0 ELSE 1 END ASC,
|
||||
c.sort_order ASC,
|
||||
c.title ASC
|
||||
LIMIT $1`,
|
||||
[limit],
|
||||
);
|
||||
|
||||
@@ -54,6 +54,8 @@ export interface CourseRow {
|
||||
body_html?: string;
|
||||
seo_description: string;
|
||||
published: boolean;
|
||||
featured?: boolean;
|
||||
sort_order?: number;
|
||||
/** Present when SELECT aggregates taxonomy as JSON. */
|
||||
categories?: unknown;
|
||||
tags?: unknown;
|
||||
@@ -78,6 +80,8 @@ export function courseToRow(course: Course): CourseRow {
|
||||
body_html: course.bodyHtml ?? "",
|
||||
seo_description: course.seoDescription,
|
||||
published: true,
|
||||
featured: course.featured ?? false,
|
||||
sort_order: course.sortOrder ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -388,6 +392,8 @@ export function rowToCourse(row: CourseRow): Course {
|
||||
leadHtml: row.lead_html ?? "",
|
||||
bodyHtml: row.body_html ?? "",
|
||||
seoDescription: row.seo_description,
|
||||
featured: Boolean(row.featured),
|
||||
sortOrder: Number(row.sort_order ?? 0),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
export const GLOBAL_ACTION_LOADING_START = "global-action-loading-start";
|
||||
export const GLOBAL_ACTION_LOADING_STOP = "global-action-loading-stop";
|
||||
|
||||
export function startActionLoading() {
|
||||
if (typeof window !== "undefined") {
|
||||
window.dispatchEvent(new Event(GLOBAL_ACTION_LOADING_START));
|
||||
}
|
||||
}
|
||||
|
||||
export function stopActionLoading() {
|
||||
if (typeof window !== "undefined") {
|
||||
window.dispatchEvent(new Event(GLOBAL_ACTION_LOADING_STOP));
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,10 @@ export interface Course {
|
||||
/** HTML main body on the course detail page; empty = omit body section. */
|
||||
bodyHtml?: string;
|
||||
seoDescription: string;
|
||||
/** Pin above other current (non-archive) courses in public lists. */
|
||||
featured?: boolean;
|
||||
/** Lower number first within the same featured/archive group. */
|
||||
sortOrder?: number;
|
||||
}
|
||||
|
||||
export type ProgramGroup = "standard" | "executive";
|
||||
|
||||
@@ -17,12 +17,53 @@ const MIME_TO_EXT = new Map<string, string>([
|
||||
["image/gif", "gif"],
|
||||
]);
|
||||
|
||||
/** Disk root for uploaded images. Override with UPLOAD_DIR for Docker volumes. */
|
||||
const EXT_TO_MIME = new Map<string, string>([
|
||||
[".jpg", "image/jpeg"],
|
||||
[".jpeg", "image/jpeg"],
|
||||
[".png", "image/png"],
|
||||
[".webp", "image/webp"],
|
||||
[".gif", "image/gif"],
|
||||
]);
|
||||
|
||||
/** UUID filenames written by saveUploadedImage. */
|
||||
const STORED_FILENAME = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.(jpg|jpeg|png|webp|gif)$/;
|
||||
|
||||
/**
|
||||
* Disk root for uploaded images.
|
||||
* Keep this *outside* `public/` in production: Next standalone does not
|
||||
* reliably serve files added to `public/` after the image is built.
|
||||
* Override with UPLOAD_DIR for Docker volumes.
|
||||
*/
|
||||
export function getUploadsRoot(): string {
|
||||
if (process.env.UPLOAD_DIR) {
|
||||
return path.resolve(process.env.UPLOAD_DIR);
|
||||
}
|
||||
return path.join(process.cwd(), "public", "uploads");
|
||||
return path.join(process.cwd(), "uploads");
|
||||
}
|
||||
|
||||
export function mimeForUploadExt(ext: string): string | undefined {
|
||||
return EXT_TO_MIME.get(ext.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve `folder/uuid.ext` to an absolute path under the uploads root.
|
||||
* Returns null for anything that is not a stored upload (traversal, extra
|
||||
* segments, unknown folder, or unexpected filename).
|
||||
*/
|
||||
export function resolveStoredUploadPath(segments: string[]): string | null {
|
||||
if (segments.length !== 2) return null;
|
||||
const [folder, filename] = segments;
|
||||
if (!folder || !filename) return null;
|
||||
if (!isUploadFolder(folder)) return null;
|
||||
if (!STORED_FILENAME.test(filename)) return null;
|
||||
|
||||
const root = getUploadsRoot();
|
||||
const absolutePath = path.resolve(root, folder, filename);
|
||||
const relative = path.relative(root, absolutePath);
|
||||
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) {
|
||||
return null;
|
||||
}
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
export function publicUrlFor(relativePath: string): string {
|
||||
|
||||
@@ -12,3 +12,8 @@ export type UploadFolder = (typeof UPLOAD_FOLDERS)[number];
|
||||
export function isUploadFolder(value: string): value is UploadFolder {
|
||||
return (UPLOAD_FOLDERS as readonly string[]).includes(value);
|
||||
}
|
||||
|
||||
/** True for images written at runtime (`/uploads/{folder}/{uuid}.ext`). */
|
||||
export function isRuntimeUploadSrc(src: string): boolean {
|
||||
return src.startsWith("/uploads/");
|
||||
}
|
||||
@@ -47,6 +47,8 @@ const courseFields = {
|
||||
bodyHtml: z.string(),
|
||||
seoDescription: z.string(),
|
||||
published: z.boolean(),
|
||||
featured: z.boolean(),
|
||||
sortOrder: z.number().int(),
|
||||
};
|
||||
|
||||
const courseCategoryFields = {
|
||||
@@ -101,6 +103,8 @@ export const courseCreateSchema = z.object({
|
||||
bodyHtml: z.string().default(""),
|
||||
seoDescription: z.string().default(""),
|
||||
published: z.boolean().default(true),
|
||||
featured: z.boolean().default(false),
|
||||
sortOrder: z.number().int().default(0),
|
||||
});
|
||||
|
||||
export const coursePatchSchema = z
|
||||
|
||||
Reference in new issue
Block a user