From a38d2615fd5db26a1bff34a3c8ec94cbaebb751b Mon Sep 17 00:00:00 2001 From: Jelaletdin12 Date: Tue, 26 May 2026 00:23:14 +0500 Subject: [PATCH] refoctored some view pages --- src/components/viewPageComponents.tsx | 312 ++++++++++------ src/pages/dashboard/index.tsx | 345 +++++++++++++----- .../loanDepartment/loanOrderView/index.tsx | 131 ++++--- src/pages/users/allUsersView/index.tsx | 251 +++++++------ src/pages/users/clientsView/index.tsx | 144 ++------ src/pages/users/operators/index.tsx | 13 +- src/pages/users/operatorsView/index.tsx | 339 +++++++++++------ 7 files changed, 940 insertions(+), 595 deletions(-) diff --git a/src/components/viewPageComponents.tsx b/src/components/viewPageComponents.tsx index 971b447..e9f8bf6 100644 --- a/src/components/viewPageComponents.tsx +++ b/src/components/viewPageComponents.tsx @@ -1,16 +1,25 @@ -import { Download, Eye, ChevronRight } from "lucide-react"; +import { useMemo, useState } from "react"; +import { Download, Eye, ChevronDown } from "lucide-react"; import { useTranslation } from "react-i18next"; +import { Badge } from "@/components/ui/badge"; +import { DataTable, type ColumnDef } from "@/components/dataTable"; // ─── BentoGrid ──────────────────────────────────────────────────────────────── -export function BentoGrid({ cols = 2, children }: { cols?: 1 | 2 | 3 | 4; children: React.ReactNode }) { +export function BentoGrid({ + cols = 2, + children, +}: { + cols?: 1 | 2 | 3 | 4; + children: React.ReactNode; +}) { const colClass = { 1: "grid-cols-1", 2: "grid-cols-1 sm:grid-cols-2", 3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3", 4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4", - }[cols] - return
{children}
+ }[cols]; + return
{children}
; } // ─── BentoCard ──────────────────────────────────────────────────────────────── @@ -22,14 +31,25 @@ interface BentoCardProps { noPadding?: boolean; } -export function BentoCard({ title, span, children, noPadding }: BentoCardProps) { +export function BentoCard({ + title, + span, + children, + noPadding, +}: BentoCardProps) { const spanClass = - span === "full" ? "sm:col-span-full" : - span === 2 ? "sm:col-span-2" : - span === 3 ? "sm:col-span-3" : "" + span === "full" + ? "sm:col-span-full" + : span === 2 + ? "sm:col-span-2" + : span === 3 + ? "sm:col-span-3" + : ""; return ( -
+
{title && (

@@ -39,34 +59,31 @@ export function BentoCard({ title, span, children, noPadding }: BentoCardProps) )} {noPadding ?

{children}
: children}
- ) + ); } // ─── InfoRow ────────────────────────────────────────────────────────────────── -// Supports both: -// -// {data.id} export interface InfoRowProps { label: string; - /** Plain string/number value — use this or children, not both */ value?: string | number | null; - /** Arbitrary JSX — status badges, links, custom formatting, etc. */ children?: React.ReactNode; isLink?: boolean; } - -// ─── InfoRow ────────────────────────────────────────────────────────────────── export function InfoRow({ label, value, children, isLink }: InfoRowProps) { const content = children ?? (value != null ? String(value) : null); return (
- {label} + + {label} + {content != null && content !== "" ? ( typeof content === "string" ? ( - + {content} ) : ( @@ -87,9 +104,7 @@ export interface MultiLangRowProps { } export function MultiLangRow({ label, value }: MultiLangRowProps) { - if (!value) { - return ; - } + if (!value) return ; const langs = [ { code: "TK", val: value.tk }, @@ -101,7 +116,9 @@ export function MultiLangRow({ label, value }: MultiLangRowProps) { return (
- {label} + + {label} +
{langs.map((l) => l.val ? ( @@ -113,7 +130,7 @@ export function MultiLangRow({ label, value }: MultiLangRowProps) { {l.val}
- ) : null + ) : null, )} {!hasAny && —}
@@ -122,7 +139,6 @@ export function MultiLangRow({ label, value }: MultiLangRowProps) { } // ─── Section ────────────────────────────────────────────────────────────────── -// title is optional — omit or pass empty string to skip the heading export interface SectionProps { title?: string; @@ -144,8 +160,38 @@ export function Section({ title, children }: SectionProps) { ); } +// ─── CollapsibleSection ──────────────────────────────────────────────────────── + +export interface CollapsibleSectionProps { + title: string; + children: React.ReactNode; +} + +export function CollapsibleSection({ title, children }: CollapsibleSectionProps) { + const [open, setOpen] = useState(true); + + return ( +
+
setOpen((v) => !v)} + > +

{title}

+ +
+ {open && ( +
+ {children} +
+ )} +
+ ); +} + // ─── PassportImage ──────────────────────────────────────────────────────────── -// Accepts both `src` and `url` prop names for compatibility export interface PassportImageProps { label: string; @@ -153,7 +199,6 @@ export interface PassportImageProps { url?: string | null; } -// ─── PassportImage ──────────────────────────────────────────────────────────── export function PassportImage({ label, src, url }: PassportImageProps) { const { t } = useTranslation(); const imageSrc = src ?? url ?? null; @@ -190,7 +235,7 @@ export function PassportImage({ label, src, url }: PassportImageProps) { ); } -// ─── AuditRow ───────────────────────────────────────────────────────────────── +// ─── AuditRowProps ──────────────────────────────────────────────────────────── export interface AuditRowProps { id: string; @@ -201,105 +246,138 @@ export interface AuditRowProps { date: string; } -export function AuditRow({ - id, - action, - by, - target, - status, - date, -}: AuditRowProps) { - return ( - - {id} - {action} - {by} - {target} - - - - {status} - - - - {date} - - - - - +// ─── StatusBadge ────────────────────────────────────────────────────────────── + +export function StatusBadge({ status }: { status: string }) { + const normalized = status.toLowerCase(); + const variant = + normalized === "success" || normalized === "completed" + ? "default" + : normalized === "failed" || normalized === "error" + ? "destructive" + : normalized === "pending" + ? "secondary" + : "outline"; + + return {status}; +} + +// ─── useAuditColumns ────────────────────────────────────────────────────────── + +export function useAuditColumns( + onView?: (log: AuditRowProps) => void, +): ColumnDef[] { + const { t } = useTranslation(); + + return useMemo( + () => [ + { + accessorKey: "id", + header: "ID", + cell: ({ row }) => ( + + {row.original.id} + + ), + size: 130, + }, + { + accessorKey: "action", + header: t("audit.columns.action", "AMALYŇ ADY"), + cell: ({ row }) => ( + + {row.original.action} + + ), + }, + { + accessorKey: "by", + header: t("audit.columns.by", "KIM TARAPYNDAN"), + cell: ({ row }) => ( + {row.original.by} + ), + }, + { + accessorKey: "target", + header: t("audit.columns.target", "AMALYŇ NYŞANY"), + cell: ({ row }) => ( + {row.original.target} + ), + }, + { + accessorKey: "status", + header: t("audit.columns.status", "AMALYŇ STATUSY"), + cell: ({ row }) => , + size: 160, + }, + { + accessorKey: "date", + header: t("audit.columns.date", "SENE"), + cell: ({ row }) => ( + + {row.original.date} + + ), + size: 160, + }, + { + id: "actions", + header: "", + enableHiding: false, + size: 60, + cell: ({ row }) => + onView ? ( +
+ +
+ ) : null, + }, + ], + [t, onView], ); } -// ─── AuditLog (full collapsible table) ─────────────────────────────────────── +// ─── AuditLog ───────────────────────────────────────────────────────────────── export interface AuditLogProps { logs: AuditRowProps[]; - defaultOpen?: boolean; + currentPage?: number; + totalPages?: number; + totalCount?: number; + onPageChange?: (page: number) => void; + isLoading?: boolean; + onView?: (log: AuditRowProps) => void; } -export function AuditLog({ logs, defaultOpen = true }: AuditLogProps) { - const { t } = useTranslation(); - - const columns = [ - "ID", - t("audit.columns.action", "AMALYŇ ADY"), - t("audit.columns.by", "KIM TARAPYNDAN"), - t("audit.columns.target", "AMALYŇ NYŞANY (TARIBESI)"), - t("audit.columns.status", "AMALYŇ STATUSY"), - t("audit.columns.date", "SENE"), - "", - ]; +export function AuditLog({ + logs, + currentPage, + totalPages, + totalCount, + onPageChange, + isLoading, + onView, +}: AuditLogProps) { + const columns = useAuditColumns(onView); return ( -
-
- - {t("loanOrders.sections.audit", "Ammallar")} - - -
-
- - - - {columns.map((col, i) => ( - - ))} - - - - {logs.length === 0 ? ( - - - - ) : ( - logs.map((log) => ) - )} - -
- {col} -
- {t("common.noData", "Maglumat ýok")} -
-
-
- {t("common.prev", "Öňki")} - - 1–{logs.length} / {logs.length} - - {t("common.next", "Soňky")} -
-
-
+
+ row.id} + />
); } diff --git a/src/pages/dashboard/index.tsx b/src/pages/dashboard/index.tsx index f5b754f..5b6cb29 100644 --- a/src/pages/dashboard/index.tsx +++ b/src/pages/dashboard/index.tsx @@ -1,4 +1,4 @@ -import { useTranslation } from 'react-i18next' +import { useTranslation } from "react-i18next"; import { ArrowUpRight, ArrowDownRight, @@ -7,7 +7,7 @@ import { Users, DollarSign, Activity, -} from 'lucide-react' +} from "lucide-react"; import { AreaChart, Area, @@ -19,80 +19,87 @@ import { PieChart, Pie, Cell, -} from 'recharts' +} from "recharts"; import { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, -} from '@/components/ui/chart' -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' -import { Badge } from '@/components/ui/badge' -import { cn } from '@/lib/utils' +} from "@/components/ui/chart"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { Badge } from "@/components/ui/badge"; +import { Skeleton } from "@/components/ui/skeleton"; +import { cn } from "@/lib/utils"; // ─── Mock data ──────────────────────────────────────────────────────────────── const areaData = [ - { month: 'Ýan', loans: 420, cards: 240 }, - { month: 'Few', loans: 380, cards: 290 }, - { month: 'Mar', loans: 510, cards: 310 }, - { month: 'Apr', loans: 470, cards: 280 }, - { month: 'Maý', loans: 630, cards: 390 }, - { month: 'Iýun', loans: 580, cards: 420 }, - { month: 'Iýul', loans: 720, cards: 460 }, - { month: 'Awg', loans: 690, cards: 500 }, - { month: 'Sen', loans: 810, cards: 530 }, - { month: 'Okt', loans: 760, cards: 480 }, - { month: 'Noý', loans: 890, cards: 560 }, - { month: 'Dek', loans: 950, cards: 610 }, -] + { month: "Ýan", loans: 420, cards: 240 }, + { month: "Few", loans: 380, cards: 290 }, + { month: "Mar", loans: 510, cards: 310 }, + { month: "Apr", loans: 470, cards: 280 }, + { month: "Maý", loans: 630, cards: 390 }, + { month: "Iýun", loans: 580, cards: 420 }, + { month: "Iýul", loans: 720, cards: 460 }, + { month: "Awg", loans: 690, cards: 500 }, + { month: "Sen", loans: 810, cards: 530 }, + { month: "Okt", loans: 760, cards: 480 }, + { month: "Noý", loans: 890, cards: 560 }, + { month: "Dek", loans: 950, cards: 610 }, +]; const barData = [ - { day: 'Du', approved: 28, rejected: 4 }, - { day: 'Si', approved: 35, rejected: 6 }, - { day: 'Ça', approved: 22, rejected: 3 }, - { day: 'Pe', approved: 41, rejected: 8 }, - { day: 'An', approved: 33, rejected: 5 }, - { day: 'Şe', approved: 18, rejected: 2 }, - { day: 'Ýe', approved: 12, rejected: 1 }, -] + { day: "Du", approved: 28, rejected: 4 }, + { day: "Si", approved: 35, rejected: 6 }, + { day: "Ça", approved: 22, rejected: 3 }, + { day: "Pe", approved: 41, rejected: 8 }, + { day: "An", approved: 33, rejected: 5 }, + { day: "Şe", approved: 18, rejected: 2 }, + { day: "Ýe", approved: 12, rejected: 1 }, +]; const pieData = [ - { name: 'Kanagatlandyrylan', value: 6746, key: 'approved' }, - { name: 'Garaşylýar', value: 208, key: 'pending' }, - { name: 'Işlenilýär', value: 157, key: 'processing' }, - { name: 'Ýatyrylan', value: 245, key: 'rejected' }, - { name: 'Bellige alyndy', value: 450, key: 'registered' }, -] + { name: "Kanagatlandyrylan", value: 6746, key: "approved" }, + { name: "Garaşylýar", value: 208, key: "pending" }, + { name: "Işlenilýär", value: 157, key: "processing" }, + { name: "Ýatyrylan", value: 245, key: "rejected" }, + { name: "Bellige alyndy", value: 450, key: "registered" }, +]; const recentActivity = [ - { id: '#KS-2841', name: 'Serdar Annagurban', amount: '12 500 TMT', status: 'approved', time: '2 min öň' }, - { id: '#KS-2840', name: 'Aýgül Myradowa', amount: '8 000 TMT', status: 'pending', time: '14 min öň' }, - { id: '#KS-2839', name: 'Kakajan Durdyýew', amount: '25 000 TMT', status: 'approved', time: '31 min öň' }, - { id: '#KS-2838', name: 'Ogulgerek Sähedowa', amount: '5 500 TMT', status: 'rejected', time: '1 sa öň' }, - { id: '#KS-2837', name: 'Merdan Hojamyradow', amount: '18 000 TMT', status: 'approved', time: '2 sa öň' }, -] + { id: "#KS-2841", name: "Serdar Annagurban", amount: "12 500 TMT", status: "approved", time: "2 min öň" }, + { id: "#KS-2840", name: "Aýgül Myradowa", amount: "8 000 TMT", status: "pending", time: "14 min öň" }, + { id: "#KS-2839", name: "Kakajan Durdyýew", amount: "25 000 TMT", status: "approved", time: "31 min öň" }, + { id: "#KS-2838", name: "Ogulgerek Sähedowa", amount: "5 500 TMT", status: "rejected", time: "1 sa öň" }, + { id: "#KS-2837", name: "Merdan Hojamyradow", amount: "18 000 TMT", status: "approved", time: "2 sa öň" }, +]; // ─── Chart configs ──────────────────────────────────────────────────────────── const areaConfig = { - loans: { label: 'Karzlar', color: 'var(--chart-1)' }, - cards: { label: 'Kartlar', color: 'var(--chart-2)' }, -} satisfies Record + loans: { label: "Karzlar", color: "var(--chart-1)" }, + cards: { label: "Kartlar", color: "var(--chart-2)" }, +} satisfies Record; const barConfig = { - approved: { label: 'Tassyklanan', color: 'var(--chart-1)' }, - rejected: { label: 'Ýatyryldy', color: 'var(--chart-5)' }, -} satisfies Record + approved: { label: "Tassyklanan", color: "var(--chart-1)" }, + rejected: { label: "Ýatyryldy", color: "var(--chart-5)" }, +} satisfies Record; const pieConfig = { - approved: { label: 'Kanagatlandyrylan', color: 'var(--chart-2)' }, - pending: { label: 'Garaşylýar', color: 'var(--chart-4)' }, - processing: { label: 'Işlenilýär', color: 'var(--chart-1)' }, - rejected: { label: 'Ýatyrylan', color: 'var(--chart-5)' }, - registered: { label: 'Bellige alyndy', color: 'var(--chart-3)' }, -} satisfies Record + approved: { label: "Kanagatlandyrylan", color: "var(--chart-2)" }, + pending: { label: "Garaşylýar", color: "var(--chart-4)" }, + processing: { label: "Işlenilýär", color: "var(--chart-1)" }, + rejected: { label: "Ýatyrylan", color: "var(--chart-5)" }, + registered: { label: "Bellige alyndy", color: "var(--chart-3)" }, +} satisfies Record; // ─── Stat card ──────────────────────────────────────────────────────────────── @@ -105,82 +112,232 @@ function StatCard({ icon: React.ElementType accent: string }) { - const positive = change >= 0 + const positive = change >= 0; return ( {title} -
+

