From caae9413468b6b6a9f3a839a8a873974fa5da81d Mon Sep 17 00:00:00 2001 From: "@jcarymuhammedow" Date: Wed, 3 Jun 2026 18:19:16 +0500 Subject: [PATCH] refactord some files --- src/components/createButton.tsx | 26 ++ src/components/dataTableToolbar.tsx | 322 ++++++-------- src/components/deleteDialog.tsx | 45 ++ src/components/tableButton.tsx | 36 -- src/components/tableSearch.tsx | 44 +- src/pages/backups/index.tsx | 205 ++++----- .../cardDepartment/cardBalance/index.tsx | 54 ++- src/pages/cardDepartment/cardPins/index.tsx | 171 +++----- .../cardDepartment/cardRequisites/index.tsx | 147 ++----- .../cardDepartment/cardTransactions/index.tsx | 267 +++++------ .../cardDepartment/orderNewCard/index.tsx | 309 +++++++------ src/pages/currencies/currencyRates/index.tsx | 66 ++- .../visaMasterSberSettings/index.tsx | 58 +-- .../sberPayments/index.tsx | 415 ++++++++++-------- .../visaMasterPayments/index.tsx | 304 ++++++------- .../loanDepartment/loanOrderMobile/index.tsx | 336 +++++++------- src/pages/loanDepartment/loanOrders/index.tsx | 317 +++++++------ .../loanPaidOffLetters/index.tsx | 30 +- .../loanDepartment/loanRemaining/index.tsx | 186 ++++---- src/pages/settings/card/cardTypes/index.tsx | 299 ++++++------- src/pages/settings/card/reasons/index.tsx | 298 ++++++------- src/pages/settings/loan/loanTypes/index.tsx | 259 +++++------ .../settings/loan/requiredDocuments/index.tsx | 197 +++++---- .../settings/location/branches/index.tsx | 323 +++++++------- .../settings/location/districts/index.tsx | 289 ++++++------ .../settings/users/permissions/index.tsx | 241 +++++----- src/pages/settings/users/roles/index.tsx | 238 +++++----- src/pages/users/allUsers/index.tsx | 17 +- src/pages/users/clients/index.tsx | 238 +++++----- src/pages/users/operators/index.tsx | 63 ++- 30 files changed, 2761 insertions(+), 3039 deletions(-) create mode 100644 src/components/createButton.tsx create mode 100644 src/components/deleteDialog.tsx delete mode 100644 src/components/tableButton.tsx diff --git a/src/components/createButton.tsx b/src/components/createButton.tsx new file mode 100644 index 0000000..03a3b65 --- /dev/null +++ b/src/components/createButton.tsx @@ -0,0 +1,26 @@ +import { Plus } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { cn } from "@/lib/utils"; + +interface CreateButtonProps { + label: string; + onClick: () => void; + icon?: React.ReactNode; + disabled?: boolean; + className?: string; + variant?: "primary" | "destructive" | "secondary"; +} + +export function CreateButton({ label, onClick, icon, disabled = false, className, variant = "primary" }: CreateButtonProps) { + return ( + + ); +} diff --git a/src/components/dataTableToolbar.tsx b/src/components/dataTableToolbar.tsx index 28c211f..d14af4c 100644 --- a/src/components/dataTableToolbar.tsx +++ b/src/components/dataTableToolbar.tsx @@ -1,79 +1,69 @@ -import { useRef, useState } from 'react' -import { useTranslation } from 'react-i18next' -import { SlidersHorizontal, Clock, Filter, ChevronDown, X, GripVertical } from 'lucide-react' -import type { VisibilityState } from '@tanstack/react-table' -import { useOutsideClick } from '@/lib/hooks/useOutsideClick' -import { cn } from '@/lib/utils' -import { TableSearchInput } from '@/components/tableSearch' -import { TableActionButton } from '@/components/tableButton' -import { - Popover, - PopoverContent, - PopoverTrigger, -} from '@/components/ui/popover' -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from '@/components/ui/select' +import { useRef, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { SlidersHorizontal, Filter, ChevronDown, X, GripVertical } from "lucide-react"; +import type { VisibilityState } from "@tanstack/react-table"; +import { useOutsideClick } from "@/lib/hooks/useOutsideClick"; +import { cn } from "@/lib/utils"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; // ─── Types ──────────────────────────────────────────────────────────────────── export interface ColumnMeta { - id: string - label: string + id: string; + label: string; } export interface FilterField { - id: string - label: string - options: { value: string; label: string }[] + id: string; + label: string; + options: { value: string; label: string }[]; } export interface ActiveFilter { - fieldId: string - value: string + fieldId: string; + value: string; } interface DataTableToolbarProps { - searchValue: string - onSearchChange: (value: string) => void - searchPlaceholder?: string + searchValue: string; + onSearchChange: (value: string) => void; + searchPlaceholder?: string; - columns: ColumnMeta[] - columnVisibility: VisibilityState - onColumnVisibilityChange: (visibility: VisibilityState) => void - columnOrder: string[] - onColumnOrderChange: (order: string[]) => void + columns: ColumnMeta[]; + columnVisibility: VisibilityState; + onColumnVisibilityChange: (visibility: VisibilityState) => void; + columnOrder: string[]; + onColumnOrderChange: (order: string[]) => void; - filterFields?: FilterField[] - activeFilters?: ActiveFilter[] - onFilterChange?: (fieldId: string, value: string) => void - onFilterReset?: () => void + filterFields?: FilterField[]; + activeFilters?: ActiveFilter[]; + onFilterChange?: (fieldId: string, value: string) => void; + onFilterReset?: () => void; - perPageOptions?: number[] - perPage?: number - onPerPageChange?: (value: number) => void + perPageOptions?: number[]; + perPage?: number; + onPerPageChange?: (value: number) => void; - actionLabel?: string - onAction?: () => void + actionLabel?: string; + onAction?: () => void; - hideSearch?: boolean - hideAction?: boolean + hideSearch?: boolean; + hideAction?: boolean; - extraActions?: React.ReactNode + extraActions?: React.ReactNode; } // ─── Toggle Columns Dropdown ────────────────────────────────────────────────── interface ToggleColumnsDropdownProps { - columns: ColumnMeta[] - columnVisibility: VisibilityState - onColumnVisibilityChange: (visibility: VisibilityState) => void - columnOrder: string[] - onColumnOrderChange: (order: string[]) => void + columns: ColumnMeta[]; + columnVisibility: VisibilityState; + onColumnVisibilityChange: (visibility: VisibilityState) => void; + columnOrder: string[]; + onColumnOrderChange: (order: string[]) => void; } function ToggleColumnsDropdown({ @@ -83,66 +73,67 @@ function ToggleColumnsDropdown({ columnOrder, onColumnOrderChange, }: ToggleColumnsDropdownProps) { - const { t } = useTranslation() - const [open, setOpen] = useState(false) - const ref = useRef(null) - const dragIdRef = useRef(null) - const [dragOverId, setDragOverId] = useState(null) + const { t } = useTranslation(); + const [open, setOpen] = useState(false); + const ref = useRef(null); + const dragIdRef = useRef(null); + const [dragOverId, setDragOverId] = useState(null); - useOutsideClick(ref, () => setOpen(false)) + useOutsideClick(ref, () => setOpen(false)); - const isVisible = (id: string) => - columnVisibility[id] === undefined ? true : columnVisibility[id] + const isVisible = (id: string) => (columnVisibility[id] === undefined ? true : columnVisibility[id]); const toggle = (id: string) => { - onColumnVisibilityChange({ ...columnVisibility, [id]: !isVisible(id) }) - } + onColumnVisibilityChange({ ...columnVisibility, [id]: !isVisible(id) }); + }; const orderedColumns = [...columns].sort((a, b) => { - const ai = columnOrder.indexOf(a.id) - const bi = columnOrder.indexOf(b.id) - if (ai === -1 && bi === -1) return 0 - if (ai === -1) return 1 - if (bi === -1) return -1 - return ai - bi - }) + const ai = columnOrder.indexOf(a.id); + const bi = columnOrder.indexOf(b.id); + if (ai === -1 && bi === -1) return 0; + if (ai === -1) return 1; + if (bi === -1) return -1; + return ai - bi; + }); - const handleDragStart = (id: string) => { dragIdRef.current = id } + const handleDragStart = (id: string) => { + dragIdRef.current = id; + }; const handleDragOver = (e: React.DragEvent, id: string) => { - e.preventDefault() - if (dragIdRef.current !== id) setDragOverId(id) - } + e.preventDefault(); + if (dragIdRef.current !== id) setDragOverId(id); + }; const handleDrop = (targetId: string) => { - const sourceId = dragIdRef.current - if (!sourceId || sourceId === targetId) return - const next = [...columnOrder] - const from = next.indexOf(sourceId) - const to = next.indexOf(targetId) - const safeFrom = from === -1 ? next.length : from - const safeTo = to === -1 ? next.length : to - next.splice(safeFrom, 1) - next.splice(safeTo, 0, sourceId) - onColumnOrderChange(next) - dragIdRef.current = null - setDragOverId(null) - } + const sourceId = dragIdRef.current; + if (!sourceId || sourceId === targetId) return; + const next = [...columnOrder]; + const from = next.indexOf(sourceId); + const to = next.indexOf(targetId); + const safeFrom = from === -1 ? next.length : from; + const safeTo = to === -1 ? next.length : to; + next.splice(safeFrom, 1); + next.splice(safeTo, 0, sourceId); + onColumnOrderChange(next); + dragIdRef.current = null; + setDragOverId(null); + }; const handleDragEnd = () => { - dragIdRef.current = null - setDragOverId(null) - } + dragIdRef.current = null; + setDragOverId(null); + }; return (
- ) -} - -// ─── Date Filter Button ─────────────────────────────────────────────────────── - -function DateFilterButton() { - return ( - - ) + ); } // ─── Filter Dropdown ────────────────────────────────────────────────────────── interface FilterDropdownProps { - filterFields: FilterField[] - activeFilters: ActiveFilter[] - onFilterChange: (fieldId: string, value: string) => void - onFilterReset: () => void - perPageOptions?: number[] - perPage?: number - onPerPageChange?: (value: number) => void + filterFields: FilterField[]; + activeFilters: ActiveFilter[]; + onFilterChange: (fieldId: string, value: string) => void; + onFilterReset: () => void; + perPageOptions?: number[]; + perPage?: number; + onPerPageChange?: (value: number) => void; } function FilterDropdown({ @@ -230,25 +199,24 @@ function FilterDropdown({ perPage = 25, onPerPageChange, }: FilterDropdownProps) { - const { t } = useTranslation() - const [open, setOpen] = useState(false) + const { t } = useTranslation(); + const [open, setOpen] = useState(false); - const activeCount = activeFilters.filter((f) => f.value !== '').length - const hasActive = activeCount > 0 + const activeCount = activeFilters.filter((f) => f.value !== "").length; + const hasActive = activeCount > 0; - const getActiveValue = (fieldId: string) => - activeFilters.find((f) => f.fieldId === fieldId)?.value ?? '' + const getActiveValue = (fieldId: string) => activeFilters.find((f) => f.fieldId === fieldId)?.value ?? ""; return ( )} - ) + ); } // ─── DataTableToolbar ───────────────────────────────────────────────────────── @@ -400,14 +352,8 @@ export function DataTableToolbar({ extraActions, }: DataTableToolbarProps) { return ( -
- {!hideSearch && ( - - )} +
+ {!hideSearch && }
- - {filterFields.length > 0 && onFilterChange && onFilterReset && ( - )} + {!hideAction && actionLabel && onAction && }
- ) -} \ No newline at end of file + ); +} diff --git a/src/components/deleteDialog.tsx b/src/components/deleteDialog.tsx new file mode 100644 index 0000000..cb9e7bb --- /dev/null +++ b/src/components/deleteDialog.tsx @@ -0,0 +1,45 @@ +import { useTranslation } from "react-i18next"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from "@/components/ui/alert-dialog"; + +interface DeleteDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + title: string; + description?: string; + onConfirm: () => void; + isLoading?: boolean; +} + +export function DeleteDialog({ open, onOpenChange, title, description, onConfirm, isLoading }: DeleteDialogProps) { + const { t } = useTranslation(); + + return ( + + + + {title} + {description && {description}} + + + {t("common.cancel", "Cancel")} + + {isLoading ? t("common.deleting", "Deleting...") : t("common.delete", "Delete")} + + + + + ); +} diff --git a/src/components/tableButton.tsx b/src/components/tableButton.tsx deleted file mode 100644 index a650d66..0000000 --- a/src/components/tableButton.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { Plus } from 'lucide-react' -import { Button } from '@/components/ui/button' -import { cn } from '@/lib/utils' - -interface TableActionButtonProps { - label: string - onClick: () => void - icon?: React.ReactNode - disabled?: boolean - className?: string - variant?: 'primary' | 'destructive' | 'secondary' -} - -export function TableActionButton({ - label, - onClick, - icon, - disabled = false, - className, - variant = 'primary', -}: TableActionButtonProps) { - return ( - - ) -} \ No newline at end of file diff --git a/src/components/tableSearch.tsx b/src/components/tableSearch.tsx index 46196a6..94e7609 100644 --- a/src/components/tableSearch.tsx +++ b/src/components/tableSearch.tsx @@ -1,40 +1,32 @@ -import { Search } from 'lucide-react' -import { useTranslation } from 'react-i18next' -import { cn } from '@/lib/utils' +import { Search } from "lucide-react"; +import { useTranslation } from "react-i18next"; +import { cn } from "@/lib/utils"; interface TableSearchInputProps { - value: string - onChange: (value: string) => void - placeholder?: string - className?: string + value: string; + onChange: (value: string) => void; + placeholder?: string; + className?: string; } -export function TableSearchInput({ - value, - onChange, - placeholder, - className, -}: TableSearchInputProps) { - const { t } = useTranslation() +export function TableSearchInput({ value, onChange, placeholder, className }: TableSearchInputProps) { + const { t } = useTranslation(); return ( -
- +
+ onChange(e.target.value)} - placeholder={placeholder ?? t('table.search', 'Search...')} + placeholder={placeholder ?? t("table.search", "Search...")} className={cn( - 'h-9 w-64 rounded-md border border-border bg-background pl-9 pr-3', - 'text-sm text-foreground placeholder:text-muted-foreground', - 'focus:outline-none focus:ring-1 focus:ring-ring focus:border-transparent', - 'transition-colors' + "h-9 w-64 max-w-full rounded-md border border-border bg-background pl-9 pr-3", + "text-sm text-foreground placeholder:text-muted-foreground", + "focus:outline-none focus:ring-1 focus:ring-ring focus:border-transparent", + "transition-colors", )} />
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/backups/index.tsx b/src/pages/backups/index.tsx index f471cbf..3f0b854 100644 --- a/src/pages/backups/index.tsx +++ b/src/pages/backups/index.tsx @@ -1,145 +1,156 @@ -import { useState } from 'react' -import { useTranslation } from 'react-i18next' -import { Download, Trash2, Database, CheckCircle2, XCircle, Clock } from 'lucide-react' -import { Button } from '@/components/ui/button' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { DataTable, type ColumnDef } from '@/components/dataTable' -import { DataTableToolbar, type ColumnMeta } from '@/components/dataTableToolbar' -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -import type { VisibilityState } from '@tanstack/react-table' -import { useBackups, useCreateBackup, useDeleteBackup, useDownloadBackup } from '@/features/backups/hooks/useBackups' -import type { Backup, BackupStatus } from '@/features/backups/api/backupsApi' +import { useState } from "react"; +import { useTranslation } from "react-i18next"; +import { Download, Trash2, Database, CheckCircle2, XCircle, Clock } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { DataTable, type ColumnDef } from "@/components/dataTable"; +import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge"; +import type { VisibilityState } from "@tanstack/react-table"; +import { useBackups, useCreateBackup, useDeleteBackup, useDownloadBackup } from "@/features/backups/hooks/useBackups"; +import type { Backup, BackupStatus } from "@/features/backups/api/backupsApi"; -const PER_PAGE = 25 +const PER_PAGE = 25; function BackupStatusBadge({ status }: { status: BackupStatus }) { - const { t } = useTranslation() + const { t } = useTranslation(); const cfg: Record = { - completed: { label: t('backups.status.completed', 'Tamamlandy'), variant: 'success', icon: CheckCircle2 }, - failed: { label: t('backups.status.failed', 'Şowsuz'), variant: 'error', icon: XCircle }, - in_progress: { label: t('backups.status.inProgress', 'Dowam edýär'), variant: 'warning', icon: Clock }, - } - const currentCfg = cfg[status] - return + completed: { label: t("backups.status.completed", "Tamamlandy"), variant: "success", icon: CheckCircle2 }, + failed: { label: t("backups.status.failed", "Şowsuz"), variant: "error", icon: XCircle }, + in_progress: { label: t("backups.status.inProgress", "Dowam edýär"), variant: "warning", icon: Clock }, + }; + const currentCfg = cfg[status]; + return ; } export default function BackupsPage() { - const { t } = useTranslation() + const { t } = useTranslation(); - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(PER_PAGE) - const [search, setSearch] = useState('') - const [deleteId, setDeleteId] = useState(null) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([]) + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(PER_PAGE); + const [search, setSearch] = useState(""); + const [deleteId, setDeleteId] = useState(null); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([]); - const { data, isLoading } = useBackups({ page, per_page: perPage, search }) - const createBackup = useCreateBackup() - const downloadBackup = useDownloadBackup() - const deleteBackup = useDeleteBackup() + const { data, isLoading } = useBackups({ page, per_page: perPage, search }); + const createBackup = useCreateBackup(); + const downloadBackup = useDownloadBackup(); + const deleteBackup = useDeleteBackup(); const columns: ColumnDef[] = [ { - id: 'fileName', - accessorKey: 'fileName', - header: t('backups.col.fileName', 'Faýl ady'), - cell: ({ row }) => ( - {row.original.fileName} - ), + id: "fileName", + accessorKey: "fileName", + header: t("backups.col.fileName", "Faýl ady"), + cell: ({ row }) => {row.original.fileName}, }, { - id: 'fileSize', - accessorKey: 'fileSize', - header: t('backups.col.fileSize', 'Ölçegi'), + id: "fileSize", + accessorKey: "fileSize", + header: t("backups.col.fileSize", "Ölçegi"), cell: ({ row }) => {row.original.fileSize}, size: 100, }, { - id: 'status', - accessorKey: 'status', - header: t('backups.col.status', 'Status'), + id: "status", + accessorKey: "status", + header: t("backups.col.status", "Status"), cell: ({ row }) => , size: 140, }, { - id: 'createdAt', - accessorKey: 'createdAt', - header: t('backups.col.createdAt', 'Döredilen wagty'), + id: "createdAt", + accessorKey: "createdAt", + header: t("backups.col.createdAt", "Döredilen wagty"), cell: ({ row }) => {row.original.createdAt}, size: 160, }, { - id: 'createdBy', - accessorKey: 'createdBy', - header: t('backups.col.createdBy', 'Döreden'), + id: "createdBy", + accessorKey: "createdBy", + header: t("backups.col.createdBy", "Döreden"), size: 100, }, { - id: 'actions', - header: '', + id: "actions", + header: "", enableHiding: false, cell: ({ row }) => (
), }, - ] + ]; const columnMeta: ColumnMeta[] = columns - .filter((c) => c.id !== 'actions') + .filter((c) => c.id !== "actions") .map((c) => ({ id: c.id!, - label: typeof c.header === 'string' ? c.header : c.id!, - })) + label: typeof c.header === "string" ? c.header : c.id!, + })); - const total = data?.total ?? 0 - const totalPages = Math.ceil(total / perPage) + const total = data?.total ?? 0; + const totalPages = Math.ceil(total / perPage); const handleDelete = async () => { - if (deleteId === null) return - await deleteBackup.mutateAsync(deleteId) - setDeleteId(null) - } + if (deleteId === null) return; + await deleteBackup.mutateAsync(deleteId); + setDeleteId(null); + }; return (

- {t('backups.title', 'Bekaplar')} + {t("backups.title", "Bekaplar")}

+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + createBackup.mutate()} + /> +
{ setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} + onSearchChange={(v) => { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} columns={columnMeta} columnVisibility={columnVisibility} onColumnVisibilityChange={setColumnVisibility} @@ -147,9 +158,12 @@ export default function BackupsPage() { onColumnOrderChange={setColumnOrder} perPageOptions={[10, 25, 50, 100]} perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={createBackup.isPending ? t('common.loading', 'Döredilýär...') : t('backups.create', 'Backup dörediň')} - onAction={() => createBackup.mutate()} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + hideSearch + hideAction />
- !open && setDeleteId(null)}> - - - {t('backups.deleteConfirm.title', 'Eminsiňizmi?')} - - {t('backups.deleteConfirm.description', 'Bu backup pozulsynmy? Bu amal yzyna gaýtarylmaz.')} - - - - {t('common.cancel', 'Ýatyr')} - - {deleteBackup.isPending ? t('common.deleting', 'Pozulýar...') : t('common.delete', 'Poz')} - - - - + { + if (!o) setDeleteId(null); + }} + title={t("backups.deleteConfirm.title", "Eminsiňizmi?")} + description={t("backups.deleteConfirm.description", "Bu backup pozulsynmy? Bu amal yzyna gaýtarylmaz.")} + onConfirm={handleDelete} + isLoading={deleteBackup.isPending} + />
- ) + ); } diff --git a/src/pages/cardDepartment/cardBalance/index.tsx b/src/pages/cardDepartment/cardBalance/index.tsx index 6ad9597..3e01030 100644 --- a/src/pages/cardDepartment/cardBalance/index.tsx +++ b/src/pages/cardDepartment/cardBalance/index.tsx @@ -3,18 +3,11 @@ import { useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Download, Eye, Pencil, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from "@/components/ui/alert-dialog"; +import { DeleteDialog } from "@/components/deleteDialog"; import { DataTable, type ColumnDef } from "@/components/dataTable"; import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; import type { VisibilityState } from "@tanstack/react-table"; import { useCardBalances, useDeleteCardBalance, useDownloadCardBalance } from "@/features/cardBalance/hooks/useCardBalance"; import { type CardBalance } from "@/features/cardBalance/api/cardBalanceApi"; @@ -147,6 +140,17 @@ export default function CardBalancesPage() {

{t("Card balances", "Kart galyndylary")}

+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/card-balances/create")} /> +
navigate("/card-balances/create")} + hideSearch + hideAction perPageOptions={[10, 25, 50, 100]} perPage={perPage} onPerPageChange={(v) => { @@ -187,22 +191,16 @@ export default function CardBalancesPage() { />
- !open && setDeleteId(null)}> - - - {t("Are you sure?", "Eminsiňizmi?")} - - {t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz. Kart galyndysy hemişelik öçüriler.")} - - - - {t("Cancel", "Ýatyr")} - - {deleteMutation.isPending ? t("Deleting...", "Öçürilýär...") : t("Delete", "Öçür")} - - - - + { + if (!o) setDeleteId(null); + }} + title={t("Are you sure?", "Eminsiňizmi?")} + description={t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz. Kart galyndysy hemişelik öçüriler.")} + onConfirm={handleDelete} + isLoading={deleteMutation.isPending} + />
); } diff --git a/src/pages/cardDepartment/cardPins/index.tsx b/src/pages/cardDepartment/cardPins/index.tsx index 541b781..2fc4191 100644 --- a/src/pages/cardDepartment/cardPins/index.tsx +++ b/src/pages/cardDepartment/cardPins/index.tsx @@ -4,38 +4,18 @@ import { useTranslation } from "react-i18next"; import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; import { DataTable } from "@/components/dataTable"; import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; import { useCardPins } from "@/features/cardPins/hooks/useCardPins"; import { useDeleteCardPin } from "@/features/cardPins/hooks/useCardPins"; -import type { - CardPinItem, - CardPinStatus, -} from "@/features/cardPins/api/cardPinApi"; +import type { CardPinItem, CardPinStatus } from "@/features/cardPins/api/cardPinApi"; import { Button } from "@/components/ui/button"; -import { - Eye, - Pencil, - Trash2, - AlertCircle, - CheckCircle2, - XCircle, -} from "lucide-react"; -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from "@/components/ui/alert-dialog"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { Eye, Pencil, Trash2, AlertCircle, CheckCircle2, XCircle } from "lucide-react"; // ─── Status Badge ───────────────────────────────────────────────────────────── -import { - StatusBadge, - type StatusBadgeVariant, -} from "@/components/ui/statusBadge"; +import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge"; // ─── Status badge ───────────────────────────────────────────────────────────── @@ -55,20 +35,12 @@ const STATUS_CONFIG = { variant: "error" as StatusBadgeVariant, icon: XCircle, }, -} satisfies Record< - CardPinStatus, - { label: string; variant: StatusBadgeVariant; icon: React.ElementType } ->; +} satisfies Record; function CardPinStatusStatusBadge({ status }: { status: CardPinStatus }) { const cfg = STATUS_CONFIG[status]; - if (!cfg) - return ( - {String(status)} - ); - return ( - - ); + if (!cfg) return {String(status)}; + return ; } // ─── Page ───────────────────────────────────────────────────────────────────── @@ -99,29 +71,17 @@ export default function CardPinsPage() { { accessorKey: "id", header: "ID", - cell: ({ row }) => ( - - {row.original.id} - - ), + cell: ({ row }) => {row.original.id}, }, { accessorKey: "card_type_label", header: t("cardPin.cardType", "Görnüşi"), - cell: ({ row }) => ( - - {row.original.card_type_label} - - ), + cell: ({ row }) => {row.original.card_type_label}, }, { accessorKey: "created_at", header: t("cardPin.createdAt", "Döredilen wagty"), - cell: ({ row }) => ( - - {row.original.created_at} - - ), + cell: ({ row }) => {row.original.created_at}, }, { accessorKey: "province_label", @@ -130,11 +90,7 @@ export default function CardPinsPage() { { accessorKey: "branch_label", header: t("cardPin.branch", "Şahamça"), - cell: ({ row }) => ( - - {row.original.branch_label} - - ), + cell: ({ row }) => {row.original.branch_label}, }, { accessorKey: "first_name", @@ -147,36 +103,22 @@ export default function CardPinsPage() { { accessorKey: "phone", header: t("cardPin.phone", "Telefon"), - cell: ({ row }) => ( - {row.original.phone} - ), + cell: ({ row }) => {row.original.phone}, }, { accessorKey: "status", header: t("cardPin.status", "Status"), - cell: ({ row }) => ( - - ), + cell: ({ row }) => , }, { id: "actions", enableHiding: false, cell: ({ row }) => (
- - - -
); } diff --git a/src/pages/cardDepartment/cardTransactions/index.tsx b/src/pages/cardDepartment/cardTransactions/index.tsx index 8e26383..2e07606 100644 --- a/src/pages/cardDepartment/cardTransactions/index.tsx +++ b/src/pages/cardDepartment/cardTransactions/index.tsx @@ -1,54 +1,47 @@ -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Download, Eye, Pencil, Trash2 } from 'lucide-react' -import { Button } from '@/components/ui/button' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { DataTable, type ColumnDef } from '@/components/dataTable' -import { DataTableToolbar, type ColumnMeta } from '@/components/dataTableToolbar' -import type { VisibilityState } from '@tanstack/react-table' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Download, Eye, Pencil, Trash2 } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { DataTable, type ColumnDef } from "@/components/dataTable"; +import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import type { VisibilityState } from "@tanstack/react-table"; import { useCardTransactions, useDeleteCardTransaction, useDownloadCardTransaction, -} from '@/features/cardTransactions/hooks/useCardTransactions' -import type { CardTransaction } from '@/features/cardTransactions/api/cardTransactionsApi' +} from "@/features/cardTransactions/hooks/useCardTransactions"; +import type { CardTransaction } from "@/features/cardTransactions/api/cardTransactionsApi"; // ─── Page ───────────────────────────────────────────────────────────────────── -const PER_PAGE = 25 +const PER_PAGE = 25; export default function CardTransactionsPage() { - const { t } = useTranslation() - const navigate = useNavigate() + const { t } = useTranslation(); + const navigate = useNavigate(); - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(PER_PAGE) - const [search, setSearch] = useState('') - const [deleteId, setDeleteId] = useState(null) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([]) + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(PER_PAGE); + const [search, setSearch] = useState(""); + const [deleteId, setDeleteId] = useState(null); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([]); - const { data, isLoading } = useCardTransactions({ page, per_page: perPage, search }) - const deleteMutation = useDeleteCardTransaction() - const downloadMutation = useDownloadCardTransaction() + const { data, isLoading } = useCardTransactions({ page, per_page: perPage, search }); + const deleteMutation = useDeleteCardTransaction(); + const downloadMutation = useDownloadCardTransaction(); // ── Columns ────────────────────────────────────────────────────────────────── const columns: ColumnDef[] = [ { - id: 'id', - accessorKey: 'id', - header: t('ID', 'ID'), + id: "id", + accessorKey: "id", + header: t("ID", "ID"), cell: ({ row }) => (
), }, - ] + ]; // ── Column meta for toolbar ─────────────────────────────────────────────────── const columnMeta: ColumnMeta[] = columns - .filter((c) => c.id !== 'actions') + .filter((c) => c.id !== "actions") .map((c) => ({ id: c.id!, - label: typeof c.header === 'string' ? c.header : c.id!, - })) + label: typeof c.header === "string" ? c.header : c.id!, + })); // ── Pagination ──────────────────────────────────────────────────────────────── - const total = data?.total ?? 0 - const totalPages = Math.ceil(total / perPage) + const total = data?.total ?? 0; + const totalPages = Math.ceil(total / perPage); const handleDelete = async () => { - if (deleteId === null) return - await deleteMutation.mutateAsync(deleteId) - setDeleteId(null) - } + if (deleteId === null) return; + await deleteMutation.mutateAsync(deleteId); + setDeleteId(null); + }; return (
{/* Header */}
-

