feat: implement 8 features across full stack

- Leaderboard: rank-based percentile tiers (champion/gold/silver/bronze),
    deterministic tie-breaking (xp DESC, user_id ASC)
  - Mentor chat: md: breakpoints, safe-area-inset-bottom padding
  - Learning progress: server-side progressPct, curriculum expansion safety
  - Physical orders: hard-disabled with 410 Gone
  - Certificate approval: pending/issued flow, admin issue/revoke endpoints,
    certificate_requires_approval setting (migration 0031)
  - Draft/publish: is_published on lessons and chapters, admin publish UI
    (migration 0030)
  - Video panel: static thumbnails (no preload), client-side pagination
  - Rich editor: TipTap + tiptap-markdown for lesson descriptions,
    marked + DOMPurify for SafeMarkdown rendering
This commit is contained in:
ahp
2026-10-18 10:14:22 +03:30
parent 75e2892e36
commit 03610bc3d3
23 changed files with 1641 additions and 474 deletions
@@ -3,18 +3,17 @@
import { useEffect, useRef, useState } from "react";
import { useRouter } from "next/navigation";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { Award, Copy, ExternalLink, Loader2, Lock, Package } from "lucide-react";
import { Award, Clock, Copy, ExternalLink, Loader2, Lock } from "lucide-react";
import { http, toUserError } from "@/lib/api";
import type { Certificate, CertificatePhysicalOrder, PhysicalCertSettings } from "@/lib/types";
import type { Certificate, CertificatePhysicalOrder } from "@/lib/types";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/providers";
import { cn, formatFaNumber } from "@/lib/utils";
import { cn } from "@/lib/utils";
type MineCertificateResponse = {
certificate: Certificate | null;
eligible: boolean;
physicalOrder: CertificatePhysicalOrder | null;
physical: PhysicalCertSettings;
};
const ORDER_LABEL: Record<string, string> = {
@@ -37,7 +36,6 @@ export function ProfileCertificateSlot() {
const cert = data?.certificate ?? null;
const eligible = !!data?.eligible;
const physical = data?.physical;
const order = data?.physicalOrder;
// Auto-issue once when the student becomes eligible (same path as /cap).
@@ -83,14 +81,6 @@ export function ProfileCertificateSlot() {
}
};
const physicalOpen =
!!physical?.enabled &&
!!cert &&
(!order || order.status === "cancelled") &&
(!cert.issuedAt ||
Date.now() <
new Date(cert.issuedAt).getTime() + (physical.windowDays || 30) * 24 * 60 * 60 * 1000);
return (
<section
aria-label="جایگاه گواهینامه"
@@ -118,7 +108,17 @@ export function ProfileCertificateSlot() {
<Loader2 className="h-3.5 w-3.5 animate-spin" />
در حال بارگذاری…
</div>
) : cert ? (
) : cert?.status === "pending" ? (
<div className="flex items-start gap-2 rounded-lg border border-border/70 bg-background/60 px-3 py-2.5">
<Clock className="mt-0.5 h-3.5 w-3.5 shrink-0 text-warning" />
<div>
<p className="text-[11px] font-bold text-foreground">در انتظار تأیید</p>
<p className="mt-0.5 text-[10px] leading-relaxed text-muted-foreground">
درخواست گواهینامه ثبت شد و پس از بررسی توسط تیم آموزش صادر می‌شود.
</p>
</div>
</div>
) : cert?.status === "issued" && cert.publicId ? (
<div className="space-y-2.5">
<div className="rounded-lg border border-primary/25 bg-primary/5 px-3 py-2.5">
<p className="text-sm font-bold text-foreground">{cert.fullName}</p>
@@ -129,12 +129,6 @@ export function ProfileCertificateSlot() {
{cert.publicId}
</p>
</div>
{order && order.status !== "cancelled" ? (
<p className="text-[11px] font-medium text-muted-foreground">
{ORDER_LABEL[order.status] ?? order.status}
{order.trackingCode ? ` · کد پیگیری ${order.trackingCode}` : ""}
</p>
) : null}
<div className="flex flex-wrap gap-1.5">
<Button type="button" size="sm" className="h-8 flex-1" onClick={openCert}>
<ExternalLink className="h-3.5 w-3.5" />
@@ -144,12 +138,6 @@ export function ProfileCertificateSlot() {
<Copy className="h-3.5 w-3.5" />
کپی لینک
</Button>
{physicalOpen ? (
<Button type="button" size="sm" variant="outline" className="h-8" onClick={openCert}>
<Package className="h-3.5 w-3.5" />
فیزیکی
</Button>
) : null}
</div>
</div>
) : eligible ? (
@@ -172,10 +160,7 @@ export function ProfileCertificateSlot() {
<div>
<p className="text-[11px] font-bold text-foreground">هنوز صادر نشده</p>
<p className="mt-0.5 text-[10px] leading-relaxed text-muted-foreground">
با پاس کردن همه درس‌های فعال، گواهینامه همین‌جا نمایش داده می‌شود
{physical?.enabled
? `؛ در صورت فعال بودن، نسخه فیزیکی (پرداخت آفلاین) تا ${formatFaNumber(physical.windowDays)} روز پس از صدور قابل درخواست است.`
: "."}
با پاس کردن همه درس‌های فعال، گواهینامه همین‌جا نمایش داده می‌شود.
</p>
</div>
</div>