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

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

View File

@@ -1,136 +1,90 @@
import { useState, useMemo } from "react";
import { useNavigate } from "react-router-dom";
import { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { Pencil, CheckCircle2, Eye, Trash2 } from "lucide-react";
import { Pencil, CheckCircle2, UserRound, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton";
import { Section, InfoRow, CollapsibleSection, EmptyState, AuditLog, type AuditRowProps } from "@/components/viewPageComponents";
import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar";
import { DataTable, type ColumnDef } from "@/components/dataTable";
import { BentoGrid, BentoCard, InfoRow, CollapsibleSection, EmptyState, AuditLog } from "@/components/viewPageComponents";
import { DataTableToolbar } from "@/components/dataTableToolbar";
import { FormInput } from "@/components/formInput";
import { AvatarUpload } from "@/components/avatarUpload";
import { FormActions } from "@/components/formActions";
import { useAuthStore } from "@/app/store/authStore";
// ─── Types ────────────────────────────────────────────────────────────────────
interface RoleRow {
id: number;
code: string;
name: string;
guardName: string;
}
// ─── Mock Data ────────────────────────────────────────────────────────────────
const MOCK_ROLES: RoleRow[] = [{ id: 2, code: "superadmin", name: "Superadmin", guardName: "web" }];
const MOCK_AUDIT: AuditRowProps[] = [
{
id: "9043",
action: "Üýtgetmek",
by: "Nurmuhammet Allanov",
target: "Ulanyç: Nurmuhammet Allanov (nurmuhammet)",
status: "success",
date: "2026-06-04 10:23",
},
{
id: "5869",
action: "Üýtgetmek",
by: "Nurmuhammet Allanov",
target: "Ulanyç: Nurmuhammet Allanov (nurmuhammet)",
status: "success",
date: "2026-06-03 14:11",
},
];
// ─── ProfilePage ──────────────────────────────────────────────────────────────
import { useProfile, useUpdateProfile } from "@/features/auth/hooks/useLogin";
export default function ProfilePage() {
const { t } = useTranslation();
const navigate = useNavigate();
const user = useAuthStore((s) => s.user);
const { data: profileQueryData, isLoading } = useProfile();
const authUser = useAuthStore((s) => s.user);
const user = profileQueryData ?? authUser;
const updateProfileMutation = useUpdateProfile();
const [isEditing, setIsEditing] = useState(false);
const [roleSearch, setRoleSearch] = useState("");
const [permSearch, setPermSearch] = useState("");
const [branchSearch, setBranchSearch] = useState("");
const [roleColVisibility, setRoleColVisibility] = useState({});
const [roleColOrder, setRoleColOrder] = useState<string[]>([]);
// ── Role table columns (ColumnDef for DataTable) ───────────────────────────
// ── Form State for Editing ──
const [formData, setFormData] = useState({
name: "",
firstName: "",
lastName: "",
phone: "",
avatar: "",
});
const roleColumns: ColumnDef<RoleRow>[] = useMemo(
() => [
{
accessorKey: "id",
header: t("common.id", "ID"),
cell: ({ row }) => <span className="text-sm font-semibold text-primary">{row.original.id}</span>,
size: 60,
},
{
accessorKey: "code",
header: t("roles.fields.code", "KOD"),
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.code}</span>,
},
{
accessorKey: "name",
header: t("roles.fields.name", "ADY"),
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name}</span>,
},
{
accessorKey: "guardName",
header: t("roles.fields.guardName", "GUARD NAME"),
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.guardName}</span>,
},
{
id: "actions",
header: "",
enableHiding: false,
size: 90,
cell: () => (
<div className="flex items-center justify-end gap-0.5">
<button className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors">
<Eye size={14} />
</button>
<button className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors">
<Pencil size={14} />
</button>
<button className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-destructive/70 hover:text-destructive transition-colors">
<Trash2 size={14} />
</button>
</div>
),
},
],
[t],
);
const [errors, setErrors] = useState<Record<string, string>>({});
// ── ColumnMeta for DataTableToolbar ───────────────────────────────────────
useEffect(() => {
if (user) {
setFormData({
name: user.name ?? "",
firstName: user.firstName ?? "",
lastName: user.lastName ?? "",
phone: user.phone ?? "",
avatar: user.avatar ?? "",
});
}
}, [user, isEditing]);
const roleColumnMeta: ColumnMeta[] = useMemo(
() => [
{ id: "id", label: t("common.id", "ID") },
{ id: "code", label: t("roles.fields.code", "KOD") },
{ id: "name", label: t("roles.fields.name", "ADY") },
{ id: "guardName", label: t("roles.fields.guardName", "GUARD NAME") },
],
[t],
);
const handleFieldChange = (field: keyof typeof formData, value: string) => {
setFormData((prev) => ({ ...prev, [field]: value }));
if (errors[field]) {
setErrors((prev) => {
const next = { ...prev };
delete next[field];
return next;
});
}
};
// ── Filtered roles ────────────────────────────────────────────────────────
const handleSave = async () => {
if (!formData.name.trim()) {
setErrors({ name: t("common.errors.required", "Meýdança hökmany doldurylmaly") });
return;
}
const filteredRoles = useMemo(() => {
const q = roleSearch.toLowerCase().trim();
if (!q) return MOCK_ROLES;
return MOCK_ROLES.filter(
(r) => r.code.toLowerCase().includes(q) || r.name.toLowerCase().includes(q) || r.guardName.toLowerCase().includes(q),
);
}, [roleSearch]);
try {
await updateProfileMutation.mutateAsync({
name: formData.name.trim(),
firstName: formData.firstName.trim() || undefined,
lastName: formData.lastName.trim() || undefined,
phone: formData.phone.trim() || undefined,
avatar: formData.avatar || undefined,
});
setIsEditing(false);
} catch {
// Error is handled in useUpdateProfile onError toast
}
};
// ── Loading skeleton ──────────────────────────────────────────────────────
if (!user) {
// ── Loading state ──
if (isLoading && !user) {
return (
<div className="p-6 space-y-4">
<Skeleton className="h-7 w-64" />
<div className="bg-card border border-border rounded-xl overflow-hidden">
<div className="bg-card border border-border rounded-xl overflow-hidden p-6 space-y-4">
{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" />
@@ -142,100 +96,198 @@ export default function ProfilePage() {
);
}
if (!user) {
return null;
}
return (
<div className="space-y-6">
{/* ── Title + actions ──────────────────────────────────────────────── */}
<div className="flex items-start justify-between">
<div className="flex items-center justify-between">
<h1 className="text-xl font-bold text-foreground leading-tight">
{t("users.viewTitle", "Ulanyjy giňişleýin")}: {user.name}
{isEditing ? t("profile.editTitle", "Profili üýtgetmek") : `${t("profile.title", "Meniň profilim")}: ${user.name}`}
</h1>
<div className="flex items-center gap-2 shrink-0 ml-4">
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
onClick={() => navigate("/profile/edit")}
title={t("common.edit", "Üýtgetmek")}
>
<Pencil size={15} />
</Button>
<div className="flex items-center gap-2 shrink-0">
{!isEditing ? (
<Button variant="outline" size="sm" className="gap-2" onClick={() => setIsEditing(true)}>
<Pencil size={15} />
{t("common.edit", "Üýtgetmek")}
</Button>
) : (
<Button
variant="ghost"
size="sm"
className="gap-2 text-muted-foreground hover:text-foreground"
onClick={() => setIsEditing(false)}
disabled={updateProfileMutation.isPending}
>
<X size={15} />
{t("common.cancel", "Yza")}
</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.name} />
<InfoRow label={t("users.fields.name", "Ady")} value={user.name} />
<InfoRow label={t("users.fields.phone", "Telefon")} value={null} />
<InfoRow label={t("users.fields.email", "E-poçta")} value={user.email} />
<InfoRow label={t("users.fields.isActive", "İşjeň")}>
<CheckCircle2 size={18} className="text-emerald-500" />
</InfoRow>
</Section>
{/* ── Main content ─────────────────────────────────────────────────── */}
{!isEditing ? (
<>
<BentoGrid cols={1}>
<BentoCard title={t("profile.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-20 h-20 rounded-full border border-border bg-muted/40 object-cover shrink-0 shadow-sm"
/>
) : (
<div className="w-20 h-20 rounded-full border border-border bg-muted/40 flex items-center justify-center shrink-0 shadow-sm">
<UserRound size={32} className="text-muted-foreground/60" />
</div>
)}
<div className="min-w-0 text-center">
<p className="text-base font-semibold text-foreground truncate">
{[user.firstName, user.lastName].filter(Boolean).join(" ") || user.name}
</p>
{user.phone && <p className="text-xs text-muted-foreground mt-0.5">{user.phone}</p>}
</div>
</div>
{/* ── Rollar ───────────────────────────────────────────────────────── */}
<CollapsibleSection title={t("users.sections.roles", "Rollar")}>
<DataTableToolbar
searchValue={roleSearch}
onSearchChange={setRoleSearch}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={roleColumnMeta}
columnVisibility={roleColVisibility}
onColumnVisibilityChange={setRoleColVisibility}
columnOrder={roleColOrder}
onColumnOrderChange={setRoleColOrder}
actionLabel={t("users.actions.addRole", "Rol birikdiriň")}
onAction={() => {}}
/>
<DataTable
columns={roleColumns}
data={filteredRoles}
getRowId={(row) => String(row.id)}
currentPage={1}
totalPages={1}
totalCount={filteredRoles.length}
/>
</CollapsibleSection>
<InfoRow label={t("common.id", "ID")} value={user.id} />
<InfoRow label={t("users.fields.username", "Ulanyjy ady")} value={user.name} />
<InfoRow label={t("users.fields.firstName", "At ady")} value={user.firstName ?? "—"} />
<InfoRow label={t("users.fields.lastName", "Familiýasy")} value={user.lastName ?? "—"} />
<InfoRow label={t("users.fields.phone", "Telefon belgisi")} value={user.phone ?? "—"} />
{user.role && <InfoRow label={t("users.fields.role", "Roly")} value={user.role} />}
{user.email && <InfoRow label={t("users.fields.email", "E-poçta")} value={user.email} />}
<InfoRow
label={t("users.fields.createdAt", "Döredilen wagty")}
value={user.createdAt ? new Date(user.createdAt).toLocaleString() : "—"}
/>
<InfoRow label={t("users.fields.isActive", "Işjeň")}>
<div className="flex items-center gap-1.5 text-emerald-500 font-medium text-sm">
<CheckCircle2 size={16} />
<span>{t("common.active", "Işjeň")}</span>
</div>
</InfoRow>
</BentoCard>
</BentoGrid>
{/* ── 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>
{/* ── 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>
{/* ── Ş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>
{/* ── 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>
{/* ── Ammallar ─────────────────────────────────────────────────────── */}
<CollapsibleSection title={t("users.sections.audit", "Ammallar")}>
<AuditLog logs={MOCK_AUDIT} currentPage={1} totalPages={1} totalCount={MOCK_AUDIT.length} />
</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")}>
<AuditLog logs={[]} currentPage={1} totalPages={1} totalCount={0} />
</CollapsibleSection>
</>
) : (
<div className="w-full">
<BentoCard title={t("profile.editTitle", "Profili üýtgetmek")}>
<div className="space-y-4 p-2">
<AvatarUpload
label={t("users.fields.avatar", "Awatar")}
value={formData.avatar}
onChange={(url) => handleFieldChange("avatar", url)}
disabled={updateProfileMutation.isPending}
/>
<FormInput
type="text"
label={t("users.fields.name", "Ulanyjy ady")}
value={formData.name}
onChange={(v) => handleFieldChange("name", v)}
error={errors.name}
required
disabled={updateProfileMutation.isPending}
/>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<FormInput
type="text"
label={t("users.fields.firstName", "At ady")}
value={formData.firstName}
onChange={(v) => handleFieldChange("firstName", v)}
disabled={updateProfileMutation.isPending}
/>
<FormInput
type="text"
label={t("users.fields.lastName", "Familiýasy")}
value={formData.lastName}
onChange={(v) => handleFieldChange("lastName", v)}
disabled={updateProfileMutation.isPending}
/>
</div>
<FormInput
type="text"
label={t("users.fields.phone", "Telefon belgisi")}
value={formData.phone}
onChange={(v) => handleFieldChange("phone", v)}
disabled={updateProfileMutation.isPending}
/>
<div className="pt-4 border-t border-border">
<FormActions
onSubmit={handleSave}
onCancel={() => setIsEditing(false)}
isPending={updateProfileMutation.isPending}
submitLabel={t("common.save", "Ýatda sakla")}
/>
</div>
</div>
</BentoCard>
</div>
)}
</div>
);
}

View File

@@ -31,7 +31,7 @@ export default function UsersListPage() {
const [search, setSearch] = useState("");
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([]);
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
const [columnOrder, setColumnOrder] = useState<string[]>(["id", "username", "name", "phone", "email", "isActive", "actions"]);
const [columnOrder, setColumnOrder] = useState<string[]>(["id", "username", "name", "phone", "email", "active", "actions"]);
// Delete confirm dialog
const [deleteTarget, setDeleteTarget] = useState<User | null>(null);

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>
);
}

View File

@@ -1,15 +1,13 @@
import { useState } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { useParams, useNavigate, Link } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Pencil, Trash2, XCircle, CheckCircle2 } from "lucide-react";
import { Pencil, Trash2, XCircle, CheckCircle2, UserRound } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton";
import { ConfirmDialog } from "@/components/confirmDialog";
import { BentoGrid, BentoCard, InfoRow, AuditLog, CollapsibleSection, EmptyState } from "@/components/viewPageComponents";
import { DataTable, type ColumnDef } from "@/components/dataTable";
import { DataTableToolbar } from "@/components/dataTableToolbar";
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
import { Badge } from "@/components/ui/badge";
import { useClient, useDeleteClient } from "@/features/clients/hooks/useClients";
import type { ClientRole, ClientBranch, ClientAuditLog } from "@/features/clients/api/clientsApi";
// ─── ActiveIndicator ──────────────────────────────────────────────────────────
@@ -29,92 +27,6 @@ export default function ClientDetailPage() {
const { data: client, isLoading } = useClient(clientId);
const [deleteOpen, setDeleteOpen] = useState(false);
const [roleSearch, setRoleSearch] = useState("");
const [permSearch, setPermSearch] = useState("");
const [branchSearch, setBranchSearch] = useState("");
const [loanSearch, setLoanSearch] = useState("");
const [cardSearch, setCardSearch] = useState("");
// ── Role columns ──────────────────────────────────────────────────────────
const roleColumns: ColumnDef<ClientRole>[] = [
{
accessorKey: "id",
header: t("common.id", "ID"),
cell: ({ row }) => <span className="text-primary font-semibold text-sm">{row.original.id}</span>,
size: 80,
},
{
accessorKey: "code",
header: t("roles.fields.code", "KOD"),
cell: ({ row }) => <span className="text-sm">{row.original.code}</span>,
},
{
accessorKey: "name",
header: t("roles.fields.name", "ADY"),
cell: ({ row }) => <span className="text-sm">{row.original.name}</span>,
},
{
accessorKey: "guardName",
header: t("roles.fields.guardName", "GUARD NAME"),
cell: ({ row }) => <span className="text-sm">{row.original.guardName}</span>,
},
{
id: "actions",
header: "",
cell: () => (
<div className="flex items-center gap-1 justify-end">
<Button size="icon" variant="ghost" className="h-7 w-7 text-muted-foreground hover:text-destructive">
<Trash2 size={13} />
</Button>
</div>
),
size: 60,
},
];
// ── Branch columns ────────────────────────────────────────────────────────
const branchColumns: ColumnDef<ClientBranch>[] = [
{
accessorKey: "id",
header: t("common.id", "ID"),
cell: ({ row }) => <span className="text-primary font-semibold text-sm">{row.original.id}</span>,
size: 60,
},
{
accessorKey: "name",
header: t("branches.fields.name", "ADY"),
cell: ({ row }) => <span className="text-sm">{row.original.name}</span>,
},
{
accessorKey: "region",
header: t("branches.fields.region", "WELAÝAT"),
cell: ({ row }) => <span className="text-sm">{row.original.region}</span>,
},
{
accessorKey: "district",
header: t("branches.fields.district", "ETRAP"),
cell: ({ row }) => <span className="text-sm">{row.original.district}</span>,
},
{
accessorKey: "uniqueCode",
header: t("branches.fields.uniqueCode", "UNIKAL BELGI"),
cell: ({ row }) => <span className="text-sm">{row.original.uniqueCode}</span>,
},
{
id: "actions",
header: "",
cell: () => (
<div className="flex items-center gap-1 justify-end">
<Button size="icon" variant="ghost" className="h-7 w-7 text-muted-foreground hover:text-destructive">
<Trash2 size={13} />
</Button>
</div>
),
size: 60,
},
];
// ── Loading ───────────────────────────────────────────────────────────────
@@ -138,19 +50,9 @@ export default function ClientDetailPage() {
if (!client) return null;
const auditLogs = (client.auditLogs ?? []).map((log: ClientAuditLog) => ({
id: String(log.id),
action: log.actionName,
by: log.performedBy,
target: log.target,
status: log.status,
date: log.createdAt,
}));
const filteredRoles = (client.roles ?? []).filter(
(r) => r.name.toLowerCase().includes(roleSearch.toLowerCase()) || r.code.toLowerCase().includes(roleSearch.toLowerCase()),
);
const filteredBranches = (client.branches ?? []).filter((b) => b.name.toLowerCase().includes(branchSearch.toLowerCase()));
const roles = client.roles ?? [];
const permissions = client.permissions ?? [];
const branches = client.branches ?? [];
return (
<div className=" flex flex-col gap-6">
@@ -182,12 +84,77 @@ export default function ClientDetailPage() {
{/* ── Row 1: Esasy maglumatlar + Kontakt ──────────────────────────── */}
<BentoGrid cols={2}>
<BentoCard title={t("clients.sections.basic", "Esasy maglumatlar")}>
<div className="flex flex-col items-center gap-4 px-4 pt-4 pb-2">
{client.avatar ? (
<img
src={client.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">{client.name}</p>
</div>
</div>
<InfoRow label={t("common.id", "ID")} value={client.id} />
<InfoRow label={t("clients.fields.username", "Ulanyjy ady")} value={client.username} />
<InfoRow label={t("clients.fields.name", "Ady")} value={client.name} />
<InfoRow
label={t("clients.fields.role", "Roly")}
value={roles[0]?.name ?? client.role ?? "—"}
isLink
href={roles[0]?.id ? `/settings/users/roles/${roles[0].id}` : "/settings/users/roles"}
/>
<InfoRow label={t("clients.fields.isActive", "Işjeň")}>
<ActiveIndicator active={client.active} />
</InfoRow>
{roles.length > 0 && (
<InfoRow label={t("clients.sections.roles", "Rollar")}>
<div className="flex flex-wrap gap-1.5">
{roles.map((r) => (
<Link key={r.id} to={`/settings/users/roles/${r.id}`}>
<Badge variant="outline">{r.name}</Badge>
</Link>
))}
</div>
</InfoRow>
)}
{permissions.length > 0 && (
<InfoRow label={t("clients.sections.permissions", "Rugsatlar")}>
<div className="flex flex-wrap gap-1.5">
{permissions.map((p) => (
<Badge key={p.id} variant="secondary">
{p.name}
</Badge>
))}
</div>
</InfoRow>
)}
{branches.length > 0 && (
<InfoRow label={t("clients.sections.branches", "Şahamçalar")}>
<div className="flex flex-col gap-1">
{branches.map((b) => (
<span key={b.id} className="text-sm">
<Link to={`/settings/location/branches/${b.id}`} className="text-[#2bbae6] font-medium hover:underline">
{b.name}
</Link>
{b.region ? (
<>
{" — "}
<Link to="/settings/location/districts" className="text-[#2bbae6] font-medium hover:underline">
{b.region}
</Link>
</>
) : null}
</span>
))}
</div>
</InfoRow>
)}
</BentoCard>
<BentoCard title={t("clients.sections.contact", "Kontakt")}>
@@ -196,108 +163,6 @@ export default function ClientDetailPage() {
</BentoCard>
</BentoGrid>
{/* ── Rollar ───────────────────────────────────────────────────────── */}
<CollapsibleSection title={t("clients.sections.roles", "Rollar")}>
<DataTableToolbar
searchValue={roleSearch}
onSearchChange={setRoleSearch}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("clients.addRole", "Rol birikdiriň")}
onAction={() => {}}
/>
{filteredRoles.length > 0 ? (
<DataTable columns={roleColumns} data={filteredRoles} getRowId={(r) => String(r.id)} enableRowSelection />
) : (
<EmptyState label={t("clients.noRoles", "Berlen kriterýalara Rol gabat gelmedi.")} />
)}
</CollapsibleSection>
{/* ── Rugsatlar ────────────────────────────────────────────────────── */}
<CollapsibleSection title={t("clients.sections.permissions", "Rugsatlar")}>
<DataTableToolbar
searchValue={permSearch}
onSearchChange={setPermSearch}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("clients.addPermission", "Rugsat birikdiriň")}
onAction={() => {}}
/>
{(client.permissions ?? []).length === 0 && (
<EmptyState label={t("clients.noPermissions", "Berlen kriterýalara Rugsat gabat gelmedi.")} />
)}
</CollapsibleSection>
{/* ── Şahamçalar ───────────────────────────────────────────────────── */}
<CollapsibleSection title={t("clients.sections.branches", "Şahamçalar")}>
<DataTableToolbar
searchValue={branchSearch}
onSearchChange={setBranchSearch}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("clients.addBranch", "Şahamça birikdiriň")}
onAction={() => {}}
/>
{filteredBranches.length > 0 ? (
<DataTable columns={branchColumns} data={filteredBranches} getRowId={(r) => String(r.id)} enableRowSelection />
) : (
<EmptyState label={t("clients.noBranches", "Berlen kriterýalara Şahamça gabat gelmedi.")} />
)}
</CollapsibleSection>
{/* ── Karz sargyt ──────────────────────────────────────────────────── */}
<CollapsibleSection title={t("clients.sections.loanOrders", "Karz sargyt")}>
<DataTableToolbar
searchValue={loanSearch}
onSearchChange={setLoanSearch}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("clients.addLoanOrder", "Karz sargyt dörediň")}
onAction={() => {}}
/>
{(client.loanOrders ?? []).length === 0 && (
<EmptyState label={t("clients.noLoanOrders", "Berlen kriterýalara Karz sargyt gabat gelmedi.")} />
)}
</CollapsibleSection>
{/* ── Kart sargyt ──────────────────────────────────────────────────── */}
<CollapsibleSection title={t("clients.sections.cardOrders", "Kart sargyt")}>
<DataTableToolbar
searchValue={cardSearch}
onSearchChange={setCardSearch}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("clients.addCardOrder", "Kart sargyt dörediň")}
onAction={() => {}}
/>
{(client.cardOrders ?? []).length === 0 && (
<EmptyState label={t("clients.noCardOrders", "Berlen kriterýalara Kart sargyt gabat gelmedi.")} />
)}
</CollapsibleSection>
{/* ── Audit log ────────────────────────────────────────────────────── */}
<AuditLog logs={auditLogs} />
<ConfirmDialog
open={deleteOpen}
onOpenChange={setDeleteOpen}

View File

@@ -66,6 +66,11 @@ export default function OperatorsPage() {
header: t("operators.fields.name", "ADY"),
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name}</span>,
},
{
accessorKey: "role",
header: t("operators.fields.role", "ROLY"),
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.role ?? "—"}</span>,
},
{
accessorKey: "phone",
header: t("operators.fields.phone", "TELEFON"),

View File

@@ -1,16 +1,21 @@
import { useParams, useNavigate } from "react-router-dom";
import { useParams, useNavigate, Link } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { TableActions } from "@/components/tableActions";
import { Pencil, Trash2, CheckCircle2, XCircle } from "lucide-react";
import { Pencil, Trash2, CheckCircle2, XCircle, UserRound } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton";
import { ConfirmDialog } from "@/components/confirmDialog";
import { BentoGrid, BentoCard, InfoRow, AuditLog, CollapsibleSection, EmptyState } from "@/components/viewPageComponents";
import { DataTable, type ColumnDef } from "@/components/dataTable";
import { DataTableToolbar } from "@/components/dataTableToolbar";
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
import { Badge } from "@/components/ui/badge";
import { useOperator, useDeleteOperator } from "@/features/operators/hooks/useOperators";
import type { OperatorRole, OperatorBranch, OperatorAuditLog, OperatorPermission } from "@/features/operators/api/operatorsApi";
import type { LocalizedText } from "@/features/branches/api/branchesApi";
// ─── Helper: resolve LocalizedText | string ───────────────────────────────────
function resolveLocalizedName(name: LocalizedText | string, lang = "en"): string {
if (typeof name === "string") return name;
return name[lang as keyof LocalizedText] ?? name.en ?? "";
}
// ─── ActiveIndicator ──────────────────────────────────────────────────────────
@@ -23,145 +28,14 @@ function ActiveIndicator({ active }: { active: boolean }) {
export default function OperatorDetailPage() {
const { id } = useParams<{ id: string }>();
const operatorId = Number(id);
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const lang = i18n.language ?? "en";
const navigate = useNavigate();
const deleteMutation = useDeleteOperator();
const { data: operator, isLoading } = useOperator(operatorId);
const [deleteOpen, setDeleteOpen] = useState(false);
const [roleSearch, setRoleSearch] = useState("");
const [permSearch, setPermSearch] = useState("");
const [branchSearch, setBranchSearch] = useState("");
// ── Role columns ──────────────────────────────────────────────────────────
const roleColumns: ColumnDef<OperatorRole>[] = [
{
accessorKey: "id",
header: t("common.id", "ID"),
cell: ({ row }) => <span className="text-primary font-semibold text-sm">{row.original.id}</span>,
size: 80,
},
{
accessorKey: "code",
header: t("roles.fields.code", "KOD"),
cell: ({ row }) => <span className="text-sm">{row.original.code}</span>,
},
{
accessorKey: "name",
header: t("roles.fields.name", "ADY"),
cell: ({ row }) => <span className="text-sm">{row.original.name}</span>,
},
{
accessorKey: "guardName",
header: t("roles.fields.guardName", "GUARD NAME"),
cell: ({ row }) => <span className="text-sm">{row.original.guardName}</span>,
},
{
id: "actions",
header: "",
size: 120,
cell: ({ row }) => <TableActions onView={() => navigate(`/roles/${row.original.id}`)} />,
},
];
// ── Permission columns ────────────────────────────────────────────────────
const permissionColumns: ColumnDef<OperatorPermission>[] = [
{
accessorKey: "id",
header: t("common.id", "ID"),
cell: ({ row }) => <span className="text-primary font-semibold text-sm">{row.original.id}</span>,
size: 80,
},
{
accessorKey: "name",
header: t("permissions.fields.name", "ADY"),
cell: ({ row }) => <span className="text-sm">{row.original.name}</span>,
},
{
accessorKey: "guardName",
header: t("permissions.fields.guardName", "GUARD NAME"),
cell: ({ row }) => <span className="text-sm">{row.original.guardName}</span>,
},
{
id: "actions",
header: "",
size: 60,
cell: () => (
<div className="flex items-center justify-end">
<Button size="icon" variant="ghost" className="h-7 w-7 text-muted-foreground hover:text-destructive">
<Trash2 size={13} />
</Button>
</div>
),
},
];
// ── Branch columns ────────────────────────────────────────────────────────
const branchColumns: ColumnDef<OperatorBranch>[] = [
{
accessorKey: "id",
header: t("common.id", "ID"),
cell: ({ row }) => <span className="text-primary font-semibold text-sm">{row.original.id}</span>,
size: 60,
},
{
accessorKey: "name",
header: t("branches.fields.name", "ADY"),
cell: ({ row }) => <span className="text-sm">{row.original.name}</span>,
},
{
accessorKey: "region",
header: t("branches.fields.region", "WELAÝAT"),
cell: ({ row }) => <span className="text-sm">{row.original.region}</span>,
},
{
accessorKey: "district",
header: t("branches.fields.district", "ETRAP"),
cell: ({ row }) => <span className="text-sm">{row.original.district}</span>,
},
{
accessorKey: "uniqueCode",
header: t("branches.fields.uniqueCode", "UNIKAL BELGI"),
cell: ({ row }) => <span className="text-sm">{row.original.uniqueCode}</span>,
},
{
accessorKey: "isActive",
header: t("branches.fields.isActive", "IŞJEŇ"),
cell: ({ row }) => <ActiveIndicator active={row.original.isActive} />,
size: 80,
},
{
accessorKey: "billingUsernameIbr",
header: t("branches.fields.billingIbr", "BILLING ULANYJY ADY"),
cell: ({ row }) => <span className="text-sm font-mono">{row.original.billingUsernameIbr}</span>,
},
{
accessorKey: "billingUsernameSber",
header: t("branches.fields.billingSber", "BILLING USERNAME (SBER)"),
cell: ({ row }) => <span className="text-sm font-mono ">{row.original.billingUsernameSber}</span>,
},
{
accessorKey: "billingUsernameVisa",
header: t("branches.fields.billingVisa", "BILLING USERNAME (VISA)"),
cell: ({ row }) => <span className="text-sm font-mono ">{row.original.billingUsernameVisa}</span>,
},
{
id: "actions",
header: "",
size: 60,
cell: () => (
<div className="flex items-center justify-end">
<Button size="icon" variant="ghost" className="h-7 w-7 text-muted-foreground hover:text-destructive">
<Trash2 size={13} />
</Button>
</div>
),
},
];
// ── Loading ───────────────────────────────────────────────────────────────
@@ -185,22 +59,9 @@ export default function OperatorDetailPage() {
if (!operator) return null;
const auditLogs = (operator.auditLogs ?? []).map((log: OperatorAuditLog) => ({
id: String(log.id),
action: log.actionName,
by: log.performedBy,
target: log.target,
status: log.status,
date: log.createdAt,
}));
const filteredRoles = (operator.roles ?? []).filter(
(r) => r.name.toLowerCase().includes(roleSearch.toLowerCase()) || r.code.toLowerCase().includes(roleSearch.toLowerCase()),
);
const filteredPermissions = (operator.permissions ?? []).filter((p) => p.name.toLowerCase().includes(permSearch.toLowerCase()));
const filteredBranches = (operator.branches ?? []).filter((b) => b.name.toLowerCase().includes(branchSearch.toLowerCase()));
const roles = operator.roles ?? [];
const permissions = operator.permissions ?? [];
const branches = operator.branches ?? [];
return (
<div className="flex flex-col gap-6">
@@ -232,12 +93,77 @@ export default function OperatorDetailPage() {
{/* ── Esasy maglumatlar + Kontakt ──────────────────────────────────── */}
<BentoGrid cols={2}>
<BentoCard title={t("operators.sections.basic", "Esasy maglumatlar")}>
<div className="flex flex-col items-center gap-4 px-4 pt-4 pb-2">
{operator.avatar ? (
<img
src={operator.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">{operator.name}</p>
</div>
</div>
<InfoRow label={t("common.id", "ID")} value={operator.id} />
<InfoRow label={t("operators.fields.username", "Ulanyjy ady")} value={operator.username} />
<InfoRow label={t("operators.fields.name", "Ady")} value={operator.name} />
<InfoRow
label={t("operators.fields.role", "Roly")}
value={roles[0]?.name ?? operator.role ?? "—"}
isLink
href={roles[0]?.id ? `/settings/users/roles/${roles[0].id}` : "/settings/users/roles"}
/>
<InfoRow label={t("operators.fields.isActive", "Işjeň")}>
<ActiveIndicator active={operator.active} />
</InfoRow>
{roles.length > 0 && (
<InfoRow label={t("operators.sections.roles", "Rollar")}>
<div className="flex flex-wrap gap-1.5">
{roles.map((r) => (
<Link key={r.id} to={`/settings/users/roles/${r.id}`}>
<Badge variant="outline">{r.name}</Badge>
</Link>
))}
</div>
</InfoRow>
)}
{permissions.length > 0 && (
<InfoRow label={t("operators.sections.permissions", "Rugsatlar")}>
<div className="flex flex-wrap gap-1.5">
{permissions.map((p) => (
<Badge key={p.id} variant="secondary">
{p.name}
</Badge>
))}
</div>
</InfoRow>
)}
{branches.length > 0 && (
<InfoRow label={t("operators.sections.branches", "Şahamçalar")}>
<div className="flex flex-col gap-1">
{branches.map((b) => (
<span key={b.id} className="text-sm">
<Link to={`/settings/location/branches/${b.id}`} className="text-[#2bbae6] font-medium hover:underline">
{resolveLocalizedName(b.name, lang)}
</Link>
{b.region ? (
<>
{" — "}
<Link to="/settings/location/districts" className="text-[#2bbae6] font-medium hover:underline">
{b.region}
</Link>
</>
) : null}
</span>
))}
</div>
</InfoRow>
)}
</BentoCard>
<BentoCard title={t("operators.sections.contact", "Kontakt")}>
@@ -246,102 +172,6 @@ export default function OperatorDetailPage() {
</BentoCard>
</BentoGrid>
{/* ── Rollar ───────────────────────────────────────────────────────── */}
<CollapsibleSection title={t("operators.sections.roles", "Rollar")}>
<DataTableToolbar
searchValue={roleSearch}
onSearchChange={setRoleSearch}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("operators.addRole", "Rol birikdiriň")}
onAction={() => {}}
/>
<DataTable columns={roleColumns} data={filteredRoles} getRowId={(r) => String(r.id)} enableRowSelection />
</CollapsibleSection>
{/* ── Rugsatlar ────────────────────────────────────────────────────── */}
<CollapsibleSection title={t("operators.sections.permissions", "Rugsatlar")}>
<DataTableToolbar
searchValue={permSearch}
onSearchChange={setPermSearch}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("operators.addPermission", "Rugsat birikdiriň")}
onAction={() => {}}
/>
{filteredPermissions.length === 0 ? (
<EmptyState label={t("operators.noPermissions", "Berlen kriterýalara Rugsat gabat gelmedi.")} />
) : (
<DataTable columns={permissionColumns} data={filteredPermissions} getRowId={(p) => String(p.id)} enableRowSelection />
)}
</CollapsibleSection>
{/* ── Şahamçalar ───────────────────────────────────────────────────── */}
<CollapsibleSection title={t("operators.sections.branches", "Şahamçalar")}>
<DataTableToolbar
searchValue={branchSearch}
onSearchChange={setBranchSearch}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("operators.addBranch", "Şahamça birikdiriň")}
onAction={() => {}}
/>
<DataTable columns={branchColumns} data={filteredBranches} getRowId={(r) => String(r.id)} enableRowSelection />
</CollapsibleSection>
{/* ── Karz sargyt ──────────────────────────────────────────────────── */}
<CollapsibleSection title={t("operators.sections.loanLimits", "Karz sargyt")}>
<DataTableToolbar
searchValue=""
onSearchChange={() => {}}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("operators.addLoanLimit", "Karz sargyt döredin")}
onAction={() => {}}
hideSearch
/>
{(operator.loanLimits ?? []).length === 0 && (
<EmptyState label={t("operators.noLoanLimits", "Berlen kriterýalara Karz sargyt gabat gelmedi.")} />
)}
</CollapsibleSection>
{/* ── Kart sargyt ──────────────────────────────────────────────────── */}
<CollapsibleSection title={t("operators.sections.cardLimits", "Kart sargyt")}>
<DataTableToolbar
searchValue=""
onSearchChange={() => {}}
columns={[]}
columnVisibility={{}}
onColumnVisibilityChange={() => {}}
columnOrder={[]}
onColumnOrderChange={() => {}}
actionLabel={t("operators.addCardLimit", "Kart sargyt döredin")}
onAction={() => {}}
hideSearch
/>
{(operator.cardLimits ?? []).length === 0 && (
<EmptyState label={t("operators.noCardLimits", "Berlen kriterýalara Kart sargyt gabat gelmedi.")} />
)}
</CollapsibleSection>
{/* ── Audit log ────────────────────────────────────────────────────── */}
<AuditLog logs={auditLogs} />
<ConfirmDialog
open={deleteOpen}
onOpenChange={setDeleteOpen}