- {t('Card transactions', 'Kart hereketleri')} -

+

{t("Card transactions", "Kart hereketleri")}

-
+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/card-transactions/create")} /> +
+
+ {/* Toolbar */} + { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + hideSearch + hideAction + perPageOptions={[10, 25, 50, 100]} + perPage={perPage} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + /> - {/* Toolbar */} - { setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - actionLabel={t('Create card transaction', 'Kart herekedi dörediň')} - onAction={() => navigate('/card-transactions/create')} - perPageOptions={[10, 25, 50, 100]} - perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - /> - - {/* Table */} - row.id.toString()} - currentPage={page} - totalPages={totalPages} - totalCount={total} - onPageChange={setPage} - /> -
+ {/* Table */} + row.id.toString()} + currentPage={page} + totalPages={totalPages} + totalCount={total} + onPageChange={setPage} + /> +
{/* Delete dialog */} - !open && setDeleteId(null)}> - - - {t('Are you sure?', 'Eminsiňizmi?')} - - {t( - 'This action cannot be undone. This will permanently delete the card transaction.', - 'Bu amal yzyna gaýtarylmaz. Kart herekedi hemişelik öçüriler.', - )} - - - - {t('Cancel', 'Ýatyr')} - - {deleteMutation.isPending ? t('Deleting...', 'Öçürilýär...') : t('Delete', 'Öçür')} - - - - + { + if (!o) setDeleteId(null); + }} + title={t("Are you sure?", "Eminsiňizmi?")} + description={t( + "This action cannot be undone. This will permanently delete the card transaction.", + "Bu amal yzyna gaýtarylmaz. Kart herekedi hemişelik öçüriler.", + )} + onConfirm={handleDelete} + isLoading={deleteMutation.isPending} + />
- ) + ); } diff --git a/src/pages/cardDepartment/orderNewCard/index.tsx b/src/pages/cardDepartment/orderNewCard/index.tsx index 7c01bb1..a455328 100644 --- a/src/pages/cardDepartment/orderNewCard/index.tsx +++ b/src/pages/cardDepartment/orderNewCard/index.tsx @@ -1,197 +1,171 @@ -import { useState, useMemo, useCallback } from 'react' -import { useNavigate, Link } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2, CheckCircle2, XCircle, AlertCircle } from 'lucide-react' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' - -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar' -import { - useCardOrders, - useDeleteCardOrder, - useProvinces, - useBranches, -} from '@/features/orderNewCard/hooks/useOrderNewCard' -import type { CardOrderListItem, CardOrderStatus } from '@/features/orderNewCard/api/orderNewCardApi' -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -import { ConfirmDialog } from '@/components/confirmDialog' +import { useState, useMemo, useCallback } from "react"; +import { useNavigate, Link } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Eye, Pencil, Trash2, CheckCircle2, XCircle, AlertCircle } from "lucide-react"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { useCardOrders, useDeleteCardOrder, useProvinces, useBranches } from "@/features/orderNewCard/hooks/useOrderNewCard"; +import type { CardOrderListItem, CardOrderStatus } from "@/features/orderNewCard/api/orderNewCardApi"; +import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge"; +import { DeleteDialog } from "@/components/deleteDialog"; // ─── Status badge ───────────────────────────────────────────────────────────── function OrderNewCardStatusBadge({ status }: { status: CardOrderStatus }) { - const { t } = useTranslation() + const { t } = useTranslation(); const STATUS_CONFIG = { - PENDING: { label: t('cardOrder.status.pending', 'Garaşylýar'), variant: 'warning' as StatusBadgeVariant, icon: AlertCircle }, - APPROVED: { label: t('cardOrder.status.approved', 'Tassyklandy'), variant: 'success' as StatusBadgeVariant, icon: CheckCircle2 }, - REJECTED: { label: t('cardOrder.status.rejected', 'Ýatyryldy'), variant: 'error' as StatusBadgeVariant, icon: XCircle }, - } - const cfg = STATUS_CONFIG[status] - if (!cfg) return {status} - return + PENDING: { label: t("cardOrder.status.pending", "Garaşylýar"), variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, + APPROVED: { label: t("cardOrder.status.approved", "Tassyklandy"), variant: "success" as StatusBadgeVariant, icon: CheckCircle2 }, + REJECTED: { label: t("cardOrder.status.rejected", "Ýatyryldy"), variant: "error" as StatusBadgeVariant, icon: XCircle }, + }; + const cfg = STATUS_CONFIG[status]; + if (!cfg) return {status}; + return ; } - - // ─── Coloured text helper ───────────────────────────────────────────────────── -function HighlightText({ value, variant }: { value: string; variant: 'teal' | 'cyan' | 'muted' }) { +function HighlightText({ value, variant }: { value: string; variant: "teal" | "cyan" | "muted" }) { const cls = - variant === 'teal' ? 'text-teal-400 font-semibold' : - variant === 'cyan' ? 'text-cyan-400 font-semibold' : - 'text-muted-foreground' - return {value} + variant === "teal" ? "text-teal-400 font-semibold" : variant === "cyan" ? "text-cyan-400 font-semibold" : "text-muted-foreground"; + return {value}; } -const SPECIAL_BRANCHES = [ - 'Köpetdag', 'Türkmenabat', 'Türkmenbaşy', - 'Seýdi', 'Çandybil', 'Balkan', 'Baş bank', -] +const SPECIAL_BRANCHES = ["Köpetdag", "Türkmenabat", "Türkmenbaşy", "Seýdi", "Çandybil", "Balkan", "Baş bank"]; // ─── CardOrdersPage ─────────────────────────────────────────────────────────── export default function CardOrdersPage() { - const { t } = useTranslation() - const navigate = useNavigate() - const deleteMutation = useDeleteCardOrder() - const [deleteId, setDeleteId] = useState(null) + const { t } = useTranslation(); + const navigate = useNavigate(); + const deleteMutation = useDeleteCardOrder(); + const [deleteId, setDeleteId] = useState(null); // ── Column meta (toolbar toggle) ────────────────────────────────────────── const COLUMN_META = useMemo( () => [ - { id: 'id', label: t('cardOrder.col.id', 'ID') }, - { id: 'issuanceReasonName', label: t('cardOrder.col.reason', 'Sebäp') }, - { id: 'createdAt', label: t('cardOrder.col.createdAt', 'Döredilen wagty') }, - { id: 'cardTypeName', label: t('cardOrder.col.cardType', 'Görnüşi') }, - { id: 'provinceName', label: t('cardOrder.col.province', 'Welaýat') }, - { id: 'branchName', label: t('cardOrder.col.branch', 'Şahamça') }, - { id: 'fullName', label: t('cardOrder.col.name', 'Ady') }, - { id: 'status', label: t('cardOrder.col.status', 'Status') }, + { id: "id", label: t("cardOrder.col.id", "ID") }, + { id: "issuanceReasonName", label: t("cardOrder.col.reason", "Sebäp") }, + { id: "createdAt", label: t("cardOrder.col.createdAt", "Döredilen wagty") }, + { id: "cardTypeName", label: t("cardOrder.col.cardType", "Görnüşi") }, + { id: "provinceName", label: t("cardOrder.col.province", "Welaýat") }, + { id: "branchName", label: t("cardOrder.col.branch", "Şahamça") }, + { id: "fullName", label: t("cardOrder.col.name", "Ady") }, + { id: "status", label: t("cardOrder.col.status", "Status") }, ], - [t] - ) - const DEFAULT_ORDER = useMemo(() => COLUMN_META.map((c) => c.id), [COLUMN_META]) + [t], + ); + const DEFAULT_ORDER = useMemo(() => COLUMN_META.map((c) => c.id), [COLUMN_META]); // ── State ────────────────────────────────────────────────────────────────── - const [search, setSearch] = useState('') - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(10) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER) - const [activeFilters, setActiveFilters] = useState([ - { fieldId: 'status', value: '' }, - { fieldId: 'provinceId', value: '' }, - { fieldId: 'branchId', value: '' }, - ]) + const [search, setSearch] = useState(""); + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(10); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER); + const [activeFilters, setActiveFilters] = useState([ + { fieldId: "status", value: "" }, + { fieldId: "provinceId", value: "" }, + { fieldId: "branchId", value: "" }, + ]); // ── Lookup data ──────────────────────────────────────────────────────────── - const provinceId = activeFilters.find((f) => f.fieldId === 'provinceId')?.value - const { data: provincesData } = useProvinces() - const { data: branchesData } = useBranches(provinceId ? Number(provinceId) : undefined) + const provinceId = activeFilters.find((f) => f.fieldId === "provinceId")?.value; + const { data: provincesData } = useProvinces(); + const { data: branchesData } = useBranches(provinceId ? Number(provinceId) : undefined); // ── Query params ─────────────────────────────────────────────────────────── const queryParams = useMemo(() => { - const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])) + const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])); return { - search: search || undefined, - status: (filterMap.status as CardOrderStatus) || undefined, + search: search || undefined, + status: (filterMap.status as CardOrderStatus) || undefined, provinceId: filterMap.provinceId ? Number(filterMap.provinceId) : undefined, - branchId: filterMap.branchId ? Number(filterMap.branchId) : undefined, + branchId: filterMap.branchId ? Number(filterMap.branchId) : undefined, page, perPage, - } - }, [search, activeFilters, page, perPage]) + }; + }, [search, activeFilters, page, perPage]); - const { data, isLoading } = useCardOrders(queryParams) + const { data, isLoading } = useCardOrders(queryParams); // ── Handlers ─────────────────────────────────────────────────────────────── const handleFilterChange = useCallback((fieldId: string, value: string) => { setActiveFilters((prev) => { - const updated = prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)) - if (fieldId === 'provinceId') { - return updated.map((f) => (f.fieldId === 'branchId' ? { ...f, value: '' } : f)) + const updated = prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)); + if (fieldId === "provinceId") { + return updated.map((f) => (f.fieldId === "branchId" ? { ...f, value: "" } : f)); } - return updated - }) - setPage(1) - }, []) + return updated; + }); + setPage(1); + }, []); const handleFilterReset = useCallback(() => { - setActiveFilters((prev) => prev.map((f) => ({ ...f, value: '' }))) - setPage(1) - }, []) + setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" }))); + setPage(1); + }, []); const handleDelete = useCallback((id: string) => { - setDeleteId(id) - }, []) + setDeleteId(id); + }, []); const confirmDelete = useCallback(() => { - if (!deleteId) return - deleteMutation.mutate(deleteId) - setDeleteId(null) - }, [deleteId, deleteMutation]) + if (!deleteId) return; + deleteMutation.mutate(deleteId); + setDeleteId(null); + }, [deleteId, deleteMutation]); // ── Columns ──────────────────────────────────────────────────────────────── const columns = useMemo[]>( () => [ { - accessorKey: 'id', - header: t('cardOrder.col.id', 'ID'), + accessorKey: "id", + header: t("cardOrder.col.id", "ID"), cell: ({ row }) => ( - + {row.original.id} ), size: 130, }, { - accessorKey: 'issuanceReasonName', - header: t('cardOrder.col.reason', 'Sebäp'), - cell: ({ row }) => ( - {row.original.issuanceReasonName} - ), + accessorKey: "issuanceReasonName", + header: t("cardOrder.col.reason", "Sebäp"), + cell: ({ row }) => {row.original.issuanceReasonName}, }, { - accessorKey: 'createdAt', - header: t('cardOrder.col.createdAt', 'Döredilen wagty'), - cell: ({ row }) => ( - {row.original.createdAt} - ), + accessorKey: "createdAt", + header: t("cardOrder.col.createdAt", "Döredilen wagty"), + cell: ({ row }) => {row.original.createdAt}, size: 160, }, { - accessorKey: 'cardTypeName', - header: t('cardOrder.col.cardType', 'Görnüşi'), + accessorKey: "cardTypeName", + header: t("cardOrder.col.cardType", "Görnüşi"), cell: ({ row }) => ( - + ), }, { - accessorKey: 'provinceName', - header: t('cardOrder.col.province', 'Welaýat'), + accessorKey: "provinceName", + header: t("cardOrder.col.province", "Welaýat"), + cell: ({ row }) => {row.original.provinceName}, + }, + { + accessorKey: "branchName", + header: t("cardOrder.col.branch", "Şahamça"), cell: ({ row }) => ( - {row.original.provinceName} + ), }, { - accessorKey: 'branchName', - header: t('cardOrder.col.branch', 'Şahamça'), - cell: ({ row }) => ( - - ), - }, - { - id: 'fullName', - header: t('cardOrder.col.name', 'Ady'), + id: "fullName", + header: t("cardOrder.col.name", "Ady"), cell: ({ row }) => ( {row.original.lastName} {row.original.firstName} @@ -199,27 +173,27 @@ export default function CardOrdersPage() { ), }, { - accessorKey: 'status', - header: t('cardOrder.col.status', 'Status'), + accessorKey: "status", + header: t("cardOrder.col.status", "Status"), cell: ({ row }) => , size: 130, }, { - id: 'actions', - header: '', + id: "actions", + header: "", enableHiding: false, cell: ({ row }) => (
@@ -237,49 +211,62 @@ export default function CardOrdersPage() { size: 100, }, ], - [t, navigate, handleDelete, deleteMutation.isPending] - ) + [t, navigate, handleDelete, deleteMutation.isPending], + ); // ── Filter fields ────────────────────────────────────────────────────────── const filterFields = useMemo( () => [ { - id: 'status', - label: t('cardOrder.col.status', 'Status'), + id: "status", + label: t("cardOrder.col.status", "Status"), options: [ - { value: 'PENDING', label: t('cardOrder.status.pending', 'Garaşylýar') }, - { value: 'APPROVED', label: t('cardOrder.status.approved', 'Tassyklandy') }, - { value: 'REJECTED', label: t('cardOrder.status.rejected', 'Ýatyryldy') }, + { value: "PENDING", label: t("cardOrder.status.pending", "Garaşylýar") }, + { value: "APPROVED", label: t("cardOrder.status.approved", "Tassyklandy") }, + { value: "REJECTED", label: t("cardOrder.status.rejected", "Ýatyryldy") }, ], }, { - id: 'provinceId', - label: t('cardOrder.col.province', 'Welaýat'), + id: "provinceId", + label: t("cardOrder.col.province", "Welaýat"), options: provincesData?.map((p) => ({ value: String(p.id), label: p.name })) ?? [], }, { - id: 'branchId', - label: t('cardOrder.col.branch', 'Şahamça'), + id: "branchId", + label: t("cardOrder.col.branch", "Şahamça"), options: branchesData?.map((b) => ({ value: String(b.id), label: b.name })) ?? [], }, ], - [t, provincesData, branchesData] - ) + [t, provincesData, branchesData], + ); // ── Render ───────────────────────────────────────────────────────────────── return ( -
+
-

