"use client"; import type { ReactNode } from "react"; import dynamic from "next/dynamic"; import { useParams } from "next/navigation"; import { useQuery } from "@tanstack/react-query"; import { Flame, Heart, Sparkles } from "lucide-react"; import { ProfileHeader } from "@/components/profile-header"; import { NotFoundState, notFoundSentence } from "@/components/not-found-state"; import { http, toUserError } from "@/lib/api"; import { useAuth } from "@/lib/auth-store"; import type { PublicProfile } from "@/lib/types"; import { Skeleton } from "@/components/ui/skeleton"; import { formatFaNumber, formatStreakLabel } from "@/lib/utils"; const AdminProfileManage = dynamic( () => import("@/components/admin/profile-manage").then((m) => m.AdminProfileManage), { ssr: false }, ); export default function PublicProfilePage() { const params = useParams<{ id: string }>(); const id = Number(params.id); const enabled = Number.isFinite(id) && id > 0; const isAdmin = useAuth((s) => s.user?.role === "admin"); const profileQ = useQuery({ queryKey: ["public-profile", id], queryFn: () => http.get<{ user: PublicProfile }>(`/api/users/${id}`), enabled, retry: 1, }); if (!enabled) { return ( ); } if (profileQ.isPending) { return (
{[0, 1, 2, 3].map((i) => ( ))}
); } if (profileQ.isError || !profileQ.data?.user) { return ( ); } const person = profileQ.data.user; return (
{person.isLocked &&

حساب قفل است

} {person.private ? (

جز نام و آواتار چیزی نمایش داده نمی‌شود.

) : (
{person.xp != null && } label="امتیاز" value={formatFaNumber(person.xp)} />} {person.hearts != null && } label="قلب‌ها" value={formatFaNumber(person.hearts)} />} {person.streakCurrent != null && ( } label="زنجیرهٔ فعلی" value={formatStreakLabel(person.streakCurrent)} /> )} {person.streakLongest != null && ( } label="بلندترین زنجیره" value={formatStreakLabel(person.streakLongest)} /> )}
)} {(person.socialLinks ?? []).length > 0 && ( )} {isAdmin && }
); } function Stat({ icon, label, value }: { icon: ReactNode; label: string; value: string }) { return (
{icon}

{label}

{value}

); }