added some pages
This commit is contained in:
1 parent
c2548280a2
commit
c7797c3e31
61 files changed
+8309
-35
No files matched your search
@@ -0,0 +1,209 @@
|
||||
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 {
|
||||
useCardBalances,
|
||||
useDeleteCardBalance,
|
||||
useDownloadCardBalance,
|
||||
} from '@/features/cardBalance/hooks/useCardBalance'
|
||||
import { type CardBalance } from '@/features/cardBalance/api/cardBalanceApi'
|
||||
|
||||
const PER_PAGE = 25
|
||||
|
||||
export default function CardBalancesPage() {
|
||||
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 { data, isLoading } = useCardBalances({ page, per_page: perPage, search })
|
||||
const deleteMutation = useDeleteCardBalance()
|
||||
const downloadMutation = useDownloadCardBalance()
|
||||
|
||||
// ── Columns ───────────────────────────────────────────────────────────────
|
||||
|
||||
const columns: ColumnDef<CardBalance>[] = [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('ID', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-medium hover:underline"
|
||||
onClick={() => navigate(`/card-balances/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
},
|
||||
{
|
||||
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'),
|
||||
cell: ({ row }) => <span>{row.original.passport_number}</span>,
|
||||
},
|
||||
{
|
||||
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Ý)'),
|
||||
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)'),
|
||||
cell: ({ row }) => <span>{row.original.card_expiry_year}</span>,
|
||||
},
|
||||
{
|
||||
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"
|
||||
onClick={() => downloadMutation.mutate(row.original.id)}
|
||||
title={t('Download', 'Ýükle')}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-balances/${row.original.id}`)}
|
||||
title={t('View', 'Görmek')}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-balances/${row.original.id}/edit`)}
|
||||
title={t('Edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
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')}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
const columnMeta: ColumnMeta[] = columns
|
||||
.filter((c) => c.id !== 'actions')
|
||||
.map((c) => ({
|
||||
id: c.id!,
|
||||
label: typeof c.header === 'string' ? c.header : c.id!,
|
||||
}))
|
||||
|
||||
const total = data?.total ?? 0
|
||||
const totalPages = Math.ceil(total / perPage)
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (deleteId === null) return
|
||||
await deleteMutation.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">
|
||||
{t('Card balances', 'Kart galyndylary')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('Search', 'Gözlemek')}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t('Create card balance', 'Kart galyndysy dörediň')}
|
||||
onAction={() => navigate('/card-balances/create')}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
/>
|
||||
|
||||
<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={total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardBalanceForm } from '@/features/cardBalance/components/cardBalanceForm'
|
||||
|
||||
export default function CardBalanceCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('Create card balance', 'Kart galyndysy dörediň')}
|
||||
</h1>
|
||||
|
||||
<CardBalanceForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { CardBalanceForm } from '@/features/cardBalance/components/cardBalanceForm'
|
||||
import { useCardBalance } from '@/features/cardBalance/hooks/useCardBalance'
|
||||
|
||||
export default function CardBalanceEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading } = useCardBalance(numericId)
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-4 max-w-3xl">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t('Not found', 'Tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('Edit card balance', 'Kart galyndysyny düzetmek')}:{' '}
|
||||
<span className="text-primary font-mono">{data.id}</span>
|
||||
</h1>
|
||||
|
||||
<CardBalanceForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
cardBalanceId={numericId}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
import { useState } from 'react'
|
||||
import { useParams, useNavigate, Link } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Download, Trash2, Pencil, ChevronDown } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import {
|
||||
useCardBalance,
|
||||
useDeleteCardBalance,
|
||||
useDownloadCardBalance,
|
||||
} from '@/features/cardBalance/hooks/useCardBalance'
|
||||
|
||||
// ─── Types for operations table ───────────────────────────────────────────────
|
||||
|
||||
interface Operation {
|
||||
id: number
|
||||
action_name: string
|
||||
performed_by: string
|
||||
target: string
|
||||
status: 'FINISHED' | 'PENDING' | 'FAILED'
|
||||
date: string
|
||||
}
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_STYLES: Record<string, string> = {
|
||||
FINISHED: 'bg-emerald-500/20 text-emerald-400 border border-emerald-500/30',
|
||||
PENDING: 'bg-yellow-500/20 text-yellow-400 border border-yellow-500/30',
|
||||
FAILED: 'bg-red-500/20 text-red-400 border border-red-500/30',
|
||||
}
|
||||
|
||||
function OpStatusBadge({ status }: { status: string }) {
|
||||
return (
|
||||
<span className={`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold ${STATUS_STYLES[status] ?? STATUS_STYLES.PENDING}`}>
|
||||
<span className="w-1.5 h-1.5 rounded-full bg-current" />
|
||||
{status}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Detail row ───────────────────────────────────────────────────────────────
|
||||
|
||||
function DetailRow({ label, value }: { label: string; value: string | number }) {
|
||||
return (
|
||||
<div className="grid grid-cols-[220px_1fr] border-b border-border/50 last:border-0">
|
||||
<div className="px-4 py-3 text-sm text-muted-foreground font-medium bg-muted/10">
|
||||
{label}
|
||||
</div>
|
||||
<div className="px-4 py-3 text-sm text-foreground">{value}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function CardBalanceViewPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
const [opsExpanded, setOpsExpanded] = useState(true)
|
||||
const [opsPage, setOpsPage] = useState(1)
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading } = useCardBalance(numericId)
|
||||
const deleteMutation = useDeleteCardBalance()
|
||||
const downloadMutation = useDownloadCardBalance()
|
||||
|
||||
// Placeholder operations — in real app fetch from API using numericId
|
||||
const operations: Operation[] = []
|
||||
const opsTotal = operations.length
|
||||
|
||||
const handleDelete = async () => {
|
||||
await deleteMutation.mutateAsync(numericId)
|
||||
navigate('/card-balances')
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-7 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t('Not found', 'Tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Card balance detail', 'Kart galyndysy giňişleýin')}:
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline" size="sm"
|
||||
onClick={() => downloadMutation.mutate(numericId)}
|
||||
disabled={downloadMutation.isPending}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline" size="sm"
|
||||
className="text-destructive border-destructive/30 hover:bg-destructive/10"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" asChild>
|
||||
<Link to={`/card-balances/${numericId}/edit`}>
|
||||
<Pencil size={14} />
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Detail card */}
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
<DetailRow label={t('ID', 'ID')} value={data.id} />
|
||||
<DetailRow label={t('Passport series', 'Pasport seriýasy')} value={data.passport_series} />
|
||||
<DetailRow label={t('Passport number', 'Pasport belgisi')} value={data.passport_number} />
|
||||
<DetailRow label={t('Card number', 'Kart belgisi')} value={data.card_number} />
|
||||
<DetailRow label={t('Card expiry month', 'Kart Möhleti (aý)')} value={data.card_expiry_month} />
|
||||
<DetailRow label={t('Card expiry year', 'Kart Möhleti (ýyl)')} value={data.card_expiry_year} />
|
||||
</div>
|
||||
|
||||
{/* Ammallar (Operations) collapsible section */}
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
{/* Section toggle header */}
|
||||
<button
|
||||
className="w-full flex items-center gap-2 px-4 py-3 text-left hover:bg-muted/20 transition-colors"
|
||||
onClick={() => setOpsExpanded((v) => !v)}
|
||||
>
|
||||
<span className="font-semibold text-foreground text-sm">
|
||||
{t('Operations', 'Ammallar')}
|
||||
</span>
|
||||
<ChevronDown
|
||||
size={15}
|
||||
className={`text-muted-foreground transition-transform duration-200 ${opsExpanded ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{opsExpanded && (
|
||||
<>
|
||||
<div className="overflow-x-auto border-t border-border">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="bg-muted/30 border-b border-border">
|
||||
{[
|
||||
t('ID', 'ID'),
|
||||
t('Action name', 'AMALYŇ ADY'),
|
||||
t('Performed by', 'KIM TARAPYNDAN'),
|
||||
t('Target', 'AMALYŇ NYŞANY (TARGEDI)'),
|
||||
t('Status', 'AMALYŇ STATUSY'),
|
||||
t('Date', 'SENE'),
|
||||
].map((h) => (
|
||||
<th
|
||||
key={h}
|
||||
className="text-left px-4 py-2.5 text-xs font-semibold text-muted-foreground uppercase tracking-wide whitespace-nowrap"
|
||||
>
|
||||
{h}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{operations.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={6} className="text-center py-10 text-muted-foreground text-sm">
|
||||
{t('No operations found', 'Amal tapylmady')}
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
operations.map((op) => (
|
||||
<tr key={op.id} className="border-b border-border/50 hover:bg-muted/20 transition-colors">
|
||||
<td className="px-4 py-3 text-primary font-medium">{op.id}</td>
|
||||
<td className="px-4 py-3">{op.action_name}</td>
|
||||
<td className="px-4 py-3">{op.performed_by}</td>
|
||||
<td className="px-4 py-3">{op.target}</td>
|
||||
<td className="px-4 py-3"><OpStatusBadge status={op.status} /></td>
|
||||
<td className="px-4 py-3 text-muted-foreground">{op.date}</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* Ops pagination */}
|
||||
<div className="flex items-center justify-between px-4 py-2.5 border-t border-border text-sm text-muted-foreground">
|
||||
<Button variant="ghost" size="sm" disabled={opsPage <= 1} onClick={() => setOpsPage((p) => p - 1)}>
|
||||
{t('Previous', 'Öňki')}
|
||||
</Button>
|
||||
<span>
|
||||
{opsTotal === 0 ? '0' : `1–${opsTotal}`} {t('of', 'of')} {opsTotal}
|
||||
</span>
|
||||
<Button variant="ghost" size="sm" disabled={true}>
|
||||
{t('Next', 'Indiki')}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
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 { useCardPins } from "@/features/cardPins/hooks/useCardPins";
|
||||
import { useDeleteCardPin } from "@/features/cardPins/hooks/useCardPins";
|
||||
import type {
|
||||
CardPinItem,
|
||||
CardPinStatus,
|
||||
} from "@/features/cardPins/api/cardPinApi";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Eye, Pencil, Trash2 } from "lucide-react";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_MAP: Record<CardPinStatus, { label: string; className: string }> =
|
||||
{
|
||||
pending: {
|
||||
label: "Garaşylýar",
|
||||
className: "bg-yellow-500/20 text-yellow-400 border-yellow-500/30",
|
||||
},
|
||||
approved: {
|
||||
label: "Tassyklandy",
|
||||
className: "bg-green-500/20 text-green-400 border-green-500/30",
|
||||
},
|
||||
rejected: {
|
||||
label: "Ret edildi",
|
||||
className: "bg-red-500/20 text-red-400 border-red-500/30",
|
||||
},
|
||||
};
|
||||
|
||||
function StatusBadge({ status }: { status: CardPinStatus }) {
|
||||
const cfg = STATUS_MAP[status] ?? STATUS_MAP.pending;
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-semibold border",
|
||||
cfg.className,
|
||||
)}
|
||||
>
|
||||
{cfg.label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function CardPinsPage() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [statusFilter, setStatusFilter] = useState<CardPinStatus | "">("");
|
||||
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
|
||||
const [deleteTarget, setDeleteTarget] = useState<CardPinItem | null>(null);
|
||||
|
||||
const { data, isLoading } = useCardPins({
|
||||
page,
|
||||
per_page: perPage,
|
||||
search,
|
||||
status: statusFilter,
|
||||
});
|
||||
const { mutate: deletePin, isPending: isDeleting } = useDeleteCardPin();
|
||||
|
||||
const columns: ColumnDef<CardPinItem>[] = [
|
||||
{
|
||||
accessorKey: "id",
|
||||
header: "ID",
|
||||
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>
|
||||
),
|
||||
},
|
||||
{
|
||||
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>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "province_label",
|
||||
header: t("cardPin.province", "Welaýat"),
|
||||
},
|
||||
{
|
||||
accessorKey: "branch_label",
|
||||
header: t("cardPin.branch", "Şahamça"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-medium">
|
||||
{row.original.branch_label}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "first_name",
|
||||
header: t("cardPin.firstName", "Ady"),
|
||||
},
|
||||
{
|
||||
accessorKey: "last_name",
|
||||
header: t("cardPin.lastName", "Familiýasy"),
|
||||
},
|
||||
{
|
||||
accessorKey: "phone",
|
||||
header: t("cardPin.phone", "Telefon"),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-mono text-sm">{row.original.phone}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
header: t("cardPin.status", "Status"),
|
||||
cell: ({ row }) => <StatusBadge 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}`)}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-pins/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => setDeleteTarget(row.original)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const columnMeta = columns
|
||||
.filter((c) => "accessorKey" in c && c.id !== "actions")
|
||||
.map((c) => ({
|
||||
id: ("accessorKey" in c ? String(c.accessorKey) : c.id) as string,
|
||||
label:
|
||||
typeof c.header === "string" ? c.header : String(c.accessorKey ?? ""),
|
||||
}));
|
||||
|
||||
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>
|
||||
</div>
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t("cardPin.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={[
|
||||
{
|
||||
id: "status",
|
||||
label: t("cardPin.status", "Status"),
|
||||
options: [
|
||||
{ value: "pending", label: "Garaşylýar" },
|
||||
{ value: "approved", label: "Tassyklandy" },
|
||||
{ value: "rejected", label: "Ret edildi" },
|
||||
],
|
||||
},
|
||||
]}
|
||||
activeFilters={[{ fieldId: "status", value: statusFilter }]}
|
||||
onFilterChange={(fieldId, value) => {
|
||||
if (fieldId === "status")
|
||||
setStatusFilter(value as CardPinStatus | "");
|
||||
setPage(1);
|
||||
}}
|
||||
onFilterReset={() => {
|
||||
setStatusFilter("");
|
||||
setPage(1);
|
||||
}}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
actionLabel={t("cardPin.createBtn", "Kart pin bukja dörediň")}
|
||||
onAction={() => navigate("/card-pins/create")}
|
||||
/>
|
||||
|
||||
<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}
|
||||
/>
|
||||
|
||||
{/* Delete confirmation */}
|
||||
<AlertDialog
|
||||
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>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { CardPinForm } from '@/features/cardPins/components/cardPinForm'
|
||||
import { useCreateCardPin } from '@/features/cardPins/hooks/useCardPins'
|
||||
import type { CardPinCreatePayload } from '@/features/cardPins/api/cardPinApi'
|
||||
|
||||
export default function CardPinCreatePage() {
|
||||
const navigate = useNavigate()
|
||||
const { mutate: createPin, isPending } = useCreateCardPin()
|
||||
|
||||
const handleSubmit = (payload: CardPinCreatePayload) => {
|
||||
createPin(payload, {
|
||||
onSuccess: (data) => navigate(`/card-pins/${data.id}`),
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<CardPinForm
|
||||
mode="create"
|
||||
onSubmit={handleSubmit}
|
||||
isSubmitting={isPending}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardPinForm } from '@/features/cardPins/components/cardPinForm'
|
||||
import { useCardPin, useUpdateCardPin } from '@/features/cardPins/hooks/useCardPins'
|
||||
import type { CardPinUpdatePayload } from '@/features/cardPins/api/cardPinApi'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
|
||||
export default function CardPinEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data, isLoading, isError } = useCardPin(id!)
|
||||
const { mutate: updatePin, isPending } = useUpdateCardPin(id!)
|
||||
|
||||
const handleSubmit = (payload: CardPinUpdatePayload) => {
|
||||
updatePin(payload, {
|
||||
onSuccess: () => navigate(`/card-pins/${id}`),
|
||||
})
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-8 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !data) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24 text-muted-foreground">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<CardPinForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
onSubmit={handleSubmit}
|
||||
isSubmitting={isPending}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
import { useParams, useNavigate, Link } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useCardPin, useDeleteCardPin } from '@/features/cardPins/hooks/useCardPins'
|
||||
import type { CardPinStatus } from '@/features/cardPins/api/cardPinApi'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Pencil, Trash2, Download } from 'lucide-react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_MAP: Record<CardPinStatus, { label: string; className: string }> = {
|
||||
pending: { label: 'Garaşylýar', className: 'bg-yellow-500/20 text-yellow-500 border-yellow-500/30' },
|
||||
approved: { label: 'Tassyklandy', className: 'bg-green-500/20 text-green-500 border-green-500/30' },
|
||||
rejected: { label: 'Ret edildi', className: 'bg-red-500/20 text-red-500 border-red-500/30' },
|
||||
}
|
||||
|
||||
function StatusBadge({ status }: { status: CardPinStatus }) {
|
||||
const cfg = STATUS_MAP[status] ?? STATUS_MAP.pending
|
||||
return (
|
||||
<span className={cn('inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold border', cfg.className)}>
|
||||
<span className="w-1.5 h-1.5 rounded-full bg-current" />
|
||||
{cfg.label}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Field row ────────────────────────────────────────────────────────────────
|
||||
|
||||
function FieldRow({ label, children }: { label: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="grid grid-cols-[200px_1fr] items-start py-3 border-b border-border last:border-0 gap-4">
|
||||
<span className="text-sm text-muted-foreground">{label}</span>
|
||||
<span className="text-sm text-foreground">{children}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Passport image ───────────────────────────────────────────────────────────
|
||||
|
||||
function PassportImage({ label, url }: { label: string; url: string | null }) {
|
||||
if (!url) return null
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm text-muted-foreground">{label}</p>
|
||||
<div className="border border-border rounded-lg overflow-hidden inline-block">
|
||||
<img
|
||||
src={url}
|
||||
alt={label}
|
||||
className="max-w-[200px] max-h-[160px] object-cover block"
|
||||
/>
|
||||
<div className="px-3 py-2 bg-muted/40 border-t border-border">
|
||||
<a
|
||||
href={url}
|
||||
download
|
||||
className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<Download size={12} />
|
||||
Göçürip al
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function CardPinViewPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data, isLoading, isError } = useCardPin(id!)
|
||||
const { mutate: deletePin, isPending: isDeleting } = useDeleteCardPin()
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-8 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !data) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24 text-muted-foreground">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between">
|
||||
<h1 className="text-xl font-bold text-foreground">
|
||||
{t('cardPin.viewTitle', 'Kart pin bukja giňişleýin')}: {data.id}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button size="icon" variant="ghost" className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10">
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('cardPin.deleteTitle', 'Pozmak isleýärsiňizmi?')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('cardPin.deleteDesc', 'Bu amal yzyna dolanyp bolmaz.')} {data.id}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isDeleting}>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
disabled={isDeleting}
|
||||
className="bg-destructive hover:bg-destructive/90"
|
||||
onClick={() => deletePin(data.id, { onSuccess: () => navigate('/card-pins') })}
|
||||
>
|
||||
{t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8"
|
||||
onClick={() => navigate(`/card-pins/${id}/edit`)}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main Info */}
|
||||
<section className="bg-card border border-border rounded-lg px-6">
|
||||
<FieldRow label="ID">
|
||||
<span className="font-mono">{data.id}</span>
|
||||
</FieldRow>
|
||||
<FieldRow label={t('cardPin.createdAt', 'Döredilen wagty')}>
|
||||
{data.created_at}
|
||||
</FieldRow>
|
||||
<FieldRow label={t('cardPin.status', 'Status')}>
|
||||
<StatusBadge status={data.status} />
|
||||
</FieldRow>
|
||||
<FieldRow label={t('cardPin.note', 'Bellik')}>
|
||||
{data.note || '—'}
|
||||
</FieldRow>
|
||||
<FieldRow label={t('cardPin.createdBy', 'Sargyt eden')}>
|
||||
<span className="text-primary font-medium">{data.created_by_label}</span>
|
||||
</FieldRow>
|
||||
</section>
|
||||
|
||||
{/* Kart */}
|
||||
<section className="bg-card border border-border rounded-lg px-6 py-4">
|
||||
<h2 className="text-base font-semibold text-foreground mb-2">
|
||||
{t('cardPin.cardSection', 'Kart')}
|
||||
</h2>
|
||||
<div className="divide-y divide-border">
|
||||
<FieldRow label={t('cardPin.cardNumber', 'Kart belgisi')}>
|
||||
<span className="font-mono tracking-wider">{data.card_number}</span>
|
||||
</FieldRow>
|
||||
<FieldRow label={t('cardPin.cardExpireMonth', 'Kart Möhleti (aý)')}>—</FieldRow>
|
||||
<FieldRow label={t('cardPin.cardExpireYear', 'Kart Möhleti (ýyl)')}>—</FieldRow>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Lokasiýa */}
|
||||
<section className="bg-card border border-border rounded-lg px-6 py-4">
|
||||
<h2 className="text-base font-semibold text-foreground mb-2">
|
||||
{t('cardPin.locationSection', 'Lokasiýa')}
|
||||
</h2>
|
||||
<div className="divide-y divide-border">
|
||||
<FieldRow label={t('cardPin.province', 'Welaýat')}>{data.province_label}</FieldRow>
|
||||
<FieldRow label={t('cardPin.branch', 'Şahamça')}>
|
||||
<span className="text-primary font-medium">{data.branch_label}</span>
|
||||
</FieldRow>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Şahsy maglumatlar */}
|
||||
<section className="bg-card border border-border rounded-lg px-6 py-4">
|
||||
<h2 className="text-base font-semibold text-foreground mb-2">
|
||||
{t('cardPin.personalSection', 'Şahsy maglumatlar')}
|
||||
</h2>
|
||||
<div className="divide-y divide-border">
|
||||
<FieldRow label={t('cardPin.fullName', 'Doly ady')}>
|
||||
{`${data.last_name} ${data.first_name} ${data.father_name}`}
|
||||
</FieldRow>
|
||||
<FieldRow label={t('cardPin.birthDate', 'Doglan güni')}>{data.birth_date}</FieldRow>
|
||||
<FieldRow label={t('cardPin.phone', 'Telefon')}>+{data.phone}</FieldRow>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Pasport */}
|
||||
<section className="bg-card border border-border rounded-lg px-6 py-4">
|
||||
<h2 className="text-base font-semibold text-foreground mb-2">
|
||||
{t('cardPin.passportSection', 'Pasport')}
|
||||
</h2>
|
||||
<div className="divide-y divide-border mb-4">
|
||||
<FieldRow label={t('cardPin.passportSeries', 'Pasport seriýasy')}>
|
||||
{data.passport_series}
|
||||
</FieldRow>
|
||||
<FieldRow label={t('cardPin.passportNumber', 'Pasport belgisi')}>
|
||||
{data.passport_number}
|
||||
</FieldRow>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-4 gap-4">
|
||||
<PassportImage
|
||||
label={t('cardPin.passportFile1', 'Pasport (sahypa 1)')}
|
||||
url={data.passport_file_1}
|
||||
/>
|
||||
<PassportImage
|
||||
label={t('cardPin.passportFile2', 'Pasport (2-3-nji sahypa)')}
|
||||
url={data.passport_file_2}
|
||||
/>
|
||||
<PassportImage
|
||||
label={t('cardPin.passportFile3', 'Pasport (8-9 sahypa)')}
|
||||
url={data.passport_file_3}
|
||||
/>
|
||||
<PassportImage
|
||||
label={t('cardPin.passportFile4', 'Pasport (32-nji sahypa)')}
|
||||
url={data.passport_file_4}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
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 {
|
||||
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 }> = {
|
||||
pending: { label: 'Garaşylýar', className: 'bg-yellow-500/15 text-yellow-500 border-yellow-500/20' },
|
||||
approved: { label: 'Tassyklanan', className: 'bg-emerald-500/15 text-emerald-500 border-emerald-500/20' },
|
||||
rejected: { label: 'Ret edilen', className: 'bg-red-500/15 text-red-500 border-red-500/20' },
|
||||
}
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
const PER_PAGE = 25
|
||||
|
||||
export default function CardRequisitesPage() {
|
||||
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<string | null>(null)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
|
||||
const { data, isLoading } = useCardRequisites({ page, per_page: perPage, search })
|
||||
const deleteMutation = useDeleteCardRequisite()
|
||||
const downloadMutation = useDownloadCardRequisite()
|
||||
|
||||
// ── Columns ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const columns: ColumnDef<CardRequisite>[] = [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('ID', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-medium hover:underline text-left"
|
||||
onClick={() => navigate(`/card-requisites/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
},
|
||||
{
|
||||
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>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'created_at',
|
||||
accessorKey: 'created_at',
|
||||
header: t('Created at', 'DÖREDILEN WAGTY'),
|
||||
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>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'branch_name',
|
||||
accessorKey: 'branch_name',
|
||||
header: t('Branch', 'ŞAHAMÇA'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-medium">{row.original.branch_name ?? '—'}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'first_name',
|
||||
accessorKey: 'first_name',
|
||||
header: t('First name', 'ADY'),
|
||||
cell: ({ row }) => <span>{row.original.first_name}</span>,
|
||||
},
|
||||
{
|
||||
id: 'last_name',
|
||||
accessorKey: 'last_name',
|
||||
header: t('Last name', 'FAMILIÝASY'),
|
||||
cell: ({ row }) => <span>{row.original.last_name}</span>,
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
accessorKey: 'status',
|
||||
header: t('Status', 'STATUS'),
|
||||
cell: ({ row }) => <StatusBadge status={row.original.status} />,
|
||||
},
|
||||
{
|
||||
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"
|
||||
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}`)}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-requisites/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon"
|
||||
className="h-7 w-7 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
// ── Column meta for toolbar ───────────────────────────────────────────────────
|
||||
|
||||
const columnMeta: ColumnMeta[] = columns
|
||||
.filter((c) => c.id !== 'actions')
|
||||
.map((c) => ({
|
||||
id: c.id!,
|
||||
label: typeof c.header === 'string' ? c.header : c.id!,
|
||||
}))
|
||||
|
||||
// ── Pagination ────────────────────────────────────────────────────────────────
|
||||
|
||||
const total = data?.total ?? 0
|
||||
const totalPages = Math.ceil(total / perPage)
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (!deleteId) 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 requisites', 'Kart rekwizitler')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('Search', 'Gözlemek')}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t('Create card requisite order', 'Kart rekwiziti üçin sargyt dörediň')}
|
||||
onAction={() => navigate('/card-requisites/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}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* 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.',
|
||||
'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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardRequisiteForm } from '@/features/cardRequisites/components/cardRequisiteForm'
|
||||
|
||||
export default function CardRequisiteCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Create card requisite order', 'Kart rekwiziti üçin sargyt dörediň dörediň')}
|
||||
</h1>
|
||||
<CardRequisiteForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import { CardRequisiteForm } from '@/features/cardRequisites/components/cardRequisiteForm'
|
||||
import { useCardRequisite } from '@/features/cardRequisites/hooks/useCardRequisites'
|
||||
|
||||
export default function CardRequisiteEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
|
||||
const { data, isLoading } = useCardRequisite(id ?? '')
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-7 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t('Not found', 'Tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Edit card requisite', 'Kart rekwizitini üýtget')}
|
||||
</h1>
|
||||
<CardRequisiteForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
cardRequisiteId={data.id}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
import { useState } from 'react'
|
||||
import { useParams, useNavigate, Link } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Download, Trash2, Pencil, DownloadCloud } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import {
|
||||
useCardRequisite,
|
||||
useDeleteCardRequisite,
|
||||
useDownloadCardRequisite,
|
||||
} from '@/features/cardRequisites/hooks/useCardRequisites'
|
||||
import type { CardRequisiteStatus } from '@/features/cardRequisites/api/cardRequisitesApi'
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_BADGE: Record<CardRequisiteStatus, { label: string; className: string }> = {
|
||||
pending: { label: 'GARAŞYLÝAR', className: 'bg-yellow-500/20 text-yellow-400 border border-yellow-500/30' },
|
||||
approved: { label: 'TASSYKLANAN', className: 'bg-emerald-500/20 text-emerald-400 border border-emerald-500/30' },
|
||||
rejected: { label: 'RET EDILEN', className: 'bg-red-500/20 text-red-400 border border-red-500/30' },
|
||||
}
|
||||
|
||||
// ─── Detail row ───────────────────────────────────────────────────────────────
|
||||
|
||||
function DetailRow({
|
||||
label,
|
||||
children,
|
||||
}: {
|
||||
label: string
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div className="grid grid-cols-[220px_1fr] border-b border-border/50 last:border-0">
|
||||
<div className="px-4 py-3 text-sm text-muted-foreground font-medium bg-muted/10">
|
||||
{label}
|
||||
</div>
|
||||
<div className="px-4 py-3 text-sm text-foreground">{children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Section header ───────────────────────────────────────────────────────────
|
||||
|
||||
function SectionTitle({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<h2 className="text-base font-semibold text-foreground mt-6 mb-3">{children}</h2>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Passport image row ───────────────────────────────────────────────────────
|
||||
|
||||
function PassportImageRow({ label, url }: { label: string; url?: string }) {
|
||||
return (
|
||||
<div className="grid grid-cols-[220px_1fr] border-b border-border/50 last:border-0">
|
||||
<div className="px-4 py-3 text-sm text-muted-foreground font-medium bg-muted/10">
|
||||
{label}
|
||||
</div>
|
||||
<div className="px-4 py-4 flex flex-col gap-2">
|
||||
{url ? (
|
||||
<>
|
||||
<img
|
||||
src={url}
|
||||
alt={label}
|
||||
className="max-w-[200px] rounded-md border border-border object-cover"
|
||||
/>
|
||||
<a
|
||||
href={url}
|
||||
download
|
||||
className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit"
|
||||
>
|
||||
<DownloadCloud size={13} />
|
||||
{('Download', 'Göçürip al')}
|
||||
</a>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-muted-foreground text-sm">—</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function CardRequisiteViewPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
|
||||
const { data, isLoading } = useCardRequisite(id ?? '')
|
||||
const deleteMutation = useDeleteCardRequisite()
|
||||
const downloadMutation = useDownloadCardRequisite()
|
||||
|
||||
const handleDelete = async () => {
|
||||
await deleteMutation.mutateAsync(id ?? '')
|
||||
navigate('/card-requisites')
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-7 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t('Not found', 'Tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const statusCfg = STATUS_BADGE[data.status] ?? STATUS_BADGE.pending
|
||||
|
||||
return (
|
||||
<div className="space-y-0">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Card requisite detail', 'Kart rekwizit giňişleýin')}: {data.id}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline" size="sm"
|
||||
onClick={() => downloadMutation.mutate(data.id)}
|
||||
disabled={downloadMutation.isPending}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline" size="sm"
|
||||
className="text-destructive border-destructive/30 hover:bg-destructive/10"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" asChild>
|
||||
<Link to={`/card-requisites/${data.id}/edit`}>
|
||||
<Pencil size={14} />
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* General info */}
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
<DetailRow label={t('ID', 'ID')}>{data.id}</DetailRow>
|
||||
<DetailRow label={t('Created at', 'Döredilen wagty')}>{data.created_at}</DetailRow>
|
||||
<DetailRow label={t('Status', 'Status')}>
|
||||
<span className={`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold ${statusCfg.className}`}>
|
||||
{statusCfg.label}
|
||||
</span>
|
||||
</DetailRow>
|
||||
<DetailRow label={t('Note', 'Bellik')}>
|
||||
{data.note || '—'}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('Requested by', 'Sargyt eden:')}>
|
||||
{data.first_name && data.last_name ? (
|
||||
<span className="text-primary font-medium">
|
||||
{data.last_name}_{data.first_name} ({data.first_name})
|
||||
</span>
|
||||
) : '—'}
|
||||
</DetailRow>
|
||||
</div>
|
||||
|
||||
{/* Card */}
|
||||
<SectionTitle>{t('Card', 'Kart')}</SectionTitle>
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
<DetailRow label={t('Card number', 'Kart belgisi')}>{data.card_number}</DetailRow>
|
||||
<DetailRow label={t('Card expiry month', 'Kart Möhleti (aý)')}>{data.card_expiry_month}</DetailRow>
|
||||
<DetailRow label={t('Card expiry year', 'Kart Möhleti (ýyl)')}>{data.card_expiry_year}</DetailRow>
|
||||
</div>
|
||||
|
||||
{/* Location */}
|
||||
<SectionTitle>{t('Location', 'Lokasiýa')}</SectionTitle>
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
<DetailRow label={t('Province', 'Welaýat')}>{data.province_name ?? '—'}</DetailRow>
|
||||
<DetailRow label={t('Branch', 'Şahamça')}>
|
||||
<span className="text-primary font-medium">{data.branch_name ?? '—'}</span>
|
||||
</DetailRow>
|
||||
</div>
|
||||
|
||||
{/* Personal */}
|
||||
<SectionTitle>{t('Personal information', 'Şahsy maglumatlar')}</SectionTitle>
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
<DetailRow label={t('Full name', 'Doly ady')}>
|
||||
{[data.first_name, data.last_name, data.middle_name].filter(Boolean).join(' ')}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('Birth date', 'Doglan güni')}>{data.birth_date}</DetailRow>
|
||||
<DetailRow label={t('Phone', 'Telefon')}>{data.phone}</DetailRow>
|
||||
</div>
|
||||
|
||||
{/* Passport */}
|
||||
<SectionTitle>{t('Passport', 'Pasport')}</SectionTitle>
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
<DetailRow label={t('Passport series', 'Pasport seriýasy')}>{data.passport_series}</DetailRow>
|
||||
<DetailRow label={t('Passport number', 'Pasport belgisi')}>{data.passport_number}</DetailRow>
|
||||
<PassportImageRow
|
||||
label={t('Passport (page 1)', 'Pasport (sahypa 1)')}
|
||||
url={data.passport_page1_url}
|
||||
/>
|
||||
<PassportImageRow
|
||||
label={t('Passport (pages 2-3)', 'Pasport (2-3-nji sahypa)')}
|
||||
url={data.passport_page2_3_url}
|
||||
/>
|
||||
<PassportImageRow
|
||||
label={t('Passport (pages 8-9)', 'Pasport (8-9 sahypa)')}
|
||||
url={data.passport_page8_9_url}
|
||||
/>
|
||||
<PassportImageRow
|
||||
label={t('Passport (page 32)', 'Pasport (32-nji sahypa)')}
|
||||
url={data.passport_page32_url}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
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 {
|
||||
useCardTransactions,
|
||||
useDeleteCardTransaction,
|
||||
useDownloadCardTransaction,
|
||||
} from '@/features/cardTransactions/hooks/useCardTransactions'
|
||||
import type { CardTransaction } from '@/features/cardTransactions/api/cardTransactionsApi'
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
const PER_PAGE = 25
|
||||
|
||||
export default function CardTransactionsPage() {
|
||||
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 { 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'),
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-medium hover:underline text-left"
|
||||
onClick={() => navigate(`/card-transactions/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
},
|
||||
{
|
||||
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'),
|
||||
cell: ({ row }) => <span>{row.original.passport_number}</span>,
|
||||
},
|
||||
{
|
||||
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Ý)'),
|
||||
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)'),
|
||||
cell: ({ row }) => <span>{row.original.card_expiry_year}</span>,
|
||||
},
|
||||
{
|
||||
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"
|
||||
onClick={() => downloadMutation.mutate(row.original.id)}
|
||||
title={t('Download', 'Ýükle')}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-transactions/${row.original.id}`)}
|
||||
title={t('View', 'Görmek')}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost" size="icon" className="h-7 w-7"
|
||||
onClick={() => navigate(`/card-transactions/${row.original.id}/edit`)}
|
||||
title={t('Edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
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')}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
// ── Column meta for toolbar ───────────────────────────────────────────────────
|
||||
|
||||
const columnMeta: ColumnMeta[] = columns
|
||||
.filter((c) => c.id !== 'actions')
|
||||
.map((c) => ({
|
||||
id: c.id!,
|
||||
label: typeof c.header === 'string' ? c.header : c.id!,
|
||||
}))
|
||||
|
||||
// ── Pagination ────────────────────────────────────────────────────────────────
|
||||
|
||||
const total = data?.total ?? 0
|
||||
const totalPages = Math.ceil(total / perPage)
|
||||
|
||||
const handleDelete = async () => {
|
||||
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>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('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}
|
||||
/>
|
||||
|
||||
{/* 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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardTransactionForm } from '@/features/cardTransactions/components/cardTransactionForm'
|
||||
|
||||
export default function CardTransactionCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Create card transaction', 'Kart herekedi dörediň')}
|
||||
</h1>
|
||||
<CardTransactionForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { CardTransactionForm } from "@/features/cardTransactions/components/cardTransactionForm";
|
||||
import { useCardTransaction } from "@/features/cardTransactions/hooks/useCardTransactions";
|
||||
|
||||
export default function CardTransactionEditPage() {
|
||||
const { t } = useTranslation();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const numericId = Number(id);
|
||||
|
||||
const { data, isLoading } = useCardTransaction(numericId);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-7 text-primary" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t("Not found", "Tapylmady")}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("Edit card transaction", "Kart herekedini üýtget")}
|
||||
</h1>
|
||||
<CardTransactionForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
cardTransactionId={numericId}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
import { useState } from 'react'
|
||||
import { useParams, useNavigate, Link } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Download, Trash2, Pencil } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import {
|
||||
useCardTransaction,
|
||||
useDeleteCardTransaction,
|
||||
useDownloadCardTransaction,
|
||||
} from '@/features/cardTransactions/hooks/useCardTransactions'
|
||||
|
||||
// ─── Detail row ───────────────────────────────────────────────────────────────
|
||||
|
||||
function DetailRow({ label, value }: { label: string; value: string | number }) {
|
||||
return (
|
||||
<div className="grid grid-cols-[220px_1fr] border-b border-border/50 last:border-0">
|
||||
<div className="px-4 py-3 text-sm text-muted-foreground font-medium bg-muted/10">
|
||||
{label}
|
||||
</div>
|
||||
<div className="px-4 py-3 text-sm text-foreground">{value}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function CardTransactionViewPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading } = useCardTransaction(numericId)
|
||||
const deleteMutation = useDeleteCardTransaction()
|
||||
const downloadMutation = useDownloadCardTransaction()
|
||||
|
||||
const handleDelete = async () => {
|
||||
await deleteMutation.mutateAsync(numericId)
|
||||
navigate('/card-transactions')
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-7 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t('Not found', 'Tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Card transaction detail', 'Kart herekedi giňişleýin')}:
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-1.5"
|
||||
onClick={() => downloadMutation.mutate(numericId)}
|
||||
disabled={downloadMutation.isPending}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-1.5 text-destructive border-destructive/30 hover:bg-destructive/10"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-1.5"
|
||||
asChild
|
||||
>
|
||||
<Link to={`/card-transactions/${numericId}/edit`}>
|
||||
<Pencil size={14} />
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Detail card */}
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
<DetailRow label={t('ID', 'ID')} value={data.id} />
|
||||
<DetailRow label={t('Passport series', 'Pasport seriýasy')} value={data.passport_series} />
|
||||
<DetailRow label={t('Passport number', 'Pasport belgisi')} value={data.passport_number} />
|
||||
<DetailRow label={t('Card number', 'Kart belgisi')} value={data.card_number} />
|
||||
<DetailRow label={t('Card expiry month', 'Kart Möhleti (aý)')} value={data.card_expiry_month} />
|
||||
<DetailRow label={t('Card expiry year', 'Kart Möhleti (ýyl)')} value={data.card_expiry_year} />
|
||||
</div>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
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 { VisibilityState } from '@tanstack/react-table'
|
||||
|
||||
import { DataTable } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import type { ActiveFilter, FilterField } from '@/components/dataTableToolbar'
|
||||
import {
|
||||
useCardOrders,
|
||||
useDeleteCardOrder,
|
||||
useProvinces,
|
||||
useBranches,
|
||||
} from '@/features/orderNewCard/hooks/useOrderNewCard'
|
||||
import { useCardOrderColumns } from '@/features/orderNewCard/components/orderNewCardTable'
|
||||
import type { CardOrderStatus } from '@/features/orderNewCard/api/orderNewCardApi'
|
||||
|
||||
// ─── Column meta list (for toolbar toggle) ────────────────────────────────────
|
||||
|
||||
const COLUMN_META = [
|
||||
{ id: 'id', label: 'ID' },
|
||||
{ id: 'issuanceReasonName', label: 'Sebäp' },
|
||||
{ id: 'createdAt', label: 'Döredilen wagty' },
|
||||
{ id: 'cardTypeName', label: 'Görnüşi' },
|
||||
{ id: 'provinceName', label: 'Welaýat' },
|
||||
{ id: 'branchName', label: 'Şahamça' },
|
||||
{ id: 'fullName', label: 'Ady' },
|
||||
{ id: 'status', label: 'Status' },
|
||||
]
|
||||
|
||||
const DEFAULT_ORDER = COLUMN_META.map((c) => c.id)
|
||||
|
||||
// ─── CardOrdersPage ───────────────────────────────────────────────────────────
|
||||
|
||||
export default function CardOrdersPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const deleteMutation = useDeleteCardOrder()
|
||||
|
||||
// ── 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: '' },
|
||||
])
|
||||
|
||||
// ── Lookup data ────────────────────────────────────────────────────────────
|
||||
const provinceId = activeFilters.find((f) => f.fieldId === 'provinceId')?.value
|
||||
const { data: provincesData } = useProvinces()
|
||||
const { data: branchesData } = useBranches(provinceId ? Number(provinceId) : undefined)
|
||||
|
||||
// ── Data ───────────────────────────────────────────────────────────────────
|
||||
const queryParams = useMemo(() => {
|
||||
const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value]))
|
||||
return {
|
||||
search: search || undefined,
|
||||
status: (filterMap.status as CardOrderStatus) || undefined,
|
||||
provinceId: filterMap.provinceId ? Number(filterMap.provinceId) : undefined,
|
||||
branchId: filterMap.branchId ? Number(filterMap.branchId) : undefined,
|
||||
page,
|
||||
perPage,
|
||||
}
|
||||
}, [search, activeFilters, page, perPage])
|
||||
|
||||
const { data, isLoading } = useCardOrders(queryParams)
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => {
|
||||
const newFilters = prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))
|
||||
// Reset branch if province changes
|
||||
if (fieldId === 'provinceId') {
|
||||
return newFilters.map((f) => (f.fieldId === 'branchId' ? { ...f, value: '' } : f))
|
||||
}
|
||||
return newFilters
|
||||
})
|
||||
setPage(1)
|
||||
}, [])
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: '' })))
|
||||
setPage(1)
|
||||
}, [])
|
||||
|
||||
const handleDelete = useCallback(
|
||||
(id: string) => {
|
||||
if (!window.confirm(t('cardOrder.deleteConfirm', 'Bu sargyt pozulsynmy?'))) return
|
||||
deleteMutation.mutate(id)
|
||||
},
|
||||
[deleteMutation, t]
|
||||
)
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const baseColumns = useCardOrderColumns()
|
||||
const columns = useMemo(
|
||||
() => [
|
||||
...baseColumns,
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
enableHiding: false,
|
||||
cell: ({ row }: { row: any }) => (
|
||||
<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')}
|
||||
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')}
|
||||
onClick={() => navigate(`/order-new-card/${row.original.id}/edit`)}
|
||||
>
|
||||
<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', 'Poz')}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
],
|
||||
[baseColumns, t, navigate, handleDelete, deleteMutation.isPending]
|
||||
)
|
||||
|
||||
// ── Filter fields ──────────────────────────────────────────────────────────
|
||||
const filterFields: FilterField[] = useMemo(() => [
|
||||
{
|
||||
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') },
|
||||
],
|
||||
},
|
||||
{
|
||||
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'),
|
||||
options: branchesData?.map(b => ({ value: String(b.id), label: b.name })) || [],
|
||||
},
|
||||
], [t, provincesData, branchesData])
|
||||
|
||||
// ── Render ────────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Page Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('cardOrder.title', 'Kart sargytlary')}
|
||||
</h1>
|
||||
</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')}
|
||||
columns={COLUMN_META}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={filterFields}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
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')}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => row.id}
|
||||
currentPage={page}
|
||||
totalPages={data?.totalPages ?? 1}
|
||||
totalCount={data?.totalCount}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardOrderForm } from '@/features/orderNewCard/components/orderNewCardForm'
|
||||
|
||||
export default function CardOrderCreatePage() {
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('cardOrder.createTitle', 'Kart sargyt dörediň')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<CardOrderForm
|
||||
mode="create"
|
||||
onSuccess={() => navigate('/order-new-card')}
|
||||
onCancel={() => navigate('/order-new-card')}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { CardOrderForm } from '@/features/orderNewCard/components/orderNewCardForm'
|
||||
import { useCardOrderById } from '@/features/orderNewCard/hooks/useOrderNewCard'
|
||||
|
||||
export default function CardOrderEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data: order, isLoading } = useCardOrderById(id ?? '')
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-4 max-w-3xl">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!order) {
|
||||
return (
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{t('common.notFound', 'Tapylmady')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('cardOrder.editTitle', 'Düzetmek')}:{' '}
|
||||
<span className="text-primary font-mono">{order.id}</span>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<CardOrderForm
|
||||
mode="edit"
|
||||
initialData={order}
|
||||
cardOrderId={id}
|
||||
onSuccess={() => navigate(`/order-new-card/${id}`)}
|
||||
onCancel={() => navigate(`/order-new-card/${id}`)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
import { useState } from 'react'
|
||||
import { useParams, useNavigate, Link } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Printer, Download, Trash2, Pencil } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { useCardOrderById, useDeleteCardOrder } from '@/features/orderNewCard/hooks/useOrderNewCard'
|
||||
import type { CardOrderStatus } from '@/features/orderNewCard/api/orderNewCardApi'
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CFG: Record<CardOrderStatus, { label: string; className: string; icon: string }> = {
|
||||
PENDING: { label: 'Garaşylýar', icon: '⏳', className: 'bg-amber-500/10 text-amber-400 border border-amber-500/20' },
|
||||
APPROVED: { label: 'Tassyklandy', icon: '✓', className: 'bg-emerald-500/10 text-emerald-400 border border-emerald-500/20' },
|
||||
REJECTED: { label: 'Ýatyryldy', icon: '✕', className: 'bg-red-500/10 text-red-400 border border-red-500/20' },
|
||||
}
|
||||
|
||||
function StatusBadge({ status }: { status: CardOrderStatus }) {
|
||||
const cfg = STATUS_CFG[status]
|
||||
return (
|
||||
<span className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[11px] font-bold tracking-wide ${cfg.className}`}>
|
||||
<span className="text-[10px]">{cfg.icon}</span>
|
||||
{cfg.label}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Info row ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function InfoRow({
|
||||
label,
|
||||
children,
|
||||
}: {
|
||||
label: string
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div className="grid grid-cols-[200px_1fr] gap-4 py-2.5 px-4 border-b border-border/60 last:border-0 items-start">
|
||||
<span className="text-sm text-muted-foreground">{label}</span>
|
||||
<span className="text-sm text-foreground">{children}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Section ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function Section({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<h3 className="text-base font-semibold text-foreground mb-3">{title}</h3>
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Passport file card ───────────────────────────────────────────────────────
|
||||
|
||||
function PassportFileCard({ label, url }: { label: string; url: string | null }) {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-[200px_1fr] gap-4 py-3 px-4 border-b border-border/60 last:border-0 items-start">
|
||||
<span className="text-sm text-muted-foreground">{label}</span>
|
||||
<div className="flex flex-col gap-2">
|
||||
{url ? (
|
||||
<>
|
||||
<div className="w-20 h-14 rounded-lg overflow-hidden bg-muted border border-border">
|
||||
<img
|
||||
src={url}
|
||||
alt={label}
|
||||
className="w-full h-full object-cover"
|
||||
onError={(e) => {
|
||||
;(e.currentTarget as HTMLImageElement).style.display = 'none'
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<a
|
||||
href={url}
|
||||
download
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors w-fit"
|
||||
>
|
||||
<Download size={12} />
|
||||
{t('common.download', 'Göçürip al')}
|
||||
</a>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-sm text-muted-foreground">—</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Loading skeleton ─────────────────────────────────────────────────────────
|
||||
|
||||
function DetailSkeleton() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Skeleton className="h-8 w-64" />
|
||||
<div className="space-y-3">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── CardOrderDetailPage ──────────────────────────────────────────────────────
|
||||
|
||||
export default function CardOrderDetailPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
|
||||
const { data: order, isLoading } = useCardOrderById(id ?? '')
|
||||
const deleteMutation = useDeleteCardOrder()
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (!id) return
|
||||
await deleteMutation.mutateAsync(id)
|
||||
navigate('/order-new-card')
|
||||
}
|
||||
|
||||
if (isLoading) return <DetailSkeleton />
|
||||
if (!order) return (
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{t('common.notFound', 'Tapylmady')}
|
||||
</p>
|
||||
)
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between mb-6 gap-4">
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('cardOrder.detailTitle', 'Kart sargyt giriş üçin')}:{' '}
|
||||
<span className="text-primary font-mono">{order.id}</span>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
<Button variant="outline" size="icon" title={t('common.print', 'Çap etmek')}>
|
||||
<Printer size={15} />
|
||||
</Button>
|
||||
<Button variant="outline" size="icon" title={t('common.export', 'Eksport')}>
|
||||
<Download size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="text-destructive hover:text-destructive hover:bg-destructive/10 border-destructive/20"
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
asChild
|
||||
>
|
||||
<Link to={`/order-new-card/${order.id}/edit`}>
|
||||
<Pencil size={14} className="mr-1.5" />
|
||||
{t('common.edit', 'Düzetmek')}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main info */}
|
||||
<Section title="">
|
||||
<InfoRow label="ID">{order.id}</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.createdAt', 'Döredilen wagty')}>
|
||||
{order.createdAt}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.isPaid', 'Tölenen')}>
|
||||
<span className={`inline-flex items-center justify-center w-5 h-5 rounded-full text-xs font-bold
|
||||
${order.isPaid
|
||||
? 'bg-emerald-500/15 text-emerald-400'
|
||||
: 'bg-red-500/15 text-red-400'
|
||||
}`}
|
||||
>
|
||||
{order.isPaid ? '✓' : '✕'}
|
||||
</span>
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.status', 'Status')}>
|
||||
<StatusBadge status={order.status} />
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.note', 'Bellik')}>
|
||||
{order.note ?? '—'}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.createdBy', 'Sargyt eden')}>
|
||||
<span className="text-primary font-medium">{order.createdBy}</span>
|
||||
</InfoRow>
|
||||
</Section>
|
||||
|
||||
{/* Kart */}
|
||||
<Section title={t('cardOrder.section.card', 'Kart')}>
|
||||
<InfoRow label={t('cardOrder.field.issuanceReason', 'Kartyň çykarylmagynyň sebäbi')}>
|
||||
<span className="text-primary font-medium">{order.issuanceReasonName}</span>
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.cardType', 'Kart görnüşi')}>
|
||||
<span className="text-cyan-400 font-medium">{order.cardTypeName}</span>
|
||||
</InfoRow>
|
||||
</Section>
|
||||
|
||||
{/* Lokasiýa */}
|
||||
<Section title={t('cardOrder.section.location', 'Lokasiýa')}>
|
||||
<InfoRow label={t('cardOrder.field.province', 'Welaýat')}>
|
||||
{order.provinceName}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.branch', 'Şahamça')}>
|
||||
<span className="text-cyan-400 font-medium">{order.branchName}</span>
|
||||
</InfoRow>
|
||||
</Section>
|
||||
|
||||
{/* Şahsy maglumatlar */}
|
||||
<Section title={t('cardOrder.section.personal', 'Şahsy maglumatlar')}>
|
||||
<InfoRow label={t('cardOrder.field.fullName', 'Doly ady')}>
|
||||
{[order.lastName, order.firstName, order.middleName].filter(Boolean).join(' ')}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.birthDate', 'Doglan güni')}>
|
||||
{order.birthDate}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.phone', 'Telefon')}>
|
||||
{order.phone}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.phoneExtra', 'Telefon goşmaça')}>
|
||||
{order.phoneExtra ?? '—'}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.citizenship', 'Raýatlyk')}>
|
||||
{order.citizenship}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.registeredAddress', 'Ýazgy edilen salgyňyz')}>
|
||||
{order.registeredAddress}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.currentAddress', 'Häzirki ýaşaýyş ýeri')}>
|
||||
{order.currentAddress}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('cardOrder.field.workplace', 'Işleýän ýeriňiz we wezipäňiz')}>
|
||||
{order.workplace}
|
||||
</InfoRow>
|
||||
</Section>
|
||||
|
||||
{/* Pasport faýýlar */}
|
||||
<Section title={t('cardOrder.section.passportFiles', 'Pasport faýýlar')}>
|
||||
<PassportFileCard
|
||||
label={t('cardOrder.field.passportPage1', 'Pasport (sahypa 1)')}
|
||||
url={order.passportFiles.page1}
|
||||
/>
|
||||
<PassportFileCard
|
||||
label={t('cardOrder.field.passportPage23', 'Pasport (2-3-nji sahypa)')}
|
||||
url={order.passportFiles.page23}
|
||||
/>
|
||||
<PassportFileCard
|
||||
label={t('cardOrder.field.passportPage89', 'Pasport (8-9 sahypa)')}
|
||||
url={order.passportFiles.page89}
|
||||
/>
|
||||
<PassportFileCard
|
||||
label={t('cardOrder.field.passportPage32', 'Pasport (32-nji sahypa)')}
|
||||
url={order.passportFiles.page32}
|
||||
/>
|
||||
</Section>
|
||||
|
||||
{/* Delete confirm dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('cardOrder.deleteTitle', 'Pozmak isleýärsiňizmi?')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'cardOrder.deleteDescription',
|
||||
'Bu kart sargyt hemişelik pozular. Bu işi yzyna gaýtaryp bolmaz.',
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user