- {t('cardOrder.title', 'Kart sargytlary')} -

+

{t("cardOrder.title", "Kart sargytlary")}

+
+ +
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/order-new-card/create")} />
{ setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} + onSearchChange={(v) => { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} columns={COLUMN_META} columnVisibility={columnVisibility} onColumnVisibilityChange={setColumnVisibility} @@ -291,9 +278,12 @@ export default function CardOrdersPage() { onFilterReset={handleFilterReset} perPageOptions={[10, 25, 50, 100]} perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('cardOrder.create', 'Kart sargyt dörediň')} - onAction={() => navigate('/order-new-card/create')} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + hideSearch + hideAction />
- { if (!o) setDeleteId(null) }} - title={t('cardOrder.deleteConfirm', 'Bu sargyt pozulsynmy?')} - confirmLabel={t('common.delete', 'Poz')} + onOpenChange={(o) => { + if (!o) setDeleteId(null); + }} + title={t("cardOrder.deleteConfirm", "Bu sargyt pozulsynmy?")} onConfirm={confirmDelete} isLoading={deleteMutation.isPending} />
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/currencies/currencyRates/index.tsx b/src/pages/currencies/currencyRates/index.tsx index c6b9bed..12ec596 100644 --- a/src/pages/currencies/currencyRates/index.tsx +++ b/src/pages/currencies/currencyRates/index.tsx @@ -6,13 +6,12 @@ import { useTranslation } from "react-i18next"; import { Eye, Pencil, Trash2 } from "lucide-react"; import { DataTable, type ColumnDef } from "@/components/dataTable"; import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; import { Button } from "@/components/ui/button"; -import { - useGetCurrencyRates, - useDeleteCurrencyRate, -} from "@/features/currencyRates/hooks/useCurrencyRates"; +import { useGetCurrencyRates, useDeleteCurrencyRate } from "@/features/currencyRates/hooks/useCurrencyRates"; import type { CurrencyRate } from "@/features/currencyRates/api/currencyRatesApi"; -import { ConfirmDialog } from "@/components/confirmDialog"; +import { DeleteDialog } from "@/components/deleteDialog"; // ─── Column visibility defaults ─────────────────────────────────────────────── @@ -33,8 +32,7 @@ export default function CurrencyRatesPage() { const [page, setPage] = useState(1); const [perPage] = useState(25); const [search, setSearch] = useState(""); - const [columnVisibility, setColumnVisibility] = - useState>(DEFAULT_VISIBILITY); + const [columnVisibility, setColumnVisibility] = useState>(DEFAULT_VISIBILITY); const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER); const [deleteId, setDeleteId] = useState(null); @@ -61,9 +59,7 @@ export default function CurrencyRatesPage() { cell: ({ row }) => ( @@ -73,29 +69,17 @@ export default function CurrencyRatesPage() { { accessorKey: "currencyFrom", header: t("currencyRates.columns.currencyFrom", "CURRENCY FROM"), - cell: ({ row }) => ( - - {row.original.currencyFrom} - - ), + cell: ({ row }) => {row.original.currencyFrom}, }, { accessorKey: "currencyTo", header: t("currencyRates.columns.currencyTo", "CURRENCY TO"), - cell: ({ row }) => ( - - {row.original.currencyTo} - - ), + cell: ({ row }) => {row.original.currencyTo}, }, { accessorKey: "value", header: t("currencyRates.columns.value", "VALUE"), - cell: ({ row }) => ( - - {row.original.value} - - ), + cell: ({ row }) => {row.original.value}, }, { id: "actions", @@ -141,19 +125,21 @@ export default function CurrencyRatesPage() { .filter((c) => "accessorKey" in c && c.accessorKey) .map((c) => ({ id: String(("accessorKey" in c ? c.accessorKey : c.id) ?? ""), - label: - typeof c.header === "string" - ? c.header - : String(("accessorKey" in c ? c.accessorKey : "") ?? ""), + label: typeof c.header === "string" ? c.header : String(("accessorKey" in c ? c.accessorKey : "") ?? ""), })); // ─── Render ─────────────────────────────────────────────────────────────── return ( -
-

- {t("currencyRates.title", "Walýuta kursy")} -

+
+

{t("currencyRates.title", "Walýuta kursy")}

+
+ + navigate("/currency-rates/create")} + /> +
navigate("/currency-rates/create")} + hideSearch + hideAction />
- { if (!o) setDeleteId(null) }} + onOpenChange={(o) => { + if (!o) setDeleteId(null); + }} title={t("currencyRates.deleteDialog.title", "Pozmak isleýärsiňizmi?")} description={t("currencyRates.deleteDialog.description", "Bu amal yzyna gaýtarylyp bilinmez. Walýuta kursy hemişelik pozular.")} - confirmLabel={deleteMutation.isPending ? t("common.deleting", "Pozulýar...") : t("common.delete", "Pozmak")} onConfirm={handleDeleteConfirm} isLoading={deleteMutation.isPending} /> diff --git a/src/pages/currencies/visaMasterSberSettings/index.tsx b/src/pages/currencies/visaMasterSberSettings/index.tsx index af9be7c..dbad87a 100644 --- a/src/pages/currencies/visaMasterSberSettings/index.tsx +++ b/src/pages/currencies/visaMasterSberSettings/index.tsx @@ -4,19 +4,12 @@ import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Pencil, Trash2 } from "lucide-react"; -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from "@/components/ui/alert-dialog"; +import { DeleteDialog } from "@/components/deleteDialog"; import { Button } from "@/components/ui/button"; import { DataTable, type ColumnDef } from "@/components/dataTable"; import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; import { useGetVisaMasterSettings, useDeleteVisaMasterSetting } from "@/features/visaMasterSberSettings/hooks/useVisaMasterSettings"; import type { VisaMasterSetting } from "@/features/visaMasterSberSettings/api/visaMasterSberSettingsApi"; @@ -117,9 +110,15 @@ export default function VisaMasterSettingsPage() { // ─── Render ─────────────────────────────────────────────────────────────── return ( -
+

{t("visaMasterSettings.title", "Visa/Master, Sber sazlamalar")}

- +
+ + navigate("/visa-master-sber-settings/create")} + /> +
navigate("/visa-master-sber-settings/create")} + hideSearch + hideAction /> {/* Delete Confirmation */} - { - if (!open) setDeleteId(null); + onOpenChange={(o) => { + if (!o) setDeleteId(null); }} - > - - - {t("visaMasterSettings.deleteDialog.title", "Pozmak isleýärsiňizmi?")} - - {t("visaMasterSettings.deleteDialog.description", "Bu amal yzyna gaýtarylyp bilinmez. Sazlama hemişelik pozular.")} - - - - {t("common.cancel", "Ýatyr")} - - {deleteMutation.isPending ? t("common.deleting", "Pozulýar...") : t("common.delete", "Pozmak")} - - - - + title={t("visaMasterSettings.deleteDialog.title", "Pozmak isleýärsiňizmi?")} + description={t("visaMasterSettings.deleteDialog.description", "Bu amal yzyna gaýtarylyp bilinmez. Sazlama hemişelik pozular.")} + onConfirm={handleDeleteConfirm} + isLoading={deleteMutation.isPending} + />
); } diff --git a/src/pages/internationalPayments/sberPayments/index.tsx b/src/pages/internationalPayments/sberPayments/index.tsx index da15f0a..979a786 100644 --- a/src/pages/internationalPayments/sberPayments/index.tsx +++ b/src/pages/internationalPayments/sberPayments/index.tsx @@ -1,85 +1,91 @@ - -import { useState, useMemo, useCallback } from 'react' -import { format } from 'date-fns' -import { Eye, Edit, ArrowUpDown, Trash2 } from 'lucide-react' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar, type ColumnMeta, type FilterField, type ActiveFilter } from '@/components/dataTableToolbar' -import { MonthSelect } from '@/components/monthSelect' -import { useSberPaymentOrders, useDeleteSberPayment } from '@/features/sberPayments/hooks/useSberPayments' -import { type SberPaymentOrder, WELAYATLAR, STATUSES, type PaymentStatus, type PaymentPaidStatus } from '@/features/sberPayments/api/sberPaymentsApi' -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -import { AlertCircle, CheckCircle2, XCircle } from 'lucide-react' - +import { useState, useMemo, useCallback } from "react"; +import { format } from "date-fns"; +import { Eye, Edit, ArrowUpDown, Trash2 } from "lucide-react"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar, type ColumnMeta, type FilterField, type ActiveFilter } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { MonthSelect } from "@/components/monthSelect"; +import { useSberPaymentOrders, useDeleteSberPayment } from "@/features/sberPayments/hooks/useSberPayments"; +import { + type SberPaymentOrder, + WELAYATLAR, + STATUSES, + type PaymentStatus, + type PaymentPaidStatus, +} from "@/features/sberPayments/api/sberPaymentsApi"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge"; +import { AlertCircle, CheckCircle2, XCircle } from "lucide-react"; // ─── Status badge ───────────────────────────────────────────────────────────── function getStatusConfig(t: (key: string, fallback?: string) => string) { return { GARASYLYYAR: { - label: t('sberPayments.status.pending', 'Garaşylýar'), - variant: 'warning' as StatusBadgeVariant, - icon: AlertCircle, + label: t("sberPayments.status.pending", "Garaşylýar"), + variant: "warning" as StatusBadgeVariant, + icon: AlertCircle, }, KANAGATLANDYRYLAN: { - label: t('sberPayments.status.approved', 'Tassyklandy'), - variant: 'success' as StatusBadgeVariant, - icon: CheckCircle2, + label: t("sberPayments.status.approved", "Tassyklandy"), + variant: "success" as StatusBadgeVariant, + icon: CheckCircle2, }, RET_EDILEN: { - label: t('sberPayments.status.rejected', 'Ýatyryldy'), - variant: 'error' as StatusBadgeVariant, - icon: XCircle, + label: t("sberPayments.status.rejected", "Ýatyryldy"), + variant: "error" as StatusBadgeVariant, + icon: XCircle, }, - } satisfies Record + } satisfies Record; } function getPaidStatusConfig(t: (key: string, fallback?: string) => string) { return { Tolenmedik: { - label: t('sberPayments.paidStatus.unpaid', 'Tölmedi'), - variant: 'error' as StatusBadgeVariant, - icon: XCircle, + label: t("sberPayments.paidStatus.unpaid", "Tölmedi"), + variant: "error" as StatusBadgeVariant, + icon: XCircle, }, Tolendi: { - label: t('sberPayments.paidStatus.paid', 'Tölendi'), - variant: 'success' as StatusBadgeVariant, - icon: CheckCircle2, + label: t("sberPayments.paidStatus.paid", "Tölendi"), + variant: "success" as StatusBadgeVariant, + icon: CheckCircle2, }, - } satisfies Record + } satisfies Record; } function PaymentPaidStatusBadge({ status, t }: { status: PaymentPaidStatus; t: (key: string, fallback?: string) => string }) { - const cfg = getPaidStatusConfig(t)[status] - if (!cfg) return {String(status)} - return + const cfg = getPaidStatusConfig(t)[status]; + if (!cfg) return {String(status)}; + return ; } function PaymentStatusBadge({ status, t }: { status: PaymentStatus; t: (key: string, fallback?: string) => string }) { - const cfg = getStatusConfig(t)[status] - if (!cfg) return {String(status)} - return + const cfg = getStatusConfig(t)[status]; + if (!cfg) return {String(status)}; + return ; } // ─── Column Definitions ─────────────────────────────────────────────────────── - // ─── Column Meta for Toolbar ────────────────────────────────────────────────── function getColumnMeta(t: (key: string, fallback?: string) => string): ColumnMeta[] { return [ - { id: 'id', label: t('sberPayments.columns.id', 'ID') }, - { id: 'createdAt', label: t('sberPayments.columns.createdAt', 'Döredilen wagty') }, - { id: 'welayat', label: t('sberPayments.columns.welayat', 'Welaýat') }, - { id: 'sahamca', label: t('sberPayments.columns.sahamca', 'Şahamça') }, - { id: 'firstName', label: t('sberPayments.columns.firstName', 'Ady') }, - { id: 'lastName', label: t('sberPayments.columns.lastName', 'Familiýasy') }, - { id: 'phone', label: t('sberPayments.columns.phone', 'Telefon') }, - { id: 'status', label: t('sberPayments.columns.status', 'Status') }, - { id: 'paidStatus', label: t('sberPayments.columns.paidStatus', 'Tölenen (şul aý)') }, - ] + { id: "id", label: t("sberPayments.columns.id", "ID") }, + { id: "createdAt", label: t("sberPayments.columns.createdAt", "Döredilen wagty") }, + { id: "welayat", label: t("sberPayments.columns.welayat", "Welaýat") }, + { id: "sahamca", label: t("sberPayments.columns.sahamca", "Şahamça") }, + { id: "firstName", label: t("sberPayments.columns.firstName", "Ady") }, + { id: "lastName", label: t("sberPayments.columns.lastName", "Familiýasy") }, + { id: "phone", label: t("sberPayments.columns.phone", "Telefon") }, + { id: "status", label: t("sberPayments.columns.status", "Status") }, + { id: "paidStatus", label: t("sberPayments.columns.paidStatus", "Tölenen (şul aý)") }, + ]; } // ─── Filter Fields ──────────────────────────────────────────────────────────── @@ -87,186 +93,176 @@ function getColumnMeta(t: (key: string, fallback?: string) => string): ColumnMet function getFilterFields(t: (key: string, fallback?: string) => string): FilterField[] { return [ { - id: 'welayat', - label: t('sberPayments.filters.welayat', 'Welaýat'), + id: "welayat", + label: t("sberPayments.filters.welayat", "Welaýat"), options: WELAYATLAR.map((w) => ({ value: w, label: w })), }, { - id: 'status', - label: t('sberPayments.filters.status', 'Status'), + id: "status", + label: t("sberPayments.filters.status", "Status"), options: STATUSES, }, - ] + ]; } // ─── List Page Component ────────────────────────────────────────────────────── export default function SberPaymentsListPage() { - const { t: _t, i18n } = useTranslation() - const t: (key: string, fallback?: string) => string = useCallback( - (key, fallback) => _t(key, fallback ?? key) as string, - [_t], - ) - const navigate = useNavigate() - const deleteMutation = useDeleteSberPayment() + const { t: _t, i18n } = useTranslation(); + const t: (key: string, fallback?: string) => string = useCallback((key, fallback) => _t(key, fallback ?? key) as string, [_t]); + const navigate = useNavigate(); + const [deleteTarget, setDeleteTarget] = useState(null); + const deleteMutation = useDeleteSberPayment(); + + const colMeta = useMemo(() => getColumnMeta(t), [i18n.language]); + const filterFlds = useMemo(() => getFilterFields(t), [i18n.language]); - const colMeta = useMemo(() => getColumnMeta(t), [i18n.language]) - const filterFlds = useMemo(() => getFilterFields(t), [i18n.language]) - const columns = useMemo[]>(() => { - const colMetaLabels = getColumnMeta(t) - const idLabel = colMetaLabels.find(c => c.id === 'id')?.label ?? 'ID' - const createdAtLabel = colMetaLabels.find(c => c.id === 'createdAt')?.label ?? 'Döredilen wagty' - const welayatLabel = colMetaLabels.find(c => c.id === 'welayat')?.label ?? 'Welaýat' - const sahamcaLabel = colMetaLabels.find(c => c.id === 'sahamca')?.label ?? 'Şahamça' - const firstNameLabel = colMetaLabels.find(c => c.id === 'firstName')?.label ?? 'Ady' - const lastNameLabel = colMetaLabels.find(c => c.id === 'lastName')?.label ?? 'Familiýasy' - const phoneLabel = colMetaLabels.find(c => c.id === 'phone')?.label ?? 'Telefon' - const statusLabel = colMetaLabels.find(c => c.id === 'status')?.label ?? 'Status' - const paidStatusLabel = colMetaLabels.find(c => c.id === 'paidStatus')?.label ?? 'Tölenen (şul aý)' + const colMetaLabels = getColumnMeta(t); + const idLabel = colMetaLabels.find((c) => c.id === "id")?.label ?? "ID"; + const createdAtLabel = colMetaLabels.find((c) => c.id === "createdAt")?.label ?? "Döredilen wagty"; + const welayatLabel = colMetaLabels.find((c) => c.id === "welayat")?.label ?? "Welaýat"; + const sahamcaLabel = colMetaLabels.find((c) => c.id === "sahamca")?.label ?? "Şahamça"; + const firstNameLabel = colMetaLabels.find((c) => c.id === "firstName")?.label ?? "Ady"; + const lastNameLabel = colMetaLabels.find((c) => c.id === "lastName")?.label ?? "Familiýasy"; + const phoneLabel = colMetaLabels.find((c) => c.id === "phone")?.label ?? "Telefon"; + const statusLabel = colMetaLabels.find((c) => c.id === "status")?.label ?? "Status"; + const paidStatusLabel = colMetaLabels.find((c) => c.id === "paidStatus")?.label ?? "Tölenen (şul aý)"; return [ { - accessorKey: 'id', + accessorKey: "id", header: ({ column }) => ( ), - cell: ({ row }) => ( - {row.getValue('id')} - ), + cell: ({ row }) => {row.getValue("id")}, }, { - accessorKey: 'createdAt', + accessorKey: "createdAt", header: createdAtLabel, cell: ({ row }) => { - const date = new Date(row.getValue('createdAt')) + const date = new Date(row.getValue("createdAt")); return (
-
{format(date, 'HH:mm, dd.MM.yyyy')}
+
{format(date, "HH:mm, dd.MM.yyyy")}
- ) + ); }, }, { - accessorKey: 'welayat', + accessorKey: "welayat", header: welayatLabel, - cell: ({ row }) => {row.getValue('welayat')}, + cell: ({ row }) => {row.getValue("welayat")}, }, { - accessorKey: 'sahamca', + accessorKey: "sahamca", header: ({ column }) => ( ), - cell: ({ row }) => ( - {row.getValue('sahamca')} - ), + cell: ({ row }) => {row.getValue("sahamca")}, }, { - accessorKey: 'firstName', + accessorKey: "firstName", header: firstNameLabel, - cell: ({ row }) => {row.getValue('firstName')}, + cell: ({ row }) => {row.getValue("firstName")}, }, { - accessorKey: 'lastName', + accessorKey: "lastName", header: lastNameLabel, - cell: ({ row }) => {row.getValue('lastName')}, + cell: ({ row }) => {row.getValue("lastName")}, }, { - accessorKey: 'phone', + accessorKey: "phone", header: phoneLabel, - cell: ({ row }) => {row.getValue('phone')}, + cell: ({ row }) => {row.getValue("phone")}, }, { - accessorKey: 'status', + accessorKey: "status", header: ({ column }) => ( ), - cell: ({ row }) => , + cell: ({ row }) => , }, { - accessorKey: 'paidStatus', + accessorKey: "paidStatus", header: paidStatusLabel, - cell: ({ row }) => , + cell: ({ row }) => , }, { - id: 'actions', - header: '', + id: "actions", + header: "", cell: ({ row }) => { - const order = row.original - + const order = row.original; + return (
- ) + ); }, }, - ] - }, [navigate, deleteMutation, t, i18n.language]) - + ]; + }, [navigate, deleteMutation, t, i18n.language]); + // Pagination state - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + // Search state - const [search, setSearch] = useState('') - + const [search, setSearch] = useState(""); + // Filter state - const [activeFilters, setActiveFilters] = useState([]) - + const [activeFilters, setActiveFilters] = useState([]); + // Column visibility & order - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState(colMeta.map((c) => c.id)) - + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState(colMeta.map((c) => c.id)); + // Month filter - const [selectedMonth, setSelectedMonth] = useState('') - + const [selectedMonth, setSelectedMonth] = useState(""); + // Get filter values - const welayatFilter = activeFilters.find((f) => f.fieldId === 'welayat')?.value ?? '' - const statusFilter = activeFilters.find((f) => f.fieldId === 'status')?.value ?? '' - + const welayatFilter = activeFilters.find((f) => f.fieldId === "welayat")?.value ?? ""; + const statusFilter = activeFilters.find((f) => f.fieldId === "status")?.value ?? ""; + // Fetch data const { data, isLoading } = useSberPaymentOrders({ page, @@ -274,81 +270,110 @@ export default function SberPaymentsListPage() { search, welayat: welayatFilter, status: statusFilter, - }) - + }); + const handleFilterChange = (fieldId: string, value: string) => { setActiveFilters((prev) => { - const existing = prev.find((f) => f.fieldId === fieldId) + const existing = prev.find((f) => f.fieldId === fieldId); if (existing) { - return prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)) + return prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)); } - return [...prev, { fieldId, value }] - }) - setPage(1) - } - + return [...prev, { fieldId, value }]; + }); + setPage(1); + }; + const handleFilterReset = () => { - setActiveFilters([]) - setPage(1) - } - + setActiveFilters([]); + setPage(1); + }; + return (
{/* Page Title */} -

- {t('sberPayments.list.title', 'Sber tölegler (talyplar üçin)')} -

+

{t("sberPayments.list.title", "Sber tölegler (talyplar üçin)")}

