"use client"; import { useCallback, useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { Heart, Lock, MessageSquare, Send, Loader2 } from "lucide-react"; import { useAuth } from "@/lib/auth-store"; import { api, http, toUserError } from "@/lib/api"; import { MAX_HEARTS, clampHearts, hasInfiniteHearts } from "@/lib/hearts"; import type { Mentor, User } from "@/lib/types"; import { Card } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { toast } from "@/components/providers"; import { cn } from "@/lib/utils"; export default function LockoutPage() { const router = useRouter(); const user = useAuth((s) => s.user); const [note, setNote] = useState(""); const [busy, setBusy] = useState(false); const [requested, setRequested] = useState(false); const [mentorId, setMentorId] = useState(null); const syncUser = useCallback(async () => { try { const res = await api<{ user: User }>("/api/auth/me"); useAuth.getState().setUser(res.user); if (!res.user.isLocked || hasInfiniteHearts(res.user.role)) { router.replace("/cap"); } } catch { /* ignore */ } }, [router]); useEffect(() => { if (user && (!user.isLocked || hasInfiniteHearts(user.role))) { router.replace("/cap"); return; } const onFocus = () => void syncUser(); window.addEventListener("focus", onFocus); void syncUser(); return () => { window.removeEventListener("focus", onFocus); }; }, [syncUser, user, router]); useEffect(() => { void http .get<{ mentors: Mentor[] }>("/api/mentors") .then((r) => { const first = r.mentors?.[0]; if (first) setMentorId(first.id); }) .catch(() => undefined); }, []); const requestUnlock = async () => { setBusy(true); try { const res = await http.post<{ message?: string }>("/api/me/request-unlock", { note }); setRequested(true); toast.success(res.message || "درخواست ثبت شد"); } catch (e) { toast.error(toUserError(e)); } finally { setBusy(false); } }; const openMentorChat = () => { const draft = "سلام، حسابم بعد از اتمام جان‌ها قفل شده. لطفاً برای رفع محدودیت راهنمایی‌ام کنید."; window.dispatchEvent( new CustomEvent("pargar:chat", { detail: { open: true, with: mentorId ?? undefined, draft }, }), ); }; const hearts = clampHearts(user?.hearts ?? 0); return (

حساب قفل شد

جان‌هایتان تمام شد

جان‌ها معمولاً خودشان برمی‌گردند. این صفحه وقتی دیده می‌شود که مدیریت حساب را قفل کرده باشد.

{Array.from({ length: MAX_HEARTS }).map((_, i) => i < hearts ? ( ) : ( ), )}

گام بعدی

  1. از طریق گفتگو با منتور وضعیت را توضیح دهید.
  2. درخواست بررسی را برای تیم ثبت کنید (حداکثر یک‌بار در ۱۲ ساعت).
  3. بعد از تأیید متصدی، ۳ جان برمی‌گردد و مسیر دوباره باز می‌شود.