connect users section api, fixed some ui, added some lang support to missed words

This commit is contained in:
Jelaletdin12 committed 2026-08-18 21:41:13 +05:00
1 parent 0e75c85fe1
commit 7bb37f9b43
24 files changed
+1871 -1543

No files matched your search

+113 -120
View File
@@ -1,49 +1,45 @@
import { useState } from "react";
import { useNavigate, useParams } from "react-router-dom";
import { useParams, useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Pencil, Trash2, CheckCircle2, XCircle, Link2 } from "lucide-react";
import { Pencil, Trash2, XCircle, CheckCircle2, UserRound, Link2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Section, InfoRow } from "@/components/viewPageComponents";
import { ConfirmDialog } from "@/components/confirmDialog";
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
import { useUser, useDeleteUser } from "@/features/allUsers/hooks/useAllUsers";
// ─── UserViewPage ─────────────────────────────────────────────────────────────
// ─── 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 { t } = useTranslation();
const navigate = useNavigate();
const { id } = useParams<{ id: string }>();
const userId = Number(id);
const { data: user, isLoading, isError } = useUser(userId);
const { t } = useTranslation();
const navigate = useNavigate();
const deleteUser = useDeleteUser();
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
const { data: user, isLoading, isError } = useUser(userId);
const handleDeleteConfirm = async () => {
await deleteUser.mutateAsync(userId);
navigate("/all-users");
};
const [deleteOpen, setDeleteOpen] = useState(false);
// ── Loading ───────────────────────────────────────────────────────────────
if (isLoading) {
return (
<div className="p-6 space-y-4">
<div className="flex flex-col gap-4">
<Skeleton className="h-7 w-64" />
<div className="bg-card border border-border rounded-xl overflow-hidden">
{Array.from({ length: 5 }).map((_, i) => (
<div key={i} className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0">
<Skeleton className="h-4 w-24" />
<Skeleton className="h-4 w-40" />
<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>
@@ -51,9 +47,7 @@ export default function UserViewPage() {
);
}
if (isError || !user) {
return <div className="p-6 text-center text-muted-foreground">{t("common.notFound", "Maglumat tapylmady")}</div>;
}
if (isError || !user) return null;
const socialLinks = [
{ key: "facebook", url: user.socialMedia?.facebook, label: t("users.fields.facebook", "Facebook") },
@@ -62,107 +56,106 @@ export default function UserViewPage() {
].filter((s) => !!s.url);
return (
<div className="space-y-0">
{/* Title + actions */}
<div className="flex items-start justify-between mb-6">
<h1 className="text-xl font-bold text-foreground leading-tight">
{t("users.viewTitle", "Ulanyjy giňişleýin")}: {user.name} ({user.username})
<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 shrink-0 ml-4">
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"
onClick={() => setShowDeleteDialog(true)}
variant="ghost"
className="h-8 w-8 text-muted-foreground hover:text-destructive"
onClick={() => setDeleteOpen(true)}
>
<Trash2 size={15} />
</Button>
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={() => navigate(`/all-users/${userId}/edit`)}>
<Button
size="icon"
variant="ghost"
className="h-8 w-8 text-muted-foreground hover:text-foreground"
onClick={() => navigate(`/all-users/${userId}/edit`)}
>
<Pencil size={15} />
</Button>
</div>
</div>
{/* Main info */}
<Section>
<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.phone", "Telefon")} value={user.phone} />
<InfoRow label={t("users.fields.email", "E-poçta")} value={user.email || "—"} />
<InfoRow label={t("users.fields.role", "Roly")} value={user.role} />
<InfoRow label={t("users.fields.lightMode", "Light režimi")}>
{user.lightMode ? (
<span className="text-sm text-foreground">{t("common.yes", "Hawa")}</span>
) : (
<span className="text-sm text-muted-foreground">{t("common.no", "Ýok")}</span>
)}
</InfoRow>
<InfoRow label={t("users.fields.isActive", "Işjeň")}>
{user.active ? (
<CheckCircle2 size={18} className="text-emerald-500" />
) : (
<XCircle size={18} className="text-muted-foreground/40" />
)}
</InfoRow>
{user.avatar && (
<InfoRow label={t("users.fields.avatar", "Awatar URL")}>
<a href={user.avatar} target="_blank" rel="noopener noreferrer" className="text-sm text-primary underline break-all">
{user.avatar}
</a>
{/* ── 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>
<ConfirmDialog
open={deleteOpen}
onOpenChange={setDeleteOpen}
title={t("users.deleteDialog.title", "Ulanyjyny öçürmek")}
description={t("users.deleteDialog.description", 'Siz "{name}" ulanyjysyny öçürjekmi? Bu amal yzyna gaýtarylyp bilinmez.').replace(
"{name}",
user.username,
)}
<InfoRow
label={t("users.fields.createdAt", "Döredilen wagty")}
value={user.createdAt ? new Date(user.createdAt).toLocaleString() : "—"}
/>
<InfoRow
label={t("users.fields.updatedAt", "Täzelenen wagty")}
value={user.updatedAt ? new Date(user.updatedAt).toLocaleString() : "—"}
/>
</Section>
{/* Sosial media */}
{socialLinks.length > 0 && (
<Section title={t("users.fields.socialMedia", "Sosial media")}>
{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>
))}
</Section>
)}
{/* Delete dialog */}
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t("users.deleteDialog.title", "Ulanyjyny öçürmek")}</AlertDialogTitle>
<AlertDialogDescription>
{t("users.deleteDialog.description", 'Siz "{name}" ulanyjysyny öçürjekmi? Bu amal yzyna gaýtarylyp bilinmez.').replace(
"{name}",
user.username,
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t("common.cancel", "Ýok")}</AlertDialogCancel>
<AlertDialogAction onClick={handleDeleteConfirm} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
{t("common.delete", "Öçür")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
confirmLabel={t("common.delete", "Öçür")}
onConfirm={async () => {
await deleteUser.mutateAsync(userId);
navigate("/all-users");
}}
isLoading={deleteUser.isPending}
/>
</div>
);
}