+
+ { + setSearch(val); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/sber-payments/create")} + /> +
+ {/* Toolbar */} + { + setSearch(val); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} + columns={colMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + filterFields={filterFlds} + activeFilters={activeFilters} + onFilterChange={handleFilterChange} + onFilterReset={handleFilterReset} + perPage={perPage} + onPerPageChange={(val) => { + setPerPage(val); + setPage(1); + }} + hideSearch + hideAction + extraActions={ + { + setSelectedMonth(v); + setPage(1); + }} + /> + } + /> - {/* Toolbar */} - { - setSearch(val) - setPage(1) + {/* Data Table */} + row.id} + currentPage={data?.pagination.currentPage ?? 1} + totalPages={data?.pagination.totalPages ?? 1} + totalCount={data?.pagination.totalCount ?? 0} + onPageChange={setPage} + /> +
+ {/* Delete confirmation dialog */} + { + if (!o) setDeleteTarget(null); }} - searchPlaceholder={t('common.search', 'Gözlemek')} - columns={colMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - filterFields={filterFlds} - activeFilters={activeFilters} - onFilterChange={handleFilterChange} - onFilterReset={handleFilterReset} - perPage={perPage} - onPerPageChange={(val) => { - setPerPage(val) - setPage(1) + title={t("sberPayments.deleteDialog.title", "Bu tölegi pozmak isleýärsiňizmi?")} + onConfirm={async () => { + if (deleteTarget) { + await deleteMutation.mutateAsync(deleteTarget.id); + setDeleteTarget(null); + } }} - actionLabel={t('sberPayments.list.actionLabel', 'Sber töleg (talyplar üçin) dörediň')} - onAction={() => navigate('/sber-payments/create')} - extraActions={ - { setSelectedMonth(v); setPage(1) }} - /> - } - /> - - {/* Data Table */} - row.id} - currentPage={data?.pagination.currentPage ?? 1} - totalPages={data?.pagination.totalPages ?? 1} - totalCount={data?.pagination.totalCount ?? 0} - onPageChange={setPage} + isLoading={deleteMutation.isPending} />
-
- ) + ); } diff --git a/src/pages/internationalPayments/visaMasterPayments/index.tsx b/src/pages/internationalPayments/visaMasterPayments/index.tsx index 23bda6f..6b67255 100644 --- a/src/pages/internationalPayments/visaMasterPayments/index.tsx +++ b/src/pages/internationalPayments/visaMasterPayments/index.tsx @@ -1,122 +1,109 @@ -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import { useIntlPayments, useDeleteIntlPayment } from '@/features/visaMasterPayments/hooks/useVisaMasterPayments' -import type { IntlPaymentItem, IntlPaymentStatus } from '@/features/visaMasterPayments/api/visaMasterPaymentsApi' -import { Button } from '@/components/ui/button' -import { Eye, Pencil, Trash2 } from 'lucide-react' -import { ConfirmDialog } from '@/components/confirmDialog' -import { MonthSelect } from '@/components/monthSelect' -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -import { AlertCircle, CheckCircle2, XCircle } from 'lucide-react' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { useIntlPayments, useDeleteIntlPayment } from "@/features/visaMasterPayments/hooks/useVisaMasterPayments"; +import type { IntlPaymentItem, IntlPaymentStatus } from "@/features/visaMasterPayments/api/visaMasterPaymentsApi"; +import { Button } from "@/components/ui/button"; +import { Eye, Pencil, Trash2 } from "lucide-react"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { MonthSelect } from "@/components/monthSelect"; +import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge"; +import { AlertCircle, CheckCircle2, XCircle } from "lucide-react"; // ─── Status badge (defined inside component for t() access) ─────────────────── // ─── Page ───────────────────────────────────────────────────────────────────── export default function IntlPaymentsPage() { - const { t } = useTranslation() - const navigate = useNavigate() + const { t } = useTranslation(); + const navigate = useNavigate(); - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [search, setSearch] = useState('') - const [month, setMonth] = useState('') - const [statusFilter, setStatusFilter] = useState('') + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [search, setSearch] = useState(""); + const [month, setMonth] = useState(""); + const [statusFilter, setStatusFilter] = useState(""); - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([]) + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([]); - const [deleteTarget, setDeleteTarget] = useState(null) + const [deleteTarget, setDeleteTarget] = useState(null); - const { data, isLoading } = useIntlPayments({ page, per_page: perPage, search, status: statusFilter, month }) - const { mutate: deletePayment, isPending: isDeleting } = useDeleteIntlPayment() + const { data, isLoading } = useIntlPayments({ page, per_page: perPage, search, status: statusFilter, month }); + const { mutate: deletePayment, isPending: isDeleting } = useDeleteIntlPayment(); function IntlPaymentStatusBadge({ status }: { status: IntlPaymentStatus }) { const STATUS_CONFIG = { - pending: { label: t('intlPayment.status.pending', 'Garaşylýar'), variant: 'warning' as StatusBadgeVariant, icon: AlertCircle }, - approved: { label: t('intlPayment.status.approved', 'Tassyklandy'), variant: 'success' as StatusBadgeVariant, icon: CheckCircle2 }, - rejected: { label: t('intlPayment.status.rejected', 'Ret edildi'), variant: 'error' as StatusBadgeVariant, icon: XCircle }, - } - const cfg = STATUS_CONFIG[status] - if (!cfg) return {status} - return + pending: { label: t("intlPayment.status.pending", "Garaşylýar"), variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, + approved: { label: t("intlPayment.status.approved", "Tassyklandy"), variant: "success" as StatusBadgeVariant, icon: CheckCircle2 }, + rejected: { label: t("intlPayment.status.rejected", "Ret edildi"), variant: "error" as StatusBadgeVariant, icon: XCircle }, + }; + const cfg = STATUS_CONFIG[status]; + if (!cfg) return {status}; + return ; } const columns: ColumnDef[] = [ { - accessorKey: 'id', - header: t('intlPayment.col.id', 'ID'), - cell: ({ row }) => ( - {row.original.id} - ), + accessorKey: "id", + header: t("intlPayment.col.id", "ID"), + cell: ({ row }) => {row.original.id}, }, { - accessorKey: 'currency_type_label', - header: t('intlPayment.currencyType', 'Ýüztumanyň görnüşi'), - cell: ({ row }) => ( - {row.original.currency_type_label} - ), + accessorKey: "currency_type_label", + header: t("intlPayment.currencyType", "Ýüztumanyň görnüşi"), + cell: ({ row }) => {row.original.currency_type_label}, }, { - accessorKey: 'created_at', - header: t('intlPayment.createdAt', 'Döredilen wagty'), - cell: ({ row }) => ( - {row.original.created_at} - ), + accessorKey: "created_at", + header: t("intlPayment.createdAt", "Döredilen wagty"), + cell: ({ row }) => {row.original.created_at}, }, { - accessorKey: 'province_label', - header: t('intlPayment.province', 'Welaýat'), + accessorKey: "province_label", + header: t("intlPayment.province", "Welaýat"), }, { - accessorKey: 'branch_label', - header: t('intlPayment.branch', 'Şahamça'), - cell: ({ row }) => ( - {row.original.branch_label} - ), + accessorKey: "branch_label", + header: t("intlPayment.branch", "Şahamça"), + cell: ({ row }) => {row.original.branch_label}, }, { - accessorKey: 'passport_first_name', - header: t('intlPayment.firstName', 'Ady'), + accessorKey: "passport_first_name", + header: t("intlPayment.firstName", "Ady"), }, { - accessorKey: 'passport_last_name', - header: t('intlPayment.lastName', 'Familiýasy'), + accessorKey: "passport_last_name", + header: t("intlPayment.lastName", "Familiýasy"), }, { - accessorKey: 'phone', - header: t('intlPayment.phone', 'Telefon'), - cell: ({ row }) => ( - {row.original.phone} - ), + accessorKey: "phone", + header: t("intlPayment.phone", "Telefon"), + cell: ({ row }) => {row.original.phone}, }, { - accessorKey: 'status', - header: t('intlPayment.status', 'Status'), + accessorKey: "status", + header: t("intlPayment.status", "Status"), cell: ({ row }) => , }, { - id: 'actions', + id: "actions", enableHiding: false, cell: ({ row }) => (
- -
), }, - ] + ]; const columnMeta = columns - .filter((c) => ('accessorKey' in c || 'id' in c) && c.id !== 'actions') + .filter((c) => ("accessorKey" in c || "id" in c) && c.id !== "actions") .map((c) => { - const id = ('accessorKey' in c ? String(c.accessorKey) : c.id) as string - const label = - typeof c.header === "string" - ? c.header - : "accessorKey" in c - ? String(c.accessorKey) - : id; + const id = ("accessorKey" in c ? String(c.accessorKey) : c.id) as string; + const label = typeof c.header === "string" ? c.header : "accessorKey" in c ? String(c.accessorKey) : id; return { id, label }; }); return (
-

- {t("intlPayment.title", "Halkara tölegler (Visa/Mastercard)")} -

+

{t("intlPayment.title", "Halkara tölegler (Visa/Mastercard)")}

-
+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("intlPayment.search", "Gözlemek")} + /> + navigate("/visa-master/create")} + /> +
+
+ { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("intlPayment.search", "Gözlemek")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + filterFields={[ + { + id: "status", + label: t("intlPayment.status", "Status"), + options: [ + { value: "pending", label: t("intlPayment.status.pending", "Garaşylýar") }, + { value: "approved", label: t("intlPayment.status.approved", "Tassyklandy") }, + { value: "rejected", label: t("intlPayment.status.rejected", "Ret edildi") }, + ], + }, + ]} + activeFilters={[{ fieldId: "status", value: statusFilter }]} + onFilterChange={(fieldId, value) => { + if (fieldId === "status") setStatusFilter(value as IntlPaymentStatus | ""); + setPage(1); + }} + onFilterReset={() => { + setStatusFilter(""); + setPage(1); + }} + perPage={perPage} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + hideSearch + hideAction + extraActions={ + { + setMonth(v); + setPage(1); + }} + /> + } + /> - { setSearch(v); setPage(1) }} - searchPlaceholder={t('intlPayment.search', 'Gözlemek')} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - filterFields={[ - { - id: 'status', - label: t('intlPayment.status', 'Status'), - options: [ - { value: 'pending', label: t('intlPayment.status.pending', 'Garaşylýar') }, - { value: 'approved', label: t('intlPayment.status.approved', 'Tassyklandy') }, - { value: 'rejected', label: t('intlPayment.status.rejected', 'Ret edildi') }, - ], - }, - ]} - activeFilters={[{ fieldId: 'status', value: statusFilter }]} - onFilterChange={(fieldId, value) => { - if (fieldId === 'status') setStatusFilter(value as IntlPaymentStatus | '') - setPage(1) - }} - onFilterReset={() => { setStatusFilter(''); setPage(1) }} - perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('intlPayment.createBtn', 'Visa/Master tölegler (talyplar üçin) dörediň')} - onAction={() => navigate('/visa-master/create')} - extraActions={ - { setMonth(v); setPage(1) }} - /> - } - /> + +
- -
- - { if (!o) setDeleteTarget(null) }} - title={t('intlPayment.deleteTitle', 'Pozmak isleýärsiňizmi?')} - description={`${t('intlPayment.deleteDesc', 'Bu amal yzyna dolanyp bolmaz.')} ${deleteTarget?.id ?? ''}`} - confirmLabel={t('common.delete', 'Poz')} + onOpenChange={(o) => { + if (!o) setDeleteTarget(null); + }} + title={t("intlPayment.deleteTitle", "Pozmak isleýärsiňizmi?")} + description={`${t("intlPayment.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")} ${deleteTarget?.id ?? ""}`} onConfirm={() => { if (deleteTarget) { - deletePayment(deleteTarget.id, { onSuccess: () => setDeleteTarget(null) }) + deletePayment(deleteTarget.id, { onSuccess: () => setDeleteTarget(null) }); } }} isLoading={isDeleting} />
- ) + ); } diff --git a/src/pages/loanDepartment/loanOrderMobile/index.tsx b/src/pages/loanDepartment/loanOrderMobile/index.tsx index 96f1cb8..7188ce7 100644 --- a/src/pages/loanDepartment/loanOrderMobile/index.tsx +++ b/src/pages/loanDepartment/loanOrderMobile/index.tsx @@ -1,222 +1,191 @@ -import { useState, useMemo, useCallback } from 'react' -import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2, AlertCircle, CheckCircle2, XCircle, Loader2 } from 'lucide-react' -import { useNavigate } from 'react-router-dom' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar' -import { - useLoanOrderMobiles, - useDeleteLoanOrderMobile, -} from '@/features/loanOrderMobiles/hooks/useLoanOrderMobiles' -import type { LoanOrderMobile, LoanOrderMobileStatus } from '@/features/loanOrderMobiles/api/loanOrderMobilesApi' -import { ConfirmDialog } from '@/components/confirmDialog' - - +import { useState, useMemo, useCallback } from "react"; +import { useTranslation } from "react-i18next"; +import { Eye, Pencil, Trash2, AlertCircle, CheckCircle2, XCircle, Loader2 } from "lucide-react"; +import { useNavigate } from "react-router-dom"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { useLoanOrderMobiles, useDeleteLoanOrderMobile } from "@/features/loanOrderMobiles/hooks/useLoanOrderMobiles"; +import type { LoanOrderMobile, LoanOrderMobileStatus } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi"; +import { DeleteDialog } from "@/components/deleteDialog"; // ─── Status Badge (inline) ──────────────────────────────────────────────────── const STATUS_CONFIG = { - GARAŞYLÝAR: { label: 'Garaşylýar', variant: 'warning' as StatusBadgeVariant, icon: AlertCircle }, - KANAGATLANDYRYLAN: { label: 'Kanagatlandyrylan', variant: 'success' as StatusBadgeVariant, icon: CheckCircle2 }, - RED_EDILDI: { label: 'Red edildi', variant: 'error' as StatusBadgeVariant, icon: XCircle }, - IŞLENÝÄR: { label: 'Işlenýär', variant: 'info' as StatusBadgeVariant, icon: Loader2 }, -} satisfies Record + GARAŞYLÝAR: { label: "Garaşylýar", variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, + KANAGATLANDYRYLAN: { label: "Kanagatlandyrylan", variant: "success" as StatusBadgeVariant, icon: CheckCircle2 }, + RED_EDILDI: { label: "Red edildi", variant: "error" as StatusBadgeVariant, icon: XCircle }, + IŞLENÝÄR: { label: "Işlenýär", variant: "info" as StatusBadgeVariant, icon: Loader2 }, +} satisfies Record; function LoanOrderStatusBadge({ status }: { status: LoanOrderMobileStatus }) { - const cfg = STATUS_CONFIG[status] - if (!cfg) return {String(status)} - return + const cfg = STATUS_CONFIG[status]; + if (!cfg) return {String(status)}; + return ; } // ─── Column IDs ──────────────────────────────────────────────────────────────── -const COLUMN_IDS = [ - 'id', - 'loanType', - 'createdAt', - 'region', - 'branch', - 'firstName', - 'lastName', - 'phone', - 'status', -] as const +const COLUMN_IDS = ["id", "loanType", "createdAt", "region", "branch", "firstName", "lastName", "phone", "status"] as const; // ─── Filter options ──────────────────────────────────────────────────────────── // ─── Filter options (Internal keys/values) ─────────────────────────────────── -const REGION_OPTIONS = ['Balkan', 'Ahal', 'Daşoguz', 'Lebap', 'Mary', 'Aşgabat'] -const STATUS_OPTIONS: LoanOrderMobileStatus[] = ['GARAŞYLÝAR', 'KANAGATLANDYRYLAN', 'RED_EDILDI', 'IŞLENÝÄR'] +const REGION_OPTIONS = ["Balkan", "Ahal", "Daşoguz", "Lebap", "Mary", "Aşgabat"]; +const STATUS_OPTIONS: LoanOrderMobileStatus[] = ["GARAŞYLÝAR", "KANAGATLANDYRYLAN", "RED_EDILDI", "IŞLENÝÄR"]; // ─── Page Component ──────────────────────────────────────────────────────────── export default function LoanOrderMobilesPage() { - const { t } = useTranslation() - const navigate = useNavigate() - const deleteMutation = useDeleteLoanOrderMobile() - const [deleteId, setDeleteId] = useState(null) + const { t } = useTranslation(); + const navigate = useNavigate(); + const deleteMutation = useDeleteLoanOrderMobile(); + const [deleteId, setDeleteId] = useState(null); // ── State ────────────────────────────────────────────────────────────────── - const [search, setSearch] = useState('') - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([...COLUMN_IDS]) - const [activeFilters, setActiveFilters] = useState([ - { fieldId: 'region', value: '' }, - { fieldId: 'status', value: '' }, - { fieldId: 'branch', value: '' }, - { fieldId: 'archived', value: '' }, - ]) + const [search, setSearch] = useState(""); + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([...COLUMN_IDS]); + const [activeFilters, setActiveFilters] = useState([ + { fieldId: "region", value: "" }, + { fieldId: "status", value: "" }, + { fieldId: "branch", value: "" }, + { fieldId: "archived", value: "" }, + ]); // ── Query params ─────────────────────────────────────────────────────────── const queryParams = useMemo(() => { - const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])) + const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])); return { - search: search || undefined, - region: filterMap.region || undefined, - status: (filterMap.status as LoanOrderMobileStatus) || undefined, - branch: filterMap.branch || undefined, + search: search || undefined, + region: filterMap.region || undefined, + status: (filterMap.status as LoanOrderMobileStatus) || undefined, + branch: filterMap.branch || undefined, archived: filterMap.archived || undefined, page, perPage, - } - }, [search, activeFilters, page, perPage]) + }; + }, [search, activeFilters, page, perPage]); - const { data, isLoading } = useLoanOrderMobiles(queryParams) - const totalPages = data ? Math.ceil(data.total / perPage) : 1 + const { data, isLoading } = useLoanOrderMobiles(queryParams); + const totalPages = data ? Math.ceil(data.total / perPage) : 1; // ── Handlers ─────────────────────────────────────────────────────────────── const handleFilterChange = useCallback((fieldId: string, value: string) => { - setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))) - setPage(1) - }, []) + setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))); + setPage(1); + }, []); const handleFilterReset = useCallback(() => { - setActiveFilters((prev) => prev.map((f) => ({ ...f, value: '' }))) - setPage(1) - }, []) + setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" }))); + setPage(1); + }, []); const handleDelete = useCallback((id: string) => { - setDeleteId(id) - }, []) + setDeleteId(id); + }, []); const confirmDelete = useCallback(() => { - if (!deleteId) return - deleteMutation.mutate(deleteId) - setDeleteId(null) - }, [deleteId, deleteMutation]) + if (!deleteId) return; + deleteMutation.mutate(deleteId); + setDeleteId(null); + }, [deleteId, deleteMutation]); // ── Columns ──────────────────────────────────────────────────────────────── const columns = useMemo[]>( () => [ { - id: 'id', - accessorKey: 'id', - header: t('loanOrderMobiles.columns.id', 'ID'), - cell: ({ row }) => ( - {row.original.id} - ), + id: "id", + accessorKey: "id", + header: t("loanOrderMobiles.columns.id", "ID"), + cell: ({ row }) => {row.original.id}, size: 130, }, { - id: 'loanType', - accessorKey: 'loanType', - header: t('loanOrderMobiles.columns.loanType', 'KARZ GÖRNÜŞI'), - cell: ({ row }) => ( - - {row.original.loanType} - - ), + id: "loanType", + accessorKey: "loanType", + header: t("loanOrderMobiles.columns.loanType", "KARZ GÖRNÜŞI"), + cell: ({ row }) => {row.original.loanType}, }, { - id: 'createdAt', - accessorKey: 'createdAt', - header: t('loanOrderMobiles.columns.createdAt', 'DÖREDILEN WAGTY'), - cell: ({ row }) => ( - {row.original.createdAt} - ), + id: "createdAt", + accessorKey: "createdAt", + header: t("loanOrderMobiles.columns.createdAt", "DÖREDILEN WAGTY"), + cell: ({ row }) => {row.original.createdAt}, size: 160, }, { - id: 'region', - accessorKey: 'region', - header: t('loanOrderMobiles.columns.region', 'WELAÝAT'), - cell: ({ row }) => ( - {row.original.region} - ), + id: "region", + accessorKey: "region", + header: t("loanOrderMobiles.columns.region", "WELAÝAT"), + cell: ({ row }) => {row.original.region}, size: 100, }, { - id: 'branch', - accessorKey: 'branch', - header: t('loanOrderMobiles.columns.branch', 'ŞAHAMÇA'), - cell: ({ row }) => ( - {row.original.branch} - ), + id: "branch", + accessorKey: "branch", + header: t("loanOrderMobiles.columns.branch", "ŞAHAMÇA"), + cell: ({ row }) => {row.original.branch}, size: 100, }, { - id: 'firstName', - accessorKey: 'firstName', - header: t('loanOrderMobiles.columns.firstName', 'ADY'), - cell: ({ row }) => ( - {row.original.firstName} - ), + id: "firstName", + accessorKey: "firstName", + header: t("loanOrderMobiles.columns.firstName", "ADY"), + cell: ({ row }) => {row.original.firstName}, size: 110, }, { - id: 'lastName', - accessorKey: 'lastName', - header: t('loanOrderMobiles.columns.lastName', 'FAMILIÝASY'), - cell: ({ row }) => ( - {row.original.lastName} - ), + id: "lastName", + accessorKey: "lastName", + header: t("loanOrderMobiles.columns.lastName", "FAMILIÝASY"), + cell: ({ row }) => {row.original.lastName}, size: 120, }, { - id: 'phone', - accessorKey: 'phone', - header: t('loanOrderMobiles.columns.phone', 'TELEFON'), - cell: ({ row }) => ( - {row.original.phone} - ), + id: "phone", + accessorKey: "phone", + header: t("loanOrderMobiles.columns.phone", "TELEFON"), + cell: ({ row }) => {row.original.phone}, size: 110, }, { - id: 'status', - accessorKey: 'status', - header: t('loanOrderMobiles.columns.status', 'STATUS'), + id: "status", + accessorKey: "status", + header: t("loanOrderMobiles.columns.status", "STATUS"), cell: ({ row }) => , size: 180, }, { - id: 'actions', - header: '', + id: "actions", + header: "", enableHiding: false, cell: ({ row }) => ( -
- - +
+ + @@ -226,59 +195,72 @@ export default function LoanOrderMobilesPage() { }, ], [t, handleDelete, deleteMutation.isPending, navigate], - ) + ); // ── Column meta for toolbar ──────────────────────────────────────────────── - const toggleableColumns = useMemo( - () => COLUMN_IDS.map((id) => ({ id, label: t(`loanOrderMobiles.columns.${id}`, id) })), - [t], - ) + const toggleableColumns = useMemo(() => COLUMN_IDS.map((id) => ({ id, label: t(`loanOrderMobiles.columns.${id}`, id) })), [t]); const filterFields = useMemo( () => [ { - id: 'region', - label: t('loanOrderMobiles.filters.region', 'WELAÝAT'), + id: "region", + label: t("loanOrderMobiles.filters.region", "WELAÝAT"), options: REGION_OPTIONS.map((v) => ({ value: v, label: t(v) })), }, { - id: 'status', - label: t('loanOrderMobiles.filters.status', 'STATUS'), + id: "status", + label: t("loanOrderMobiles.filters.status", "STATUS"), options: STATUS_OPTIONS.map((v) => ({ value: v, label: t(`loanOrderStatus.${v}`) })), }, { - id: 'branch', - label: t('loanOrderMobiles.filters.branch', 'ŞAHAMÇA'), + id: "branch", + label: t("loanOrderMobiles.filters.branch", "ŞAHAMÇA"), options: [], }, { - id: 'archived', - label: t('loanOrderMobiles.filters.archived', 'ARHIWLENEN'), + id: "archived", + label: t("loanOrderMobiles.filters.archived", "ARHIWLENEN"), options: [ - { value: 'true', label: t('common.yes', 'Hawa') }, - { value: 'false', label: t('common.no', 'Ýok') }, + { value: "true", label: t("common.yes", "Hawa") }, + { value: "false", label: t("common.no", "Ýok") }, ], }, ], [t], - ) + ); // ────────────────────────────────────────────────────────────────────────── return ( -
+
{/* Page Header */}
-

