added loan pages
This commit is contained in:
1 parent
5920420f07
commit
f834f29e53
41 files changed
+7942
-648
No files matched your search
@@ -1,36 +1,76 @@
|
||||
import { useAuthStore } from '@/app/store/authStore'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { TrendingDown, CreditCard } from 'lucide-react'
|
||||
|
||||
export default function DashboardPage() {
|
||||
const logout = useAuthStore((s) => s.logout)
|
||||
const user = useAuthStore((s) => s.user)
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[var(--bg-base)] p-8">
|
||||
<div className="max-w-4xl mx-auto">
|
||||
<header className="flex justify-between items-center mb-8">
|
||||
<h1 className="text-3xl font-bold text-[var(--text-primary)]">Dashboard</h1>
|
||||
<Button onClick={logout} variant="outline">
|
||||
Logout
|
||||
</Button>
|
||||
</header>
|
||||
|
||||
<main className="grid gap-6">
|
||||
<div className="p-6 bg-[var(--bg-surface)] rounded-[var(--radius-lg)] shadow-[var(--shadow-sm)] border border-[var(--border-default)]">
|
||||
<h2 className="text-xl font-semibold text-[var(--text-primary)] mb-2">Welcome, {user?.username || 'Admin'}!</h2>
|
||||
<p className="text-[var(--text-secondary)]">This is your TBBank Admin Dashboard.</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
{[1, 2, 3].map((i) => (
|
||||
<div key={i} className="p-4 bg-[var(--bg-surface)] rounded-[var(--radius-md)] border border-[var(--border-default)]">
|
||||
<h3 className="font-medium text-[var(--text-primary)]">Stat {i}</h3>
|
||||
<p className="text-2xl font-bold text-[var(--brand-500)]">0</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</main>
|
||||
<div className="w-full">
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">{t('Dashboard', 'Baş sahypa')}</h1>
|
||||
</div>
|
||||
|
||||
<main className="grid gap-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
|
||||
<div className="p-6 bg-card rounded-lg border border-border shadow-sm flex flex-col relative overflow-hidden">
|
||||
<div className="flex justify-between items-start mb-4">
|
||||
<h3 className="font-medium text-muted-foreground">{t('Loan orders (all)', 'Karz sargytlary (ählisi)')}</h3>
|
||||
<div className="bg-accent text-xs px-2 py-1 rounded text-muted-foreground">30 gün</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="bg-primary/20 p-3 rounded-md">
|
||||
<CreditCard className="text-primary size-6" />
|
||||
</div>
|
||||
<p className="text-4xl font-bold text-foreground">135</p>
|
||||
</div>
|
||||
<div className="mt-4 flex items-center text-destructive text-sm font-medium">
|
||||
<TrendingDown size={16} className="mr-1" />
|
||||
12.34% Pese gaçmak
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-6 bg-card rounded-lg border border-border shadow-sm flex flex-col relative overflow-hidden">
|
||||
<div className="flex justify-between items-start mb-4">
|
||||
<h3 className="font-medium text-muted-foreground">{t('Loan orders (all)', 'Karz sargytlary (ählisi)')}</h3>
|
||||
<div className="bg-accent text-xs px-2 py-1 rounded text-muted-foreground">30 gün</div>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<p className="text-4xl font-bold text-foreground">0</p>
|
||||
</div>
|
||||
<div className="mt-4 h-12 w-full flex items-end">
|
||||
{/* Mock chart */}
|
||||
<svg className="w-full h-full" viewBox="0 0 200 40" preserveAspectRatio="none">
|
||||
<path d="M0,35 L20,30 L40,32 L60,20 L80,25 L100,10 L120,15 L140,5 L160,25 L180,20 L200,30" fill="none" stroke="hsl(var(--primary))" strokeWidth="2" strokeLinejoin="round" />
|
||||
<circle cx="100" cy="10" r="3" fill="hsl(var(--primary))" />
|
||||
<circle cx="140" cy="5" r="3" fill="hsl(var(--primary))" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-6 bg-card rounded-lg border border-border shadow-sm flex flex-col">
|
||||
<div className="flex justify-between items-start mb-4">
|
||||
<h3 className="font-medium text-muted-foreground">{t('Loan orders (all)', 'Karz sargytlary (ählisi)')}</h3>
|
||||
<div className="text-xs text-muted-foreground">(6,968 jemi)</div>
|
||||
</div>
|
||||
<div className="flex gap-4 items-center">
|
||||
<div className="flex-1 space-y-2 text-sm">
|
||||
<div className="flex items-center gap-2"><span className="size-2 rounded-full bg-yellow-500"></span><span className="text-muted-foreground">Bellige alyndy (1 - 0%)</span></div>
|
||||
<div className="flex items-center gap-2"><span className="size-2 rounded-full bg-green-500"></span><span className="text-muted-foreground">Kanagatlandyrylan (6,746 - 97%)</span></div>
|
||||
<div className="flex items-center gap-2"><span className="size-2 rounded-full bg-red-500"></span><span className="text-muted-foreground">Ýatyrylan (5 - 0%)</span></div>
|
||||
<div className="flex items-center gap-2"><span className="size-2 rounded-full bg-orange-500"></span><span className="text-muted-foreground">Garaşylýar (208 - 3%)</span></div>
|
||||
<div className="flex items-center gap-2"><span className="size-2 rounded-full bg-blue-500"></span><span className="text-muted-foreground">Işlenilýär (8 - 0%)</span></div>
|
||||
</div>
|
||||
<div className="size-20 rounded-full border-8 border-green-500 flex-shrink-0"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div className="text-center text-xs text-muted-foreground mt-8">
|
||||
© 2026 TBBANK.GOV.TM.
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
import { useState, useMemo, useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||
|
||||
import { DataTable } from '@/components/dataTable'
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar'
|
||||
import { LoanOrderStatusBadge } from '@/features/loanOrders/components/loanOrderStatusBadge'
|
||||
import {
|
||||
useLoanOrderMobiles,
|
||||
useDeleteLoanOrderMobile,
|
||||
} from '@/features/loanOrderMobiles/hooks/useLoanOrderMobiles'
|
||||
import type { LoanOrderMobile, LoanOrderMobileStatus } from '@/features/loanOrderMobiles/api/loanOrderMobilesApi'
|
||||
|
||||
// ─── Column IDs ────────────────────────────────────────────────────────────────
|
||||
|
||||
const COLUMN_IDS = [
|
||||
'id',
|
||||
'loanType',
|
||||
'createdAt',
|
||||
'region',
|
||||
'branch',
|
||||
'firstName',
|
||||
'lastName',
|
||||
'phone',
|
||||
'status',
|
||||
] as const
|
||||
|
||||
// ─── Filter options ────────────────────────────────────────────────────────────
|
||||
|
||||
const REGION_OPTIONS = [
|
||||
{ value: 'Balkan', label: 'Balkan' },
|
||||
{ value: 'Ahal', label: 'Ahal' },
|
||||
{ value: 'Daşoguz', label: 'Daşoguz' },
|
||||
{ value: 'Lebap', label: 'Lebap' },
|
||||
{ value: 'Mary', label: 'Mary' },
|
||||
{ value: 'Aşgabat', label: 'Aşgabat' },
|
||||
]
|
||||
|
||||
const STATUS_OPTIONS: { value: LoanOrderMobileStatus; label: string }[] = [
|
||||
{ value: 'GARAŞYLÝAR', label: 'GARAŞYLÝAR' },
|
||||
{ value: 'KANAGATLANDYRYLAN', label: 'KANAGATLANDYRYLAN' },
|
||||
{ value: 'RED_EDILDI', label: 'RED EDILDI' },
|
||||
{ value: 'IŞLENÝÄR', label: 'IŞLENÝÄR' },
|
||||
]
|
||||
|
||||
// ─── Page Component ────────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanOrderMobilesPage() {
|
||||
const { t } = useTranslation()
|
||||
const deleteMutation = useDeleteLoanOrderMobile()
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS])
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ fieldId: 'region', value: '' },
|
||||
{ fieldId: 'status', value: '' },
|
||||
{ fieldId: 'branch', value: '' },
|
||||
{ fieldId: 'archived', value: '' },
|
||||
])
|
||||
|
||||
// ── Query params ───────────────────────────────────────────────────────────
|
||||
const queryParams = useMemo(() => {
|
||||
const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value]))
|
||||
return {
|
||||
search: search || undefined,
|
||||
region: filterMap.region || undefined,
|
||||
status: (filterMap.status as LoanOrderMobileStatus) || undefined,
|
||||
branch: filterMap.branch || undefined,
|
||||
archived: filterMap.archived || undefined,
|
||||
page,
|
||||
perPage,
|
||||
}
|
||||
}, [search, activeFilters, page, perPage])
|
||||
|
||||
const { data, isLoading } = useLoanOrderMobiles(queryParams)
|
||||
const totalPages = data ? Math.ceil(data.total / perPage) : 1
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)))
|
||||
setPage(1)
|
||||
}, [])
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: '' })))
|
||||
setPage(1)
|
||||
}, [])
|
||||
|
||||
const handleDelete = useCallback(
|
||||
(id: string) => {
|
||||
if (!window.confirm(t('loanOrderMobiles.deleteConfirm', 'Bu sargyt pozulsynmy?'))) return
|
||||
deleteMutation.mutate(id)
|
||||
},
|
||||
[deleteMutation, t],
|
||||
)
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns = useMemo<ColumnDef<LoanOrderMobile>[]>(
|
||||
() => [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('ID', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-xs font-mono text-muted-foreground">{row.original.id}</span>
|
||||
),
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
id: 'loanType',
|
||||
accessorKey: 'loanType',
|
||||
header: t('loanOrderMobiles.columns.loanType', 'KARZ GÖRNÜŞI'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-medium text-primary hover:underline cursor-pointer">
|
||||
{row.original.loanType}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'createdAt',
|
||||
accessorKey: 'createdAt',
|
||||
header: t('loanOrderMobiles.columns.createdAt', 'DÖREDILEN WAGTY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">{row.original.createdAt}</span>
|
||||
),
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: 'region',
|
||||
accessorKey: 'region',
|
||||
header: t('loanOrderMobiles.columns.region', 'WELAÝAT'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.region}</span>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'branch',
|
||||
accessorKey: 'branch',
|
||||
header: t('loanOrderMobiles.columns.branch', 'ŞAHAMÇA'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-emerald-500 font-medium">{row.original.branch}</span>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'firstName',
|
||||
accessorKey: 'firstName',
|
||||
header: t('loanOrderMobiles.columns.firstName', 'ADY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.firstName}</span>
|
||||
),
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: 'lastName',
|
||||
accessorKey: 'lastName',
|
||||
header: t('loanOrderMobiles.columns.lastName', 'FAMILIÝASY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.lastName}</span>
|
||||
),
|
||||
size: 120,
|
||||
},
|
||||
{
|
||||
id: 'phone',
|
||||
accessorKey: 'phone',
|
||||
header: t('loanOrderMobiles.columns.phone', 'TELEFON'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.phone}</span>
|
||||
),
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
accessorKey: 'status',
|
||||
header: t('loanOrderMobiles.columns.status', 'STATUS'),
|
||||
cell: ({ row }) => <LoanOrderStatusBadge status={row.original.status} />,
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görmek')}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDelete(row.original.id)}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
],
|
||||
[t, handleDelete, deleteMutation.isPending],
|
||||
)
|
||||
|
||||
// ── Column meta for toolbar ────────────────────────────────────────────────
|
||||
const toggleableColumns = useMemo(
|
||||
() => COLUMN_IDS.map((id) => ({ id, label: t(`loanOrderMobiles.columns.${id}`, id) })),
|
||||
[t],
|
||||
)
|
||||
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
id: 'region',
|
||||
label: t('loanOrderMobiles.filters.region', 'WELAÝAT'),
|
||||
options: REGION_OPTIONS,
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
label: t('loanOrderMobiles.filters.status', 'STATUS'),
|
||||
options: STATUS_OPTIONS,
|
||||
},
|
||||
{
|
||||
id: 'branch',
|
||||
label: t('loanOrderMobiles.filters.branch', 'ŞAHAMÇA'),
|
||||
options: [],
|
||||
},
|
||||
{
|
||||
id: 'archived',
|
||||
label: t('loanOrderMobiles.filters.archived', 'ARHIWLENEN'),
|
||||
options: [
|
||||
{ value: 'true', label: t('common.yes', 'Hawa') },
|
||||
{ value: 'false', label: t('common.no', 'Ýok') },
|
||||
],
|
||||
},
|
||||
],
|
||||
[t],
|
||||
)
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────────────
|
||||
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">
|
||||
{t('loanOrderMobiles.title', 'Karz 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('loanOrderMobiles.searchPlaceholder', 'Gözlemek')}
|
||||
columns={toggleableColumns}
|
||||
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('loanOrderMobiles.createButton', 'Karz sargyt dörediň')}
|
||||
onAction={() => {
|
||||
// navigate to create page or open modal
|
||||
}}
|
||||
/>
|
||||
|
||||
<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={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
import { useState, useMemo, useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||
|
||||
import { DataTable } from '@/components/dataTable'
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar'
|
||||
import { LoanOrderStatusBadge } from '@/features/loanOrders/components/loanOrderStatusBadge'
|
||||
import { useLoanOrders, useDeleteLoanOrder } from '@/features/loanOrders/hooks/useLoanOrders'
|
||||
import type { LoanOrder, LoanOrderStatus } from '@/features/loanOrders/api/loanOrdersApi'
|
||||
|
||||
// ─── Column meta for toggle dropdown ─────────────────────────────────────────
|
||||
|
||||
const COLUMN_IDS = [
|
||||
'id', 'loanType', 'createdAt', 'region', 'branch',
|
||||
'firstName', 'lastName', 'phone', 'status',
|
||||
] as const
|
||||
|
||||
// ─── Filter fields ────────────────────────────────────────────────────────────
|
||||
|
||||
const REGION_OPTIONS = [
|
||||
{ value: 'Balkan', label: 'Balkan' },
|
||||
{ value: 'Ahal', label: 'Ahal' },
|
||||
{ value: 'Daşoguz', label: 'Daşoguz' },
|
||||
{ value: 'Lebap', label: 'Lebap' },
|
||||
{ value: 'Mary', label: 'Mary' },
|
||||
{ value: 'Aşgabat', label: 'Aşgabat' },
|
||||
]
|
||||
|
||||
const STATUS_OPTIONS: { value: LoanOrderStatus; label: string }[] = [
|
||||
{ value: 'GARAŞYLÝAR', label: 'GARAŞYLÝAR' },
|
||||
{ value: 'KANAGATLANDYRYLAN', label: 'KANAGATLANDYRYLAN' },
|
||||
{ value: 'RED_EDILDI', label: 'RED EDILDI' },
|
||||
{ value: 'IŞLENÝÄR', label: 'IŞLENÝÄR' },
|
||||
]
|
||||
|
||||
// ─── Page Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanOrdersPage() {
|
||||
const { t } = useTranslation()
|
||||
const deleteMutation = useDeleteLoanOrder()
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS])
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ fieldId: 'region', value: '' },
|
||||
{ fieldId: 'status', value: '' },
|
||||
{ fieldId: 'branch', value: '' },
|
||||
{ fieldId: 'archived', value: '' },
|
||||
])
|
||||
|
||||
// ── Query params ───────────────────────────────────────────────────────────
|
||||
const queryParams = useMemo(() => {
|
||||
const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value]))
|
||||
return {
|
||||
search: search || undefined,
|
||||
region: filterMap.region || undefined,
|
||||
status: (filterMap.status as LoanOrderStatus) || undefined,
|
||||
branch: filterMap.branch || undefined,
|
||||
archived: filterMap.archived || undefined,
|
||||
page,
|
||||
perPage,
|
||||
}
|
||||
}, [search, activeFilters, page, perPage])
|
||||
|
||||
const { data, isLoading } = useLoanOrders(queryParams)
|
||||
|
||||
const totalPages = data ? Math.ceil(data.total / perPage) : 1
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)))
|
||||
setPage(1)
|
||||
}, [])
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: '' })))
|
||||
setPage(1)
|
||||
}, [])
|
||||
|
||||
const handleDelete = useCallback(
|
||||
(id: string) => {
|
||||
if (!window.confirm(t('loanOrders.deleteConfirm', 'Bu sargyt pozulsynmy?'))) return
|
||||
deleteMutation.mutate(id)
|
||||
},
|
||||
[deleteMutation, t]
|
||||
)
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns = useMemo<ColumnDef<LoanOrder>[]>(
|
||||
() => [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('ID', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-xs font-mono text-muted-foreground">{row.original.id}</span>
|
||||
),
|
||||
size: 130,
|
||||
},
|
||||
{
|
||||
id: 'loanType',
|
||||
accessorKey: 'loanType',
|
||||
header: t('Loan type', 'KARZ GÖRNÜŞI'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-medium text-primary hover:underline cursor-pointer">
|
||||
{row.original.loanType}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'createdAt',
|
||||
accessorKey: 'createdAt',
|
||||
header: t('Created at', 'DÖREDILEN WAGTY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">{row.original.createdAt}</span>
|
||||
),
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: 'region',
|
||||
accessorKey: 'region',
|
||||
header: t('Region', 'WELAÝAT'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.region}</span>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'branch',
|
||||
accessorKey: 'branch',
|
||||
header: t('Branch', 'ŞAHAMÇA'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-emerald-500 font-medium">{row.original.branch}</span>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'firstName',
|
||||
accessorKey: 'firstName',
|
||||
header: t('Name', 'ADY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.firstName}</span>
|
||||
),
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: 'lastName',
|
||||
accessorKey: 'lastName',
|
||||
header: t('Surname', 'FAMILIÝASY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.lastName}</span>
|
||||
),
|
||||
size: 120,
|
||||
},
|
||||
{
|
||||
id: 'phone',
|
||||
accessorKey: 'phone',
|
||||
header: t('Phone', 'TELEFON'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.phone}</span>
|
||||
),
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
accessorKey: 'status',
|
||||
header: t('Status', 'STATUS'),
|
||||
cell: ({ row }) => <LoanOrderStatusBadge status={row.original.status} />,
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'View')}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Edit')}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDelete(row.original.id)}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
|
||||
title={t('common.delete', 'Delete')}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
],
|
||||
[t, handleDelete, deleteMutation.isPending]
|
||||
)
|
||||
|
||||
// ── Column meta for toolbar ────────────────────────────────────────────────
|
||||
const toggleableColumns = useMemo(
|
||||
() => COLUMN_IDS.map((id) => ({ id, label: t(`loanOrders.columns.${id}`, id) })),
|
||||
[t]
|
||||
)
|
||||
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
id: 'region',
|
||||
label: t('Region', 'WELAÝAT'),
|
||||
options: REGION_OPTIONS,
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
label: t('Status', 'STATUS'),
|
||||
options: STATUS_OPTIONS,
|
||||
},
|
||||
{
|
||||
id: 'branch',
|
||||
label: t('Branch', 'ŞAHAMÇA'),
|
||||
options: [],
|
||||
},
|
||||
{
|
||||
id: 'archived',
|
||||
label: t('loanOrders.filters.archived', 'ARHIWLENEN'),
|
||||
options: [
|
||||
{ value: 'true', label: t('common.yes', 'Hawa') },
|
||||
{ value: 'false', label: t('common.no', 'Ýok') },
|
||||
],
|
||||
},
|
||||
],
|
||||
[t]
|
||||
)
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
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">
|
||||
{t('loanOrders.title', 'Karz 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('loanOrders.searchPlaceholder', 'Gözlemek')}
|
||||
columns={toggleableColumns}
|
||||
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('loanOrders.createButton', 'Karz sargyt dörediñ')}
|
||||
onAction={() => {
|
||||
// navigate to create page or open modal
|
||||
}}
|
||||
/>
|
||||
|
||||
<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={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Eye, Pencil, Trash2, TableProperties } from "lucide-react";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import {
|
||||
DataTableToolbar,
|
||||
type ActiveFilter,
|
||||
type FilterField,
|
||||
} from "@/components/dataTableToolbar";
|
||||
import {
|
||||
useLoanPaidOffLetters,
|
||||
useDeleteLoanPaidOffLetter,
|
||||
} from "@/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters";
|
||||
import type { LoanPaidOffLetter } from "@/features/loanPaidOffLetters/api/loanPaidOffLettersApi";
|
||||
|
||||
// ─── Column IDs ────────────────────────────────────────────────────────────────
|
||||
|
||||
const COLUMN_IDS = [
|
||||
"id",
|
||||
"passportSeries",
|
||||
"passportNumber",
|
||||
"loanAccount",
|
||||
"issuedAt",
|
||||
] as const;
|
||||
|
||||
// ─── Empty state component ─────────────────────────────────────────────────────
|
||||
|
||||
function EmptyState({ onCreate }: { onCreate: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-20 gap-5">
|
||||
{/* Grid icon matching screenshot */}
|
||||
<div className="text-muted-foreground/40">
|
||||
<TableProperties size={64} strokeWidth={1} />
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground text-center max-w-sm">
|
||||
{t(
|
||||
"loanPaidOffLetters.emptyMessage",
|
||||
"Berlen kriteriýalara Karzyň ýapylandygy barada güwanama almak gabat gelmedi.",
|
||||
)}
|
||||
</p>
|
||||
<button
|
||||
onClick={onCreate}
|
||||
className="px-4 py-2 rounded-lg border border-border text-sm text-foreground hover:bg-muted/60 transition-colors"
|
||||
>
|
||||
{t(
|
||||
"loanPaidOffLetters.createButton",
|
||||
"Karzyň ýapylandygy barada güwanama almak dörediň",
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Page Component ────────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanPaidOffLettersPage() {
|
||||
const { t } = useTranslation();
|
||||
const deleteMutation = useDeleteLoanPaidOffLetter();
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS]);
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([]);
|
||||
|
||||
// ── Query ──────────────────────────────────────────────────────────────────
|
||||
const queryParams = useMemo(
|
||||
() => ({ search: search || undefined, page, perPage }),
|
||||
[search, page, perPage],
|
||||
);
|
||||
|
||||
const { data, isLoading } = useLoanPaidOffLetters(queryParams);
|
||||
const totalPages = data ? Math.ceil(data.total / perPage) : 1;
|
||||
const isEmpty = !isLoading && (data?.data?.length ?? 0) === 0;
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) =>
|
||||
prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)),
|
||||
);
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" })));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleDelete = useCallback(
|
||||
(id: number) => {
|
||||
if (
|
||||
!window.confirm(
|
||||
t("loanPaidOffLetters.deleteConfirm", "Bu ýazgy pozulsynmy?"),
|
||||
)
|
||||
)
|
||||
return;
|
||||
deleteMutation.mutate(id);
|
||||
},
|
||||
[deleteMutation, t],
|
||||
);
|
||||
|
||||
const handleCreate = useCallback(() => {
|
||||
// navigate to create page or open modal
|
||||
}, []);
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns = useMemo<ColumnDef<LoanPaidOffLetter>[]>(
|
||||
() => [
|
||||
{
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("loanPaidOffLetters.columns.id", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-semibold text-primary">
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
id: "passportSeries",
|
||||
accessorKey: "passportSeries",
|
||||
header: t(
|
||||
"loanPaidOffLetters.columns.passportSeries",
|
||||
"PASPORT SERIÝASY",
|
||||
),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.passportSeries}
|
||||
</span>
|
||||
),
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: "passportNumber",
|
||||
accessorKey: "passportNumber",
|
||||
header: t(
|
||||
"loanPaidOffLetters.columns.passportNumber",
|
||||
"PASPORT BELGISI",
|
||||
),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">
|
||||
{row.original.passportNumber}
|
||||
</span>
|
||||
),
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: "loanAccount",
|
||||
accessorKey: "loanAccount",
|
||||
header: t("loanPaidOffLetters.columns.loanAccount", "KARZ HASABY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">
|
||||
{row.original.loanAccount}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "issuedAt",
|
||||
accessorKey: "issuedAt",
|
||||
header: t("loanPaidOffLetters.columns.issuedAt", "BERLEN WAGTY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground whitespace-nowrap">
|
||||
{row.original.issuedAt}
|
||||
</span>
|
||||
),
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t("common.edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDelete(row.original.id)}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
|
||||
title={t("common.delete", "Pozmak")}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
],
|
||||
[t, handleDelete, deleteMutation.isPending],
|
||||
);
|
||||
|
||||
// ── Toggleable columns meta ────────────────────────────────────────────────
|
||||
const toggleableColumns = useMemo(
|
||||
() =>
|
||||
COLUMN_IDS.map((id) => ({
|
||||
id,
|
||||
label: t(`loanPaidOffLetters.columns.${id}`, id),
|
||||
})),
|
||||
[t],
|
||||
);
|
||||
|
||||
const filterFields = useMemo<FilterField[]>(() => [], []);
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────────────
|
||||
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">
|
||||
{t(
|
||||
"loanPaidOffLetters.title",
|
||||
"Karzyň ýapylandygy barada güwanamalar",
|
||||
)}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Table Card */}
|
||||
<div className="bg-card border border-border rounded-xl">
|
||||
{/* Toolbar: column toggle + filter (right side only, matches screenshot) */}
|
||||
<div className="px-4 pt-3 pb-2 border-b border-border">
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={toggleableColumns}
|
||||
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(
|
||||
"loanPaidOffLetters.createButton",
|
||||
"Karzyň ýapylandygy barada güwanama almak dörediň",
|
||||
)}
|
||||
onAction={handleCreate}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Empty state OR table */}
|
||||
{isEmpty ? (
|
||||
<EmptyState onCreate={handleCreate} />
|
||||
) : (
|
||||
<div className="p-4">
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import { useState, useMemo, useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||
|
||||
import { DataTable } from '@/components/dataTable'
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar'
|
||||
import { useLoanRemaining, useDeleteLoanRemaining } from '@/features/loanRemaining/hooks/useLoanRemaining'
|
||||
import type { LoanRemaining } from '@/features/loanRemaining/api/loanRemainingApi'
|
||||
|
||||
// ─── Column IDs ────────────────────────────────────────────────────────────────
|
||||
|
||||
const COLUMN_IDS = ['id', 'passportSeries', 'passportNumber', 'loanAccount'] as const
|
||||
|
||||
// ─── Page Component ────────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanRemainingPage() {
|
||||
const { t } = useTranslation()
|
||||
const deleteMutation = useDeleteLoanRemaining()
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS])
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([])
|
||||
|
||||
// ── Query ──────────────────────────────────────────────────────────────────
|
||||
const queryParams = useMemo(
|
||||
() => ({ search: search || undefined, page, perPage }),
|
||||
[search, page, perPage],
|
||||
)
|
||||
|
||||
const { data, isLoading } = useLoanRemaining(queryParams)
|
||||
const totalPages = data ? Math.ceil(data.total / perPage) : 1
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)))
|
||||
setPage(1)
|
||||
}, [])
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: '' })))
|
||||
setPage(1)
|
||||
}, [])
|
||||
|
||||
const handleDelete = useCallback(
|
||||
(id: number) => {
|
||||
if (!window.confirm(t('loanRemaining.deleteConfirm', 'Bu ýazgy pozulsynmy?'))) return
|
||||
deleteMutation.mutate(id)
|
||||
},
|
||||
[deleteMutation, t],
|
||||
)
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns = useMemo<ColumnDef<LoanRemaining>[]>(
|
||||
() => [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: t('loanRemaining.columns.id', 'ID'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-semibold text-primary">{row.original.id}</span>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
id: 'passportSeries',
|
||||
accessorKey: 'passportSeries',
|
||||
header: t('loanRemaining.columns.passportSeries', 'PASPORT SERIÝASY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.passportSeries}</span>
|
||||
),
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: 'passportNumber',
|
||||
accessorKey: 'passportNumber',
|
||||
header: t('loanRemaining.columns.passportNumber', 'PASPORT BELGISI'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.passportNumber}</span>
|
||||
),
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: 'loanAccount',
|
||||
accessorKey: 'loanAccount',
|
||||
header: t('loanRemaining.columns.loanAccount', 'KARZ HASABY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.loanAccount}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görmek')}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDelete(row.original.id)}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
],
|
||||
[t, handleDelete, deleteMutation.isPending],
|
||||
)
|
||||
|
||||
// ── Toggleable columns meta ────────────────────────────────────────────────
|
||||
const toggleableColumns = useMemo(
|
||||
() => COLUMN_IDS.map((id) => ({ id, label: t(`loanRemaining.columns.${id}`, id) })),
|
||||
[t],
|
||||
)
|
||||
|
||||
const filterFields = useMemo<FilterField[]>(() => [], [])
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────────────
|
||||
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">
|
||||
{t('loanRemaining.title', 'Karzyň galyndysy')}
|
||||
</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={toggleableColumns}
|
||||
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('loanRemaining.createButton', 'Karzyň galyndysy dörediň')}
|
||||
onAction={() => {
|
||||
// navigate to create page or open modal
|
||||
}}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+244
-42
@@ -1,54 +1,256 @@
|
||||
import { AuthLayout } from "@/layouts/AuthLayout";
|
||||
import React, { useState } from "react";
|
||||
import BankImage from "@/assets/bank-img.png";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useLogin } from "@/features/auth/hooks/useLogin";
|
||||
import { useState } from "react";
|
||||
import { useThemeStore } from "@/app/store/themeStore";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Sun, Moon, Globe } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export default function LoginPage() {
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const { login, isLoading } = useLogin();
|
||||
type AuthView = "login" | "register" | "reset-password";
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
login({ username, password });
|
||||
function LeftPanel() {
|
||||
return (
|
||||
<div className="w-[55%] hidden md:block overflow-hidden min-w-0 bg-muted">
|
||||
<img src={BankImage} alt="Bank Logo" className="w-full h-full object-cover opacity-90 dark:opacity-80" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Header() {
|
||||
const { theme, toggleTheme } = useThemeStore();
|
||||
const { i18n } = useTranslation();
|
||||
|
||||
const changeLanguage = (lang: string) => {
|
||||
i18n.changeLanguage(lang);
|
||||
localStorage.setItem("tbbank-lang", lang);
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthLayout>
|
||||
<div className="w-full max-w-md p-8 bg-[var(--bg-surface)] rounded-[var(--radius-lg)] shadow-[var(--shadow-lg)] border border-[var(--border-default)]">
|
||||
<h1 className="text-2xl font-bold text-[var(--text-primary)] mb-6 text-center">
|
||||
Login
|
||||
</h1>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium text-[var(--text-secondary)]">
|
||||
Username
|
||||
</label>
|
||||
<Input
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
placeholder="Enter your username"
|
||||
required
|
||||
/>
|
||||
<div className="flex justify-between items-center px-6 py-3 border-b border-border text-[13px] bg-background">
|
||||
<span className="font-semibold text-foreground">"TÜRKMENBAŞY" PTB ©</span>
|
||||
<div className="flex items-center gap-4 text-muted-foreground">
|
||||
<span className="hidden sm:inline">(+99312) 44-42-34</span>
|
||||
<button
|
||||
onClick={toggleTheme}
|
||||
className="p-1.5 rounded-md hover:bg-accent text-foreground transition-colors"
|
||||
aria-label="Toggle theme"
|
||||
>
|
||||
{theme === "dark" ? <Sun size={16} /> : <Moon size={16} />}
|
||||
</button>
|
||||
<div className="flex items-center gap-1.5 bg-accent/50 px-2 py-1 rounded-md">
|
||||
<Globe size={14} className="text-foreground" />
|
||||
<div className="flex gap-1 items-center ml-1">
|
||||
{["tk", "ru", "en"].map((lang, idx) => (
|
||||
<React.Fragment key={lang}>
|
||||
<span
|
||||
onClick={() => changeLanguage(lang)}
|
||||
className={`cursor-pointer uppercase font-medium transition-colors hover:text-foreground ${
|
||||
i18n.language === lang ? "text-foreground" : "text-muted-foreground"
|
||||
}`}
|
||||
>
|
||||
{lang}
|
||||
</span>
|
||||
{idx < 2 && <span className="text-border">|</span>}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium text-[var(--text-secondary)]">
|
||||
Password
|
||||
</label>
|
||||
<Input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Enter your password"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" className="w-full" isLoading={isLoading}>
|
||||
Sign In
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</AuthLayout>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface FormInputProps extends Omit<React.ComponentProps<typeof Input>, "onChange" | "value"> {
|
||||
label: string;
|
||||
value: string;
|
||||
onChange: (val: string) => void;
|
||||
}
|
||||
|
||||
function FormInput({
|
||||
label,
|
||||
value,
|
||||
onChange,
|
||||
...props
|
||||
}: FormInputProps) {
|
||||
return (
|
||||
<div className="mb-4">
|
||||
<label className="block text-[13px] font-medium text-foreground mb-1.5">
|
||||
{label}
|
||||
</label>
|
||||
<Input
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="bg-background border-input focus-visible:ring-primary"
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AuthPage() {
|
||||
const { t } = useTranslation();
|
||||
const loginMutation = useLogin();
|
||||
const [view, setView] = useState<AuthView>("login");
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [phone, setPhone] = useState("");
|
||||
const [fullName, setFullName] = useState("");
|
||||
|
||||
const handleLogin = () => {
|
||||
if (!username || !password) {
|
||||
toast.error(t("Write a correct data please", "Please enter valid data"));
|
||||
return;
|
||||
}
|
||||
|
||||
loginMutation.mutate({ email: username, password }, {
|
||||
onError: () => {
|
||||
toast.error(t("Server Error", "An error occurred during login"));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Mock submit for other views
|
||||
const handleOtherSubmit = async () => {
|
||||
toast.info(t("Not Implemented", "This feature is not implemented yet"));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-screen bg-background text-foreground font-sans">
|
||||
<Header />
|
||||
<div className="flex flex-1 w-full overflow-hidden">
|
||||
<LeftPanel />
|
||||
|
||||
<div className="w-full md:w-[45%] flex flex-col bg-background">
|
||||
<div className="flex-1 flex flex-col justify-center px-8 sm:px-12 py-10 overflow-y-auto">
|
||||
{view === "login" && (
|
||||
<>
|
||||
<h2 className="text-[22px] font-normal text-foreground text-center mb-2 tracking-wide uppercase">
|
||||
{t("Online panel", "ONLAÝN KABULHANA")}
|
||||
</h2>
|
||||
<div className="w-14 h-0.5 bg-primary mx-auto mb-7" />
|
||||
|
||||
<FormInput
|
||||
label={t("Phone or username", "Telefon ýada ulanyjy ady")}
|
||||
value={username}
|
||||
onChange={setUsername}
|
||||
placeholder="65999990 ýada ulanyjy_ady"
|
||||
/>
|
||||
<FormInput
|
||||
label={t("Password")}
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={setPassword}
|
||||
/>
|
||||
|
||||
<div className="text-right mb-6 -mt-2">
|
||||
<span
|
||||
onClick={() => setView("reset-password")}
|
||||
className="text-[13px] text-primary cursor-pointer hover:underline"
|
||||
>
|
||||
{t("Forgot your password?")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-3">
|
||||
<Button onClick={handleLogin} disabled={loginMutation.isPending}>
|
||||
{loginMutation.isPending ? t("Loading") + "..." : t("Login")}
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setView("register")}>
|
||||
{t("Register")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="text-center mt-8">
|
||||
<span className="text-[13px] text-muted-foreground underline cursor-pointer hover:text-foreground transition-colors">
|
||||
Privacy Policy
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{view === "register" && (
|
||||
<>
|
||||
<h2 className="text-xl font-normal text-foreground text-center mb-2">
|
||||
{t("Online panel", "Onlaýn kabulhana")}
|
||||
</h2>
|
||||
<div className="w-14 h-0.5 bg-primary mx-auto mb-7" />
|
||||
|
||||
<FormInput
|
||||
label={t("Full Name")}
|
||||
value={fullName}
|
||||
onChange={setFullName}
|
||||
/>
|
||||
<FormInput label={t("Phone")} value={phone} onChange={setPhone} />
|
||||
<FormInput
|
||||
label={t("Username")}
|
||||
value={username}
|
||||
onChange={setUsername}
|
||||
/>
|
||||
<FormInput
|
||||
label={t("Password")}
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={setPassword}
|
||||
/>
|
||||
<FormInput
|
||||
label={t("Confirm Password")}
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
onChange={setConfirmPassword}
|
||||
/>
|
||||
|
||||
<div className="flex flex-col gap-3 mt-4">
|
||||
<Button onClick={handleOtherSubmit}>
|
||||
{t("Register")}
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setView("login")}>
|
||||
{t("Go to login page")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="text-center mt-8">
|
||||
<span className="text-[13px] text-muted-foreground underline cursor-pointer hover:text-foreground transition-colors">
|
||||
Privacy Policy
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{view === "reset-password" && (
|
||||
<>
|
||||
<h2 className="text-lg font-normal text-foreground text-center mb-2 leading-relaxed">
|
||||
{t("Enter your username to continue")}
|
||||
</h2>
|
||||
<div className="w-14 h-0.5 bg-primary mx-auto mb-7" />
|
||||
|
||||
<FormInput
|
||||
label={t("Username")}
|
||||
value={username}
|
||||
onChange={setUsername}
|
||||
/>
|
||||
|
||||
<div className="mt-4 flex flex-col gap-3">
|
||||
<Button onClick={handleOtherSubmit}>
|
||||
{t("Submit")}
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setView("login")}>
|
||||
{t("Go to login page")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="text-center mt-8">
|
||||
<span className="text-[13px] text-muted-foreground underline cursor-pointer hover:text-foreground transition-colors">
|
||||
Privacy Policy
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user