{value}

{positive ? : } {Math.abs(change)}% geçen aýa garanyňda

- ) + ); +} + +function StatCardSkeleton() { + return ( + + + + + + + + + + + ); } // ─── Status badge ───────────────────────────────────────────────────────────── function StatusBadge({ status }: { status: string }) { const styles: Record = { - approved: 'bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-400 hover:bg-emerald-100', - pending: 'bg-amber-100 text-amber-700 dark:bg-amber-950 dark:text-amber-400 hover:bg-amber-100', - rejected: 'bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-400 hover:bg-red-100', - } + approved: "bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-400 hover:bg-emerald-100", + pending: "bg-amber-100 text-amber-700 dark:bg-amber-950 dark:text-amber-400 hover:bg-amber-100", + rejected: "bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-400 hover:bg-red-100", + }; const labels: Record = { - approved: 'Tassyklandy', - pending: 'Garaşylýar', - rejected: 'Ýatyryldy', - } + approved: "Tassyklandy", + pending: "Garaşylýar", + rejected: "Ýatyryldy", + }; return ( - + {labels[status]} - ) + ); } // ─── Page ───────────────────────────────────────────────────────────────────── -export default function DashboardPage() { - const { t } = useTranslation() - const total = pieData.reduce((s, d) => s + d.value, 0) +export default function DashboardPage({ isLoading = false }: { isLoading?: boolean }) { + const { t } = useTranslation(); + const total = pieData.reduce((s, d) => s + d.value, 0); + + if (isLoading) { + return ( +
+
+ + +
+ +
+ {[...Array(4)].map((_, i) => )} +
+ +
+ {/* Area chart skeleton */} + + + + + + +
+
+ {[...Array(5)].map((_, i) => )} +
+
+ +
+
+ {[...Array(12)].map((_, i) => )} +
+
+
+ {[...Array(2)].map((_, i) => ( +
+ + +
+ ))} +
+
+
+ + {/* Pie chart skeleton */} + + + + + + +
+
+ +
+
+
+
+ {[...Array(5)].map((_, i) => ( +
+
+ + +
+ +
+ ))} +
+ + +
+ +
+ {/* Bar chart skeleton */} + + + + + + +
+
+ {[...Array(4)].map((_, i) => )} +
+
+ {[65, 85, 50, 95, 75, 40, 30].map((h, i) => ( +
+ + +
+ ))} +
+
+ {[...Array(7)].map((_, i) => )} +
+
+
+ {[12, 14].map((w, i) => ( +
+ + +
+ ))} +
+
+
+ + {/* Recent activity skeleton */} + + +
+ + +
+ +
+ +
+ {[...Array(5)].map((_, i) => ( +
+ +
+ + +
+
+ + +
+
+ ))} +
+
+
+
+
+ ); + } return (
- {/* Header */}

- {t('Dashboard', 'Baş sahypa')} + {t("Dashboard", "Baş sahypa")}

- {t('Overview of all operations', 'Ähli amallaryň gysgaça görünüşi')} + {t("Overview of all operations", "Ähli amallaryň gysgaça görünüşi")}

{/* Stat cards */}
- - - - + + + +
{/* Area chart + Pie chart */}
- - {t('Loan & card trend', 'Karz we kart tendensiýasy')} + {t("Loan & card trend", "Karz we kart tendensiýasy")} 2024 — ýyllyk görünüş @@ -197,8 +354,8 @@ export default function DashboardPage() { - - + + } /> @@ -210,7 +367,7 @@ export default function DashboardPage() { - {t('Loan status', 'Karz ýagdaýy')} + {t("Loan status", "Karz ýagdaýy")} {total.toLocaleString()} jemi sargyt @@ -228,10 +385,7 @@ export default function DashboardPage() { {pieData.map((d) => (
- + {d.name} @@ -242,23 +396,21 @@ export default function DashboardPage() {
-
{/* Bar chart + Recent activity */}
- - {t('Weekly orders', 'Hepdelik sargytlar')} - {t('Last 7 days', 'Soňky 7 gün')} + {t("Weekly orders", "Hepdelik sargytlar")} + {t("Last 7 days", "Soňky 7 gün")} - - + + } /> @@ -271,8 +423,10 @@ export default function DashboardPage() {
- {t('Recent activity', 'Soňky hereketler')} - {t('Latest loan orders', 'Iň soňky karz sargytlary')} + {t("Recent activity", "Soňky hereketler")} + + {t("Latest loan orders", "Iň soňky karz sargytlary")} +
@@ -299,8 +453,7 @@ export default function DashboardPage() {
-
- ) + ); } \ No newline at end of file diff --git a/src/pages/loanDepartment/loanOrderView/index.tsx b/src/pages/loanDepartment/loanOrderView/index.tsx index dce6449..fd7b281 100644 --- a/src/pages/loanDepartment/loanOrderView/index.tsx +++ b/src/pages/loanDepartment/loanOrderView/index.tsx @@ -26,25 +26,36 @@ import { ConfirmDialog } from "@/components/confirmDialog"; // ─── Status config ──────────────────────────────────────────────────────────── const STATUS_VARIANT: Record = { - GARAŞYLÝAR: "warning", + GARAŞYLÝAR: "warning", KANAGATLANDYRYLAN: "success", - RED_EDILDI: "error", - IŞLENÝÄR: "warning", -} + RED_EDILDI: "error", + IŞLENÝÄR: "warning", +}; const STATUS_ICON: Record = { - GARAŞYLÝAR: AlertCircle, + GARAŞYLÝAR: AlertCircle, KANAGATLANDYRYLAN: CheckCircle2, - RED_EDILDI: XCircle, - IŞLENÝÄR: AlertCircle, -} + RED_EDILDI: XCircle, + IŞLENÝÄR: AlertCircle, +}; -function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) { - const { t } = useTranslation() - const variant = STATUS_VARIANT[status] - const Icon = STATUS_ICON[status] - if (!variant) return {status} - return +function LoanOrderMobileStatusBadge({ + status, +}: { + status: LoanOrderMobileStatus; +}) { + const { t } = useTranslation(); + const variant = STATUS_VARIANT[status]; + const Icon = STATUS_ICON[status]; + if (!variant) + return {status}; + return ( + + ); } // ─── Skeleton ───────────────────────────────────────────────────────────────── @@ -55,7 +66,10 @@ function LoanOrderViewSkeleton() {
{[...Array(6)].map((_, i) => ( -
+
{[...Array(3)].map((_, j) => ( @@ -64,54 +78,53 @@ function LoanOrderViewSkeleton() { ))}
- ) + ); } // ─── Page ───────────────────────────────────────────────────────────────────── export default function LoanOrderViewPage() { - const { t } = useTranslation() - const navigate = useNavigate() - const { id } = useParams<{ id: string }>() - const deleteMutation = useDeleteLoanOrder() - const [showDeleteDialog, setShowDeleteDialog] = useState(false) + const { t } = useTranslation(); + const navigate = useNavigate(); + const { id } = useParams<{ id: string }>(); + const deleteMutation = useDeleteLoanOrder(); + const [showDeleteDialog, setShowDeleteDialog] = useState(false); - const { data: order, isLoading } = useLoanOrderById(id!) + const { data: order, isLoading } = useLoanOrderById(id!); const handleDelete = () => { - setShowDeleteDialog(true) - } + setShowDeleteDialog(true); + }; const confirmDelete = () => { deleteMutation.mutate(id!, { onSuccess: () => navigate("/loan-orders"), - }) - } + }); + }; - if (isLoading) return + if (isLoading) return ; if (!order) { return (
{t("common.notFound", "Tapylmady")}
- ) + ); } const auditLogs: AuditRowProps[] = [ { - id: "44548", + id: "44548", action: t("audit.actions.view", "Görmek"), - by: order.createdBy ?? "", + by: order.createdBy ?? "", target: `${t("loanOrders.title", "Karz sargyt")}: ${order.id}`, status: "FINISHED", - date: order.createdAt ?? "", + date: order.createdAt ?? "", }, - ] + ]; return (
- {/* ── Page header ──────────────────────────────────────────────────── */}

@@ -145,9 +158,7 @@ export default function LoanOrderViewPage() { label={t("loanOrders.columns.createdAt", "Döredilen wagty")} value={order.createdAt} /> - + {/* Personal */} - + @@ -248,7 +267,10 @@ export default function LoanOrderViewPage() { value={order.employer ?? undefined} /> @@ -301,19 +329,28 @@ export default function LoanOrderViewPage() { @@ -331,5 +368,5 @@ export default function LoanOrderViewPage() { isLoading={deleteMutation.isPending} />

- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/users/allUsersView/index.tsx b/src/pages/users/allUsersView/index.tsx index a307d07..6d6fef2 100644 --- a/src/pages/users/allUsersView/index.tsx +++ b/src/pages/users/allUsersView/index.tsx @@ -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, ChevronDown, Plus, Search, SlidersHorizontal, ChevronUp } from "lucide-react"; +import { Pencil, Trash2, CheckCircle2, XCircle, Inbox } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import { @@ -14,80 +14,27 @@ import { AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; -import { Section, InfoRow } from "@/components/viewPageComponents"; +import { + Section, + InfoRow, + CollapsibleSection, +} from "@/components/viewPageComponents"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; import { useUser, useDeleteUser } from "@/features/allUsers/hooks/useAllUsers"; -// ─── Collapsible Section ────────────────────────────────────────────────────── +// ─── EmptyState ─────────────────────────────────────────────────────────────── -interface CollapsibleBlockProps { - title: string; - actionLabel: string; - onAction: () => void; - emptyMessage: string; - searchPlaceholder?: string; - showFilter?: boolean; +interface EmptyStateProps { + label: string; } -function CollapsibleBlock({ title, actionLabel, onAction, emptyMessage, searchPlaceholder, showFilter = false }: CollapsibleBlockProps) { - const [open, setOpen] = useState(true); - const [search, setSearch] = useState(""); - +function EmptyState({ label }: EmptyStateProps) { return ( -
- - - {open && ( -
- {/* Sub-toolbar */} -
-
- - setSearch(e.target.value)} - placeholder={searchPlaceholder} - className="h-8 pl-8 pr-3 rounded-md border border-border bg-background text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-ring w-48" - /> -
-
- {showFilter && ( - - )} - -
-
- - {/* Empty state */} -
-
- - - - - - - - -
-

{emptyMessage}

- -
-
- )} +
+
+ +
+

{label}

); } @@ -104,6 +51,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); @@ -116,7 +67,10 @@ export default function UserViewPage() {
{Array.from({ length: 5 }).map((_, i) => ( -
+
@@ -127,7 +81,11 @@ export default function UserViewPage() { } if (isError || !user) { - return
{t("common.notFound", "Maglumat tapylmady")}
; + return ( +
+ {t("common.notFound", "Maglumat tapylmady")} +
+ ); } return ( @@ -135,7 +93,8 @@ export default function UserViewPage() { {/* Title + actions */}

- {t("users.viewTitle", "Ulanyjy giňişleýin")}: {user.name} ({user.username}) + {t("users.viewTitle", "Ulanyjy giňişleýin")}: {user.name} ( + {user.username})

-
@@ -155,10 +119,19 @@ export default function UserViewPage() { {/* Main info */}
- + - - + + {user.isActive ? ( @@ -169,57 +142,113 @@ export default function UserViewPage() {
{/* Rollar */} - {}} - emptyMessage={t("users.empty.roles", "Berlen kriteriýalara Rol gabat gelmedi.")} - searchPlaceholder={t("common.search", "Gözlemek")} - /> + + {}} + columnOrder={[]} + onColumnOrderChange={() => {}} + actionLabel={t("users.actions.addRole", "Rol birikdiriň")} + onAction={() => {}} + /> + + {/* Rugsatlar */} - {}} - emptyMessage={t("users.empty.permissions", "Berlen kriteriýalara Rugsat gabat gelmedi.")} - searchPlaceholder={t("common.search", "Gözlemek")} - /> + + {}} + columnOrder={[]} + onColumnOrderChange={() => {}} + actionLabel={t("users.actions.addPermission", "Rugsat birikdiriň")} + onAction={() => {}} + /> + + {/* Şahamçalar */} - {}} - emptyMessage={t("users.empty.branches", "Berlen kriteriýalara Şahamça gabat gelmedi.")} - searchPlaceholder={t("common.search", "Gözlemek")} - showFilter - /> + + {}} + columnOrder={[]} + onColumnOrderChange={() => {}} + actionLabel={t("users.actions.addBranch", "Şahamça birikdiriň")} + onAction={() => {}} + /> + + {/* Ammallar */} - {}} - emptyMessage={t("users.empty.audit", "Berlen kriteriýalara Hereket gabat gelmedi.")} - searchPlaceholder={t("common.search", "Gözlemek")} - /> + + {}} + columnOrder={[]} + onColumnOrderChange={() => {}} + actionLabel={t("users.actions.addAction", "Hereket")} + onAction={() => {}} + /> + + {/* Delete dialog */} - {t("users.deleteDialog.title", "Ulanyjyny öçürmek")} + + {t("users.deleteDialog.title", "Ulanyjyny öçürmek")} + - {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)} {t("common.cancel", "Ýok")} - + {t("common.delete", "Öçür")} diff --git a/src/pages/users/clientsView/index.tsx b/src/pages/users/clientsView/index.tsx index c889774..6529c49 100644 --- a/src/pages/users/clientsView/index.tsx +++ b/src/pages/users/clientsView/index.tsx @@ -1,11 +1,11 @@ import { useState } from 'react' import { useParams, useNavigate } from 'react-router-dom' import { useTranslation } from 'react-i18next' -import { Pencil, Trash2, ChevronDown, XCircle, CheckCircle2 } from 'lucide-react' +import { Pencil, Trash2, XCircle, CheckCircle2, Inbox } 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 } from '@/components/viewPageComponents' +import { BentoGrid, BentoCard, InfoRow, AuditLog, CollapsibleSection } from '@/components/viewPageComponents' import { DataTable, type ColumnDef } from '@/components/dataTable' import { DataTableToolbar } from '@/components/dataTableToolbar' import { useClient, useDeleteClient } from '@/features/clients/hooks/useClients' @@ -21,73 +21,21 @@ function ActiveIndicator({ active }: { active: boolean }) { ); } -// ─── CollapsibleSection ─────────────────────────────────────────────────────── - -interface CollapsibleSectionProps { - title: string - actionLabel: string - onAction: () => void - children: React.ReactNode -} - -function CollapsibleSection({ title, actionLabel, onAction, children }: CollapsibleSectionProps) { - const [open, setOpen] = useState(true) - return ( -
-
setOpen((v) => !v)} - > -

{title}

- -
- {open && ( -
-
- -
- {children} -
- )} -
- ) -} - // ─── EmptyState ─────────────────────────────────────────────────────────────── interface EmptyStateProps { - label: string - actionLabel: string - onAction: () => void + label: string; } -function EmptyState({ label, actionLabel, onAction }: EmptyStateProps) { +function EmptyState({ label }: EmptyStateProps) { return (
- - - - - - - +