- {t('loanOrderMobiles.title', 'Karz sargytlary')} -

+

{t("loanOrderMobiles.title", "Karz sargytlary")}

+
+ +
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/loan-order-mobiles/create")} + />
{/* Table Card */}
{ setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} + onSearchChange={(v) => { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} columns={toggleableColumns} columnVisibility={columnVisibility} onColumnVisibilityChange={setColumnVisibility} @@ -290,11 +272,12 @@ export default function LoanOrderMobilesPage() { onFilterReset={handleFilterReset} perPageOptions={[10, 25, 50, 100]} perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('loanOrderMobiles.createButton', 'Karz sargyt dörediň')} - onAction={() => { - navigate('/loan-order-mobiles/create') + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); }} + hideSearch + hideAction />
- { if (!o) setDeleteId(null) }} - title={t('loanOrderMobiles.deleteConfirm', 'Bu sargyt pozulsynmy?')} - confirmLabel={t('common.delete', 'Poz')} + onOpenChange={(o) => { + if (!o) setDeleteId(null); + }} + title={t("loanOrderMobiles.deleteConfirm", "Bu sargyt pozulsynmy?")} onConfirm={confirmDelete} isLoading={deleteMutation.isPending} />
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/loanDepartment/loanOrders/index.tsx b/src/pages/loanDepartment/loanOrders/index.tsx index 7617923..adeb72a 100644 --- a/src/pages/loanDepartment/loanOrders/index.tsx +++ b/src/pages/loanDepartment/loanOrders/index.tsx @@ -1,210 +1,191 @@ -import { useState, useMemo, useCallback } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2, AlertCircle, CheckCircle2, XCircle, Loader2 } from 'lucide-react' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' +import { useState, useMemo, useCallback } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Eye, Pencil, Trash2, AlertCircle, CheckCircle2, XCircle, Loader2 } from "lucide-react"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar' -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -import { useLoanOrders, useDeleteLoanOrder } from '@/features/loanOrders/hooks/useLoanOrders' -import type { LoanOrder, LoanOrderStatus } from '@/features/loanOrders/api/loanOrdersApi' -import { ConfirmDialog } from '@/components/confirmDialog' +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge"; +import { useLoanOrders, useDeleteLoanOrder } from "@/features/loanOrders/hooks/useLoanOrders"; +import type { LoanOrder, LoanOrderStatus } from "@/features/loanOrders/api/loanOrdersApi"; +import { DeleteDialog } from "@/components/deleteDialog"; // ─── Status Badge (inline) ──────────────────────────────────────────────────── const STATUS_CONFIG = { - GARAŞYLÝAR: { label: 'Garaşylýar', variant: 'warning' as StatusBadgeVariant, icon: AlertCircle }, - KANAGATLANDYRYLAN: { label: 'Kanagatlandyrylan', variant: 'success' as StatusBadgeVariant, icon: CheckCircle2 }, - RED_EDILDI: { label: 'Red edildi', variant: 'error' as StatusBadgeVariant, icon: XCircle }, - IŞLENÝÄR: { label: 'Işlenýär', variant: 'info' as StatusBadgeVariant, icon: Loader2 }, -} satisfies Record + GARAŞYLÝAR: { label: "Garaşylýar", variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, + KANAGATLANDYRYLAN: { label: "Kanagatlandyrylan", variant: "success" as StatusBadgeVariant, icon: CheckCircle2 }, + RED_EDILDI: { label: "Red edildi", variant: "error" as StatusBadgeVariant, icon: XCircle }, + IŞLENÝÄR: { label: "Işlenýär", variant: "info" as StatusBadgeVariant, icon: Loader2 }, +} satisfies Record; function LoanOrderStatusBadge({ status }: { status: LoanOrderStatus }) { - const cfg = STATUS_CONFIG[status] - if (!cfg) return {String(status)} - return + const cfg = STATUS_CONFIG[status]; + if (!cfg) return {String(status)}; + return ; } // ─── Column meta for toggle dropdown ───────────────────────────────────────── -const COLUMN_IDS = [ - 'id', 'loanType', 'createdAt', 'region', 'branch', - 'firstName', 'lastName', 'phone', 'status', -] as const +const COLUMN_IDS = ["id", "loanType", "createdAt", "region", "branch", "firstName", "lastName", "phone", "status"] as const; // ─── Filter fields ──────────────────────────────────────────────────────────── const REGION_OPTIONS = [ - { value: 'Balkan', label: 'Balkan' }, - { value: 'Ahal', label: 'Ahal' }, - { value: 'Daşoguz', label: 'Daşoguz' }, - { value: 'Lebap', label: 'Lebap' }, - { value: 'Mary', label: 'Mary' }, - { value: 'Aşgabat', label: 'Aşgabat' }, -] + { value: "Balkan", label: "Balkan" }, + { value: "Ahal", label: "Ahal" }, + { value: "Daşoguz", label: "Daşoguz" }, + { value: "Lebap", label: "Lebap" }, + { value: "Mary", label: "Mary" }, + { value: "Aşgabat", label: "Aşgabat" }, +]; const STATUS_OPTIONS: { value: LoanOrderStatus; label: string }[] = [ - { value: 'GARAŞYLÝAR', label: 'Garaşylýar' }, - { value: 'KANAGATLANDYRYLAN', label: 'Kanagatlandyrylan' }, - { value: 'RED_EDILDI', label: 'Red edildi' }, - { value: 'IŞLENÝÄR', label: 'Işlenýär' }, -] + { value: "GARAŞYLÝAR", label: "Garaşylýar" }, + { value: "KANAGATLANDYRYLAN", label: "Kanagatlandyrylan" }, + { value: "RED_EDILDI", label: "Red edildi" }, + { value: "IŞLENÝÄR", label: "Işlenýär" }, +]; // ─── Page Component ─────────────────────────────────────────────────────────── export default function LoanOrdersPage() { - const { t } = useTranslation() - const navigate = useNavigate() - const deleteMutation = useDeleteLoanOrder() - const [deleteId, setDeleteId] = useState(null) + const { t } = useTranslation(); + const navigate = useNavigate(); + const deleteMutation = useDeleteLoanOrder(); + const [deleteId, setDeleteId] = useState(null); - const [search, setSearch] = useState('') - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(10) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([...COLUMN_IDS]) + const [search, setSearch] = useState(""); + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(10); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([...COLUMN_IDS]); const [activeFilters, setActiveFilters] = useState([ - { fieldId: 'region', value: '' }, - { fieldId: 'status', value: '' }, - { fieldId: 'branch', value: '' }, - { fieldId: 'archived', value: '' }, - ]) + { fieldId: "region", value: "" }, + { fieldId: "status", value: "" }, + { fieldId: "branch", value: "" }, + { fieldId: "archived", value: "" }, + ]); const queryParams = useMemo(() => { - const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])) + const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])); return { - search: search || undefined, - region: filterMap.region || undefined, - status: (filterMap.status as LoanOrderStatus) || undefined, - branch: filterMap.branch || undefined, + search: search || undefined, + region: filterMap.region || undefined, + status: (filterMap.status as LoanOrderStatus) || undefined, + branch: filterMap.branch || undefined, archived: filterMap.archived || undefined, page, perPage, - } - }, [search, activeFilters, page, perPage]) + }; + }, [search, activeFilters, page, perPage]); - const { data, isLoading } = useLoanOrders(queryParams) - const totalPages = data ? Math.ceil(data.total / perPage) : 1 + const { data, isLoading } = useLoanOrders(queryParams); + const totalPages = data ? Math.ceil(data.total / perPage) : 1; const handleFilterChange = useCallback((fieldId: string, value: string) => { - setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))) - setPage(1) - }, []) + setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))); + setPage(1); + }, []); const handleFilterReset = useCallback(() => { - setActiveFilters((prev) => prev.map((f) => ({ ...f, value: '' }))) - setPage(1) - }, []) + setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" }))); + setPage(1); + }, []); const handleDelete = useCallback((id: string) => { - setDeleteId(id) - }, []) + setDeleteId(id); + }, []); const confirmDelete = useCallback(() => { - if (!deleteId) return - deleteMutation.mutate(deleteId) - setDeleteId(null) - }, [deleteId, deleteMutation]) + if (!deleteId) return; + deleteMutation.mutate(deleteId); + setDeleteId(null); + }, [deleteId, deleteMutation]); const columns = useMemo[]>( () => [ { - id: 'id', - accessorKey: 'id', - header: t('ID', 'ID'), - cell: ({ row }) => ( - {row.original.id} - ), + id: "id", + accessorKey: "id", + header: t("ID", "ID"), + cell: ({ row }) => {row.original.id}, size: 130, }, { - id: 'loanType', - accessorKey: 'loanType', - header: t('Loan type', 'KARZ GÖRNÜŞI'), - cell: ({ row }) => ( - - {row.original.loanType} - - ), + id: "loanType", + accessorKey: "loanType", + header: t("Loan type", "KARZ GÖRNÜŞI"), + cell: ({ row }) => {row.original.loanType}, }, { - id: 'createdAt', - accessorKey: 'createdAt', - header: t('Created at', 'DÖREDILEN WAGTY'), - cell: ({ row }) => ( - {row.original.createdAt} - ), + id: "createdAt", + accessorKey: "createdAt", + header: t("Created at", "DÖREDILEN WAGTY"), + cell: ({ row }) => {row.original.createdAt}, size: 160, }, { - id: 'region', - accessorKey: 'region', - header: t('Region', 'WELAÝAT'), - cell: ({ row }) => ( - {row.original.region} - ), + id: "region", + accessorKey: "region", + header: t("Region", "WELAÝAT"), + cell: ({ row }) => {row.original.region}, size: 100, }, { - id: 'branch', - accessorKey: 'branch', - header: t('Branch', 'ŞAHAMÇA'), - cell: ({ row }) => ( - {row.original.branch} - ), + id: "branch", + accessorKey: "branch", + header: t("Branch", "ŞAHAMÇA"), + cell: ({ row }) => {row.original.branch}, size: 100, }, { - id: 'firstName', - accessorKey: 'firstName', - header: t('Name', 'ADY'), - cell: ({ row }) => ( - {row.original.firstName} - ), + id: "firstName", + accessorKey: "firstName", + header: t("Name", "ADY"), + cell: ({ row }) => {row.original.firstName}, size: 110, }, { - id: 'lastName', - accessorKey: 'lastName', - header: t('Surname', 'FAMILIÝASY'), - cell: ({ row }) => ( - {row.original.lastName} - ), + id: "lastName", + accessorKey: "lastName", + header: t("Surname", "FAMILIÝASY"), + cell: ({ row }) => {row.original.lastName}, size: 120, }, { - id: 'phone', - accessorKey: 'phone', - header: t('Phone', 'TELEFON'), - cell: ({ row }) => ( - {row.original.phone} - ), + id: "phone", + accessorKey: "phone", + header: t("Phone", "TELEFON"), + cell: ({ row }) => {row.original.phone}, size: 110, }, { - id: 'status', - accessorKey: 'status', - header: t('Status', 'STATUS'), + id: "status", + accessorKey: "status", + header: t("Status", "STATUS"), cell: ({ row }) => , size: 180, }, { - id: 'actions', - header: '', + id: "actions", + header: "", enableHiding: false, cell: ({ row }) => (
@@ -222,56 +203,68 @@ export default function LoanOrdersPage() { size: 100, }, ], - [t, navigate, handleDelete, deleteMutation.isPending] - ) + [t, navigate, handleDelete, deleteMutation.isPending], + ); - const toggleableColumns = useMemo( - () => COLUMN_IDS.map((id) => ({ id, label: t(`loanOrders.columns.${id}`, id) })), - [t] - ) + const toggleableColumns = useMemo(() => COLUMN_IDS.map((id) => ({ id, label: t(`loanOrders.columns.${id}`, id) })), [t]); const filterFields = useMemo( () => [ { - id: 'region', - label: t('Region', 'WELAÝAT'), + id: "region", + label: t("Region", "WELAÝAT"), options: REGION_OPTIONS, }, { - id: 'status', - label: t('Status', 'STATUS'), + id: "status", + label: t("Status", "STATUS"), options: STATUS_OPTIONS, }, { - id: 'branch', - label: t('Branch', 'ŞAHAMÇA'), + id: "branch", + label: t("Branch", "ŞAHAMÇA"), options: [], }, { - id: 'archived', - label: t('loanOrders.filters.archived', 'ARHIWLENEN'), + id: "archived", + label: t("loanOrders.filters.archived", "ARHIWLENEN"), options: [ - { value: 'true', label: t('common.yes', 'Hawa') }, - { value: 'false', label: t('common.no', 'Ýok') }, + { value: "true", label: t("common.yes", "Hawa") }, + { value: "false", label: t("common.no", "Ýok") }, ], }, ], - [t] - ) + [t], + ); return ( -
+
-

- {t('loanOrders.title', 'Karz sargytlary')} -

+

{t("loanOrders.title", "Karz sargytlary")}

+
+ +
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("loanOrderMobiles.searchPlaceholder", "Gözlemek")} + /> + navigate("/loan-orders/create")} />
{ setSearch(v); setPage(1) }} - searchPlaceholder={t('loanOrderMobiles.searchPlaceholder', 'Gözlemek')} + onSearchChange={(v) => { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("loanOrderMobiles.searchPlaceholder", "Gözlemek")} columns={toggleableColumns} columnVisibility={columnVisibility} onColumnVisibilityChange={setColumnVisibility} @@ -283,9 +276,10 @@ export default function LoanOrdersPage() { onFilterReset={handleFilterReset} perPageOptions={[10, 25, 50, 100]} perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('loanOrderMobiles.createButton', 'Karz sargyt dörediñ')} - onAction={() => navigate('/loan-orders/create')} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} />
- { if (!o) setDeleteId(null) }} - title={t('loanOrders.deleteConfirm', 'Bu sargyt pozulsynmy?')} - confirmLabel={t('common.delete', 'Poz')} + onOpenChange={(o) => { + if (!o) setDeleteId(null); + }} + title={t("loanOrders.deleteConfirm", "Bu sargyt pozulsynmy?")} onConfirm={confirmDelete} isLoading={deleteMutation.isPending} />
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/loanDepartment/loanPaidOffLetters/index.tsx b/src/pages/loanDepartment/loanPaidOffLetters/index.tsx index 6a86354..d87942d 100644 --- a/src/pages/loanDepartment/loanPaidOffLetters/index.tsx +++ b/src/pages/loanDepartment/loanPaidOffLetters/index.tsx @@ -6,9 +6,11 @@ import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; import { DataTable } from "@/components/dataTable"; import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; import { useLoanPaidOffLetters, useDeleteLoanPaidOffLetter } from "@/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters"; import type { LoanPaidOffLetter } from "@/features/loanPaidOffLetters/api/loanPaidOffLettersApi"; -import { ConfirmDialog } from "@/components/confirmDialog"; +import { DeleteDialog } from "@/components/deleteDialog"; // ─── Column IDs ──────────────────────────────────────────────────────────────── @@ -173,10 +175,25 @@ export default function LoanPaidOffLettersPage() { // ────────────────────────────────────────────────────────────────────────── return ( -
+
{/* Page Header */}
-

{t("loanPaidOffLetters.title", "Karzyň ýapylandygy barada güwanamalar")}

+

{t("loanPaidOffLetters.title", "Karzyň ýapylandygy barada güwanamalar")}

+
+ +
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> +
{/* Table Card */} @@ -205,8 +222,8 @@ export default function LoanPaidOffLettersPage() { setPerPage(v); setPage(1); }} - actionLabel={t("loanPaidOffLetters.createButton", "Karzyň ýapylandygy barada güwanama almak dörediň")} - onAction={handleCreate} + hideSearch + hideAction /> {/* Empty state OR table */} @@ -231,13 +248,12 @@ export default function LoanPaidOffLettersPage() { )}
- { if (!o) setDeleteId(null); }} title={t("loanPaidOffLetters.deleteConfirm", "Bu ýazgy pozulsynmy?")} - confirmLabel={t("common.delete", "Poz")} onConfirm={confirmDelete} isLoading={deleteMutation.isPending} /> diff --git a/src/pages/loanDepartment/loanRemaining/index.tsx b/src/pages/loanDepartment/loanRemaining/index.tsx index 26e27b5..13096dc 100644 --- a/src/pages/loanDepartment/loanRemaining/index.tsx +++ b/src/pages/loanDepartment/loanRemaining/index.tsx @@ -1,120 +1,111 @@ -import { useState, useMemo, useCallback } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2 } from 'lucide-react' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' +import { useState, useMemo, useCallback } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Eye, Pencil, Trash2 } from "lucide-react"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar' -import { useLoanRemaining, useDeleteLoanRemaining } from '@/features/loanRemaining/hooks/useLoanRemaining' -import type { LoanRemaining } from '@/features/loanRemaining/api/loanRemainingApi' -import { ConfirmDialog } from '@/components/confirmDialog' +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { useLoanRemaining, useDeleteLoanRemaining } from "@/features/loanRemaining/hooks/useLoanRemaining"; +import type { LoanRemaining } from "@/features/loanRemaining/api/loanRemainingApi"; +import { DeleteDialog } from "@/components/deleteDialog"; // ─── Column IDs ──────────────────────────────────────────────────────────────── -const COLUMN_IDS = ['id', 'passportSeries', 'passportNumber', 'loanAccount'] as const +const COLUMN_IDS = ["id", "passportSeries", "passportNumber", "loanAccount"] as const; // ─── Page Component ──────────────────────────────────────────────────────────── export default function LoanRemainingPage() { - const { t } = useTranslation() - const navigate = useNavigate() - const deleteMutation = useDeleteLoanRemaining() - const [deleteId, setDeleteId] = useState(null) + const { t } = useTranslation(); + const navigate = useNavigate(); + const deleteMutation = useDeleteLoanRemaining(); + const [deleteId, setDeleteId] = useState(null); // ── State ────────────────────────────────────────────────────────────────── - const [search, setSearch] = useState('') - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([...COLUMN_IDS]) - const [activeFilters, setActiveFilters] = useState([]) + const [search, setSearch] = useState(""); + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([...COLUMN_IDS]); + const [activeFilters, setActiveFilters] = useState([]); // ── Query ────────────────────────────────────────────────────────────────── - const queryParams = useMemo( - () => ({ search: search || undefined, page, perPage }), - [search, page, perPage], - ) + const queryParams = useMemo(() => ({ search: search || undefined, page, perPage }), [search, page, perPage]); - const { data, isLoading } = useLoanRemaining(queryParams) - const totalPages = data ? Math.ceil(data.total / perPage) : 1 + const { data, isLoading } = useLoanRemaining(queryParams); + const totalPages = data ? Math.ceil(data.total / perPage) : 1; // ── Handlers ─────────────────────────────────────────────────────────────── const handleFilterChange = useCallback((fieldId: string, value: string) => { - setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))) - setPage(1) - }, []) + setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))); + setPage(1); + }, []); const handleFilterReset = useCallback(() => { - setActiveFilters((prev) => prev.map((f) => ({ ...f, value: '' }))) - setPage(1) - }, []) + setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" }))); + setPage(1); + }, []); const handleDelete = useCallback((id: number) => { - setDeleteId(id) - }, []) + setDeleteId(id); + }, []); const confirmDelete = useCallback(() => { - if (deleteId === null) return - deleteMutation.mutate(deleteId) - setDeleteId(null) - }, [deleteId, deleteMutation]) + if (deleteId === null) return; + deleteMutation.mutate(deleteId); + setDeleteId(null); + }, [deleteId, deleteMutation]); // ── Columns ──────────────────────────────────────────────────────────────── const columns = useMemo[]>( () => [ { - id: 'id', - accessorKey: 'id', - header: t('loanRemaining.columns.id', 'ID'), - cell: ({ row }) => ( - {row.original.id} - ), + id: "id", + accessorKey: "id", + header: t("loanRemaining.columns.id", "ID"), + cell: ({ row }) => {row.original.id}, size: 80, }, { - id: 'passportSeries', - accessorKey: 'passportSeries', - header: t('loanRemaining.columns.passportSeries', 'PASPORT SERIÝASY'), - cell: ({ row }) => ( - {row.original.passportSeries} - ), + id: "passportSeries", + accessorKey: "passportSeries", + header: t("loanRemaining.columns.passportSeries", "PASPORT SERIÝASY"), + cell: ({ row }) => {row.original.passportSeries}, size: 160, }, { - id: 'passportNumber', - accessorKey: 'passportNumber', - header: t('loanRemaining.columns.passportNumber', 'PASPORT BELGISI'), - cell: ({ row }) => ( - {row.original.passportNumber} - ), + id: "passportNumber", + accessorKey: "passportNumber", + header: t("loanRemaining.columns.passportNumber", "PASPORT BELGISI"), + cell: ({ row }) => {row.original.passportNumber}, size: 140, }, { - id: 'loanAccount', - accessorKey: 'loanAccount', - header: t('loanRemaining.columns.loanAccount', 'KARZ HASABY'), - cell: ({ row }) => ( - {row.original.loanAccount} - ), + id: "loanAccount", + accessorKey: "loanAccount", + header: t("loanRemaining.columns.loanAccount", "KARZ HASABY"), + cell: ({ row }) => {row.original.loanAccount}, }, { - id: 'actions', - header: '', + id: "actions", + header: "", enableHiding: false, cell: ({ row }) => (
@@ -122,7 +113,7 @@ export default function LoanRemainingPage() { onClick={() => handleDelete(row.original.id)} disabled={deleteMutation.isPending} className="p-1.5 cursor-pointer rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50" - title={t('common.delete', 'Pozmak')} + title={t("common.delete", "Pozmak")} > @@ -132,32 +123,45 @@ export default function LoanRemainingPage() { }, ], [t, handleDelete, deleteMutation.isPending], - ) + ); // ── Toggleable columns meta ──────────────────────────────────────────────── - const toggleableColumns = useMemo( - () => COLUMN_IDS.map((id) => ({ id, label: t(`loanRemaining.columns.${id}`, id) })), - [t], - ) + const toggleableColumns = useMemo(() => COLUMN_IDS.map((id) => ({ id, label: t(`loanRemaining.columns.${id}`, id) })), [t]); - const filterFields = useMemo(() => [], []) + const filterFields = useMemo(() => [], []); // ────────────────────────────────────────────────────────────────────────── return ( -
+
{/* Page Header */}
-

