refactord some files
This commit is contained in:
26
src/components/createButton.tsx
Normal file
26
src/components/createButton.tsx
Normal file
@@ -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 (
|
||||
<Button
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
variant={variant === "destructive" ? "destructive" : variant === "secondary" ? "secondary" : "default"}
|
||||
className={cn("font-medium text-sm h-9 px-4 max-[680px]:px-2.5 transition-colors shadow-sm cursor-pointer min-w-0 shrink", className)}
|
||||
>
|
||||
{icon ?? <Plus size={15} className="mr-1.5 max-[680px]:mr-0 shrink-0" />}
|
||||
<span className="truncate max-[680px]:hidden">{label}</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -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<HTMLDivElement>(null)
|
||||
const dragIdRef = useRef<string | null>(null)
|
||||
const [dragOverId, setDragOverId] = useState<string | null>(null)
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const dragIdRef = useRef<string | null>(null);
|
||||
const [dragOverId, setDragOverId] = useState<string | null>(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 (
|
||||
<div ref={ref} className="relative">
|
||||
<button
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className={cn(
|
||||
'flex items-center gap-1.5 h-9 px-3 rounded-md border border-border cursor-pointer',
|
||||
'text-sm text-muted-foreground bg-background',
|
||||
'hover:bg-muted/50 hover:text-foreground transition-colors',
|
||||
open && 'bg-muted/50 text-foreground border-ring'
|
||||
"flex items-center gap-1.5 h-9 px-3 rounded-md border border-border cursor-pointer",
|
||||
"text-sm text-muted-foreground bg-background",
|
||||
"hover:bg-muted/50 hover:text-foreground transition-colors",
|
||||
open && "bg-muted/50 text-foreground border-ring",
|
||||
)}
|
||||
>
|
||||
<SlidersHorizontal size={14} />
|
||||
@@ -152,7 +143,7 @@ function ToggleColumnsDropdown({
|
||||
{open && (
|
||||
<div className="absolute right-0 mt-1.5 w-52 bg-card border border-border rounded-md shadow-lg z-50 py-2">
|
||||
<p className="px-3 pb-1.5 text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{t('table.toggleColumns', 'Toggle Columns')}
|
||||
{t("table.toggleColumns", "Toggle Columns")}
|
||||
</p>
|
||||
{orderedColumns.map((col) => (
|
||||
<div
|
||||
@@ -163,15 +154,12 @@ function ToggleColumnsDropdown({
|
||||
onDrop={() => handleDrop(col.id)}
|
||||
onDragEnd={handleDragEnd}
|
||||
className={cn(
|
||||
'flex items-center gap-2.5 px-3 py-1.5 transition-colors cursor-default',
|
||||
'hover:bg-muted/40',
|
||||
dragOverId === col.id && 'bg-primary/10 border-l-2 border-primary'
|
||||
"flex items-center gap-2.5 px-3 py-1.5 transition-colors cursor-default",
|
||||
"hover:bg-muted/40",
|
||||
dragOverId === col.id && "bg-primary/10 border-l-2 border-primary",
|
||||
)}
|
||||
>
|
||||
<GripVertical
|
||||
size={13}
|
||||
className="text-muted-foreground cursor-grab shrink-0 active:cursor-grabbing"
|
||||
/>
|
||||
<GripVertical size={13} className="text-muted-foreground cursor-grab shrink-0 active:cursor-grabbing" />
|
||||
<input
|
||||
type="checkbox"
|
||||
id={`col-toggle-${col.id}`}
|
||||
@@ -179,10 +167,7 @@ function ToggleColumnsDropdown({
|
||||
onChange={() => toggle(col.id)}
|
||||
className="w-4 h-4 rounded cursor-pointer accent-[#005f78] dark:accent-primary"
|
||||
/>
|
||||
<label
|
||||
htmlFor={`col-toggle-${col.id}`}
|
||||
className="text-sm text-foreground cursor-pointer flex-1 truncate select-none"
|
||||
>
|
||||
<label htmlFor={`col-toggle-${col.id}`} className="text-sm text-foreground cursor-pointer flex-1 truncate select-none">
|
||||
{col.label}
|
||||
</label>
|
||||
</div>
|
||||
@@ -190,35 +175,19 @@ function ToggleColumnsDropdown({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Date Filter Button ───────────────────────────────────────────────────────
|
||||
|
||||
function DateFilterButton() {
|
||||
return (
|
||||
<button
|
||||
className={cn(
|
||||
'flex items-center h-9 px-3 rounded-md border border-border cursor-pointer',
|
||||
'text-muted-foreground bg-background',
|
||||
'hover:bg-muted/50 hover:text-foreground transition-colors'
|
||||
)}
|
||||
>
|
||||
<Clock size={14} />
|
||||
</button>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── 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 (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
className={cn(
|
||||
'flex items-center gap-1.5 h-9 px-3 rounded-md border border-border cursor-pointer',
|
||||
'text-muted-foreground bg-background',
|
||||
'hover:bg-muted/50 hover:text-foreground transition-colors',
|
||||
open && 'bg-muted/50 text-foreground border-ring',
|
||||
hasActive && 'border-primary text-primary'
|
||||
"flex items-center gap-1.5 h-9 px-3 rounded-md border border-border cursor-pointer",
|
||||
"text-muted-foreground bg-background",
|
||||
"hover:bg-muted/50 hover:text-foreground transition-colors",
|
||||
open && "bg-muted/50 text-foreground border-ring",
|
||||
hasActive && "border-primary text-primary",
|
||||
)}
|
||||
>
|
||||
<Filter size={14} />
|
||||
@@ -264,47 +232,34 @@ function FilterDropdown({
|
||||
<PopoverContent align="end" sideOffset={4} className="w-64 p-0">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between px-3 py-2 border-b border-border">
|
||||
<p className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{t('table.filters', 'Filters')}
|
||||
</p>
|
||||
<p className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">{t("table.filters", "Filters")}</p>
|
||||
</div>
|
||||
|
||||
{/* Fields */}
|
||||
<div className="px-3 py-3 space-y-3">
|
||||
{filterFields.map((field) => {
|
||||
const current = getActiveValue(field.id)
|
||||
const isFieldActive = current !== ''
|
||||
const current = getActiveValue(field.id);
|
||||
const isFieldActive = current !== "";
|
||||
|
||||
return (
|
||||
<div key={field.id} className="space-y-1">
|
||||
<label className="block text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{field.label}
|
||||
</label>
|
||||
<label className="block text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">{field.label}</label>
|
||||
|
||||
{/* MonthSelect ile aynı pattern: manuel span + sentinel */}
|
||||
<div className="flex items-center gap-1">
|
||||
<Select
|
||||
value={current || '__all__'}
|
||||
onValueChange={(val) =>
|
||||
onFilterChange(field.id, val === '__all__' ? '' : val)
|
||||
}
|
||||
>
|
||||
<Select value={current || "__all__"} onValueChange={(val) => onFilterChange(field.id, val === "__all__" ? "" : val)}>
|
||||
<SelectTrigger
|
||||
className={cn(
|
||||
'h-8 flex-1 text-sm gap-1.5 transition-colors',
|
||||
isFieldActive
|
||||
? 'border-primary text-primary [&>svg:last-child]:text-primary'
|
||||
: 'text-muted-foreground'
|
||||
"h-8 flex-1 text-sm gap-1.5 transition-colors",
|
||||
isFieldActive ? "border-primary text-primary [&>svg:last-child]:text-primary" : "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{/* SelectValue kullanmıyoruz — MonthSelect gibi manuel */}
|
||||
<span className="flex-1 text-left truncate">
|
||||
{isFieldActive
|
||||
? field.options.find((o) => o.value === current)?.label
|
||||
: '—'}
|
||||
{isFieldActive ? field.options.find((o) => o.value === current)?.label : "—"}
|
||||
</span>
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper" sideOffset={4} className='p-1'>
|
||||
<SelectContent position="popper" sideOffset={4} className="p-1">
|
||||
<SelectItem value="__all__">
|
||||
<span className="text-muted-foreground">— Ählisi</span>
|
||||
</SelectItem>
|
||||
@@ -320,7 +275,7 @@ function FilterDropdown({
|
||||
{isFieldActive && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onFilterChange(field.id, '')}
|
||||
onClick={() => onFilterChange(field.id, "")}
|
||||
className="h-6 w-6 rounded flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors shrink-0"
|
||||
>
|
||||
<X size={11} />
|
||||
@@ -328,22 +283,19 @@ function FilterDropdown({
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
})}
|
||||
|
||||
{onPerPageChange && (
|
||||
<div className="space-y-1">
|
||||
<label className="block text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{t('table.perPage', 'Sahypa başyna')}
|
||||
{t("table.perPage", "Sahypa başyna")}
|
||||
</label>
|
||||
<Select
|
||||
value={String(perPage)}
|
||||
onValueChange={(val) => onPerPageChange(Number(val))}
|
||||
>
|
||||
<Select value={String(perPage)} onValueChange={(val) => onPerPageChange(Number(val))}>
|
||||
<SelectTrigger className="h-8 w-full text-sm">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper" sideOffset={4} className='p-1'>
|
||||
<SelectContent position="popper" sideOffset={4} className="p-1">
|
||||
{perPageOptions.map((n) => (
|
||||
<SelectItem key={n} value={String(n)}>
|
||||
{n}
|
||||
@@ -360,19 +312,19 @@ function FilterDropdown({
|
||||
type="button"
|
||||
onClick={onFilterReset}
|
||||
className={cn(
|
||||
'w-full cursor-pointer flex items-center justify-center gap-1.5 h-8 rounded-md text-xs font-medium transition-colors',
|
||||
'bg-destructive/10 text-destructive border border-destructive/20',
|
||||
'hover:bg-destructive/30 hover:text-destructive-foreground'
|
||||
"w-full cursor-pointer flex items-center justify-center gap-1.5 h-8 rounded-md text-xs font-medium transition-colors",
|
||||
"bg-destructive/10 text-destructive border border-destructive/20",
|
||||
"hover:bg-destructive/30 hover:text-destructive-foreground",
|
||||
)}
|
||||
>
|
||||
<X size={11} />
|
||||
{t('table.reset', 'Reset')} ({activeCount})
|
||||
{t("table.reset", "Reset")} ({activeCount})
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── DataTableToolbar ─────────────────────────────────────────────────────────
|
||||
@@ -400,14 +352,8 @@ export function DataTableToolbar({
|
||||
extraActions,
|
||||
}: DataTableToolbarProps) {
|
||||
return (
|
||||
<div className={cn('flex items-center gap-3 mb-3', hideSearch ? 'justify-end' : 'justify-between')}>
|
||||
{!hideSearch && (
|
||||
<TableSearchInput
|
||||
value={searchValue}
|
||||
onChange={onSearchChange}
|
||||
placeholder={searchPlaceholder}
|
||||
/>
|
||||
)}
|
||||
<div className={cn("flex items-center gap-3 mb-3", hideSearch ? "justify-end" : "justify-between")}>
|
||||
{!hideSearch && <TableSearchInput value={searchValue} onChange={onSearchChange} placeholder={searchPlaceholder} />}
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<ToggleColumnsDropdown
|
||||
@@ -418,8 +364,6 @@ export function DataTableToolbar({
|
||||
onColumnOrderChange={onColumnOrderChange}
|
||||
/>
|
||||
|
||||
<DateFilterButton />
|
||||
|
||||
{filterFields.length > 0 && onFilterChange && onFilterReset && (
|
||||
<FilterDropdown
|
||||
filterFields={filterFields}
|
||||
@@ -434,10 +378,8 @@ export function DataTableToolbar({
|
||||
|
||||
{extraActions}
|
||||
|
||||
{!hideAction && actionLabel && onAction && (
|
||||
<TableActionButton label={actionLabel} onClick={onAction} />
|
||||
)}
|
||||
{!hideAction && actionLabel && onAction && <CreateButton label={actionLabel} onClick={onAction} />}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
45
src/components/deleteDialog.tsx
Normal file
45
src/components/deleteDialog.tsx
Normal file
@@ -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 (
|
||||
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{title}</AlertDialogTitle>
|
||||
{description && <AlertDialogDescription>{description}</AlertDialogDescription>}
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isLoading}>{t("common.cancel", "Cancel")}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={onConfirm}
|
||||
disabled={isLoading}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{isLoading ? t("common.deleting", "Deleting...") : t("common.delete", "Delete")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<Button
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
variant={variant === 'destructive' ? 'destructive' : variant === 'secondary' ? 'secondary' : 'default'}
|
||||
className={cn(
|
||||
'font-medium text-sm h-9 px-4 transition-colors shadow-sm cursor-pointer',
|
||||
className
|
||||
)}
|
||||
>
|
||||
{icon ?? <Plus size={15} className="mr-1.5" />}
|
||||
{label}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -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 (
|
||||
<div className={cn('relative', className)}>
|
||||
<Search
|
||||
size={15}
|
||||
className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"
|
||||
/>
|
||||
<div className={cn("relative min-w-0", className)}>
|
||||
<Search size={15} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" />
|
||||
<input
|
||||
type="text"
|
||||
value={value}
|
||||
onChange={(e) => 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",
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<BackupStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }> = {
|
||||
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 <StatusBadge label={currentCfg.label} variant={currentCfg.variant} icon={currentCfg.icon} />
|
||||
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 <StatusBadge label={currentCfg.label} variant={currentCfg.variant} icon={currentCfg.icon} />;
|
||||
}
|
||||
|
||||
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<number | null>(null)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(PER_PAGE);
|
||||
const [search, setSearch] = useState("");
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
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<Backup>[] = [
|
||||
{
|
||||
id: 'fileName',
|
||||
accessorKey: 'fileName',
|
||||
header: t('backups.col.fileName', 'Faýl ady'),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-mono text-sm">{row.original.fileName}</span>
|
||||
),
|
||||
id: "fileName",
|
||||
accessorKey: "fileName",
|
||||
header: t("backups.col.fileName", "Faýl ady"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.fileName}</span>,
|
||||
},
|
||||
{
|
||||
id: 'fileSize',
|
||||
accessorKey: 'fileSize',
|
||||
header: t('backups.col.fileSize', 'Ölçegi'),
|
||||
id: "fileSize",
|
||||
accessorKey: "fileSize",
|
||||
header: t("backups.col.fileSize", "Ölçegi"),
|
||||
cell: ({ row }) => <span>{row.original.fileSize}</span>,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
accessorKey: 'status',
|
||||
header: t('backups.col.status', 'Status'),
|
||||
id: "status",
|
||||
accessorKey: "status",
|
||||
header: t("backups.col.status", "Status"),
|
||||
cell: ({ row }) => <BackupStatusBadge status={row.original.status} />,
|
||||
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 }) => <span className="text-sm text-muted-foreground">{row.original.createdAt}</span>,
|
||||
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 }) => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => downloadBackup.mutate(row.original.id)}
|
||||
disabled={row.original.status === 'in_progress'}
|
||||
title={t('common.download', 'Ýükle')}
|
||||
disabled={row.original.status === "in_progress"}
|
||||
title={t("common.download", "Ýükle")}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('common.delete', 'Poz')}
|
||||
title={t("common.delete", "Poz")}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
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 (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground flex items-center gap-2">
|
||||
<Database className="size-5 text-muted-foreground" />
|
||||
{t('backups.title', 'Bekaplar')}
|
||||
{t("backups.title", "Bekaplar")}
|
||||
</h1>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={createBackup.isPending ? t("common.loading", "Döredilýär...") : t("backups.create", "Backup dörediň")}
|
||||
onClick={() => createBackup.mutate()}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -169,25 +183,16 @@ export default function BackupsPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('backups.deleteConfirm.title', 'Eminsiňizmi?')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('backups.deleteConfirm.description', 'Bu backup pozulsynmy? Bu amal yzyna gaýtarylmaz.')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteBackup.isPending ? t('common.deleting', 'Pozulýar...') : t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("Card balances", "Kart galyndylary")}</h1>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("Create card balance", "Kart galyndysy dörediň")} onClick={() => navigate("/card-balances/create")} />
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
@@ -160,8 +164,8 @@ export default function CardBalancesPage() {
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t("Create card balance", "Kart galyndysy dörediň")}
|
||||
onAction={() => navigate("/card-balances/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
@@ -187,22 +191,16 @@ export default function CardBalancesPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t("Are you sure?", "Eminsiňizmi?")}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz. Kart galyndysy hemişelik öçüriler.")}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t("Cancel", "Ýatyr")}</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDelete} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
|
||||
{deleteMutation.isPending ? t("Deleting...", "Öçürilýär...") : t("Delete", "Öçür")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<CardPinStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>;
|
||||
|
||||
function CardPinStatusStatusBadge({ status }: { status: CardPinStatus }) {
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg)
|
||||
return (
|
||||
<span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
);
|
||||
return (
|
||||
<StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
);
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
@@ -99,29 +71,17 @@ export default function CardPinsPage() {
|
||||
{
|
||||
accessorKey: "id",
|
||||
header: "ID",
|
||||
cell: ({ row }) => (
|
||||
<span className="font-mono text-xs text-muted-foreground">
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="font-mono text-xs text-muted-foreground">{row.original.id}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "card_type_label",
|
||||
header: t("cardPin.cardType", "Görnüşi"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-medium text-primary">
|
||||
{row.original.card_type_label}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm font-medium text-primary">{row.original.card_type_label}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "created_at",
|
||||
header: t("cardPin.createdAt", "Döredilen wagty"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">
|
||||
{row.original.created_at}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground whitespace-nowrap">{row.original.created_at}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "province_label",
|
||||
@@ -130,11 +90,7 @@ export default function CardPinsPage() {
|
||||
{
|
||||
accessorKey: "branch_label",
|
||||
header: t("cardPin.branch", "Şahamça"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-medium">
|
||||
{row.original.branch_label}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-medium">{row.original.branch_label}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "first_name",
|
||||
@@ -147,36 +103,22 @@ export default function CardPinsPage() {
|
||||
{
|
||||
accessorKey: "phone",
|
||||
header: t("cardPin.phone", "Telefon"),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-mono text-sm">{row.original.phone}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.phone}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
header: t("cardPin.status", "Status"),
|
||||
cell: ({ row }) => (
|
||||
<CardPinStatusStatusBadge status={row.original.status} />
|
||||
),
|
||||
cell: ({ row }) => <CardPinStatusStatusBadge status={row.original.status} />,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-pins/${row.original.id}`)}
|
||||
>
|
||||
<Button size="icon" variant="ghost" className="h-7 w-7" onClick={() => navigate(`/card-pins/${row.original.id}`)}>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-pins/${row.original.id}/edit`)}
|
||||
>
|
||||
<Button size="icon" variant="ghost" className="h-7 w-7" onClick={() => navigate(`/card-pins/${row.original.id}/edit`)}>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -196,21 +138,25 @@ export default function CardPinsPage() {
|
||||
.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 label = typeof c.header === "string" ? c.header : "accessorKey" in c ? String(c.accessorKey) : id;
|
||||
return { id, label };
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("Card pins", "Kart pin bukjalary")}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("Card pins", "Kart pin bukjalary")}</h1>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("cardPin.createBtn", "Kart pin bukja dörediň")} onClick={() => navigate("/card-pins/create")} />
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
@@ -219,7 +165,7 @@ export default function CardPinsPage() {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
@@ -238,8 +184,7 @@ export default function CardPinsPage() {
|
||||
]}
|
||||
activeFilters={[{ fieldId: "status", value: statusFilter }]}
|
||||
onFilterChange={(fieldId, value) => {
|
||||
if (fieldId === "status")
|
||||
setStatusFilter(value as CardPinStatus | "");
|
||||
if (fieldId === "status") setStatusFilter(value as CardPinStatus | "");
|
||||
setPage(1);
|
||||
}}
|
||||
onFilterReset={() => {
|
||||
@@ -251,8 +196,8 @@ export default function CardPinsPage() {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
actionLabel={t("cardPin.createBtn", "Kart pin bukja dörediň")}
|
||||
onAction={() => navigate("/card-pins/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -272,40 +217,22 @@ export default function CardPinsPage() {
|
||||
</div>
|
||||
|
||||
{/* Delete confirmation */}
|
||||
<AlertDialog
|
||||
<DeleteDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(o) => !o && setDeleteTarget(null)}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t("cardPin.deleteTitle", "Pozmak isleýärsiňizmi?")}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")}{" "}
|
||||
{deleteTarget?.id}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isDeleting}>
|
||||
{t("common.cancel", "Ýatyr")}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
disabled={isDeleting}
|
||||
className="bg-destructive hover:bg-destructive/90"
|
||||
onClick={() => {
|
||||
if (deleteTarget) {
|
||||
deletePin(deleteTarget.id, {
|
||||
onSuccess: () => setDeleteTarget(null),
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
{t("common.delete", "Poz")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteTarget(null);
|
||||
}}
|
||||
title={t("cardPin.deleteTitle", "Pozmak isleýärsiňizmi?")}
|
||||
description={`${t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")} ${deleteTarget?.id ?? ""}`}
|
||||
onConfirm={() => {
|
||||
if (deleteTarget) {
|
||||
deletePin(deleteTarget.id, {
|
||||
onSuccess: () => setDeleteTarget(null),
|
||||
});
|
||||
}
|
||||
}}
|
||||
isLoading={isDeleting}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,38 +3,18 @@ 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 { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import type { VisibilityState } from "@tanstack/react-table";
|
||||
import {
|
||||
useCardRequisites,
|
||||
useDeleteCardRequisite,
|
||||
useDownloadCardRequisite,
|
||||
} from "@/features/cardRequisites/hooks/useCardRequisites";
|
||||
import type {
|
||||
CardRequisite,
|
||||
CardRequisiteStatus,
|
||||
} from "@/features/cardRequisites/api/cardRequisitesApi";
|
||||
import { useCardRequisites, useDeleteCardRequisite, useDownloadCardRequisite } from "@/features/cardRequisites/hooks/useCardRequisites";
|
||||
import type { CardRequisite, CardRequisiteStatus } from "@/features/cardRequisites/api/cardRequisitesApi";
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_BADGE: Record<
|
||||
CardRequisiteStatus,
|
||||
{ label: string; className: string }
|
||||
> = {
|
||||
const STATUS_BADGE: Record<CardRequisiteStatus, { label: string; className: string }> = {
|
||||
pending: {
|
||||
label: "Garaşylýar",
|
||||
className: "bg-yellow-500/15 text-yellow-500 border-yellow-500/20",
|
||||
@@ -52,11 +32,7 @@ const STATUS_BADGE: Record<
|
||||
function StatusBadge({ status }: { status: CardRequisiteStatus }) {
|
||||
const cfg = STATUS_BADGE[status] ?? STATUS_BADGE.pending;
|
||||
return (
|
||||
<span
|
||||
className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border ${cfg.className}`}
|
||||
>
|
||||
{cfg.label}
|
||||
</span>
|
||||
<span className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border ${cfg.className}`}>{cfg.label}</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -103,39 +79,25 @@ export default function CardRequisitesPage() {
|
||||
id: "card_type",
|
||||
accessorKey: "card_type",
|
||||
header: t("Card type", "GÖRNÜŞI"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-medium">
|
||||
{row.original.card_type}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-medium">{row.original.card_type}</span>,
|
||||
},
|
||||
{
|
||||
id: "created_at",
|
||||
accessorKey: "created_at",
|
||||
header: t("Created at", "DÖREDILEN WAGTY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground">{row.original.created_at}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-foreground">{row.original.created_at}</span>,
|
||||
},
|
||||
{
|
||||
id: "province_name",
|
||||
accessorKey: "province_name",
|
||||
header: t("Province", "WELAÝAT"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground">
|
||||
{row.original.province_name ?? "—"}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-foreground">{row.original.province_name ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
id: "branch_name",
|
||||
accessorKey: "branch_name",
|
||||
header: t("Branch", "ŞAHAMÇA"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-medium">
|
||||
{row.original.branch_name ?? "—"}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-medium">{row.original.branch_name ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
id: "first_name",
|
||||
@@ -161,28 +123,13 @@ export default function CardRequisitesPage() {
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => downloadMutation.mutate(row.original.id)}
|
||||
>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => downloadMutation.mutate(row.original.id)}>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-requisites/${row.original.id}`)}
|
||||
>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => navigate(`/card-requisites/${row.original.id}`)}>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-requisites/${row.original.id}/edit`)}
|
||||
>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => navigate(`/card-requisites/${row.original.id}/edit`)}>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -222,9 +169,21 @@ export default function CardRequisitesPage() {
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("Card requisites", "Kart rekwizitler")}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("Card requisites", "Kart rekwizitler")}</h1>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("cardRequisites.createTitle", "Kart rekwiziti üçin sargyt dörediň")}
|
||||
onClick={() => navigate("/card-requisites/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
@@ -233,17 +192,14 @@ export default function CardRequisitesPage() {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t(
|
||||
"cardRequisites.createTitle",
|
||||
"Kart rekwiziti üçin sargyt dörediň",
|
||||
)}
|
||||
onAction={() => navigate("/card-requisites/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
@@ -270,35 +226,16 @@ export default function CardRequisitesPage() {
|
||||
/>
|
||||
</div>
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(open) => !open && setDeleteId(null)}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t("Are you sure?", "Eminsiňizmi?")}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
"This action cannot be undone.",
|
||||
"Bu amal yzyna gaýtarylmaz. Kart rekwiziti hemişelik öçüriler.",
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t("Cancel", "Ýatyr")}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t("Deleting...", "Öçürilýär...")
|
||||
: t("Delete", "Öçür")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteId(null);
|
||||
}}
|
||||
title={t("Are you sure?", "Eminsiňizmi?")}
|
||||
description={t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz. Kart rekwiziti hemişelik öçüriler.")}
|
||||
onConfirm={handleDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<number | null>(null)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(PER_PAGE);
|
||||
const [search, setSearch] = useState("");
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
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<CardTransaction>[] = [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('ID', 'ID'),
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("ID", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-medium hover:underline text-left"
|
||||
@@ -59,165 +52,177 @@ export default function CardTransactionsPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'passport_series',
|
||||
accessorKey: 'passport_series',
|
||||
header: t('Passport series', 'PASPORT SERIYASY'),
|
||||
id: "passport_series",
|
||||
accessorKey: "passport_series",
|
||||
header: t("Passport series", "PASPORT SERIYASY"),
|
||||
cell: ({ row }) => <span>{row.original.passport_series}</span>,
|
||||
},
|
||||
{
|
||||
id: 'passport_number',
|
||||
accessorKey: 'passport_number',
|
||||
header: t('Passport number', 'PASPORT BELGISI'),
|
||||
id: "passport_number",
|
||||
accessorKey: "passport_number",
|
||||
header: t("Passport number", "PASPORT BELGISI"),
|
||||
cell: ({ row }) => <span>{row.original.passport_number}</span>,
|
||||
},
|
||||
{
|
||||
id: 'card_number',
|
||||
accessorKey: 'card_number',
|
||||
header: t('Card number', 'KART BELGISI'),
|
||||
id: "card_number",
|
||||
accessorKey: "card_number",
|
||||
header: t("Card number", "KART BELGISI"),
|
||||
cell: ({ row }) => <span className="font-mono">{row.original.card_number}</span>,
|
||||
},
|
||||
{
|
||||
id: 'card_expiry_month',
|
||||
accessorKey: 'card_expiry_month',
|
||||
header: t('Expiry month', 'KART MÖHLETI (AÝ)'),
|
||||
id: "card_expiry_month",
|
||||
accessorKey: "card_expiry_month",
|
||||
header: t("Expiry month", "KART MÖHLETI (AÝ)"),
|
||||
cell: ({ row }) => <span>{row.original.card_expiry_month}</span>,
|
||||
},
|
||||
{
|
||||
id: 'card_expiry_year',
|
||||
accessorKey: 'card_expiry_year',
|
||||
header: t('Expiry year', 'KART MÖHLETI (ÝYL)'),
|
||||
id: "card_expiry_year",
|
||||
accessorKey: "card_expiry_year",
|
||||
header: t("Expiry year", "KART MÖHLETI (ÝYL)"),
|
||||
cell: ({ row }) => <span>{row.original.card_expiry_year}</span>,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => downloadMutation.mutate(row.original.id)}
|
||||
title={t('Download', 'Ýükle')}
|
||||
title={t("Download", "Ýükle")}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-transactions/${row.original.id}`)}
|
||||
title={t('View', 'Görmek')}
|
||||
title={t("View", "Görmek")}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-transactions/${row.original.id}/edit`)}
|
||||
title={t('Edit', 'Üýtgetmek')}
|
||||
title={t("Edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('Delete', 'Öçürmek')}
|
||||
title={t("Delete", "Öçürmek")}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
// ── 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 (
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Card transactions', 'Kart hereketleri')}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("Card transactions", "Kart hereketleri")}</h1>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("Create card transaction", "Kart herekedi dörediň")} onClick={() => navigate("/card-transactions/create")} />
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
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 */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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 */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => row.id.toString()}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => row.id.toString()}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('Are you sure?', 'Eminsiňizmi?')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'This action cannot be undone. This will permanently delete the card transaction.',
|
||||
'Bu amal yzyna gaýtarylmaz. Kart herekedi hemişelik öçüriler.',
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('Cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending ? t('Deleting...', 'Öçürilýär...') : t('Delete', 'Öçür')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 <span className="text-xs text-muted-foreground">{status}</span>
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
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 <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ─── 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 <span className={cls}>{value}</span>
|
||||
variant === "teal" ? "text-teal-400 font-semibold" : variant === "cyan" ? "text-cyan-400 font-semibold" : "text-muted-foreground";
|
||||
return <span className={cls}>{value}</span>;
|
||||
}
|
||||
|
||||
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<string | null>(null)
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const deleteMutation = useDeleteCardOrder();
|
||||
const [deleteId, setDeleteId] = useState<string | null>(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<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(DEFAULT_ORDER)
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ 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<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(DEFAULT_ORDER);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ 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<ColumnDef<CardOrderListItem>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('cardOrder.col.id', 'ID'),
|
||||
accessorKey: "id",
|
||||
header: t("cardOrder.col.id", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<Link
|
||||
to={`/order-new-card/${row.original.id}`}
|
||||
className="font-mono text-xs text-primary hover:underline"
|
||||
>
|
||||
<Link to={`/order-new-card/${row.original.id}`} className="font-mono text-xs text-primary hover:underline">
|
||||
{row.original.id}
|
||||
</Link>
|
||||
),
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
accessorKey: 'issuanceReasonName',
|
||||
header: t('cardOrder.col.reason', 'Sebäp'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.issuanceReasonName}</span>
|
||||
),
|
||||
accessorKey: "issuanceReasonName",
|
||||
header: t("cardOrder.col.reason", "Sebäp"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.issuanceReasonName}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'createdAt',
|
||||
header: t('cardOrder.col.createdAt', 'Döredilen wagty'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">{row.original.createdAt}</span>
|
||||
),
|
||||
accessorKey: "createdAt",
|
||||
header: t("cardOrder.col.createdAt", "Döredilen wagty"),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground whitespace-nowrap">{row.original.createdAt}</span>,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
accessorKey: 'cardTypeName',
|
||||
header: t('cardOrder.col.cardType', 'Görnüşi'),
|
||||
accessorKey: "cardTypeName",
|
||||
header: t("cardOrder.col.cardType", "Görnüşi"),
|
||||
cell: ({ row }) => (
|
||||
<HighlightText
|
||||
value={row.original.cardTypeName}
|
||||
variant={row.original.cardTypeName === 'Altyn Asyr' ? 'cyan' : 'teal'}
|
||||
/>
|
||||
<HighlightText value={row.original.cardTypeName} variant={row.original.cardTypeName === "Altyn Asyr" ? "cyan" : "teal"} />
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'provinceName',
|
||||
header: t('cardOrder.col.province', 'Welaýat'),
|
||||
accessorKey: "provinceName",
|
||||
header: t("cardOrder.col.province", "Welaýat"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.provinceName}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "branchName",
|
||||
header: t("cardOrder.col.branch", "Şahamça"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.provinceName}</span>
|
||||
<HighlightText value={row.original.branchName} variant={SPECIAL_BRANCHES.includes(row.original.branchName) ? "cyan" : "muted"} />
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'branchName',
|
||||
header: t('cardOrder.col.branch', 'Şahamça'),
|
||||
cell: ({ row }) => (
|
||||
<HighlightText
|
||||
value={row.original.branchName}
|
||||
variant={SPECIAL_BRANCHES.includes(row.original.branchName) ? 'cyan' : 'muted'}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'fullName',
|
||||
header: t('cardOrder.col.name', 'Ady'),
|
||||
id: "fullName",
|
||||
header: t("cardOrder.col.name", "Ady"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{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 }) => <OrderNewCardStatusBadge status={row.original.status} />,
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görkez')}
|
||||
title={t("common.view", "Görkez")}
|
||||
onClick={() => navigate(`/order-new-card/${row.original.id}`)}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Düzet')}
|
||||
title={t("common.edit", "Düzet")}
|
||||
onClick={() => navigate(`/order-new-card/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
@@ -228,7 +202,7 @@ export default function CardOrdersPage() {
|
||||
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', 'Poz')}
|
||||
title={t("common.delete", "Poz")}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
@@ -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<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
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 (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('cardOrder.title', 'Kart sargytlary')}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">{t("cardOrder.title", "Kart sargytlary")}</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("cardOrder.create", "Kart sargyt dörediň")} onClick={() => navigate("/order-new-card/create")} />
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -313,14 +303,15 @@ export default function CardOrdersPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => { 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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<Record<string, boolean>>(DEFAULT_VISIBILITY);
|
||||
const [columnVisibility, setColumnVisibility] = useState<Record<string, boolean>>(DEFAULT_VISIBILITY);
|
||||
const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
|
||||
@@ -61,9 +59,7 @@ export default function CurrencyRatesPage() {
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-semibold hover:underline"
|
||||
onClick={() =>
|
||||
navigate(`/resources/currency-rates/${row.original.id}`)
|
||||
}
|
||||
onClick={() => navigate(`/resources/currency-rates/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</button>
|
||||
@@ -73,29 +69,17 @@ export default function CurrencyRatesPage() {
|
||||
{
|
||||
accessorKey: "currencyFrom",
|
||||
header: t("currencyRates.columns.currencyFrom", "CURRENCY FROM"),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-medium text-foreground">
|
||||
{row.original.currencyFrom}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="font-medium text-foreground">{row.original.currencyFrom}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "currencyTo",
|
||||
header: t("currencyRates.columns.currencyTo", "CURRENCY TO"),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-medium text-foreground">
|
||||
{row.original.currencyTo}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="font-medium text-foreground">{row.original.currencyTo}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "value",
|
||||
header: t("currencyRates.columns.value", "VALUE"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground tabular-nums">
|
||||
{row.original.value}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-foreground tabular-nums">{row.original.value}</span>,
|
||||
},
|
||||
{
|
||||
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 (
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-5">
|
||||
{t("currencyRates.title", "Walýuta kursy")}
|
||||
</h1>
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-5">{t("currencyRates.title", "Walýuta kursy")}</h1>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput value={search} onChange={handleSearchChange} placeholder={t("common.search", "Gözlemek")} />
|
||||
<CreateButton
|
||||
label={t("currencyRates.actions.create", "Walýuta kursy dörediň")}
|
||||
onClick={() => navigate("/currency-rates/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
@@ -164,11 +150,8 @@ export default function CurrencyRatesPage() {
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t(
|
||||
"currencyRates.actions.create",
|
||||
"Walýuta kursy dörediň",
|
||||
)}
|
||||
onAction={() => navigate("/currency-rates/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -188,12 +171,13 @@ export default function CurrencyRatesPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => { 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}
|
||||
/>
|
||||
|
||||
@@ -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 (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-5">{t("visaMasterSettings.title", "Visa/Master, Sber sazlamalar")}</h1>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput value={search} onChange={handleSearchChange} placeholder={t("common.search", "Gözlemek")} />
|
||||
<CreateButton
|
||||
label={t("visaMasterSettings.actions.create", "Visa/Master, Sber sazlamalar dörediň")}
|
||||
onClick={() => navigate("/visa-master-sber-settings/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
@@ -130,8 +129,8 @@ export default function VisaMasterSettingsPage() {
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t("visaMasterSettings.actions.create", "Visa/Master, Sber sazlamalar dörediň")}
|
||||
onAction={() => navigate("/visa-master-sber-settings/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -152,31 +151,16 @@ export default function VisaMasterSettingsPage() {
|
||||
</div>
|
||||
|
||||
{/* Delete Confirmation */}
|
||||
<AlertDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setDeleteId(null);
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteId(null);
|
||||
}}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t("visaMasterSettings.deleteDialog.title", "Pozmak isleýärsiňizmi?")}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t("visaMasterSettings.deleteDialog.description", "Bu amal yzyna gaýtarylyp bilinmez. Sazlama hemişelik pozular.")}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t("common.cancel", "Ýatyr")}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDeleteConfirm}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending ? t("common.deleting", "Pozulýar...") : t("common.delete", "Pozmak")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<PaymentStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>
|
||||
} satisfies Record<PaymentStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>;
|
||||
}
|
||||
|
||||
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<PaymentPaidStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>
|
||||
} satisfies Record<PaymentPaidStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>;
|
||||
}
|
||||
|
||||
function PaymentPaidStatusBadge({ status, t }: { status: PaymentPaidStatus; t: (key: string, fallback?: string) => string }) {
|
||||
const cfg = getPaidStatusConfig(t)[status]
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
const cfg = getPaidStatusConfig(t)[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
function PaymentStatusBadge({ status, t }: { status: PaymentStatus; t: (key: string, fallback?: string) => string }) {
|
||||
const cfg = getStatusConfig(t)[status]
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
const cfg = getStatusConfig(t)[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── 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<SberPaymentOrder | null>(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<ColumnDef<SberPaymentOrder>[]>(() => {
|
||||
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 }) => (
|
||||
<button
|
||||
className="flex items-center gap-1 hover:text-foreground transition-colors"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||
>
|
||||
{idLabel}
|
||||
<ArrowUpDown size={12} />
|
||||
</button>
|
||||
),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-medium text-foreground">{row.getValue('id')}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="font-medium text-foreground">{row.getValue("id")}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'createdAt',
|
||||
accessorKey: "createdAt",
|
||||
header: createdAtLabel,
|
||||
cell: ({ row }) => {
|
||||
const date = new Date(row.getValue('createdAt'))
|
||||
const date = new Date(row.getValue("createdAt"));
|
||||
return (
|
||||
<div className="text-sm">
|
||||
<div>{format(date, 'HH:mm, dd.MM.yyyy')}</div>
|
||||
<div>{format(date, "HH:mm, dd.MM.yyyy")}</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'welayat',
|
||||
accessorKey: "welayat",
|
||||
header: welayatLabel,
|
||||
cell: ({ row }) => <span>{row.getValue('welayat')}</span>,
|
||||
cell: ({ row }) => <span>{row.getValue("welayat")}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'sahamca',
|
||||
accessorKey: "sahamca",
|
||||
header: ({ column }) => (
|
||||
<button
|
||||
className="flex items-center gap-1 hover:text-foreground transition-colors"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||
>
|
||||
{sahamcaLabel}
|
||||
<ArrowUpDown size={12} />
|
||||
</button>
|
||||
),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-medium">{row.getValue('sahamca')}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-medium">{row.getValue("sahamca")}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'firstName',
|
||||
accessorKey: "firstName",
|
||||
header: firstNameLabel,
|
||||
cell: ({ row }) => <span>{row.getValue('firstName')}</span>,
|
||||
cell: ({ row }) => <span>{row.getValue("firstName")}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'lastName',
|
||||
accessorKey: "lastName",
|
||||
header: lastNameLabel,
|
||||
cell: ({ row }) => <span>{row.getValue('lastName')}</span>,
|
||||
cell: ({ row }) => <span>{row.getValue("lastName")}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'phone',
|
||||
accessorKey: "phone",
|
||||
header: phoneLabel,
|
||||
cell: ({ row }) => <span className="text-muted-foreground">{row.getValue('phone')}</span>,
|
||||
cell: ({ row }) => <span className="text-muted-foreground">{row.getValue("phone")}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'status',
|
||||
accessorKey: "status",
|
||||
header: ({ column }) => (
|
||||
<button
|
||||
className="flex items-center gap-1 hover:text-foreground transition-colors"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||
>
|
||||
{statusLabel}
|
||||
<ArrowUpDown size={12} />
|
||||
</button>
|
||||
),
|
||||
cell: ({ row }) => <PaymentStatusBadge status={row.getValue('status')} t={t} />,
|
||||
cell: ({ row }) => <PaymentStatusBadge status={row.getValue("status")} t={t} />,
|
||||
},
|
||||
{
|
||||
accessorKey: 'paidStatus',
|
||||
accessorKey: "paidStatus",
|
||||
header: paidStatusLabel,
|
||||
cell: ({ row }) => <PaymentPaidStatusBadge status={row.getValue('paidStatus')} t={t} />,
|
||||
cell: ({ row }) => <PaymentPaidStatusBadge status={row.getValue("paidStatus")} t={t} />,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
cell: ({ row }) => {
|
||||
const order = row.original
|
||||
|
||||
const order = row.original;
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
onClick={() => navigate(`/sber-payments/${order.id}`)}
|
||||
className="p-1.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'View')}
|
||||
title={t("common.view", "View")}
|
||||
>
|
||||
<Eye size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate(`/sber-payments/${order.id}/edit`)}
|
||||
className="p-1.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Edit')}
|
||||
title={t("common.edit", "Edit")}
|
||||
>
|
||||
<Edit size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={async () => {
|
||||
if (confirm(t('sberPayments.deleteDialog.title', 'Bu tölegi pozmak isleýärsiňizmi?'))) {
|
||||
await deleteMutation.mutateAsync(order.id)
|
||||
}
|
||||
}}
|
||||
onClick={() => setDeleteTarget(order)}
|
||||
className="p-1.5 rounded hover:bg-accent text-destructive hover:bg-destructive/10 transition-colors"
|
||||
title={t('common.delete', 'Delete')}
|
||||
title={t("common.delete", "Delete")}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
},
|
||||
},
|
||||
]
|
||||
}, [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<ActiveFilter[]>([])
|
||||
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([]);
|
||||
|
||||
// Column visibility & order
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(colMeta.map((c) => c.id))
|
||||
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(colMeta.map((c) => c.id));
|
||||
|
||||
// Month filter
|
||||
const [selectedMonth, setSelectedMonth] = useState<string>('')
|
||||
|
||||
const [selectedMonth, setSelectedMonth] = useState<string>("");
|
||||
|
||||
// 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 (
|
||||
<div className="space-y-4">
|
||||
{/* Page Title */}
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('sberPayments.list.title', 'Sber tölegler (talyplar üçin)')}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("sberPayments.list.title", "Sber tölegler (talyplar üçin)")}</h1>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(val) => {
|
||||
setSearch(val);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("sberPayments.list.actionLabel", "Sber töleg (talyplar üçin) dörediň")}
|
||||
onClick={() => navigate("/sber-payments/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(val) => {
|
||||
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={
|
||||
<MonthSelect
|
||||
value={selectedMonth}
|
||||
onChange={(v) => {
|
||||
setSelectedMonth(v);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(val) => {
|
||||
setSearch(val)
|
||||
setPage(1)
|
||||
{/* Data Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => row.id}
|
||||
currentPage={data?.pagination.currentPage ?? 1}
|
||||
totalPages={data?.pagination.totalPages ?? 1}
|
||||
totalCount={data?.pagination.totalCount ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
{/* Delete confirmation dialog */}
|
||||
<DeleteDialog
|
||||
open={deleteTarget !== null}
|
||||
onOpenChange={(o) => {
|
||||
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={
|
||||
<MonthSelect
|
||||
value={selectedMonth}
|
||||
onChange={(v) => { setSelectedMonth(v); setPage(1) }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Data Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => row.id}
|
||||
currentPage={data?.pagination.currentPage ?? 1}
|
||||
totalPages={data?.pagination.totalPages ?? 1}
|
||||
totalCount={data?.pagination.totalCount ?? 0}
|
||||
onPageChange={setPage}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<IntlPaymentStatus | ''>('')
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [month, setMonth] = useState("");
|
||||
const [statusFilter, setStatusFilter] = useState<IntlPaymentStatus | "">("");
|
||||
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
const [deleteTarget, setDeleteTarget] = useState<IntlPaymentItem | null>(null)
|
||||
const [deleteTarget, setDeleteTarget] = useState<IntlPaymentItem | null>(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 <span className="text-xs text-muted-foreground">{status}</span>
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
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 <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
const columns: ColumnDef<IntlPaymentItem>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('intlPayment.col.id', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-mono text-xs text-muted-foreground">{row.original.id}</span>
|
||||
),
|
||||
accessorKey: "id",
|
||||
header: t("intlPayment.col.id", "ID"),
|
||||
cell: ({ row }) => <span className="font-mono text-xs text-muted-foreground">{row.original.id}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'currency_type_label',
|
||||
header: t('intlPayment.currencyType', 'Ýüztumanyň görnüşi'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-medium">{row.original.currency_type_label}</span>
|
||||
),
|
||||
accessorKey: "currency_type_label",
|
||||
header: t("intlPayment.currencyType", "Ýüztumanyň görnüşi"),
|
||||
cell: ({ row }) => <span className="text-sm font-medium">{row.original.currency_type_label}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'created_at',
|
||||
header: t('intlPayment.createdAt', 'Döredilen wagty'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">{row.original.created_at}</span>
|
||||
),
|
||||
accessorKey: "created_at",
|
||||
header: t("intlPayment.createdAt", "Döredilen wagty"),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground whitespace-nowrap">{row.original.created_at}</span>,
|
||||
},
|
||||
{
|
||||
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 }) => (
|
||||
<span className="text-primary font-medium">{row.original.branch_label}</span>
|
||||
),
|
||||
accessorKey: "branch_label",
|
||||
header: t("intlPayment.branch", "Şahamça"),
|
||||
cell: ({ row }) => <span className="text-primary font-medium">{row.original.branch_label}</span>,
|
||||
},
|
||||
{
|
||||
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 }) => (
|
||||
<span className="font-mono text-sm">{row.original.phone}</span>
|
||||
),
|
||||
accessorKey: "phone",
|
||||
header: t("intlPayment.phone", "Telefon"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.phone}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'status',
|
||||
header: t('intlPayment.status', 'Status'),
|
||||
accessorKey: "status",
|
||||
header: t("intlPayment.status", "Status"),
|
||||
cell: ({ row }) => <IntlPaymentStatusBadge status={row.original.status} />,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
id: "actions",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
size="icon" variant="ghost" className="h-7 w-7"
|
||||
onClick={() => navigate(`/visa-master/${row.original.id}`)}
|
||||
>
|
||||
<Button size="icon" variant="ghost" className="h-7 w-7" onClick={() => navigate(`/visa-master/${row.original.id}`)}>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon" variant="ghost" className="h-7 w-7"
|
||||
onClick={() => navigate(`/visa-master/${row.original.id}/edit`)}
|
||||
>
|
||||
<Button size="icon" variant="ghost" className="h-7 w-7" onClick={() => navigate(`/visa-master/${row.original.id}/edit`)}>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon" variant="ghost"
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => setDeleteTarget(row.original)}
|
||||
>
|
||||
@@ -125,97 +112,116 @@ export default function IntlPaymentsPage() {
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
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 (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("intlPayment.title", "Halkara tölegler (Visa/Mastercard)")}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("intlPayment.title", "Halkara tölegler (Visa/Mastercard)")}</h1>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("intlPayment.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("intlPayment.createBtn", "Visa/Master tölegler (talyplar üçin) dörediň")}
|
||||
onClick={() => navigate("/visa-master/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
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={
|
||||
<MonthSelect
|
||||
value={month}
|
||||
onChange={(v) => {
|
||||
setMonth(v);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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={
|
||||
<MonthSelect
|
||||
value={month}
|
||||
onChange={(v) => { setMonth(v); setPage(1) }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
currentPage={data?.meta?.current_page ?? 1}
|
||||
totalPages={data?.meta?.last_page ?? 1}
|
||||
totalCount={data?.meta?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
currentPage={data?.meta?.current_page ?? 1}
|
||||
totalPages={data?.meta?.last_page ?? 1}
|
||||
totalCount={data?.meta?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={deleteTarget !== null}
|
||||
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 ?? ''}`}
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<LoanOrderMobileStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>
|
||||
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<LoanOrderMobileStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>;
|
||||
|
||||
function LoanOrderStatusBadge({ status }: { status: LoanOrderMobileStatus }) {
|
||||
const cfg = STATUS_CONFIG[status]
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── 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<string | null>(null)
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const deleteMutation = useDeleteLoanOrderMobile();
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS])
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ 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<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS]);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ 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<ColumnDef<LoanOrderMobile>[]>(
|
||||
() => [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('loanOrderMobiles.columns.id', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-xs font-mono text-muted-foreground">{row.original.id}</span>
|
||||
),
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("loanOrderMobiles.columns.id", "ID"),
|
||||
cell: ({ row }) => <span className="text-xs font-mono text-muted-foreground">{row.original.id}</span>,
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
id: 'loanType',
|
||||
accessorKey: 'loanType',
|
||||
header: t('loanOrderMobiles.columns.loanType', 'KARZ GÖRNÜŞI'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-medium text-primary hover:underline cursor-pointer">
|
||||
{row.original.loanType}
|
||||
</span>
|
||||
),
|
||||
id: "loanType",
|
||||
accessorKey: "loanType",
|
||||
header: t("loanOrderMobiles.columns.loanType", "KARZ GÖRNÜŞI"),
|
||||
cell: ({ row }) => <span className="text-sm font-medium text-primary hover:underline cursor-pointer">{row.original.loanType}</span>,
|
||||
},
|
||||
{
|
||||
id: 'createdAt',
|
||||
accessorKey: 'createdAt',
|
||||
header: t('loanOrderMobiles.columns.createdAt', 'DÖREDILEN WAGTY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">{row.original.createdAt}</span>
|
||||
),
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("loanOrderMobiles.columns.createdAt", "DÖREDILEN WAGTY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground whitespace-nowrap">{row.original.createdAt}</span>,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: 'region',
|
||||
accessorKey: 'region',
|
||||
header: t('loanOrderMobiles.columns.region', 'WELAÝAT'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.region}</span>
|
||||
),
|
||||
id: "region",
|
||||
accessorKey: "region",
|
||||
header: t("loanOrderMobiles.columns.region", "WELAÝAT"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.region}</span>,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'branch',
|
||||
accessorKey: 'branch',
|
||||
header: t('loanOrderMobiles.columns.branch', 'ŞAHAMÇA'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-emerald-500 font-medium">{row.original.branch}</span>
|
||||
),
|
||||
id: "branch",
|
||||
accessorKey: "branch",
|
||||
header: t("loanOrderMobiles.columns.branch", "ŞAHAMÇA"),
|
||||
cell: ({ row }) => <span className="text-sm text-emerald-500 font-medium">{row.original.branch}</span>,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'firstName',
|
||||
accessorKey: 'firstName',
|
||||
header: t('loanOrderMobiles.columns.firstName', 'ADY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.firstName}</span>
|
||||
),
|
||||
id: "firstName",
|
||||
accessorKey: "firstName",
|
||||
header: t("loanOrderMobiles.columns.firstName", "ADY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.firstName}</span>,
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: 'lastName',
|
||||
accessorKey: 'lastName',
|
||||
header: t('loanOrderMobiles.columns.lastName', 'FAMILIÝASY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.lastName}</span>
|
||||
),
|
||||
id: "lastName",
|
||||
accessorKey: "lastName",
|
||||
header: t("loanOrderMobiles.columns.lastName", "FAMILIÝASY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.lastName}</span>,
|
||||
size: 120,
|
||||
},
|
||||
{
|
||||
id: 'phone',
|
||||
accessorKey: 'phone',
|
||||
header: t('loanOrderMobiles.columns.phone', 'TELEFON'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.phone}</span>
|
||||
),
|
||||
id: "phone",
|
||||
accessorKey: "phone",
|
||||
header: t("loanOrderMobiles.columns.phone", "TELEFON"),
|
||||
cell: ({ row }) => <span className="text-sm font-mono text-foreground">{row.original.phone}</span>,
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
accessorKey: 'status',
|
||||
header: t('loanOrderMobiles.columns.status', 'STATUS'),
|
||||
id: "status",
|
||||
accessorKey: "status",
|
||||
header: t("loanOrderMobiles.columns.status", "STATUS"),
|
||||
cell: ({ row }) => <LoanOrderStatusBadge status={row.original.status} />,
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
onClick={() => navigate(`/loan-order-mobiles/${row.original.id}`)}
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görmek')}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate(`/loan-order-mobiles/${row.original.id}/edit`)}
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</button>
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
onClick={() => navigate(`/loan-order-mobiles/${row.original.id}`)}
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate(`/loan-order-mobiles/${row.original.id}/edit`)}
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t("common.edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</button>
|
||||
<button
|
||||
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")}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
@@ -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<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
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 (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="space-y-4">
|
||||
{/* Page Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('loanOrderMobiles.title', 'Karz sargytlary')}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("loanOrderMobiles.title", "Karz sargytlary")}</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("loanOrderMobiles.createButton", "Karz sargyt dörediň")}
|
||||
onClick={() => navigate("/loan-order-mobiles/create")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Table Card */}
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -314,14 +297,15 @@ export default function LoanOrderMobilesPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => { 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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<LoanOrderStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>
|
||||
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<LoanOrderStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>;
|
||||
|
||||
function LoanOrderStatusBadge({ status }: { status: LoanOrderStatus }) {
|
||||
const cfg = STATUS_CONFIG[status]
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── 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<string | null>(null)
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const deleteMutation = useDeleteLoanOrder();
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(10)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS])
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS]);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ 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<ColumnDef<LoanOrder>[]>(
|
||||
() => [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('ID', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-xs font-mono text-muted-foreground">{row.original.id}</span>
|
||||
),
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("ID", "ID"),
|
||||
cell: ({ row }) => <span className="text-xs font-mono text-muted-foreground">{row.original.id}</span>,
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
id: 'loanType',
|
||||
accessorKey: 'loanType',
|
||||
header: t('Loan type', 'KARZ GÖRNÜŞI'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-medium text-primary hover:underline cursor-pointer">
|
||||
{row.original.loanType}
|
||||
</span>
|
||||
),
|
||||
id: "loanType",
|
||||
accessorKey: "loanType",
|
||||
header: t("Loan type", "KARZ GÖRNÜŞI"),
|
||||
cell: ({ row }) => <span className="text-sm font-medium text-primary hover:underline cursor-pointer">{row.original.loanType}</span>,
|
||||
},
|
||||
{
|
||||
id: 'createdAt',
|
||||
accessorKey: 'createdAt',
|
||||
header: t('Created at', 'DÖREDILEN WAGTY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">{row.original.createdAt}</span>
|
||||
),
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("Created at", "DÖREDILEN WAGTY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground whitespace-nowrap">{row.original.createdAt}</span>,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: 'region',
|
||||
accessorKey: 'region',
|
||||
header: t('Region', 'WELAÝAT'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.region}</span>
|
||||
),
|
||||
id: "region",
|
||||
accessorKey: "region",
|
||||
header: t("Region", "WELAÝAT"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.region}</span>,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'branch',
|
||||
accessorKey: 'branch',
|
||||
header: t('Branch', 'ŞAHAMÇA'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-emerald-500 font-medium">{row.original.branch}</span>
|
||||
),
|
||||
id: "branch",
|
||||
accessorKey: "branch",
|
||||
header: t("Branch", "ŞAHAMÇA"),
|
||||
cell: ({ row }) => <span className="text-sm text-emerald-500 font-medium">{row.original.branch}</span>,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'firstName',
|
||||
accessorKey: 'firstName',
|
||||
header: t('Name', 'ADY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.firstName}</span>
|
||||
),
|
||||
id: "firstName",
|
||||
accessorKey: "firstName",
|
||||
header: t("Name", "ADY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.firstName}</span>,
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: 'lastName',
|
||||
accessorKey: 'lastName',
|
||||
header: t('Surname', 'FAMILIÝASY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.lastName}</span>
|
||||
),
|
||||
id: "lastName",
|
||||
accessorKey: "lastName",
|
||||
header: t("Surname", "FAMILIÝASY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.lastName}</span>,
|
||||
size: 120,
|
||||
},
|
||||
{
|
||||
id: 'phone',
|
||||
accessorKey: 'phone',
|
||||
header: t('Phone', 'TELEFON'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.phone}</span>
|
||||
),
|
||||
id: "phone",
|
||||
accessorKey: "phone",
|
||||
header: t("Phone", "TELEFON"),
|
||||
cell: ({ row }) => <span className="text-sm font-mono text-foreground">{row.original.phone}</span>,
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
accessorKey: 'status',
|
||||
header: t('Status', 'STATUS'),
|
||||
id: "status",
|
||||
accessorKey: "status",
|
||||
header: t("Status", "STATUS"),
|
||||
cell: ({ row }) => <LoanOrderStatusBadge status={row.original.status} />,
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'View')}
|
||||
title={t("common.view", "View")}
|
||||
onClick={() => navigate(`/loan-orders/${row.original.id}`)}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Edit')}
|
||||
title={t("common.edit", "Edit")}
|
||||
onClick={() => navigate(`/loan-orders/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
@@ -213,7 +194,7 @@ export default function LoanOrdersPage() {
|
||||
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', 'Delete')}
|
||||
title={t("common.delete", "Delete")}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
@@ -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<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
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 (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('loanOrders.title', 'Karz sargytlary')}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("loanOrders.title", "Karz sargytlary")}</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("loanOrderMobiles.searchPlaceholder", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("loanOrderMobiles.createButton", "Karz sargyt dörediñ")} onClick={() => navigate("/loan-orders/create")} />
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
hideSearch
|
||||
hideAction
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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);
|
||||
}}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -305,14 +299,15 @@ export default function LoanOrdersPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => { 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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="space-y-4">
|
||||
{/* Page Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("loanPaidOffLetters.title", "Karzyň ýapylandygy barada güwanamalar")}</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("loanPaidOffLetters.title", "Karzyň ýapylandygy barada güwanamalar")} </h1>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("loanPaidOffLetters.createButton", "Karzyň ýapylandygy barada güwanama almak dörediň")}
|
||||
onClick={handleCreate}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 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() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteId(null);
|
||||
}}
|
||||
title={t("loanPaidOffLetters.deleteConfirm", "Bu ýazgy pozulsynmy?")}
|
||||
confirmLabel={t("common.delete", "Poz")}
|
||||
onConfirm={confirmDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
|
||||
@@ -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<number | null>(null)
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const deleteMutation = useDeleteLoanRemaining();
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS])
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([])
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS]);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([]);
|
||||
|
||||
// ── 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<ColumnDef<LoanRemaining>[]>(
|
||||
() => [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('loanRemaining.columns.id', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-semibold text-primary">{row.original.id}</span>
|
||||
),
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("loanRemaining.columns.id", "ID"),
|
||||
cell: ({ row }) => <span className="text-sm font-semibold text-primary">{row.original.id}</span>,
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
id: 'passportSeries',
|
||||
accessorKey: 'passportSeries',
|
||||
header: t('loanRemaining.columns.passportSeries', 'PASPORT SERIÝASY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.passportSeries}</span>
|
||||
),
|
||||
id: "passportSeries",
|
||||
accessorKey: "passportSeries",
|
||||
header: t("loanRemaining.columns.passportSeries", "PASPORT SERIÝASY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.passportSeries}</span>,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: 'passportNumber',
|
||||
accessorKey: 'passportNumber',
|
||||
header: t('loanRemaining.columns.passportNumber', 'PASPORT BELGISI'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.passportNumber}</span>
|
||||
),
|
||||
id: "passportNumber",
|
||||
accessorKey: "passportNumber",
|
||||
header: t("loanRemaining.columns.passportNumber", "PASPORT BELGISI"),
|
||||
cell: ({ row }) => <span className="text-sm font-mono text-foreground">{row.original.passportNumber}</span>,
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: 'loanAccount',
|
||||
accessorKey: 'loanAccount',
|
||||
header: t('loanRemaining.columns.loanAccount', 'KARZ HASABY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.loanAccount}</span>
|
||||
),
|
||||
id: "loanAccount",
|
||||
accessorKey: "loanAccount",
|
||||
header: t("loanRemaining.columns.loanAccount", "KARZ HASABY"),
|
||||
cell: ({ row }) => <span className="text-sm font-mono text-foreground">{row.original.loanAccount}</span>,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
onClick={() => navigate(`/loan-remaining/${row.original.id}`)}
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görmek')}
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate(`/loan-remaining/${row.original.id}/edit`)}
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
title={t("common.edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</button>
|
||||
@@ -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")}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
@@ -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<FilterField[]>(() => [], [])
|
||||
const filterFields = useMemo<FilterField[]>(() => [], []);
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="space-y-4">
|
||||
{/* Page Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('loanRemaining.title', 'Karzyň galyndysy')}
|
||||
</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("loanRemaining.title", "Karzyň galyndysy")}</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("loanRemaining.createButton", "Karzyň galyndysy dörediň")}
|
||||
onClick={() => navigate("/loan-remaining/create")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Table Card */}
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
@@ -193,14 +198,15 @@ export default function LoanRemainingPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => { 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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<ActiveFilter[]>([
|
||||
{ fieldId: 'isActive', value: '' },
|
||||
])
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([
|
||||
'id', 'name', 'value', 'description', 'isActive', 'actions',
|
||||
])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([{ fieldId: "isActive", value: "" }]);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(["id", "name", "value", "description", "isActive", "actions"]);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(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<CardType>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('common.id', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-mono text-sm font-medium">{row.original.id}</span>
|
||||
),
|
||||
accessorKey: "id",
|
||||
header: t("common.id", "ID"),
|
||||
cell: ({ row }) => <span className="text-primary font-mono text-sm font-medium">{row.original.id}</span>,
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
id: 'name',
|
||||
header: t('cardTypes.fields.name', 'ADY').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
accessorKey: "name",
|
||||
id: "name",
|
||||
header: t("cardTypes.fields.name", "ADY").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name[lang]}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'value',
|
||||
header: t('cardTypes.fields.value', 'BAHA').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.value}</span>
|
||||
),
|
||||
accessorKey: "value",
|
||||
header: t("cardTypes.fields.value", "BAHA").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.value}</span>,
|
||||
size: 120,
|
||||
},
|
||||
{
|
||||
accessorKey: 'description',
|
||||
header: t('cardTypes.fields.description', 'BELLIKLER').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{row.original.description ?? '—'}
|
||||
</span>
|
||||
),
|
||||
accessorKey: "description",
|
||||
header: t("cardTypes.fields.description", "BELLIKLER").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground">{row.original.description ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
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 ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
@@ -112,28 +89,28 @@ export function CardTypesListPage() {
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-2 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/card/card-types/${row.original.id}`)}
|
||||
title={t('common.view', 'Görmek')}
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/card/card-types/${row.original.id}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
title={t("common.edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('common.delete', 'Öçürmek')}
|
||||
title={t("common.delete", "Öçürmek")}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
@@ -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 (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('cardTypes.title', 'Kart görnüşleri')}
|
||||
</h1>
|
||||
<h1 className="text-2xl font-bold text-foreground">{t("cardTypes.title", "Kart görnüşleri")}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("cardTypes.actions.create", "Kart görnüşi döretdiň")}
|
||||
onClick={() => navigate("/settings/card/card-types/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
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 */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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 */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={() => setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('cardTypes.deleteConfirm', 'Bu kart görnüşini öçürmek isleýärsiňizmi?')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={() => {
|
||||
if (deleteId !== null) {
|
||||
deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) })
|
||||
}
|
||||
}}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default CardTypesListPage
|
||||
export default CardTypesListPage;
|
||||
|
||||
@@ -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<ActiveFilter[]>([
|
||||
{ fieldId: 'isActive', value: '' },
|
||||
])
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([
|
||||
'id', 'name', 'value', 'description', 'isActive', 'actions',
|
||||
])
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([{ fieldId: "isActive", value: "" }]);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(["id", "name", "value", "description", "isActive", "actions"]);
|
||||
|
||||
// ── Delete dialog ────────────────────────────────────────────────────────────
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
const deleteMutation = useDeleteCardReason()
|
||||
const [deleteId, setDeleteId] = useState<number | null>(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<CardReason>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('common.id', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-mono text-sm font-medium">
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
accessorKey: "id",
|
||||
header: t("common.id", "ID"),
|
||||
cell: ({ row }) => <span className="text-primary font-mono text-sm font-medium">{row.original.id}</span>,
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
id: 'name',
|
||||
header: t('cardReasons.fields.name', 'ADY').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
accessorKey: "name",
|
||||
id: "name",
|
||||
header: t("cardReasons.fields.name", "ADY").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name[lang]}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'value',
|
||||
header: t('cardReasons.fields.value', 'BAHA').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.value}</span>
|
||||
),
|
||||
accessorKey: "value",
|
||||
header: t("cardReasons.fields.value", "BAHA").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.value}</span>,
|
||||
size: 120,
|
||||
},
|
||||
{
|
||||
accessorKey: 'description',
|
||||
header: t('cardReasons.fields.description', 'BELLIKLER').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{row.original.description ?? '—'}
|
||||
</span>
|
||||
),
|
||||
accessorKey: "description",
|
||||
header: t("cardReasons.fields.description", "BELLIKLER").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground">{row.original.description ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
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 ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
@@ -125,28 +100,28 @@ export function CardReasonsListPage() {
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-2 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/card/card-reasons/${row.original.id}`)}
|
||||
title={t('common.view', 'Görmek')}
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/card/card-reasons/${row.original.id}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
title={t("common.edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('common.delete', 'Öçürmek')}
|
||||
title={t("common.delete", "Öçürmek")}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
@@ -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 (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('cardReasons.title', 'Kartyň çykarylmagynyň sebäpleri')}
|
||||
</h1>
|
||||
<h1 className="text-2xl font-bold text-foreground">{t("cardReasons.title", "Kartyň çykarylmagynyň sebäpleri")}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("cardReasons.actions.create", "Kartyň çykarylmagynyň sebäbini döretdiň")}
|
||||
onClick={() => navigate("/settings/card/card-reasons/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
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 */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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 */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={() => setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('common.confirmDelete', 'Öçürmegi tassyklaň')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('cardReasons.deleteConfirm', 'Bu kartyň çykarylmagynyň sebäbini öçürmek isleýärsiňizmi?')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={() => {
|
||||
if (deleteId !== null) {
|
||||
deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) })
|
||||
}
|
||||
}}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default CardReasonsListPage
|
||||
export default CardReasonsListPage;
|
||||
|
||||
@@ -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<LoanType>[] {
|
||||
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 }) => (
|
||||
<span className="text-primary font-semibold text-sm">{row.original.id}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-semibold text-sm">{row.original.id}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('loanTypes.columns.name', 'ADY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
accessorKey: "name",
|
||||
header: t("loanTypes.columns.name", "ADY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name[lang]}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'tax',
|
||||
header: t('loanTypes.columns.tax', 'SALGYT'),
|
||||
accessorKey: "tax",
|
||||
header: t("loanTypes.columns.tax", "SALGYT"),
|
||||
size: 90,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.tax}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.tax}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'loanTerm',
|
||||
header: t('loanTypes.columns.loanTerm', 'KARZ MÖHLETI'),
|
||||
accessorKey: "loanTerm",
|
||||
header: t("loanTypes.columns.loanTerm", "KARZ MÖHLETI"),
|
||||
size: 130,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.loanTerm}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.loanTerm}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'notes',
|
||||
header: t('loanTypes.columns.notes', 'BELLIKLER'),
|
||||
accessorKey: "notes",
|
||||
header: t("loanTypes.columns.notes", "BELLIKLER"),
|
||||
cell: ({ row }) => {
|
||||
const notes = row.original.notes
|
||||
return (
|
||||
<span className="text-sm text-foreground">
|
||||
{notes ? notes[lang] || '—' : '—'}
|
||||
</span>
|
||||
)
|
||||
const notes = row.original.notes;
|
||||
return <span className="text-sm text-foreground">{notes ? notes[lang] || "—" : "—"}</span>;
|
||||
},
|
||||
},
|
||||
{
|
||||
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(
|
||||
<button
|
||||
onClick={() => onView(row.original.id)}
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görmek')}
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onEdit(row.original.id)}
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Redaktirlemek')}
|
||||
title={t("common.edit", "Redaktirlemek")}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onDelete(row.original.id)}
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
title={t("common.delete", "Pozmak")}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
// ─── 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<number | null>(null)
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
|
||||
const [columnVisibility, setColumnVisibility] = useState<Record<string, boolean>>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
const [columnVisibility, setColumnVisibility] = useState<Record<string, boolean>>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
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 (
|
||||
<div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">{t("loanTypes.title", "Karz görnüşleri")}</h1>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("loanTypes.actions.create", "Karz görnüşi dörediň")}
|
||||
onClick={() => navigate("/settings/loan/loan-types/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{t('loanTypes.title', 'Karz görnüşleri')}
|
||||
</h1>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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')}
|
||||
/>
|
||||
|
||||
<DataTable<LoanType>
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
<DataTable<LoanType>
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Delete confirmation dialog */}
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('loanTypes.deleteDialog.title', 'Pozmak')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('loanTypes.deleteDialog.description', 'Bu karz görnüşini pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylyp bilinmez.')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={deleteMutation.isPending}>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={confirmDelete}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="bg-destructive hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending ? t('common.deleting', 'Pozulýar...') : t('common.delete', 'Pozmak')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<VisibilityState>(DEFAULT_VISIBILITY)
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(DEFAULT_ORDER)
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage] = useState(10);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>(DEFAULT_VISIBILITY);
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(DEFAULT_ORDER);
|
||||
|
||||
// ── Data ────────────────────────────────────────────────────────────────────
|
||||
const { data, isLoading } = useGetRequiredDocuments({ page, perPage, search })
|
||||
const deleteMutation = useDeleteRequiredDocument()
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
const { data, isLoading } = useGetRequiredDocuments({ page, perPage, search });
|
||||
const deleteMutation = useDeleteRequiredDocument();
|
||||
const [deleteId, setDeleteId] = useState<number | null>(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<LoanDocument>[] = [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('common.id', 'ID'),
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("common.id", "ID"),
|
||||
size: 72,
|
||||
cell: ({ row }) => (
|
||||
<span
|
||||
@@ -59,16 +61,14 @@ export default function RequiredDocumentsListPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'name',
|
||||
header: t('loanDocuments.columns.name', 'ADY'),
|
||||
id: "name",
|
||||
header: t("loanDocuments.columns.name", "ADY"),
|
||||
accessorFn: (row) => row.name[lang],
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name[lang]}</span>,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
size: 100,
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => (
|
||||
@@ -76,14 +76,14 @@ export default function RequiredDocumentsListPage() {
|
||||
<button
|
||||
onClick={() => navigate(`/settings/loan/required-documents/${row.original.id}`)}
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görüntüle')}
|
||||
title={t("common.view", "Görüntüle")}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate(`/settings/loan/required-documents/${row.original.id}/edit`)}
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Düzet')}
|
||||
title={t("common.edit", "Düzet")}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</button>
|
||||
@@ -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")}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
{/* Page heading */}
|
||||
<h1 className="text-xl font-semibold text-foreground mb-4">
|
||||
{t('loanDocuments.title', 'Karz gerekli resminamalary')}
|
||||
</h1>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<h1 className="text-xl font-semibold text-foreground mb-4">{t("loanDocuments.title", "Karz gerekli resminamalary")}</h1>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("loanDocuments.createBtn", "Karz gerekli resminamalary döretiň")}
|
||||
onClick={() => navigate("/settings/loan/required-documents/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMetas}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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 */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => String(row.id)}
|
||||
enableRowSelection
|
||||
currentPage={page}
|
||||
totalPages={data?.totalPages ?? 1}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => String(row.id)}
|
||||
enableRowSelection
|
||||
currentPage={page}
|
||||
totalPages={data?.totalPages ?? 1}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
<ConfirmDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => { if (!o) setDeleteId(null) }}
|
||||
title={t('loanDocuments.deleteConfirm', 'Bu resminamany öçürmek isleýärsiňizmi?')}
|
||||
confirmLabel={t('common.delete', 'Poz')}
|
||||
onConfirm={confirmDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteId(null);
|
||||
}}
|
||||
title={t("loanDocuments.deleteConfirm", "Bu resminamany öçürmek isleýärsiňizmi?")}
|
||||
onConfirm={confirmDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<ActiveFilter[]>([
|
||||
{ fieldId: 'isActive', value: '' },
|
||||
{ fieldId: 'districtId', value: '' },
|
||||
])
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([
|
||||
'id', 'code', 'name', 'districtName', 'phone', 'isActive', 'actions',
|
||||
])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
{ fieldId: "isActive", value: "" },
|
||||
{ fieldId: "districtId", value: "" },
|
||||
]);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(["id", "code", "name", "districtName", "phone", "isActive", "actions"]);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(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<Branch>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('common.id', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-mono text-sm font-medium">{row.original.id}</span>
|
||||
),
|
||||
accessorKey: "id",
|
||||
header: t("common.id", "ID"),
|
||||
cell: ({ row }) => <span className="text-primary font-mono text-sm font-medium">{row.original.id}</span>,
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
accessorKey: 'code',
|
||||
id: 'code',
|
||||
header: t('branches.fields.code', 'KOD').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.code}</span>
|
||||
),
|
||||
accessorKey: "code",
|
||||
id: "code",
|
||||
header: t("branches.fields.code", "KOD").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm font-mono text-foreground">{row.original.code}</span>,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
id: 'name',
|
||||
header: t('branches.fields.name', 'ADY').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
accessorKey: "name",
|
||||
id: "name",
|
||||
header: t("branches.fields.name", "ADY").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name[lang]}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'districtName',
|
||||
id: 'districtName',
|
||||
header: t('branches.fields.district', 'ETRAP').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground">{row.original.districtName[lang]}</span>
|
||||
),
|
||||
accessorKey: "districtName",
|
||||
id: "districtName",
|
||||
header: t("branches.fields.district", "ETRAP").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground">{row.original.districtName[lang]}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'phone',
|
||||
header: t('branches.fields.phone', 'TELEFON').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.phone}</span>
|
||||
),
|
||||
accessorKey: "phone",
|
||||
header: t("branches.fields.phone", "TELEFON").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.phone}</span>,
|
||||
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 ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
@@ -136,28 +115,28 @@ export function BranchesListPage() {
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-2 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/location/branches/${row.original.id}`)}
|
||||
title={t('common.view', 'Görmek')}
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/location/branches/${row.original.id}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
title={t("common.edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('common.delete', 'Öçürmek')}
|
||||
title={t("common.delete", "Öçürmek")}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
@@ -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 (
|
||||
<div >
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('branches.title', 'Şahamçalar')}
|
||||
</h1>
|
||||
<h1 className="text-2xl font-bold text-foreground">{t("branches.title", "Şahamçalar")}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("branches.actions.create", "Şahamça döret")}
|
||||
onClick={() => navigate("/settings/location/branches/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
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
|
||||
/>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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')}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
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}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={() => setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('branches.deleteConfirm', 'Bu şahamçany öçürmek isleýärsiňizmi?')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={() => {
|
||||
if (deleteId !== null) {
|
||||
deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) })
|
||||
}
|
||||
}}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default BranchesListPage
|
||||
export default BranchesListPage;
|
||||
|
||||
@@ -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<ActiveFilter[]>([
|
||||
{ fieldId: 'isActive', value: '' },
|
||||
])
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([
|
||||
'id', 'name', 'description', 'isActive', 'actions',
|
||||
])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([{ fieldId: "isActive", value: "" }]);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(["id", "name", "description", "isActive", "actions"]);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(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<District>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('common.id', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-mono text-sm font-medium">{row.original.id}</span>
|
||||
),
|
||||
accessorKey: "id",
|
||||
header: t("common.id", "ID"),
|
||||
cell: ({ row }) => <span className="text-primary font-mono text-sm font-medium">{row.original.id}</span>,
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
id: 'name',
|
||||
header: t('districts.fields.name', 'ADY').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
accessorKey: "name",
|
||||
id: "name",
|
||||
header: t("districts.fields.name", "ADY").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name[lang]}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'description',
|
||||
header: t('districts.fields.description', 'BELLIKLER').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{row.original.description ?? '—'}
|
||||
</span>
|
||||
),
|
||||
accessorKey: "description",
|
||||
header: t("districts.fields.description", "BELLIKLER").toUpperCase(),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground">{row.original.description ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
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 ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
@@ -104,28 +83,28 @@ export function DistrictsListPage() {
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-2 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/location/districts/${row.original.id}`)}
|
||||
title={t('common.view', 'Görmek')}
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/location/districts/${row.original.id}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
title={t("common.edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('common.delete', 'Öçürmek')}
|
||||
title={t("common.delete", "Öçürmek")}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
@@ -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 (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('districts.title', 'Etraplar')}
|
||||
</h1>
|
||||
<h1 className="text-2xl font-bold text-foreground">{t("districts.title", "Etraplar")}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("districts.actions.create", "Etrap döret")}
|
||||
onClick={() => navigate("/settings/location/districts/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
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
|
||||
/>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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')}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(o) => {
|
||||
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}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={() => setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('districts.deleteConfirm', 'Bu etrapy öçürmek isleýärsiňizmi?')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={() => {
|
||||
if (deleteId !== null) {
|
||||
deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) })
|
||||
}
|
||||
}}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default DistrictsListPage
|
||||
export default DistrictsListPage;
|
||||
|
||||
@@ -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<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(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<Permission>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('common.id', 'ID'),
|
||||
accessorKey: "id",
|
||||
header: t("common.id", "ID"),
|
||||
size: 70,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-semibold">{row.original.id}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-semibold">{row.original.id}</span>,
|
||||
},
|
||||
{
|
||||
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 }) => <span>{row.original.name?.tk ?? '—'}</span>,
|
||||
accessorKey: "name",
|
||||
header: t("permissions.fields.name", "Ady"),
|
||||
cell: ({ row }) => <span>{row.original.name?.tk ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
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() {
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
// ── 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 (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
{/* Page heading */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('permissions.title', 'Rugsatlar')}
|
||||
</h1>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">{t("permissions.title", "Rugsatlar")}</h1>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("permissions.searchPlaceholder", "Gözlemek...")}
|
||||
/>
|
||||
<CreateButton
|
||||
label={t("permissions.actions.create", "Rugsat dörediň")}
|
||||
onClick={() => navigate("/settings/users/permissions/create")}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
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 */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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 */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={data?.meta?.current_page ?? 1}
|
||||
totalPages={data?.meta?.last_page ?? 1}
|
||||
totalCount={data?.meta?.total ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={data?.meta?.current_page ?? 1}
|
||||
totalPages={data?.meta?.last_page ?? 1}
|
||||
totalCount={data?.meta?.total ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Delete confirmation dialog */}
|
||||
<AlertDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(open) => { if (!open) setDeleteId(null) }}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('permissions.deleteDialog.title', 'Rugsaty pozmak')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'permissions.deleteDialog.description',
|
||||
'Bu rugsaty pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleConfirmDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deletePermission.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(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<Role>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('common.id', 'ID'),
|
||||
accessorKey: "id",
|
||||
header: t("common.id", "ID"),
|
||||
size: 70,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-semibold">{row.original.id}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-primary font-semibold">{row.original.id}</span>,
|
||||
},
|
||||
{
|
||||
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 }) => <span>{row.original.name?.tk ?? '—'}</span>,
|
||||
accessorKey: "name",
|
||||
header: t("roles.fields.name", "Ady"),
|
||||
cell: ({ row }) => <span>{row.original.name?.tk ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
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() {
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
// ── 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 (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
{/* Page heading */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('roles.title', 'Rollar')}
|
||||
</h1>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">{t("roles.title", "Rollar")}</h1>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("roles.searchPlaceholder", "Gözlemek...")}
|
||||
/>
|
||||
<CreateButton label={t("roles.actions.create", "Rol dörediň")} onClick={() => navigate("/settings/users/roles/create")} />
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
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 */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { 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 */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={data?.meta?.current_page ?? 1}
|
||||
totalPages={data?.meta?.last_page ?? 1}
|
||||
totalCount={data?.meta?.total ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={data?.meta?.current_page ?? 1}
|
||||
totalPages={data?.meta?.last_page ?? 1}
|
||||
totalCount={data?.meta?.total ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
{/* Delete confirmation dialog */}
|
||||
<AlertDialog
|
||||
<DeleteDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(open) => { if (!open) setDeleteId(null) }}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('roles.deleteDialog.title', 'Roly pozmak')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'roles.deleteDialog.description',
|
||||
'Bu roly pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleConfirmDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteRole.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">{t("users.title", "Ähli ulanyjylar")}</h1>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput value={search} onChange={handleSearchChange} placeholder={t("users.searchPlaceholder", "Gözlemek")} />
|
||||
<CreateButton label={t("users.actions.create", "Ulanyjy dörediň")} onClick={() => navigate("/all-users/create")} />
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
@@ -181,8 +187,8 @@ export default function UsersListPage() {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
actionLabel={t("users.actions.create", "Ulanyjy dörediň")}
|
||||
onAction={() => navigate("/all-users/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
@@ -203,7 +209,7 @@ export default function UsersListPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(o) => {
|
||||
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}
|
||||
/>
|
||||
|
||||
@@ -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<string[]>([])
|
||||
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<string[]>([]);
|
||||
|
||||
const [deleteTarget, setDeleteTarget] = useState<Client | null>(null)
|
||||
const [deleteTarget, setDeleteTarget] = useState<Client | null>(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<Client>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: t('common.id', 'ID'),
|
||||
accessorKey: "id",
|
||||
header: t("common.id", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<span
|
||||
className="text-primary font-semibold cursor-pointer hover:underline text-sm"
|
||||
@@ -49,39 +51,39 @@ export default function ClientsPage() {
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
accessorKey: 'username',
|
||||
header: t('clients.fields.username', 'ULANYJY ADY'),
|
||||
accessorKey: "username",
|
||||
header: t("clients.fields.username", "ULANYJY ADY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.username}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('clients.fields.name', 'ADY'),
|
||||
accessorKey: "name",
|
||||
header: t("clients.fields.name", "ADY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'phone',
|
||||
header: t('clients.fields.phone', 'TELEFON'),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.phone ?? '—'}</span>,
|
||||
accessorKey: "phone",
|
||||
header: t("clients.fields.phone", "TELEFON"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.phone ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'email',
|
||||
header: t('clients.fields.email', 'E-POÇTA'),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.email ?? '—'}</span>,
|
||||
accessorKey: "email",
|
||||
header: t("clients.fields.email", "E-POÇTA"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.email ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
header: t('clients.fields.isActive', 'IŞJEŇ'),
|
||||
accessorKey: "isActive",
|
||||
header: t("clients.fields.isActive", "IŞJEŇ"),
|
||||
cell: ({ row }) =>
|
||||
row.original.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-destructive" />
|
||||
<XCircle size={18} className="text-destructive" />
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
id: "actions",
|
||||
header: "",
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button
|
||||
@@ -113,89 +115,107 @@ export default function ClientsPage() {
|
||||
size: 120,
|
||||
enableSorting: false,
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
const columnMetas = columns
|
||||
.filter((c) => 'accessorKey' in c && c.accessorKey)
|
||||
.filter((c) => "accessorKey" in c && c.accessorKey)
|
||||
.map((c) => ({
|
||||
id: ('accessorKey' in c ? String(c.accessorKey) : c.id) as string,
|
||||
label: typeof c.header === 'string' ? c.header : ('accessorKey' in c ? String(c.accessorKey) : '') ?? '',
|
||||
}))
|
||||
id: ("accessorKey" in c ? String(c.accessorKey) : c.id) as string,
|
||||
label: typeof c.header === "string" ? c.header : (("accessorKey" in c ? String(c.accessorKey) : "") ?? ""),
|
||||
}));
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">
|
||||
{t('clients.title', 'Müşderiler')}
|
||||
</h1>
|
||||
<h1 className="text-2xl font-semibold text-foreground">{t("clients.title", "Müşderiler")}</h1>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("clients.createBtn", "Müşderi dörediň")} onClick={() => navigate("/clients/create")} />
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMetas}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={[
|
||||
{
|
||||
id: "isActive",
|
||||
label: t("clients.fields.isActive", "Işjeň"),
|
||||
options: [
|
||||
{ value: "true", label: t("common.active", "Işjeň") },
|
||||
{ value: "false", label: t("common.inactive", "Işjeň däl") },
|
||||
],
|
||||
},
|
||||
]}
|
||||
activeFilters={[{ fieldId: "isActive", value: isActiveFilter }]}
|
||||
onFilterChange={(fieldId, value) => {
|
||||
if (fieldId === "isActive") setIsActiveFilter(value);
|
||||
setPage(1);
|
||||
}}
|
||||
onFilterReset={() => {
|
||||
setIsActiveFilter("");
|
||||
setPage(1);
|
||||
}}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMetas}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={[
|
||||
{
|
||||
id: 'isActive',
|
||||
label: t('clients.fields.isActive', 'Işjeň'),
|
||||
options: [
|
||||
{ value: 'true', label: t('common.active', 'Işjeň') },
|
||||
{ value: 'false', label: t('common.inactive', 'Işjeň däl') },
|
||||
],
|
||||
},
|
||||
]}
|
||||
activeFilters={[{ fieldId: 'isActive', value: isActiveFilter }]}
|
||||
onFilterChange={(fieldId, value) => {
|
||||
if (fieldId === 'isActive') setIsActiveFilter(value)
|
||||
setPage(1)
|
||||
}}
|
||||
onFilterReset={() => { setIsActiveFilter(''); setPage(1) }}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
actionLabel={t('clients.createBtn', 'Müşderi dörediň')}
|
||||
onAction={() => navigate('/clients/create')}
|
||||
/>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={clients}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={totalCount}
|
||||
onPageChange={setPage}
|
||||
enableRowSelection
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={clients}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={totalCount}
|
||||
onPageChange={setPage}
|
||||
enableRowSelection
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(o) => { if (!o) setDeleteTarget(null) }}
|
||||
title={t('clients.deleteTitle', 'Müşderini pozmak')}
|
||||
description={t('clients.deleteConfirm', '{{name}} müşderisini pozmak isleýärsiňizmi? Bu amaly yzyna gaýtaryp bolmaz.', {
|
||||
name: deleteTarget?.name ?? '',
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteTarget(null);
|
||||
}}
|
||||
title={t("clients.deleteTitle", "Müşderini pozmak")}
|
||||
description={t("clients.deleteConfirm", "{{name}} müşderisini pozmak isleýärsiňizmi? Bu amaly yzyna gaýtaryp bolmaz.", {
|
||||
name: deleteTarget?.name ?? "",
|
||||
})}
|
||||
confirmLabel={t('common.delete', 'Poz')}
|
||||
onConfirm={() => {
|
||||
if (deleteTarget) {
|
||||
deleteMutation.mutate(deleteTarget.id)
|
||||
setDeleteTarget(null)
|
||||
deleteMutation.mutate(deleteTarget.id);
|
||||
setDeleteTarget(null);
|
||||
}
|
||||
}}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@ 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 { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||
import {
|
||||
useOperators,
|
||||
useDeleteOperator,
|
||||
} from "@/features/operators/hooks/useOperators";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { useOperators, useDeleteOperator } from "@/features/operators/hooks/useOperators";
|
||||
import type { Operator } from "@/features/operators/api/operatorsApi";
|
||||
|
||||
// ─── OperatorsPage ────────────────────────────────────────────────────────────
|
||||
@@ -60,34 +59,22 @@ export default function OperatorsPage() {
|
||||
{
|
||||
accessorKey: "username",
|
||||
header: t("operators.fields.username", "ULANYJY ADY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.username}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.username}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "name",
|
||||
header: t("operators.fields.name", "ADY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name}</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "phone",
|
||||
header: t("operators.fields.phone", "TELEFON"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.phone ?? "—"}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.phone ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "email",
|
||||
header: t("operators.fields.email", "E-POÇTA"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.email ?? "—"}
|
||||
</span>
|
||||
),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.email ?? "—"}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "isActive",
|
||||
@@ -140,20 +127,26 @@ export default function OperatorsPage() {
|
||||
.filter((c) => "accessorKey" in c && c.accessorKey)
|
||||
.map((c) => ({
|
||||
id: ("accessorKey" in c ? String(c.accessorKey) : c.id) as string,
|
||||
label:
|
||||
typeof c.header === "string"
|
||||
? c.header
|
||||
: (("accessorKey" in c ? String(c.accessorKey) : "") ?? ""),
|
||||
label: typeof c.header === "string" ? c.header : (("accessorKey" in c ? String(c.accessorKey) : "") ?? ""),
|
||||
}));
|
||||
|
||||
// ── Render ───────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div>
|
||||
<div className="space-y-4">
|
||||
{/* Page header */}
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">
|
||||
{t("operators.title", "Operatorlar")}
|
||||
</h1>
|
||||
<h1 className="text-2xl font-semibold text-foreground">{t("operators.title", "Operatorlar")}</h1>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
onChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
<CreateButton label={t("operators.createBtn", "Operator döredin")} onClick={() => navigate("/operators/create")} />
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
{/* Toolbar */}
|
||||
@@ -194,8 +187,8 @@ export default function OperatorsPage() {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
actionLabel={t("operators.createBtn", "Operator döredin")}
|
||||
onAction={() => navigate("/operators/create")}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
@@ -217,17 +210,13 @@ export default function OperatorsPage() {
|
||||
</div>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<ConfirmDialog
|
||||
<DeleteDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setDeleteTarget(null);
|
||||
}}
|
||||
title={t("operators.deleteTitle", "Operatory pozmak")}
|
||||
description={t(
|
||||
"operators.deleteDescription",
|
||||
'Siz "{name}" operatoryny pozjakmy?',
|
||||
).replace("{name}", deleteTarget?.name ?? "")}
|
||||
confirmLabel={t("common.delete", "Poz")}
|
||||
description={t("operators.deleteDescription", 'Siz "{name}" operatoryny pozjakmy?').replace("{name}", deleteTarget?.name ?? "")}
|
||||
onConfirm={() => {
|
||||
if (deleteTarget) {
|
||||
deleteMutation.mutate(deleteTarget.id);
|
||||
|
||||
Reference in New Issue
Block a user