started connect with api
This commit is contained in:
1 parent
0ca218505d
commit
6da59f42d9
112 files changed
+7091
-6989
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Pencil, Trash2, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { Pencil, Trash2, CheckCircle2, XCircle, Link2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
@@ -14,13 +14,7 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import {
|
||||
Section,
|
||||
InfoRow,
|
||||
CollapsibleSection,
|
||||
EmptyState,
|
||||
} from "@/components/viewPageComponents";
|
||||
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||
import { Section, InfoRow } from "@/components/viewPageComponents";
|
||||
import { useUser, useDeleteUser } from "@/features/allUsers/hooks/useAllUsers";
|
||||
|
||||
// ─── UserViewPage ─────────────────────────────────────────────────────────────
|
||||
@@ -35,14 +29,10 @@ export default function UserViewPage() {
|
||||
const deleteUser = useDeleteUser();
|
||||
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||
const [roleSearch, setRoleSearch] = useState("");
|
||||
const [permSearch, setPermSearch] = useState("");
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const [auditSearch, setAuditSearch] = useState("");
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
await deleteUser.mutateAsync(userId);
|
||||
navigate("/users");
|
||||
navigate("/all-users");
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
@@ -51,10 +41,7 @@ export default function UserViewPage() {
|
||||
<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"
|
||||
>
|
||||
<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>
|
||||
@@ -65,20 +52,21 @@ export default function UserViewPage() {
|
||||
}
|
||||
|
||||
if (isError || !user) {
|
||||
return (
|
||||
<div className="p-6 text-center text-muted-foreground">
|
||||
{t("common.notFound", "Maglumat tapylmady")}
|
||||
</div>
|
||||
);
|
||||
return <div className="p-6 text-center text-muted-foreground">{t("common.notFound", "Maglumat tapylmady")}</div>;
|
||||
}
|
||||
|
||||
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="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})
|
||||
{t("users.viewTitle", "Ulanyjy giňişleýin")}: {user.name} ({user.username})
|
||||
</h1>
|
||||
<div className="flex items-center gap-2 shrink-0 ml-4">
|
||||
<Button
|
||||
@@ -89,12 +77,7 @@ export default function UserViewPage() {
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
onClick={() => navigate(`/users/${userId}/edit`)}
|
||||
>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={() => navigate(`/all-users/${userId}/edit`)}>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
@@ -103,136 +86,78 @@ export default function UserViewPage() {
|
||||
{/* 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.username", "Ulanyjy ady")} value={user.username} />
|
||||
<InfoRow label={t("users.fields.name", "Ady")} value={user.name} />
|
||||
<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.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.isActive ? (
|
||||
{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>
|
||||
</InfoRow>
|
||||
)}
|
||||
<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>
|
||||
|
||||
{/* Rollar */}
|
||||
<CollapsibleSection title={t("users.sections.roles", "Rollar")}>
|
||||
<DataTableToolbar
|
||||
searchValue={roleSearch}
|
||||
onSearchChange={setRoleSearch}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
actionLabel={t("users.actions.addRole", "Rol birikdiriň")}
|
||||
onAction={() => {}}
|
||||
/>
|
||||
<EmptyState
|
||||
label={t(
|
||||
"users.empty.roles",
|
||||
"Berlen kriteriýalara Rol gabat gelmedi.",
|
||||
)}
|
||||
/>
|
||||
</CollapsibleSection>
|
||||
|
||||
{/* Rugsatlar */}
|
||||
<CollapsibleSection title={t("users.sections.permissions", "Rugsatlar")}>
|
||||
<DataTableToolbar
|
||||
searchValue={permSearch}
|
||||
onSearchChange={setPermSearch}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
actionLabel={t("users.actions.addPermission", "Rugsat birikdiriň")}
|
||||
onAction={() => {}}
|
||||
/>
|
||||
<EmptyState
|
||||
label={t(
|
||||
"users.empty.permissions",
|
||||
"Berlen kriteriýalara Rugsat gabat gelmedi.",
|
||||
)}
|
||||
/>
|
||||
</CollapsibleSection>
|
||||
|
||||
{/* Şahamçalar */}
|
||||
<CollapsibleSection title={t("users.sections.branches", "Şahamçalar")}>
|
||||
<DataTableToolbar
|
||||
searchValue={branchSearch}
|
||||
onSearchChange={setBranchSearch}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
actionLabel={t("users.actions.addBranch", "Şahamça birikdiriň")}
|
||||
onAction={() => {}}
|
||||
/>
|
||||
<EmptyState
|
||||
label={t(
|
||||
"users.empty.branches",
|
||||
"Berlen kriteriýalara Şahamça gabat gelmedi.",
|
||||
)}
|
||||
/>
|
||||
</CollapsibleSection>
|
||||
|
||||
{/* Ammallar */}
|
||||
<CollapsibleSection title={t("users.sections.audit", "Ammallar")}>
|
||||
<DataTableToolbar
|
||||
searchValue={auditSearch}
|
||||
onSearchChange={setAuditSearch}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
actionLabel={t("users.actions.addAction", "Hereket")}
|
||||
onAction={() => {}}
|
||||
/>
|
||||
<EmptyState
|
||||
label={t(
|
||||
"users.empty.audit",
|
||||
"Berlen kriteriýalara Hereket gabat gelmedi.",
|
||||
)}
|
||||
/>
|
||||
</CollapsibleSection>
|
||||
{/* 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>
|
||||
<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)}
|
||||
{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"
|
||||
>
|
||||
<AlertDialogAction onClick={handleDeleteConfirm} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
|
||||
{t("common.delete", "Öçür")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
|
||||
Reference in new issue
Block a user