- {t('loanRemaining.title', 'Karzyň galyndysy')} -

+

{t("loanRemaining.title", "Karzyň galyndysy")}

+
+ +
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/loan-remaining/create")} + />
{/* Table Card */}
{ setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} + onSearchChange={(v) => { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} columns={toggleableColumns} columnVisibility={columnVisibility} onColumnVisibilityChange={setColumnVisibility} @@ -169,11 +173,12 @@ export default function LoanRemainingPage() { onFilterReset={handleFilterReset} perPageOptions={[10, 25, 50, 100]} perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('loanRemaining.createButton', 'Karzyň galyndysy dörediň')} - onAction={() => { - navigate('/loan-remaining/create') + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); }} + hideSearch + hideAction />
- { if (!o) setDeleteId(null) }} - title={t('loanRemaining.deleteConfirm', 'Bu ýazgy pozulsynmy?')} - confirmLabel={t('common.delete', 'Poz')} + onOpenChange={(o) => { + if (!o) setDeleteId(null); + }} + title={t("loanRemaining.deleteConfirm", "Bu ýazgy pozulsynmy?")} onConfirm={confirmDelete} isLoading={deleteMutation.isPending} />
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/settings/card/cardTypes/index.tsx b/src/pages/settings/card/cardTypes/index.tsx index 8a1f1b3..1533457 100644 --- a/src/pages/settings/card/cardTypes/index.tsx +++ b/src/pages/settings/card/cardTypes/index.tsx @@ -1,108 +1,85 @@ -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' -import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import type { FilterField, ActiveFilter } from '@/components/dataTableToolbar' -import { useCardTypes, useDeleteCardType } from '@/features/cardTypes/hooks/useCardTypes' -import type { CardType } from '@/features/cardTypes/api/cardTypesApi' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from "lucide-react"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import type { FilterField, ActiveFilter } from "@/components/dataTableToolbar"; +import { useCardTypes, useDeleteCardType } from "@/features/cardTypes/hooks/useCardTypes"; +import type { CardType } from "@/features/cardTypes/api/cardTypesApi"; export function CardTypesListPage() { - const { t, i18n } = useTranslation() - const navigate = useNavigate() + const { t, i18n } = useTranslation(); + const navigate = useNavigate(); - const lang = (i18n.language?.slice(0, 2) ?? 'tk') as 'tk' | 'ru' | 'en' + const lang = (i18n.language?.slice(0, 2) ?? "tk") as "tk" | "ru" | "en"; - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [search, setSearch] = useState('') - const [activeFilters, setActiveFilters] = useState([ - { fieldId: 'isActive', value: '' }, - ]) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([ - 'id', 'name', 'value', 'description', 'isActive', 'actions', - ]) - const [deleteId, setDeleteId] = useState(null) + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [search, setSearch] = useState(""); + const [activeFilters, setActiveFilters] = useState([{ fieldId: "isActive", value: "" }]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState(["id", "name", "value", "description", "isActive", "actions"]); + const [deleteId, setDeleteId] = useState(null); - const deleteMutation = useDeleteCardType() - const isActiveFilter = activeFilters.find((f) => f.fieldId === 'isActive')?.value ?? '' + const deleteMutation = useDeleteCardType(); + const isActiveFilter = activeFilters.find((f) => f.fieldId === "isActive")?.value ?? ""; - const { data, isLoading } = useCardTypes({ page, perPage, search, isActive: isActiveFilter }) + const { data, isLoading } = useCardTypes({ page, perPage, search, isActive: isActiveFilter }); const filterFields: FilterField[] = [ { - id: 'isActive', - label: t('cardTypes.fields.isActive', 'Işjeň'), + id: "isActive", + label: t("cardTypes.fields.isActive", "Işjeň"), options: [ - { value: 'true', label: t('common.active', 'Işjeň') }, - { value: 'false', label: t('common.inactive', 'Işjeň däl') }, + { value: "true", label: t("common.active", "Işjeň") }, + { value: "false", label: t("common.inactive", "Işjeň däl") }, ], }, - ] + ]; const handleFilterChange = (fieldId: string, value: string) => { - setActiveFilters((prev) => - prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)) - ) - setPage(1) - } + setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))); + setPage(1); + }; const handleFilterReset = () => { - setActiveFilters([{ fieldId: 'isActive', value: '' }]) - setPage(1) - } + setActiveFilters([{ fieldId: "isActive", value: "" }]); + setPage(1); + }; const columns: ColumnDef[] = [ { - accessorKey: 'id', - header: t('common.id', 'ID'), - cell: ({ row }) => ( - {row.original.id} - ), + accessorKey: "id", + header: t("common.id", "ID"), + cell: ({ row }) => {row.original.id}, size: 70, }, { - accessorKey: 'name', - id: 'name', - header: t('cardTypes.fields.name', 'ADY').toUpperCase(), - cell: ({ row }) => ( - {row.original.name[lang]} - ), + accessorKey: "name", + id: "name", + header: t("cardTypes.fields.name", "ADY").toUpperCase(), + cell: ({ row }) => {row.original.name[lang]}, }, { - accessorKey: 'value', - header: t('cardTypes.fields.value', 'BAHA').toUpperCase(), - cell: ({ row }) => ( - {row.original.value} - ), + accessorKey: "value", + header: t("cardTypes.fields.value", "BAHA").toUpperCase(), + cell: ({ row }) => {row.original.value}, size: 120, }, { - accessorKey: 'description', - header: t('cardTypes.fields.description', 'BELLIKLER').toUpperCase(), - cell: ({ row }) => ( - - {row.original.description ?? '—'} - - ), + accessorKey: "description", + header: t("cardTypes.fields.description", "BELLIKLER").toUpperCase(), + cell: ({ row }) => {row.original.description ?? "—"}, }, { - accessorKey: 'isActive', - id: 'isActive', - header: t('cardTypes.fields.isActive', 'IŞJEŇ').toUpperCase(), + accessorKey: "isActive", + id: "isActive", + header: t("cardTypes.fields.isActive", "IŞJEŇ").toUpperCase(), cell: ({ row }) => row.original.isActive ? ( @@ -112,28 +89,28 @@ export function CardTypesListPage() { size: 100, }, { - id: 'actions', - header: '', + id: "actions", + header: "", cell: ({ row }) => (
@@ -143,103 +120,99 @@ export function CardTypesListPage() { enableHiding: false, size: 120, }, - ] + ]; const columnMeta = columns - .filter( - (c) => - c.id !== 'actions' && - (c as { accessorKey?: string }).accessorKey !== undefined - ) + .filter((c) => c.id !== "actions" && (c as { accessorKey?: string }).accessorKey !== undefined) .map((c) => ({ id: (c.id ?? (c as { accessorKey?: string }).accessorKey) as string, - label: - typeof c.header === 'string' - ? c.header - : (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ''), - })) + label: typeof c.header === "string" ? c.header : (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ""), + })); - const totalPages = data ? Math.ceil(data.total / perPage) : 1 + const totalPages = data ? Math.ceil(data.total / perPage) : 1; return ( -
+
{/* Header */}
- -

- {t('cardTypes.title', 'Kart görnüşleri')} -

+

{t("cardTypes.title", "Kart görnüşleri")}

-
+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/settings/card/card-types/create")} + /> +
+
+ {/* Toolbar */} + { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + filterFields={filterFields} + activeFilters={activeFilters} + onFilterChange={handleFilterChange} + onFilterReset={handleFilterReset} + perPage={perPage} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + hideSearch + hideAction + /> - {/* Toolbar */} - { setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - filterFields={filterFields} - activeFilters={activeFilters} - onFilterChange={handleFilterChange} - onFilterReset={handleFilterReset} - perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('cardTypes.actions.create', 'Kart görnüşi döretdiň')} - onAction={() => navigate('/settings/card/card-types/create')} - /> - - {/* Table */} - String(row.id)} - currentPage={page} - totalPages={totalPages} - totalCount={data?.total} - onPageChange={setPage} - /> -
+ {/* Table */} + String(row.id)} + currentPage={page} + totalPages={totalPages} + totalCount={data?.total} + onPageChange={setPage} + /> +
{/* Delete dialog */} - setDeleteId(null)}> - - - {t('common.confirmDelete', 'Öçürmegi tassyklaň')} - - {t('cardTypes.deleteConfirm', 'Bu kart görnüşini öçürmek isleýärsiňizmi?')} - - - - {t('common.cancel', 'Ýatyr')} - { - if (deleteId !== null) { - deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) }) - } - }} - > - {deleteMutation.isPending - ? t('common.deleting', 'Öçürilýär...') - : t('common.delete', 'Öçürmek')} - - - - + { + if (!o) setDeleteId(null); + }} + title={t("common.confirmDelete", "Öçürmegi tassyklaň")} + description={t("cardTypes.deleteConfirm", "Bu kart görnüşini öçürmek isleýärsiňizmi?")} + onConfirm={() => { + if (deleteId !== null) deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) }); + }} + isLoading={deleteMutation.isPending} + />
- ) + ); } -export default CardTypesListPage +export default CardTypesListPage; diff --git a/src/pages/settings/card/reasons/index.tsx b/src/pages/settings/card/reasons/index.tsx index 84ae842..d1d86b2 100644 --- a/src/pages/settings/card/reasons/index.tsx +++ b/src/pages/settings/card/reasons/index.tsx @@ -1,121 +1,96 @@ -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' -import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import type { FilterField, ActiveFilter } from '@/components/dataTableToolbar' -import { useCardReasons, useDeleteCardReason } from '@/features/cardReasons/hooks/useCardReasons' -import type { CardReason } from '@/features/cardReasons/api/cardReasonsApi' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from "lucide-react"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import type { FilterField, ActiveFilter } from "@/components/dataTableToolbar"; +import { useCardReasons, useDeleteCardReason } from "@/features/cardReasons/hooks/useCardReasons"; +import type { CardReason } from "@/features/cardReasons/api/cardReasonsApi"; // ─── CardReasonsListPage ─────────────────────────────────────────────────────── export function CardReasonsListPage() { - const { t, i18n } = useTranslation() - const navigate = useNavigate() + const { t, i18n } = useTranslation(); + const navigate = useNavigate(); - const lang = (i18n.language?.slice(0, 2) ?? 'tk') as 'tk' | 'ru' | 'en' + const lang = (i18n.language?.slice(0, 2) ?? "tk") as "tk" | "ru" | "en"; // ── Table state ───────────────────────────────────────────────────────────── - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [search, setSearch] = useState('') - const [activeFilters, setActiveFilters] = useState([ - { fieldId: 'isActive', value: '' }, - ]) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([ - 'id', 'name', 'value', 'description', 'isActive', 'actions', - ]) + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [search, setSearch] = useState(""); + const [activeFilters, setActiveFilters] = useState([{ fieldId: "isActive", value: "" }]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState(["id", "name", "value", "description", "isActive", "actions"]); // ── Delete dialog ──────────────────────────────────────────────────────────── - const [deleteId, setDeleteId] = useState(null) - const deleteMutation = useDeleteCardReason() + const [deleteId, setDeleteId] = useState(null); + const deleteMutation = useDeleteCardReason(); - const isActiveFilter = activeFilters.find((f) => f.fieldId === 'isActive')?.value ?? '' + const isActiveFilter = activeFilters.find((f) => f.fieldId === "isActive")?.value ?? ""; const { data, isLoading } = useCardReasons({ page, perPage, search, isActive: isActiveFilter, - }) + }); const filterFields: FilterField[] = [ { - id: 'isActive', - label: t('cardReasons.fields.isActive', 'Işjeň'), + id: "isActive", + label: t("cardReasons.fields.isActive", "Işjeň"), options: [ - { value: 'true', label: t('common.active', 'Işjeň') }, - { value: 'false', label: t('common.inactive', 'Işjeň däl') }, + { value: "true", label: t("common.active", "Işjeň") }, + { value: "false", label: t("common.inactive", "Işjeň däl") }, ], }, - ] + ]; const handleFilterChange = (fieldId: string, value: string) => { - setActiveFilters((prev) => - prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)) - ) - setPage(1) - } + setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))); + setPage(1); + }; const handleFilterReset = () => { - setActiveFilters([{ fieldId: 'isActive', value: '' }]) - setPage(1) - } + setActiveFilters([{ fieldId: "isActive", value: "" }]); + setPage(1); + }; // ── Columns ────────────────────────────────────────────────────────────────── const columns: ColumnDef[] = [ { - accessorKey: 'id', - header: t('common.id', 'ID'), - cell: ({ row }) => ( - - {row.original.id} - - ), + accessorKey: "id", + header: t("common.id", "ID"), + cell: ({ row }) => {row.original.id}, size: 70, }, { - accessorKey: 'name', - id: 'name', - header: t('cardReasons.fields.name', 'ADY').toUpperCase(), - cell: ({ row }) => ( - {row.original.name[lang]} - ), + accessorKey: "name", + id: "name", + header: t("cardReasons.fields.name", "ADY").toUpperCase(), + cell: ({ row }) => {row.original.name[lang]}, }, { - accessorKey: 'value', - header: t('cardReasons.fields.value', 'BAHA').toUpperCase(), - cell: ({ row }) => ( - {row.original.value} - ), + accessorKey: "value", + header: t("cardReasons.fields.value", "BAHA").toUpperCase(), + cell: ({ row }) => {row.original.value}, size: 120, }, { - accessorKey: 'description', - header: t('cardReasons.fields.description', 'BELLIKLER').toUpperCase(), - cell: ({ row }) => ( - - {row.original.description ?? '—'} - - ), + accessorKey: "description", + header: t("cardReasons.fields.description", "BELLIKLER").toUpperCase(), + cell: ({ row }) => {row.original.description ?? "—"}, }, { - accessorKey: 'isActive', - id: 'isActive', - header: t('cardReasons.fields.isActive', 'IŞJEŇ').toUpperCase(), + accessorKey: "isActive", + id: "isActive", + header: t("cardReasons.fields.isActive", "IŞJEŇ").toUpperCase(), cell: ({ row }) => row.original.isActive ? ( @@ -125,28 +100,28 @@ export function CardReasonsListPage() { size: 100, }, { - id: 'actions', - header: '', + id: "actions", + header: "", cell: ({ row }) => (
@@ -156,100 +131,99 @@ export function CardReasonsListPage() { enableHiding: false, size: 120, }, - ] + ]; const columnMeta = columns - .filter((c) => c.id !== 'actions' && (c as { accessorKey?: string }).accessorKey !== undefined) + .filter((c) => c.id !== "actions" && (c as { accessorKey?: string }).accessorKey !== undefined) .map((c) => ({ id: (c.id ?? (c as { accessorKey?: string }).accessorKey) as string, - label: - typeof c.header === 'string' - ? c.header - : (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ''), - })) + label: typeof c.header === "string" ? c.header : (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ""), + })); - const totalPages = data ? Math.ceil(data.total / perPage) : 1 + const totalPages = data ? Math.ceil(data.total / perPage) : 1; return ( -
+
{/* Header */}
-

- {t('cardReasons.title', 'Kartyň çykarylmagynyň sebäpleri')} -

+

{t("cardReasons.title", "Kartyň çykarylmagynyň sebäpleri")}

-
+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/settings/card/card-reasons/create")} + /> +
+
+ {/* Toolbar */} + { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + filterFields={filterFields} + activeFilters={activeFilters} + onFilterChange={handleFilterChange} + onFilterReset={handleFilterReset} + perPage={perPage} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + hideSearch + hideAction + /> - {/* Toolbar */} - { setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - filterFields={filterFields} - activeFilters={activeFilters} - onFilterChange={handleFilterChange} - onFilterReset={handleFilterReset} - perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('cardReasons.actions.create', 'Kartyň çykarylmagynyň sebäbini döretdiň')} - onAction={() => navigate('/settings/card/card-reasons/create')} - /> - - {/* Table */} - String(row.id)} - currentPage={page} - totalPages={totalPages} - totalCount={data?.total} - onPageChange={setPage} - /> -
+ {/* Table */} + String(row.id)} + currentPage={page} + totalPages={totalPages} + totalCount={data?.total} + onPageChange={setPage} + /> +
{/* Delete dialog */} - setDeleteId(null)}> - - - - {t('common.confirmDelete', 'Öçürmegi tassyklaň')} - - - {t('cardReasons.deleteConfirm', 'Bu kartyň çykarylmagynyň sebäbini öçürmek isleýärsiňizmi?')} - - - - {t('common.cancel', 'Ýatyr')} - { - if (deleteId !== null) { - deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) }) - } - }} - > - {deleteMutation.isPending - ? t('common.deleting', 'Öçürilýär...') - : t('common.delete', 'Öçürmek')} - - - - + { + if (!o) setDeleteId(null); + }} + title={t("common.confirmDelete", "Öçürmegi tassyklaň")} + description={t("cardReasons.deleteConfirm", "Bu kartyň çykarylmagynyň sebäbini öçürmek isleýärsiňizmi?")} + onConfirm={() => { + if (deleteId !== null) deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) }); + }} + isLoading={deleteMutation.isPending} + />
- ) + ); } -export default CardReasonsListPage +export default CardReasonsListPage; diff --git a/src/pages/settings/loan/loanTypes/index.tsx b/src/pages/settings/loan/loanTypes/index.tsx index 3965ea8..935fd9b 100644 --- a/src/pages/settings/loan/loanTypes/index.tsx +++ b/src/pages/settings/loan/loanTypes/index.tsx @@ -1,81 +1,62 @@ // pages/LoanTypesListPage.tsx -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react' -import { DataTable, type ColumnDef } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import { useGetLoanTypes, useDeleteLoanType } from '@/features/loanTypes/hooks/useLoanTypes' -import type { LoanType } from '@/features/loanTypes/api/loanTypesApi' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '@/components/ui/alert-dialog' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from "lucide-react"; +import { DataTable, type ColumnDef } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { useGetLoanTypes, useDeleteLoanType } from "@/features/loanTypes/hooks/useLoanTypes"; +import type { LoanType } from "@/features/loanTypes/api/loanTypesApi"; +import { DeleteDialog } from "@/components/deleteDialog"; // ─── Column definitions ─────────────────────────────────────────────────────── function useLoanTypeColumns( onView: (id: number) => void, onEdit: (id: number) => void, - onDelete: (id: number) => void + onDelete: (id: number) => void, ): ColumnDef[] { - const { t, i18n } = useTranslation() - const lang = (i18n.language ?? 'tk') as 'tk' | 'ru' | 'en' + const { t, i18n } = useTranslation(); + const lang = (i18n.language ?? "tk") as "tk" | "ru" | "en"; return [ { - accessorKey: 'id', - header: t('common.id', 'ID'), + accessorKey: "id", + header: t("common.id", "ID"), size: 60, - cell: ({ row }) => ( - {row.original.id} - ), + cell: ({ row }) => {row.original.id}, }, { - accessorKey: 'name', - header: t('loanTypes.columns.name', 'ADY'), - cell: ({ row }) => ( - {row.original.name[lang]} - ), + accessorKey: "name", + header: t("loanTypes.columns.name", "ADY"), + cell: ({ row }) => {row.original.name[lang]}, }, { - accessorKey: 'tax', - header: t('loanTypes.columns.tax', 'SALGYT'), + accessorKey: "tax", + header: t("loanTypes.columns.tax", "SALGYT"), size: 90, - cell: ({ row }) => ( - {row.original.tax} - ), + cell: ({ row }) => {row.original.tax}, }, { - accessorKey: 'loanTerm', - header: t('loanTypes.columns.loanTerm', 'KARZ MÖHLETI'), + accessorKey: "loanTerm", + header: t("loanTypes.columns.loanTerm", "KARZ MÖHLETI"), size: 130, - cell: ({ row }) => ( - {row.original.loanTerm} - ), + cell: ({ row }) => {row.original.loanTerm}, }, { - accessorKey: 'notes', - header: t('loanTypes.columns.notes', 'BELLIKLER'), + accessorKey: "notes", + header: t("loanTypes.columns.notes", "BELLIKLER"), cell: ({ row }) => { - const notes = row.original.notes - return ( - - {notes ? notes[lang] || '—' : '—'} - - ) + const notes = row.original.notes; + return {notes ? notes[lang] || "—" : "—"}; }, }, { - accessorKey: 'isActive', - header: t('loanTypes.columns.isActive', 'IŞJEŇ'), + accessorKey: "isActive", + header: t("loanTypes.columns.isActive", "IŞJEŇ"), size: 80, cell: ({ row }) => row.original.isActive ? ( @@ -85,8 +66,8 @@ function useLoanTypeColumns( ), }, { - id: 'actions', - header: '', + id: "actions", + header: "", size: 120, enableSorting: false, cell: ({ row }) => ( @@ -94,128 +75,128 @@ function useLoanTypeColumns(
), }, - ] + ]; } // ─── LoanTypesListPage ──────────────────────────────────────────────────────── export default function LoanTypesListPage() { - const { t } = useTranslation() - const navigate = useNavigate() + const { t } = useTranslation(); + const navigate = useNavigate(); - const [page, setPage] = useState(1) - const [perPage] = useState(25) - const [search, setSearch] = useState('') - const [deleteId, setDeleteId] = useState(null) + const [page, setPage] = useState(1); + const [perPage] = useState(25); + const [search, setSearch] = useState(""); + const [deleteId, setDeleteId] = useState(null); - const [columnVisibility, setColumnVisibility] = useState>({}) - const [columnOrder, setColumnOrder] = useState([]) + const [columnVisibility, setColumnVisibility] = useState>({}); + const [columnOrder, setColumnOrder] = useState([]); - const { data, isLoading } = useGetLoanTypes({ page, perPage, search }) - const deleteMutation = useDeleteLoanType() + const { data, isLoading } = useGetLoanTypes({ page, perPage, search }); + const deleteMutation = useDeleteLoanType(); - const handleView = (id: number) => navigate(`/settings/loan/loan-types/${id}`) - const handleEdit = (id: number) => navigate(`/settings/loan/loan-types/${id}/edit`) - const handleDelete = (id: number) => setDeleteId(id) + const handleView = (id: number) => navigate(`/settings/loan/loan-types/${id}`); + const handleEdit = (id: number) => navigate(`/settings/loan/loan-types/${id}/edit`); + const handleDelete = (id: number) => setDeleteId(id); const confirmDelete = async () => { - if (deleteId === null) return - await deleteMutation.mutateAsync(deleteId) - setDeleteId(null) - } + if (deleteId === null) return; + await deleteMutation.mutateAsync(deleteId); + setDeleteId(null); + }; - const columns = useLoanTypeColumns(handleView, handleEdit, handleDelete) + const columns = useLoanTypeColumns(handleView, handleEdit, handleDelete); const columnMeta = columns - .filter((c) => c.id !== 'actions' && 'accessorKey' in c) + .filter((c) => c.id !== "actions" && "accessorKey" in c) .map((c) => ({ - id: 'accessorKey' in c ? String(c.accessorKey) : String(c.id), - label: typeof c.header === 'string' ? c.header : String(c.id ?? ''), - })) + id: "accessorKey" in c ? String(c.accessorKey) : String(c.id), + label: typeof c.header === "string" ? c.header : String(c.id ?? ""), + })); return ( -
- +
+

