Files
pargar/frontend/src/components/profile-certificate-slot.tsx
T
ahp 3bf6dae724 feat: manual cert gating, chat layout overhaul, and video player UX fixes
- Certificate: Hardcode approval gate — completely removed the auto-issue path;
  `certRequiresApproval()` now strictly returns `true`, ignoring DB configuration.
- Certificate: Quiz completion now queues a pending record and triggers a
  "Pending approval" notification instead of falsely confirming issuance.
- Certificate: Public endpoints now enforce a guard on `status=issued`; frontend
  strips the auto-issue side effect and claim button (issuance restricted to admins).
- Chats tab: Refactor layout into a full-width centered banner above two
  equal-height side-by-side panels (`grid-cols-1 lg:grid-cols-2`), utilizing
  `max-h` and `overflow-y-auto` to eliminate whitespace bleed.
- Video player: Fix settings flyout prematurely closing on mouse movement (removed
  `setSettingsOpen` from `poke`); add a click-outside listener via `mousedown`.
- Video player: Deduplicate controls — the speed pill now directly cycles playback
  speed, leaving the gear icon as the single entry point for settings (eliminating
  overlapping popovers).
- Video player: Implement full-bleed theater mode using the `-mx-[50vw] w-screen`
  technique, keeping the progress strip constrained to `max-w-5xl` below.
2026-10-18 12:09:30 +03:30

132 lines
5.3 KiB
TypeScript

"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useQuery } from "@tanstack/react-query";
import { Award, Clock, Copy, ExternalLink, Loader2, Lock } from "lucide-react";
import { http, toUserError } from "@/lib/api";
import type { Certificate } from "@/lib/types";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/providers";
import { cn } from "@/lib/utils";
type MineCertificateResponse = {
certificate: Certificate | null;
eligible: boolean;
};
export function ProfileCertificateSlot() {
const router = useRouter();
const { data, isLoading, isError, error, refetch } = useQuery({
queryKey: ["me", "certificate"],
queryFn: () => http.get<MineCertificateResponse>("/api/me/certificate"),
});
const cert = data?.certificate ?? null;
const eligible = !!data?.eligible;
const copyLink = async () => {
if (!cert?.publicId) return;
const url = `${window.location.origin}/c/${cert.publicId}`;
try {
await navigator.clipboard.writeText(url);
toast.success("لینک گواهینامه کپی شد");
} catch {
toast.error("کپی ممکن نشد");
}
};
const openCert = () => {
if (!cert?.publicId) return;
router.push(`/c/${cert.publicId}`);
};
return (
<section
aria-label="جایگاه گواهینامه"
className="rounded-xl border border-dashed border-border bg-muted/20 p-3"
>
<div className="mb-2 flex items-center gap-2">
<span className="grid h-8 w-8 place-items-center rounded-lg bg-primary/10 text-primary">
<Award className="h-4 w-4" />
</span>
<div className="min-w-0 flex-1">
<p className="text-xs font-extrabold">گواهینامه پایان دوره</p>
<p className="text-[10px] text-muted-foreground">جایگاه ثابت گواهی شما در پروفایل</p>
</div>
</div>
{isError ? (
<div className="space-y-2 py-2 text-xs">
<p className="font-medium text-destructive">{toUserError(error)}</p>
<Button type="button" size="sm" variant="outline" className="h-8" onClick={() => refetch()}>
تلاش دوباره
</Button>
</div>
) : isLoading ? (
<div className="flex items-center gap-2 py-3 text-xs text-muted-foreground">
<Loader2 className="h-3.5 w-3.5 animate-spin" />
در حال بارگذاری…
</div>
) : 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>
<p className="mt-0.5 text-[11px] text-muted-foreground">
صادر شده در {new Date(cert.issuedAt).toLocaleDateString("fa-IR")}
</p>
<p className="mt-1 truncate font-mono text-[10px] text-muted-foreground" dir="ltr">
{cert.publicId}
</p>
</div>
<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" />
مشاهده
</Button>
<Button type="button" size="sm" variant="outline" className="h-8" onClick={() => void copyLink()}>
<Copy className="h-3.5 w-3.5" />
کپی لینک
</Button>
</div>
</div>
) : eligible ? (
<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>
) : (
<div
className={cn(
"flex items-start gap-2 rounded-lg border border-border/70 bg-background/60 px-3 py-2.5",
)}
>
<Lock className="mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" />
<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>
)}
</section>
);
}