139 lines
6.2 KiB
TypeScript
139 lines
6.2 KiB
TypeScript
import { useParams, useNavigate } from "react-router-dom";
|
|
import { useTranslation } from "react-i18next";
|
|
import { XCircle, CheckCircle2, UserRound, Link2 } from "lucide-react";
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
import { BentoGrid, BentoCard, InfoRow, ViewActions } from "@/components/viewPageComponents";
|
|
import { useUser, useDeleteUser } from "@/features/allUsers/hooks/useAllUsers";
|
|
|
|
// ─── ActiveIndicator ──────────────────────────────────────────────────────────
|
|
|
|
function ActiveIndicator({ active }: { active: boolean }) {
|
|
return active ? <CheckCircle2 size={18} className="text-emerald-500" /> : <XCircle size={18} className="text-destructive" />;
|
|
}
|
|
|
|
// ─── Page ─────────────────────────────────────────────────────────────────────
|
|
|
|
export default function UserViewPage() {
|
|
const { id } = useParams<{ id: string }>();
|
|
const userId = Number(id);
|
|
const { t } = useTranslation();
|
|
const navigate = useNavigate();
|
|
const deleteUser = useDeleteUser();
|
|
|
|
const { data: user, isLoading, isError } = useUser(userId);
|
|
|
|
// ── Loading ───────────────────────────────────────────────────────────────
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<div className="flex flex-col gap-4">
|
|
<Skeleton className="h-7 w-64" />
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
|
{Array.from({ length: 4 }).map((_, i) => (
|
|
<div key={i} className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3">
|
|
<Skeleton className="h-3 w-24 mb-1" />
|
|
{Array.from({ length: 3 }).map((_, j) => (
|
|
<Skeleton key={j} className="h-4 w-full" />
|
|
))}
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (isError || !user) return null;
|
|
|
|
const socialLinks = [
|
|
{ key: "facebook", url: user.socialMedia?.facebook, label: t("users.fields.facebook", "Facebook") },
|
|
{ key: "instagram", url: user.socialMedia?.instagram, label: t("users.fields.instagram", "Instagram") },
|
|
{ key: "telegram", url: user.socialMedia?.telegram, label: t("users.fields.telegram", "Telegram") },
|
|
].filter((s) => !!s.url);
|
|
|
|
return (
|
|
<div className="flex flex-col gap-6">
|
|
{/* ── Page header ──────────────────────────────────────────────────── */}
|
|
<div className="flex items-center justify-between">
|
|
<h1 className="text-2xl font-semibold text-foreground">
|
|
{t("users.viewTitle", "Ulanyjy giňişleýin")}: {user.name}
|
|
</h1>
|
|
<div className="flex items-center gap-2">
|
|
<ViewActions
|
|
editTo={`/all-users/${userId}/edit`}
|
|
onDelete={async () => {
|
|
await deleteUser.mutateAsync(userId);
|
|
navigate("/all-users");
|
|
}}
|
|
deleting={deleteUser.isPending}
|
|
deleteTitle={t("users.deleteDialog.title", "Ulanyjyny öçürmek")}
|
|
deleteDescription={t(
|
|
"users.deleteDialog.description",
|
|
'Siz "{name}" ulanyjysyny öçürjekmi? Bu amal yzyna gaýtarylyp bilinmez.',
|
|
).replace("{name}", user.username)}
|
|
deleteConfirmLabel={t("common.delete", "Öçür")}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{/* ── Esasy maglumatlar + Kontakt ──────────────────────────────────── */}
|
|
<BentoGrid cols={2}>
|
|
<BentoCard title={t("users.sections.basic", "Esasy maglumatlar")}>
|
|
<div className="flex flex-col items-center gap-4 px-4 pt-4 pb-2">
|
|
{user.avatar ? (
|
|
<img
|
|
src={user.avatar}
|
|
alt="avatar"
|
|
className="w-18 h-18 rounded-full border border-border bg-muted/40 object-cover shrink-0"
|
|
/>
|
|
) : (
|
|
<div className="w-18 h-18 rounded-full border border-border bg-muted/40 flex items-center justify-center shrink-0">
|
|
<UserRound size={28} className="text-muted-foreground" />
|
|
</div>
|
|
)}
|
|
<div className="min-w-0">
|
|
<p className="text-base font-semibold text-foreground truncate">{user.name}</p>
|
|
</div>
|
|
</div>
|
|
<InfoRow label={t("common.id", "ID")} value={user.id} />
|
|
<InfoRow label={t("users.fields.username", "Ulanyjy ady")} value={user.username} />
|
|
<InfoRow label={t("users.fields.name", "Ady")} value={user.name} />
|
|
<InfoRow label={t("users.fields.firstName", "Ady (at)")} value={user.firstName || "—"} />
|
|
<InfoRow label={t("users.fields.lastName", "Familiýasy")} value={user.lastName || "—"} />
|
|
<InfoRow
|
|
label={t("users.fields.role", "Roly")}
|
|
value={user.role || "—"}
|
|
isLink
|
|
href={user.role ? "/settings/users/roles" : undefined}
|
|
/>
|
|
|
|
<InfoRow label={t("users.fields.isActive", "Işjeň")}>
|
|
<ActiveIndicator active={user.active} />
|
|
</InfoRow>
|
|
</BentoCard>
|
|
|
|
<BentoCard title={t("users.sections.contact", "Kontakt")}>
|
|
<InfoRow label={t("users.fields.phone", "Telefon")} value={user.phone ?? "—"} />
|
|
<InfoRow label={t("users.fields.email", "E-poçta")} value={user.email ?? "—"} />
|
|
{socialLinks.length > 0 && (
|
|
<>
|
|
{socialLinks.map((s) => (
|
|
<InfoRow key={s.key} label={s.label}>
|
|
<a
|
|
href={s.url!}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="inline-flex items-center gap-2 text-sm text-primary underline"
|
|
>
|
|
<Link2 size={15} />
|
|
{s.url}
|
|
</a>
|
|
</InfoRow>
|
|
))}
|
|
</>
|
|
)}
|
|
</BentoCard>
|
|
</BentoGrid>
|
|
</div>
|
|
);
|
|
}
|