{t("loanTypes.title", "Karz görnüşleri")}

+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/settings/loan/loan-types/create")} + /> +
+
+ { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + hideSearch + hideAction + /> -

- {t('loanTypes.title', 'Karz görnüşleri')} -

-
- - { setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - actionLabel={t('loanTypes.actions.create', 'Karz görnüşi dörediň')} - onAction={() => navigate('/settings/loan/loan-types/create')} - /> - - - columns={columns} - data={data?.data ?? []} - isLoading={isLoading} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - enableRowSelection - getRowId={(row) => String(row.id)} - currentPage={page} - totalPages={data?.totalPages ?? 1} - totalCount={data?.total} - onPageChange={setPage} - /> -
+ + columns={columns} + data={data?.data ?? []} + isLoading={isLoading} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + enableRowSelection + getRowId={(row) => String(row.id)} + currentPage={page} + totalPages={data?.totalPages ?? 1} + totalCount={data?.total} + onPageChange={setPage} + /> +
{/* Delete confirmation dialog */} - !open && setDeleteId(null)}> - - - {t('loanTypes.deleteDialog.title', 'Pozmak')} - - {t('loanTypes.deleteDialog.description', 'Bu karz görnüşini pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylyp bilinmez.')} - - - - - {t('common.cancel', 'Ýatyr')} - - - {deleteMutation.isPending ? t('common.deleting', 'Pozulýar...') : t('common.delete', 'Pozmak')} - - - - + { + if (!o) setDeleteId(null); + }} + title={t("loanTypes.deleteDialog.title", "Pozmak")} + description={t("loanTypes.deleteDialog.description", "Bu karz görnüşini pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylyp bilinmez.")} + onConfirm={confirmDelete} + isLoading={deleteMutation.isPending} + />
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/settings/loan/requiredDocuments/index.tsx b/src/pages/settings/loan/requiredDocuments/index.tsx index 3e1ac34..953c1f5 100644 --- a/src/pages/settings/loan/requiredDocuments/index.tsx +++ b/src/pages/settings/loan/requiredDocuments/index.tsx @@ -1,53 +1,55 @@ -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2 } from 'lucide-react' -import { DataTable, type ColumnDef } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import { useGetRequiredDocuments, useDeleteRequiredDocument } from '@/features/requiredDocuments/hooks/useRequiredDocuments' -import type { LoanDocument } from '@/features/requiredDocuments/api/requiredDocumentsApi' -import type { VisibilityState } from '@tanstack/react-table' -import { ConfirmDialog } from '@/components/confirmDialog' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Eye, Pencil, Trash2 } from "lucide-react"; +import { DataTable, type ColumnDef } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { useGetRequiredDocuments, useDeleteRequiredDocument } from "@/features/requiredDocuments/hooks/useRequiredDocuments"; +import type { LoanDocument } from "@/features/requiredDocuments/api/requiredDocumentsApi"; +import type { VisibilityState } from "@tanstack/react-table"; +import { DeleteDialog } from "@/components/deleteDialog"; // ─── Column visibility defaults ─────────────────────────────────────────────── -const DEFAULT_VISIBILITY: VisibilityState = {} -const DEFAULT_ORDER = ['id', 'name', 'actions'] +const DEFAULT_VISIBILITY: VisibilityState = {}; +const DEFAULT_ORDER = ["id", "name", "actions"]; export default function RequiredDocumentsListPage() { - const { t, i18n } = useTranslation() - const navigate = useNavigate() + const { t, i18n } = useTranslation(); + const navigate = useNavigate(); - const lang = (i18n.language?.slice(0, 2) ?? 'tk') as 'tk' | 'ru' | 'en' + const lang = (i18n.language?.slice(0, 2) ?? "tk") as "tk" | "ru" | "en"; // ── Table state ───────────────────────────────────────────────────────────── - const [search, setSearch] = useState('') - const [page, setPage] = useState(1) - const [perPage] = useState(10) - const [columnVisibility, setColumnVisibility] = useState(DEFAULT_VISIBILITY) - const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER) + const [search, setSearch] = useState(""); + const [page, setPage] = useState(1); + const [perPage] = useState(10); + const [columnVisibility, setColumnVisibility] = useState(DEFAULT_VISIBILITY); + const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER); // ── Data ──────────────────────────────────────────────────────────────────── - const { data, isLoading } = useGetRequiredDocuments({ page, perPage, search }) - const deleteMutation = useDeleteRequiredDocument() - const [deleteId, setDeleteId] = useState(null) + const { data, isLoading } = useGetRequiredDocuments({ page, perPage, search }); + const deleteMutation = useDeleteRequiredDocument(); + const [deleteId, setDeleteId] = useState(null); const handleDelete = (id: number) => { - setDeleteId(id) - } + setDeleteId(id); + }; const confirmDelete = () => { - if (deleteId === null) return - deleteMutation.mutate(deleteId) - setDeleteId(null) - } + if (deleteId === null) return; + deleteMutation.mutate(deleteId); + setDeleteId(null); + }; // ── Columns ───────────────────────────────────────────────────────────────── const columns: ColumnDef[] = [ { - id: 'id', - accessorKey: 'id', - header: t('common.id', 'ID'), + id: "id", + accessorKey: "id", + header: t("common.id", "ID"), size: 72, cell: ({ row }) => ( row.name[lang], - cell: ({ row }) => ( - {row.original.name[lang]} - ), + cell: ({ row }) => {row.original.name[lang]}, }, { - id: 'actions', - header: '', + id: "actions", + header: "", size: 100, enableSorting: false, cell: ({ row }) => ( @@ -76,14 +76,14 @@ export default function RequiredDocumentsListPage() { @@ -91,67 +91,82 @@ export default function RequiredDocumentsListPage() { onClick={() => handleDelete(row.original.id)} disabled={deleteMutation.isPending} className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors" - title={t('common.delete', 'Öçür')} + title={t("common.delete", "Öçür")} >
), }, - ] + ]; const columnMetas = columns - .filter((c) => c.id !== 'actions' && c.id !== 'select') - .map((c) => ({ id: c.id as string, label: typeof c.header === 'string' ? c.header : c.id as string })) + .filter((c) => c.id !== "actions" && c.id !== "select") + .map((c) => ({ id: c.id as string, label: typeof c.header === "string" ? c.header : (c.id as string) })); return ( -
+
{/* Page heading */} -

- {t('loanDocuments.title', 'Karz gerekli resminamalary')} -

-
+

{t("loanDocuments.title", "Karz gerekli resminamalary")}

+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/settings/loan/required-documents/create")} + /> +
+
+ {/* Toolbar */} + { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} + columns={columnMetas} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + hideSearch + hideAction + /> - {/* Toolbar */} - { setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} - columns={columnMetas} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - actionLabel={t('loanDocuments.createBtn', 'Karz gerekli resminamalary döretiň')} - onAction={() => navigate('/settings/loan/required-documents/create')} - /> + {/* Table */} + String(row.id)} + enableRowSelection + currentPage={page} + totalPages={data?.totalPages ?? 1} + totalCount={data?.total} + onPageChange={setPage} + /> - {/* Table */} - String(row.id)} - enableRowSelection - currentPage={page} - totalPages={data?.totalPages ?? 1} - totalCount={data?.total} - onPageChange={setPage} - /> - - { if (!o) setDeleteId(null) }} - title={t('loanDocuments.deleteConfirm', 'Bu resminamany öçürmek isleýärsiňizmi?')} - confirmLabel={t('common.delete', 'Poz')} - onConfirm={confirmDelete} - isLoading={deleteMutation.isPending} - /> + { + if (!o) setDeleteId(null); + }} + title={t("loanDocuments.deleteConfirm", "Bu resminamany öçürmek isleýärsiňizmi?")} + onConfirm={confirmDelete} + isLoading={deleteMutation.isPending} + /> +
-
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/settings/location/branches/index.tsx b/src/pages/settings/location/branches/index.tsx index cdb9322..679467c 100644 --- a/src/pages/settings/location/branches/index.tsx +++ b/src/pages/settings/location/branches/index.tsx @@ -1,132 +1,111 @@ -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' -import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import type { FilterField, ActiveFilter } from '@/components/dataTableToolbar' -import { useBranches, useDeleteBranch } from '@/features/branches/hooks/useBranches' -import type { Branch } from '@/features/branches/api/branchesApi' -import { getDistrictOptions } from '@/features/branches/api/branchesApi' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from "lucide-react"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import type { FilterField, ActiveFilter } from "@/components/dataTableToolbar"; +import { useBranches, useDeleteBranch } from "@/features/branches/hooks/useBranches"; +import type { Branch } from "@/features/branches/api/branchesApi"; +import { getDistrictOptions } from "@/features/branches/api/branchesApi"; export function BranchesListPage() { - const { t, i18n } = useTranslation() - const navigate = useNavigate() + const { t, i18n } = useTranslation(); + const navigate = useNavigate(); - const lang = (i18n.language?.slice(0, 2) ?? 'tk') as 'tk' | 'ru' | 'en' + const lang = (i18n.language?.slice(0, 2) ?? "tk") as "tk" | "ru" | "en"; - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [search, setSearch] = useState('') + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [search, setSearch] = useState(""); const [activeFilters, setActiveFilters] = useState([ - { fieldId: 'isActive', value: '' }, - { fieldId: 'districtId', value: '' }, - ]) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([ - 'id', 'code', 'name', 'districtName', 'phone', 'isActive', 'actions', - ]) - const [deleteId, setDeleteId] = useState(null) + { fieldId: "isActive", value: "" }, + { fieldId: "districtId", value: "" }, + ]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState(["id", "code", "name", "districtName", "phone", "isActive", "actions"]); + const [deleteId, setDeleteId] = useState(null); - const deleteMutation = useDeleteBranch() - const isActiveFilter = activeFilters.find((f) => f.fieldId === 'isActive')?.value ?? '' - const districtIdFilter = activeFilters.find((f) => f.fieldId === 'districtId')?.value ?? '' + const deleteMutation = useDeleteBranch(); + const isActiveFilter = activeFilters.find((f) => f.fieldId === "isActive")?.value ?? ""; + const districtIdFilter = activeFilters.find((f) => f.fieldId === "districtId")?.value ?? ""; - const { data, isLoading } = useBranches({ page, perPage, search, isActive: isActiveFilter, districtId: districtIdFilter }) + const { data, isLoading } = useBranches({ page, perPage, search, isActive: isActiveFilter, districtId: districtIdFilter }); const districtOptions = getDistrictOptions().map((d) => ({ value: String(d.id), label: d.name[lang], - })) + })); const filterFields: FilterField[] = [ { - id: 'isActive', - label: t('branches.fields.isActive', 'Işjeň'), + id: "isActive", + label: t("branches.fields.isActive", "Işjeň"), options: [ - { value: 'true', label: t('common.active', 'Işjeň') }, - { value: 'false', label: t('common.inactive', 'Işjeň däl') }, + { value: "true", label: t("common.active", "Işjeň") }, + { value: "false", label: t("common.inactive", "Işjeň däl") }, ], }, { - id: 'districtId', - label: t('branches.fields.district', 'Etrap'), + id: "districtId", + label: t("branches.fields.district", "Etrap"), options: districtOptions, }, - ] + ]; const handleFilterChange = (fieldId: string, value: string) => { - setActiveFilters((prev) => - prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)) - ) - setPage(1) - } + setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))); + setPage(1); + }; const handleFilterReset = () => { setActiveFilters([ - { fieldId: 'isActive', value: '' }, - { fieldId: 'districtId', value: '' }, - ]) - setPage(1) - } + { fieldId: "isActive", value: "" }, + { fieldId: "districtId", value: "" }, + ]); + setPage(1); + }; const columns: ColumnDef[] = [ { - accessorKey: 'id', - header: t('common.id', 'ID'), - cell: ({ row }) => ( - {row.original.id} - ), + accessorKey: "id", + header: t("common.id", "ID"), + cell: ({ row }) => {row.original.id}, size: 70, }, { - accessorKey: 'code', - id: 'code', - header: t('branches.fields.code', 'KOD').toUpperCase(), - cell: ({ row }) => ( - {row.original.code} - ), + accessorKey: "code", + id: "code", + header: t("branches.fields.code", "KOD").toUpperCase(), + cell: ({ row }) => {row.original.code}, size: 100, }, { - accessorKey: 'name', - id: 'name', - header: t('branches.fields.name', 'ADY').toUpperCase(), - cell: ({ row }) => ( - {row.original.name[lang]} - ), + accessorKey: "name", + id: "name", + header: t("branches.fields.name", "ADY").toUpperCase(), + cell: ({ row }) => {row.original.name[lang]}, }, { - accessorKey: 'districtName', - id: 'districtName', - header: t('branches.fields.district', 'ETRAP').toUpperCase(), - cell: ({ row }) => ( - {row.original.districtName[lang]} - ), + accessorKey: "districtName", + id: "districtName", + header: t("branches.fields.district", "ETRAP").toUpperCase(), + cell: ({ row }) => {row.original.districtName[lang]}, }, { - accessorKey: 'phone', - header: t('branches.fields.phone', 'TELEFON').toUpperCase(), - cell: ({ row }) => ( - {row.original.phone} - ), + accessorKey: "phone", + header: t("branches.fields.phone", "TELEFON").toUpperCase(), + cell: ({ row }) => {row.original.phone}, size: 150, }, { - accessorKey: 'isActive', - id: 'isActive', - header: t('branches.fields.isActive', 'IŞJEŇ').toUpperCase(), + accessorKey: "isActive", + id: "isActive", + header: t("branches.fields.isActive", "IŞJEŇ").toUpperCase(), cell: ({ row }) => row.original.isActive ? ( @@ -136,28 +115,28 @@ export function BranchesListPage() { size: 100, }, { - id: 'actions', - header: '', + id: "actions", + header: "", cell: ({ row }) => (
@@ -167,99 +146,97 @@ export function BranchesListPage() { enableHiding: false, size: 120, }, - ] + ]; const columnMeta = columns - .filter( - (c) => - c.id !== 'actions' && - (c as { accessorKey?: string }).accessorKey !== undefined - ) + .filter((c) => c.id !== "actions" && (c as { accessorKey?: string }).accessorKey !== undefined) .map((c) => ({ id: (c.id ?? (c as { accessorKey?: string }).accessorKey) as string, - label: - typeof c.header === 'string' - ? c.header - : (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ''), - })) + label: typeof c.header === "string" ? c.header : (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ""), + })); - const totalPages = data ? Math.ceil(data.total / perPage) : 1 + const totalPages = data ? Math.ceil(data.total / perPage) : 1; return ( -
+
- -

- {t('branches.title', 'Şahamçalar')} -

+

{t("branches.title", "Şahamçalar")}

-
+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/settings/location/branches/create")} + /> +
+
+ { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + filterFields={filterFields} + activeFilters={activeFilters} + onFilterChange={handleFilterChange} + onFilterReset={handleFilterReset} + perPage={perPage} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + hideSearch + hideAction + /> - { setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - filterFields={filterFields} - activeFilters={activeFilters} - onFilterChange={handleFilterChange} - onFilterReset={handleFilterReset} - perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('branches.actions.create', 'Şahamça döret')} - onAction={() => navigate('/settings/location/branches/create')} + String(row.id)} + currentPage={page} + totalPages={totalPages} + totalCount={data?.total} + onPageChange={setPage} + /> +
+ + { + if (!o) setDeleteId(null); + }} + title={t("common.confirmDelete", "Öçürmegi tassyklaň")} + description={t("branches.deleteConfirm", "Bu şahamçany öçürmek isleýärsiňizmi?")} + onConfirm={() => { + if (deleteId !== null) { + deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) }); + } + }} + isLoading={deleteMutation.isPending} /> - - String(row.id)} - currentPage={page} - totalPages={totalPages} - totalCount={data?.total} - onPageChange={setPage} - /> -
- - setDeleteId(null)}> - - - {t('common.confirmDelete', 'Öçürmegi tassyklaň')} - - {t('branches.deleteConfirm', 'Bu şahamçany öçürmek isleýärsiňizmi?')} - - - - {t('common.cancel', 'Ýatyr')} - { - if (deleteId !== null) { - deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) }) - } - }} - > - {deleteMutation.isPending - ? t('common.deleting', 'Öçürilýär...') - : t('common.delete', 'Öçürmek')} - - - -
- ) + ); } -export default BranchesListPage +export default BranchesListPage; diff --git a/src/pages/settings/location/districts/index.tsx b/src/pages/settings/location/districts/index.tsx index 1db973c..3abdd76 100644 --- a/src/pages/settings/location/districts/index.tsx +++ b/src/pages/settings/location/districts/index.tsx @@ -1,100 +1,79 @@ -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' -import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import type { FilterField, ActiveFilter } from '@/components/dataTableToolbar' -import { useDistricts, useDeleteDistrict } from '@/features/districts/hooks/useDistricts' -import type { District } from '@/features/districts/api/districtsApi' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from "lucide-react"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import type { FilterField, ActiveFilter } from "@/components/dataTableToolbar"; +import { useDistricts, useDeleteDistrict } from "@/features/districts/hooks/useDistricts"; +import type { District } from "@/features/districts/api/districtsApi"; export function DistrictsListPage() { - const { t, i18n } = useTranslation() - const navigate = useNavigate() + const { t, i18n } = useTranslation(); + const navigate = useNavigate(); - const lang = (i18n.language?.slice(0, 2) ?? 'tk') as 'tk' | 'ru' | 'en' + const lang = (i18n.language?.slice(0, 2) ?? "tk") as "tk" | "ru" | "en"; - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [search, setSearch] = useState('') - const [activeFilters, setActiveFilters] = useState([ - { fieldId: 'isActive', value: '' }, - ]) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([ - 'id', 'name', 'description', 'isActive', 'actions', - ]) - const [deleteId, setDeleteId] = useState(null) + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [search, setSearch] = useState(""); + const [activeFilters, setActiveFilters] = useState([{ fieldId: "isActive", value: "" }]); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState(["id", "name", "description", "isActive", "actions"]); + const [deleteId, setDeleteId] = useState(null); - const deleteMutation = useDeleteDistrict() - const isActiveFilter = activeFilters.find((f) => f.fieldId === 'isActive')?.value ?? '' + const deleteMutation = useDeleteDistrict(); + const isActiveFilter = activeFilters.find((f) => f.fieldId === "isActive")?.value ?? ""; - const { data, isLoading } = useDistricts({ page, perPage, search, isActive: isActiveFilter }) + const { data, isLoading } = useDistricts({ page, perPage, search, isActive: isActiveFilter }); const filterFields: FilterField[] = [ { - id: 'isActive', - label: t('districts.fields.isActive', 'Işjeň'), + id: "isActive", + label: t("districts.fields.isActive", "Işjeň"), options: [ - { value: 'true', label: t('common.active', 'Işjeň') }, - { value: 'false', label: t('common.inactive', 'Işjeň däl') }, + { value: "true", label: t("common.active", "Işjeň") }, + { value: "false", label: t("common.inactive", "Işjeň däl") }, ], }, - ] + ]; const handleFilterChange = (fieldId: string, value: string) => { - setActiveFilters((prev) => - prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)) - ) - setPage(1) - } + setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))); + setPage(1); + }; const handleFilterReset = () => { - setActiveFilters([{ fieldId: 'isActive', value: '' }]) - setPage(1) - } + setActiveFilters([{ fieldId: "isActive", value: "" }]); + setPage(1); + }; const columns: ColumnDef[] = [ { - accessorKey: 'id', - header: t('common.id', 'ID'), - cell: ({ row }) => ( - {row.original.id} - ), + accessorKey: "id", + header: t("common.id", "ID"), + cell: ({ row }) => {row.original.id}, size: 70, }, { - accessorKey: 'name', - id: 'name', - header: t('districts.fields.name', 'ADY').toUpperCase(), - cell: ({ row }) => ( - {row.original.name[lang]} - ), + accessorKey: "name", + id: "name", + header: t("districts.fields.name", "ADY").toUpperCase(), + cell: ({ row }) => {row.original.name[lang]}, }, { - accessorKey: 'description', - header: t('districts.fields.description', 'BELLIKLER').toUpperCase(), - cell: ({ row }) => ( - - {row.original.description ?? '—'} - - ), + accessorKey: "description", + header: t("districts.fields.description", "BELLIKLER").toUpperCase(), + cell: ({ row }) => {row.original.description ?? "—"}, }, { - accessorKey: 'isActive', - id: 'isActive', - header: t('districts.fields.isActive', 'IŞJEŇ').toUpperCase(), + accessorKey: "isActive", + id: "isActive", + header: t("districts.fields.isActive", "IŞJEŇ").toUpperCase(), cell: ({ row }) => row.original.isActive ? ( @@ -104,28 +83,28 @@ export function DistrictsListPage() { size: 100, }, { - id: 'actions', - header: '', + id: "actions", + header: "", cell: ({ row }) => (
@@ -135,99 +114,97 @@ export function DistrictsListPage() { enableHiding: false, size: 120, }, - ] + ]; const columnMeta = columns - .filter( - (c) => - c.id !== 'actions' && - (c as { accessorKey?: string }).accessorKey !== undefined - ) + .filter((c) => c.id !== "actions" && (c as { accessorKey?: string }).accessorKey !== undefined) .map((c) => ({ id: (c.id ?? (c as { accessorKey?: string }).accessorKey) as string, - label: - typeof c.header === 'string' - ? c.header - : (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ''), - })) + label: typeof c.header === "string" ? c.header : (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ""), + })); - const totalPages = data ? Math.ceil(data.total / perPage) : 1 + const totalPages = data ? Math.ceil(data.total / perPage) : 1; return ( -
+
- -

- {t('districts.title', 'Etraplar')} -

+

{t("districts.title", "Etraplar")}

-
+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("common.search", "Gözlemek")} + /> + navigate("/settings/location/districts/create")} + /> +
+
+ { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("common.search", "Gözlemek")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + filterFields={filterFields} + activeFilters={activeFilters} + onFilterChange={handleFilterChange} + onFilterReset={handleFilterReset} + perPage={perPage} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + hideSearch + hideAction + /> - { setSearch(v); setPage(1) }} - searchPlaceholder={t('common.search', 'Gözlemek')} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - filterFields={filterFields} - activeFilters={activeFilters} - onFilterChange={handleFilterChange} - onFilterReset={handleFilterReset} - perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('districts.actions.create', 'Etrap döret')} - onAction={() => navigate('/settings/location/districts/create')} + String(row.id)} + currentPage={page} + totalPages={totalPages} + totalCount={data?.total} + onPageChange={setPage} + /> +
+ + { + if (!o) setDeleteId(null); + }} + title={t("common.confirmDelete", "Öçürmegi tassyklaň")} + description={t("districts.deleteConfirm", "Bu etrapy öçürmek isleýärsiňizmi?")} + onConfirm={() => { + if (deleteId !== null) { + deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) }); + } + }} + isLoading={deleteMutation.isPending} /> - - String(row.id)} - currentPage={page} - totalPages={totalPages} - totalCount={data?.total} - onPageChange={setPage} - /> -
- - setDeleteId(null)}> - - - {t('common.confirmDelete', 'Öçürmegi tassyklaň')} - - {t('districts.deleteConfirm', 'Bu etrapy öçürmek isleýärsiňizmi?')} - - - - {t('common.cancel', 'Ýatyr')} - { - if (deleteId !== null) { - deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) }) - } - }} - > - {deleteMutation.isPending - ? t('common.deleting', 'Öçürilýär...') - : t('common.delete', 'Öçürmek')} - - - -
- ) + ); } -export default DistrictsListPage +export default DistrictsListPage; diff --git a/src/pages/settings/users/permissions/index.tsx b/src/pages/settings/users/permissions/index.tsx index 890dec4..67687f8 100644 --- a/src/pages/settings/users/permissions/index.tsx +++ b/src/pages/settings/users/permissions/index.tsx @@ -1,75 +1,69 @@ -import { useState, useMemo } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2 } from 'lucide-react' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import { Button } from '@/components/ui/button' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { usePermissions, useDeletePermission } from '@/features/permissions/hooks/usePermissions' -import type { Permission } from '@/features/permissions/api/permissionsApi' +import { useState, useMemo } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Eye, Pencil, Trash2 } from "lucide-react"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { Button } from "@/components/ui/button"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { usePermissions, useDeletePermission } from "@/features/permissions/hooks/usePermissions"; +import type { Permission } from "@/features/permissions/api/permissionsApi"; // ─── PermissionsPage ────────────────────────────────────────────────────────── export default function PermissionsPage() { - const { t } = useTranslation() - const navigate = useNavigate() + const { t } = useTranslation(); + const navigate = useNavigate(); - const columnMeta = useMemo(() => [ - { id: 'id', label: t('common.id', 'ID') }, - { id: 'code', label: t('permissions.fields.code', 'Kod') }, - { id: 'name', label: t('permissions.fields.name', 'Ady') }, - { id: 'guard_name', label: t('permissions.fields.guardName', 'Guard name') }, - ], [t]) + const columnMeta = useMemo( + () => [ + { id: "id", label: t("common.id", "ID") }, + { id: "code", label: t("permissions.fields.code", "Kod") }, + { id: "name", label: t("permissions.fields.name", "Ady") }, + { id: "guard_name", label: t("permissions.fields.guardName", "Guard name") }, + ], + [t], + ); // ── State ────────────────────────────────────────────────────────────────── - const [search, setSearch] = useState('') - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([]) - const [deleteId, setDeleteId] = useState(null) + const [search, setSearch] = useState(""); + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([]); + const [deleteId, setDeleteId] = useState(null); // ── Data ─────────────────────────────────────────────────────────────────── - const { data, isLoading } = usePermissions({ search, page, per_page: perPage }) - const deletePermission = useDeletePermission() + const { data, isLoading } = usePermissions({ search, page, per_page: perPage }); + const deletePermission = useDeletePermission(); // ── Columns ──────────────────────────────────────────────────────────────── const columns: ColumnDef[] = [ { - accessorKey: 'id', - header: t('common.id', 'ID'), + accessorKey: "id", + header: t("common.id", "ID"), size: 70, - cell: ({ row }) => ( - {row.original.id} - ), + cell: ({ row }) => {row.original.id}, }, { - accessorKey: 'code', - header: t('permissions.fields.code', 'Kod'), + accessorKey: "code", + header: t("permissions.fields.code", "Kod"), }, { - accessorKey: 'name', - header: t('permissions.fields.name', 'Ady'), - cell: ({ row }) => {row.original.name?.tk ?? '—'}, + accessorKey: "name", + header: t("permissions.fields.name", "Ady"), + cell: ({ row }) => {row.original.name?.tk ?? "—"}, }, { - accessorKey: 'guard_name', - header: t('permissions.fields.guardName', 'Guard name'), + accessorKey: "guard_name", + header: t("permissions.fields.guardName", "Guard name"), }, { - id: 'actions', - header: '', + id: "actions", + header: "", size: 120, enableSorting: false, enableHiding: false, @@ -102,94 +96,91 @@ export default function PermissionsPage() {
), }, - ] + ]; // ── Handlers ─────────────────────────────────────────────────────────────── const handleConfirmDelete = () => { - if (deleteId === null) return + if (deleteId === null) return; deletePermission.mutate(deleteId, { onSuccess: () => setDeleteId(null), - onError: () => setDeleteId(null), - }) - } + onError: () => setDeleteId(null), + }); + }; // ── Render ───────────────────────────────────────────────────────────────── return ( -
+
{/* Page heading */}
-