{label}

-
- ) + ); } // ─── Page ───────────────────────────────────────────────────────────────────── @@ -284,116 +232,86 @@ export default function ClientDetailPage() { {/* ── Rollar ───────────────────────────────────────────────────────── */} - {}} - > + {}} - columnOrder={[]} onColumnOrderChange={() => {}} hideAction + columnOrder={[]} onColumnOrderChange={() => {}} + actionLabel={t('clients.addRole', 'Rol birikdiriň')} + onAction={() => {}} /> {filteredRoles.length > 0 ? ( String(r.id)} enableRowSelection /> ) : ( - {}} - /> + )} {/* ── Rugsatlar ────────────────────────────────────────────────────── */} - {}} - > + {}} - columnOrder={[]} onColumnOrderChange={() => {}} hideAction + columnOrder={[]} onColumnOrderChange={() => {}} + actionLabel={t('clients.addPermission', 'Rugsat birikdiriň')} + onAction={() => {}} /> {(client.permissions ?? []).length === 0 && ( - {}} - /> + )} {/* ── Şahamçalar ───────────────────────────────────────────────────── */} - {}} - > + {}} - columnOrder={[]} onColumnOrderChange={() => {}} hideAction + columnOrder={[]} onColumnOrderChange={() => {}} + actionLabel={t('clients.addBranch', 'Şahamça birikdiriň')} + onAction={() => {}} /> {filteredBranches.length > 0 ? ( String(r.id)} enableRowSelection /> ) : ( - {}} - /> + )} {/* ── Karz sargyt ──────────────────────────────────────────────────── */} - {}} - > + {}} - columnOrder={[]} onColumnOrderChange={() => {}} hideAction + columnOrder={[]} onColumnOrderChange={() => {}} + actionLabel={t('clients.addLoanOrder', 'Karz sargyt dörediň')} + onAction={() => {}} /> {(client.loanOrders ?? []).length === 0 && ( - {}} - /> + )} {/* ── Kart sargyt ──────────────────────────────────────────────────── */} - {}} - > + {}} - columnOrder={[]} onColumnOrderChange={() => {}} hideAction + columnOrder={[]} onColumnOrderChange={() => {}} + actionLabel={t('clients.addCardOrder', 'Kart sargyt dörediň')} + onAction={() => {}} /> {(client.cardOrders ?? []).length === 0 && ( - {}} - /> + )} diff --git a/src/pages/users/operators/index.tsx b/src/pages/users/operators/index.tsx index ef25620..a0493e4 100644 --- a/src/pages/users/operators/index.tsx +++ b/src/pages/users/operators/index.tsx @@ -219,14 +219,19 @@ export default function OperatorsPage() { {/* Delete dialog */} { if (!o) setDeleteTarget(null) }} + onOpenChange={(o) => { + if (!o) setDeleteTarget(null); + }} title={t("operators.deleteTitle", "Operatory pozmak")} - description={t("operators.deleteDescription", 'Siz "{name}" operatoryny pozjakmy?').replace("{name}", deleteTarget?.name ?? "")} + description={t( + "operators.deleteDescription", + 'Siz "{name}" operatoryny pozjakmy?', + ).replace("{name}", deleteTarget?.name ?? "")} confirmLabel={t("common.delete", "Poz")} onConfirm={() => { if (deleteTarget) { - deleteMutation.mutate(deleteTarget.id) - setDeleteTarget(null) + deleteMutation.mutate(deleteTarget.id); + setDeleteTarget(null); } }} isLoading={deleteMutation.isPending} diff --git a/src/pages/users/operatorsView/index.tsx b/src/pages/users/operatorsView/index.tsx index d0aabdb..2606e26 100644 --- a/src/pages/users/operatorsView/index.tsx +++ b/src/pages/users/operatorsView/index.tsx @@ -1,17 +1,38 @@ import { useParams, useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; -import { Pencil, Trash2, ChevronDown, CheckCircle2, XCircle, } from "lucide-react"; +import { + Pencil, + Trash2, + CheckCircle2, + XCircle, + Inbox, + Eye, +} 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 } from "@/components/viewPageComponents"; +import { + BentoGrid, + BentoCard, + InfoRow, + AuditLog, + CollapsibleSection, +} from "@/components/viewPageComponents"; import { DataTable, type ColumnDef } from "@/components/dataTable"; import { DataTableToolbar } from "@/components/dataTableToolbar"; -import { useOperator, useDeleteOperator } from "@/features/operators/hooks/useOperators"; -import type { OperatorRole, OperatorBranch, OperatorAuditLog } from "@/features/operators/api/operatorsApi"; +import { + useOperator, + useDeleteOperator, +} from "@/features/operators/hooks/useOperators"; +import type { + OperatorRole, + OperatorBranch, + OperatorAuditLog, + OperatorPermission, +} from "@/features/operators/api/operatorsApi"; -// ─── IsActive indicator ─────────────────────────────────────────────────────── +// ─── ActiveIndicator ────────────────────────────────────────────────────────── function ActiveIndicator({ active }: { active: boolean }) { return active ? ( @@ -21,62 +42,19 @@ function ActiveIndicator({ active }: { active: boolean }) { ); } -// ─── CollapsibleSection ─────────────────────────────────────────────────────── - -interface CollapsibleSectionProps { - title: string; - actionLabel: string; - onAction: () => void; - children: React.ReactNode; -} - -function CollapsibleSection({ title, actionLabel, onAction, children }: CollapsibleSectionProps) { - const [open, setOpen] = useState(true); - - return ( -
-
setOpen((v) => !v)}> -

