{filterFields.map((field) => {
- const current = getActiveValue(field.id)
- const isFieldActive = current !== ''
+ const current = getActiveValue(field.id);
+ const isFieldActive = current !== "";
return (
- )
+ );
})}
{onPerPageChange && (
- )
+ );
}
// ─── 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 }) => (
-