- {t('permissions.title', 'Rugsatlar')} -

- +

{t("permissions.title", "Rugsatlar")}

-
+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("permissions.searchPlaceholder", "Gözlemek...")} + /> + navigate("/settings/users/permissions/create")} + /> +
+
+ {/* Toolbar */} + { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("permissions.searchPlaceholder", "Gözlemek...")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + perPageOptions={[10, 25, 50, 100]} + perPage={perPage} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + hideSearch + hideAction + /> - {/* Toolbar */} - { setSearch(v); setPage(1) }} - searchPlaceholder={t('permissions.searchPlaceholder', 'Gözlemek...')} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - perPageOptions={[10, 25, 50, 100]} - perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('permissions.actions.create', 'Rugsat dörediň')} - onAction={() => navigate('/settings/users/permissions/create')} - /> - - {/* Table */} - String(row.id)} - currentPage={data?.meta?.current_page ?? 1} - totalPages={data?.meta?.last_page ?? 1} - totalCount={data?.meta?.total ?? 0} - onPageChange={setPage} - /> -
+ {/* Table */} + String(row.id)} + currentPage={data?.meta?.current_page ?? 1} + totalPages={data?.meta?.last_page ?? 1} + totalCount={data?.meta?.total ?? 0} + onPageChange={setPage} + /> +
{/* Delete confirmation dialog */} - { if (!open) setDeleteId(null) }} - > - - - - {t('permissions.deleteDialog.title', 'Rugsaty pozmak')} - - - {t( - 'permissions.deleteDialog.description', - 'Bu rugsaty pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.', - )} - - - - {t('common.cancel', 'Ýatyr')} - - {deletePermission.isPending - ? t('common.deleting', 'Pozulýar...') - : t('common.delete', 'Poz')} - - - - + onOpenChange={(o) => { + if (!o) setDeleteId(null); + }} + title={t("permissions.deleteDialog.title", "Rugsaty pozmak")} + description={t("permissions.deleteDialog.description", "Bu rugsaty pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.")} + onConfirm={handleConfirmDelete} + isLoading={deletePermission.isPending} + />
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/settings/users/roles/index.tsx b/src/pages/settings/users/roles/index.tsx index 4fedcf2..8b1ff56 100644 --- a/src/pages/settings/users/roles/index.tsx +++ b/src/pages/settings/users/roles/index.tsx @@ -1,75 +1,69 @@ -import { useState, useMemo } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2 } from 'lucide-react' -import type { ColumnDef, VisibilityState } from '@tanstack/react-table' -import { DataTable } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import { Button } from '@/components/ui/button' -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { useRoles, useDeleteRole } from '@/features/roles/hooks/useRoles' -import type { Role } from '@/features/roles/api/rolesApi' +import { useState, useMemo } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Eye, Pencil, Trash2 } from "lucide-react"; +import type { ColumnDef, VisibilityState } from "@tanstack/react-table"; +import { DataTable } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { Button } from "@/components/ui/button"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { useRoles, useDeleteRole } from "@/features/roles/hooks/useRoles"; +import type { Role } from "@/features/roles/api/rolesApi"; // ─── RolesPage ──────────────────────────────────────────────────────────────── export default function RolesPage() { - const { t } = useTranslation() - const navigate = useNavigate() + const { t } = useTranslation(); + const navigate = useNavigate(); - const 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: 'guard_name', label: t('roles.fields.guardName', 'Guard name') }, - ], [t]) + const 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: "guard_name", label: t("roles.fields.guardName", "Guard name") }, + ], + [t], + ); // ── State ────────────────────────────────────────────────────────────────── - const [search, setSearch] = useState('') - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([]) - const [deleteId, setDeleteId] = useState(null) + const [search, setSearch] = useState(""); + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([]); + const [deleteId, setDeleteId] = useState(null); // ── Data ─────────────────────────────────────────────────────────────────── - const { data, isLoading } = useRoles({ search, page, per_page: perPage }) - const deleteRole = useDeleteRole() + const { data, isLoading } = useRoles({ search, page, per_page: perPage }); + const deleteRole = useDeleteRole(); // ── Columns ──────────────────────────────────────────────────────────────── const columns: ColumnDef[] = [ { - accessorKey: 'id', - header: t('common.id', 'ID'), + accessorKey: "id", + header: t("common.id", "ID"), size: 70, - cell: ({ row }) => ( - {row.original.id} - ), + cell: ({ row }) => {row.original.id}, }, { - accessorKey: 'code', - header: t('roles.fields.code', 'Kod'), + accessorKey: "code", + header: t("roles.fields.code", "Kod"), }, { - accessorKey: 'name', - header: t('roles.fields.name', 'Ady'), - cell: ({ row }) => {row.original.name?.tk ?? '—'}, + accessorKey: "name", + header: t("roles.fields.name", "Ady"), + cell: ({ row }) => {row.original.name?.tk ?? "—"}, }, { - accessorKey: 'guard_name', - header: t('roles.fields.guardName', 'Guard name'), + accessorKey: "guard_name", + header: t("roles.fields.guardName", "Guard name"), }, { - id: 'actions', - header: '', + id: "actions", + header: "", size: 120, enableSorting: false, enableHiding: false, @@ -102,93 +96,87 @@ export default function RolesPage() {
), }, - ] + ]; // ── Handlers ─────────────────────────────────────────────────────────────── const handleConfirmDelete = () => { - if (deleteId === null) return + if (deleteId === null) return; deleteRole.mutate(deleteId, { onSuccess: () => setDeleteId(null), - onError: () => setDeleteId(null), - }) - } + onError: () => setDeleteId(null), + }); + }; // ── Render ───────────────────────────────────────────────────────────────── return ( -
+
{/* Page heading */}
-

- {t('roles.title', 'Rollar')} -

- +

{t("roles.title", "Rollar")}

-
+
+ { + setSearch(v); + setPage(1); + }} + placeholder={t("roles.searchPlaceholder", "Gözlemek...")} + /> + navigate("/settings/users/roles/create")} /> +
+
+ {/* Toolbar */} + { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("roles.searchPlaceholder", "Gözlemek...")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + perPageOptions={[10, 25, 50, 100]} + perPage={perPage} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + hideSearch + hideAction + /> - {/* Toolbar */} - { setSearch(v); setPage(1) }} - searchPlaceholder={t('roles.searchPlaceholder', 'Gözlemek...')} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - perPageOptions={[10, 25, 50, 100]} - perPage={perPage} - onPerPageChange={(v) => { setPerPage(v); setPage(1) }} - actionLabel={t('roles.actions.create', 'Rol dörediň')} - onAction={() => navigate('/settings/users/roles/create')} - /> - - {/* Table */} - String(row.id)} - currentPage={data?.meta?.current_page ?? 1} - totalPages={data?.meta?.last_page ?? 1} - totalCount={data?.meta?.total ?? 0} - onPageChange={setPage} - /> -
+ {/* Table */} + String(row.id)} + currentPage={data?.meta?.current_page ?? 1} + totalPages={data?.meta?.last_page ?? 1} + totalCount={data?.meta?.total ?? 0} + onPageChange={setPage} + /> +
{/* Delete confirmation dialog */} - { if (!open) setDeleteId(null) }} - > - - - - {t('roles.deleteDialog.title', 'Roly pozmak')} - - - {t( - 'roles.deleteDialog.description', - 'Bu roly pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.', - )} - - - - {t('common.cancel', 'Ýatyr')} - - {deleteRole.isPending - ? t('common.deleting', 'Pozulýar...') - : t('common.delete', 'Poz')} - - - - + onOpenChange={(o) => { + if (!o) setDeleteId(null); + }} + title={t("roles.deleteDialog.title", "Roly pozmak")} + description={t("roles.deleteDialog.description", "Bu roly pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.")} + onConfirm={handleConfirmDelete} + isLoading={deleteRole.isPending} + />
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/users/allUsers/index.tsx b/src/pages/users/allUsers/index.tsx index 43770af..1411369 100644 --- a/src/pages/users/allUsers/index.tsx +++ b/src/pages/users/allUsers/index.tsx @@ -5,12 +5,14 @@ import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from "lucide-react"; import { DataTable, type ColumnDef } from "@/components/dataTable"; import { DataTableToolbar, type ActiveFilter } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; import { Button } from "@/components/ui/button"; import type { VisibilityState } from "@tanstack/react-table"; import { useUsers, useDeleteUser } from "@/features/allUsers/hooks/useAllUsers"; import type { UserListItem } from "@/features/allUsers/api/allUsersApi"; -import { ConfirmDialog } from "@/components/confirmDialog"; +import { DeleteDialog } from "@/components/deleteDialog"; // ─── Constants ──────────────────────────────────────────────────────────────── @@ -147,10 +149,14 @@ export default function UsersListPage() { // ── Render ───────────────────────────────────────────────────────────────── return ( -
+

{t("users.title", "Ähli ulanyjylar")}

+
+ + navigate("/all-users/create")} /> +
{/* Toolbar */} navigate("/all-users/create")} + hideSearch + hideAction /> {/* Table */} @@ -203,7 +209,7 @@ export default function UsersListPage() { />
- { if (!o) setDeleteTarget(null); @@ -213,7 +219,6 @@ export default function UsersListPage() { "{name}", deleteTarget?.username ?? "", )} - confirmLabel={t("common.delete", "Öçür")} onConfirm={handleDeleteConfirm} isLoading={deleteUser.isPending} /> diff --git a/src/pages/users/clients/index.tsx b/src/pages/users/clients/index.tsx index dbcab47..2c6b881 100644 --- a/src/pages/users/clients/index.tsx +++ b/src/pages/users/clients/index.tsx @@ -1,43 +1,45 @@ -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Trash2, Eye, Pencil, CheckCircle2, XCircle } from 'lucide-react' -import { ConfirmDialog } from '@/components/confirmDialog' -import { Button } from '@/components/ui/button' -import { DataTable, type ColumnDef } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import { useClients, useDeleteClient } from '@/features/clients/hooks/useClients' -import type { Client } from '@/features/clients/api/clientsApi' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Trash2, Eye, Pencil, CheckCircle2, XCircle } from "lucide-react"; +import { DeleteDialog } from "@/components/deleteDialog"; +import { Button } from "@/components/ui/button"; +import { DataTable, type ColumnDef } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { TableSearchInput } from "@/components/tableSearch"; +import { CreateButton } from "@/components/createButton"; +import { useClients, useDeleteClient } from "@/features/clients/hooks/useClients"; +import type { Client } from "@/features/clients/api/clientsApi"; export default function ClientsPage() { - const { t } = useTranslation() - const navigate = useNavigate() - const deleteMutation = useDeleteClient() + const { t } = useTranslation(); + const navigate = useNavigate(); + const deleteMutation = useDeleteClient(); - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(25) - const [search, setSearch] = useState('') - const [isActiveFilter, setIsActiveFilter] = useState('') - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([]) + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(25); + const [search, setSearch] = useState(""); + const [isActiveFilter, setIsActiveFilter] = useState(""); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([]); - const [deleteTarget, setDeleteTarget] = useState(null) + const [deleteTarget, setDeleteTarget] = useState(null); const { data, isLoading } = useClients({ page, perPage, search: search || undefined, isActive: isActiveFilter || undefined, - }) + }); - const clients = data?.data ?? [] - const totalPages = data?.meta.totalPages ?? 1 - const totalCount = data?.meta.totalCount ?? 0 + const clients = data?.data ?? []; + const totalPages = data?.meta.totalPages ?? 1; + const totalCount = data?.meta.totalCount ?? 0; const columns: ColumnDef[] = [ { - accessorKey: 'id', - header: t('common.id', 'ID'), + accessorKey: "id", + header: t("common.id", "ID"), cell: ({ row }) => ( {row.original.username}, }, { - accessorKey: 'name', - header: t('clients.fields.name', 'ADY'), + accessorKey: "name", + header: t("clients.fields.name", "ADY"), cell: ({ row }) => {row.original.name}, }, { - accessorKey: 'phone', - header: t('clients.fields.phone', 'TELEFON'), - cell: ({ row }) => {row.original.phone ?? '—'}, + accessorKey: "phone", + header: t("clients.fields.phone", "TELEFON"), + cell: ({ row }) => {row.original.phone ?? "—"}, }, { - accessorKey: 'email', - header: t('clients.fields.email', 'E-POÇTA'), - cell: ({ row }) => {row.original.email ?? '—'}, + accessorKey: "email", + header: t("clients.fields.email", "E-POÇTA"), + cell: ({ row }) => {row.original.email ?? "—"}, }, { - accessorKey: 'isActive', - header: t('clients.fields.isActive', 'IŞJEŇ'), + accessorKey: "isActive", + header: t("clients.fields.isActive", "IŞJEŇ"), cell: ({ row }) => row.original.isActive ? ( - + ) : ( - + ), size: 80, }, { - id: 'actions', - header: '', + id: "actions", + header: "", cell: ({ row }) => (