{title}

- -
- {open && ( -
-
- -
- {children} -
- )} -
- ); -} - // ─── EmptyState ─────────────────────────────────────────────────────────────── interface EmptyStateProps { label: string; - actionLabel: string; - onAction: () => void; } -function EmptyState({ label, actionLabel, onAction }: EmptyStateProps) { +function EmptyState({ label }: EmptyStateProps) { return (
- - - - - - - +

{label}

-
); } @@ -103,7 +81,11 @@ export default function OperatorDetailPage() { { accessorKey: "id", header: t("common.id", "ID"), - cell: ({ row }) => {row.original.id}, + cell: ({ row }) => ( + + {row.original.id} + + ), size: 80, }, { @@ -119,11 +101,14 @@ export default function OperatorDetailPage() { { accessorKey: "guardName", header: t("roles.fields.guardName", "GUARD NAME"), - cell: ({ row }) => {row.original.guardName}, + cell: ({ row }) => ( + {row.original.guardName} + ), }, { id: "actions", header: "", + size: 120, cell: ({ row }) => (
- - +
+ ), + }, + ]; + + // ── Permission columns ──────────────────────────────────────────────────── + + const permissionColumns: ColumnDef[] = [ + { + accessorKey: "id", + header: t("common.id", "ID"), + cell: ({ row }) => ( + + {row.original.id} + + ), + size: 80, + }, + { + accessorKey: "name", + header: t("permissions.fields.name", "ADY"), + cell: ({ row }) => {row.original.name}, + }, + { + accessorKey: "guardName", + header: t("permissions.fields.guardName", "GUARD NAME"), + cell: ({ row }) => ( + {row.original.guardName} + ), + }, + { + id: "actions", + header: "", + size: 60, + cell: () => ( +
+
), - size: 120, }, ]; @@ -155,7 +187,11 @@ export default function OperatorDetailPage() { { accessorKey: "id", header: t("common.id", "ID"), - cell: ({ row }) => {row.original.id}, + cell: ({ row }) => ( + + {row.original.id} + + ), size: 60, }, { @@ -171,12 +207,16 @@ export default function OperatorDetailPage() { { accessorKey: "district", header: t("branches.fields.district", "ETRAP"), - cell: ({ row }) => {row.original.district}, + cell: ({ row }) => ( + {row.original.district} + ), }, { accessorKey: "uniqueCode", header: t("branches.fields.uniqueCode", "UNIKAL BELGI"), - cell: ({ row }) => {row.original.uniqueCode}, + cell: ({ row }) => ( + {row.original.uniqueCode} + ), }, { accessorKey: "isActive", @@ -187,29 +227,45 @@ export default function OperatorDetailPage() { { accessorKey: "billingUsernameIbr", header: t("branches.fields.billingIbr", "BILLING ULANYJY ADY"), - cell: ({ row }) => {row.original.billingUsernameIbr}, + cell: ({ row }) => ( + + {row.original.billingUsernameIbr} + + ), }, { accessorKey: "billingUsernameSber", header: t("branches.fields.billingSber", "BILLING USERNAME (SBER)"), - cell: ({ row }) => {row.original.billingUsernameSber}, + cell: ({ row }) => ( + + {row.original.billingUsernameSber} + + ), }, { accessorKey: "billingUsernameVisa", header: t("branches.fields.billingVisa", "BILLING USERNAME (VISA)"), - cell: ({ row }) => {row.original.billingUsernameVisa}, + cell: ({ row }) => ( + + {row.original.billingUsernameVisa} + + ), }, { id: "actions", header: "", + size: 60, cell: () => ( -
-
), - size: 60, }, ]; @@ -221,7 +277,10 @@ export default function OperatorDetailPage() {
{Array.from({ length: 4 }).map((_, i) => ( -
+
{Array.from({ length: 3 }).map((_, j) => ( @@ -245,12 +304,21 @@ export default function OperatorDetailPage() { })); const filteredRoles = (operator.roles ?? []).filter( - (r) => r.name.toLowerCase().includes(roleSearch.toLowerCase()) || r.code.toLowerCase().includes(roleSearch.toLowerCase()), + (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 filteredBranches = (operator.branches ?? []).filter((b) => b.name.toLowerCase().includes(branchSearch.toLowerCase())); return ( -
+
{/* ── Page header ──────────────────────────────────────────────────── */}

@@ -276,29 +344,37 @@ export default function OperatorDetailPage() {

- {/* ── Row 1: Esasy maglumatlar + Kontakt ──────────────────────────── */} + {/* ── Esasy maglumatlar + Kontakt ──────────────────────────────────── */} - - + + - - + + {/* ── Rollar ───────────────────────────────────────────────────────── */} - {}} - > + {}} columnOrder={[]} onColumnOrderChange={() => {}} - hideAction + actionLabel={t("operators.addRole", "Rol birikdiriň")} + onAction={() => { + /* modal aç ya da navigate */ + }} + /> + String(r.id)} + enableRowSelection /> - String(r.id)} enableRowSelection /> {/* ── Rugsatlar ────────────────────────────────────────────────────── */} {}} > {}} columnOrder={[]} onColumnOrderChange={() => {}} - hideAction + actionLabel={t("operators.addPermission", "Rugsat birikdiriň")} + onAction={() => {}} /> - {(operator.permissions ?? []).length === 0 && ( + {filteredPermissions.length === 0 ? ( {}} + label={t( + "operators.noPermissions", + "Berlen kriterýalara Rugsat gabat gelmedi.", + )} + /> + ) : ( + String(p.id)} + enableRowSelection /> )} @@ -342,8 +433,6 @@ export default function OperatorDetailPage() { {/* ── Şahamçalar ───────────────────────────────────────────────────── */} {}} > {}} columnOrder={[]} onColumnOrderChange={() => {}} - hideAction + actionLabel={t("operators.addBranch", "Şahamça birikdiriň")} + onAction={() => {}} + /> + String(r.id)} + enableRowSelection /> - String(r.id)} enableRowSelection /> {/* ── Karz sargyt ──────────────────────────────────────────────────── */} {}} > + {}} + columns={[]} + columnVisibility={{}} + onColumnVisibilityChange={() => {}} + columnOrder={[]} + onColumnOrderChange={() => {}} + actionLabel={t("operators.addLoanLimit", "Karz sargyt döredin")} + onAction={() => {}} + hideSearch + /> {(operator.loanLimits ?? []).length === 0 && ( {}} + label={t( + "operators.noLoanLimits", + "Berlen kriterýalara Karz sargyt gabat gelmedi.", + )} /> )} @@ -377,14 +483,25 @@ export default function OperatorDetailPage() { {/* ── Kart sargyt ──────────────────────────────────────────────────── */} {}} > + {}} + columns={[]} + columnVisibility={{}} + onColumnVisibilityChange={() => {}} + columnOrder={[]} + onColumnOrderChange={() => {}} + actionLabel={t("operators.addCardLimit", "Kart sargyt döredin")} + onAction={() => {}} + hideSearch + /> {(operator.cardLimits ?? []).length === 0 && ( {}} + label={t( + "operators.noCardLimits", + "Berlen kriterýalara Kart sargyt gabat gelmedi.", + )} /> )} @@ -396,9 +513,17 @@ export default function OperatorDetailPage() { open={deleteOpen} onOpenChange={setDeleteOpen} title={t("operators.deleteTitle", "Operatory pozmak")} - description={t("operators.deleteConfirm", "{{name}} operatoryny pozmak isleýärsiňizmi?", { name: operator.name })} + description={t( + "operators.deleteConfirm", + "{{name}} operatoryny pozmak isleýärsiňizmi?", + { name: operator.name }, + )} confirmLabel={t("common.delete", "Poz")} - onConfirm={() => deleteMutation.mutate(operatorId, { onSuccess: () => navigate("/operators") })} + onConfirm={() => + deleteMutation.mutate(operatorId, { + onSuccess: () => navigate("/operators"), + }) + } isLoading={deleteMutation.isPending} />