added some settings page
This commit is contained in:
219
src/pages/settings/loan/loanTypes/index.tsx
Normal file
219
src/pages/settings/loan/loanTypes/index.tsx
Normal file
@@ -0,0 +1,219 @@
|
||||
// pages/LoanTypesListPage.tsx
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react'
|
||||
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import { useGetLoanTypes, useDeleteLoanType } from '@/features/loanTypes/hooks/useLoanTypes'
|
||||
import type { LoanType } from '@/features/loanTypes/api/loanTypesApi'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
|
||||
// ─── Column definitions ───────────────────────────────────────────────────────
|
||||
|
||||
function useLoanTypeColumns(
|
||||
onView: (id: number) => void,
|
||||
onEdit: (id: number) => void,
|
||||
onDelete: (id: number) => void
|
||||
): ColumnDef<LoanType>[] {
|
||||
const { t, i18n } = useTranslation()
|
||||
const lang = (i18n.language ?? 'tk') as 'tk' | 'ru' | 'en'
|
||||
|
||||
return [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
size: 60,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-semibold text-sm">{row.original.id}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('loanTypes.columns.name', 'ADY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'tax',
|
||||
header: t('loanTypes.columns.tax', 'SALGYT'),
|
||||
size: 90,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.tax}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'loanTerm',
|
||||
header: t('loanTypes.columns.loanTerm', 'KARZ MÖHLETI'),
|
||||
size: 130,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.loanTerm}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'notes',
|
||||
header: t('loanTypes.columns.notes', 'BELLIKLER'),
|
||||
cell: ({ row }) => {
|
||||
const notes = row.original.notes
|
||||
return (
|
||||
<span className="text-sm text-foreground">
|
||||
{notes ? notes[lang] || '—' : '—'}
|
||||
</span>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
header: t('loanTypes.columns.isActive', 'IŞJEŇ'),
|
||||
size: 80,
|
||||
cell: ({ row }) =>
|
||||
row.original.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-muted-foreground" />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
size: 120,
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
onClick={() => onView(row.original.id)}
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görmek')}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onEdit(row.original.id)}
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Redaktirlemek')}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onDelete(row.original.id)}
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// ─── LoanTypesListPage ────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanTypesListPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage] = useState(25)
|
||||
const [search, setSearch] = useState('')
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
|
||||
const [columnVisibility, setColumnVisibility] = useState<Record<string, boolean>>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
|
||||
const { data, isLoading } = useGetLoanTypes({ page, perPage, search })
|
||||
const deleteMutation = useDeleteLoanType()
|
||||
|
||||
const handleView = (id: number) => navigate(`/settings/loan/loan-types/${id}`)
|
||||
const handleEdit = (id: number) => navigate(`/settings/loan/loan-types/${id}/edit`)
|
||||
const handleDelete = (id: number) => setDeleteId(id)
|
||||
|
||||
const confirmDelete = async () => {
|
||||
if (deleteId === null) return
|
||||
await deleteMutation.mutateAsync(deleteId)
|
||||
setDeleteId(null)
|
||||
}
|
||||
|
||||
const columns = useLoanTypeColumns(handleView, handleEdit, handleDelete)
|
||||
|
||||
const columnMeta = columns
|
||||
.filter((c) => c.id !== 'actions' && 'accessorKey' in c)
|
||||
.map((c) => ({
|
||||
id: 'accessorKey' in c ? String(c.accessorKey) : String(c.id),
|
||||
label: typeof c.header === 'string' ? c.header : String(c.id ?? ''),
|
||||
}))
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{t('loanTypes.title', 'Karz görnüşleri')}
|
||||
</h1>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t('loanTypes.actions.create', 'Karz görnüşi dörediň')}
|
||||
onAction={() => navigate('/settings/loan/loan-types/create')}
|
||||
/>
|
||||
|
||||
<DataTable<LoanType>
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={data?.totalPages ?? 1}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* Delete confirmation dialog */}
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('loanTypes.deleteDialog.title', 'Pozmak')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('loanTypes.deleteDialog.description', 'Bu karz görnüşini pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylyp bilinmez.')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={deleteMutation.isPending}>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={confirmDelete}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="bg-destructive hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending ? t('common.deleting', 'Pozulýar...') : t('common.delete', 'Pozmak')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
20
src/pages/settings/loan/loanTypesCreate/index.tsx
Normal file
20
src/pages/settings/loan/loanTypesCreate/index.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
// pages/LoanTypeCreatePage.tsx
|
||||
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { LoanTypeForm } from '@/features/loanTypes/components/loanTypesForm'
|
||||
|
||||
export default function LoanTypeCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-3xl">
|
||||
|
||||
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{t('loanTypes.actions.create', 'Karz görnüşi dörediň')}
|
||||
</h1>
|
||||
|
||||
<LoanTypeForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
47
src/pages/settings/loan/loanTypesEdit/index.tsx
Normal file
47
src/pages/settings/loan/loanTypesEdit/index.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
// pages/LoanTypeEditPage.tsx
|
||||
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { LoanTypeForm } from '@/features/loanTypes/components/loanTypesForm'
|
||||
import { useGetLoanTypeById } from '@/features/loanTypes/hooks/useLoanTypes'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function LoanTypeEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const loanTypeId = Number(id)
|
||||
|
||||
const { data, isLoading, isError } = useGetLoanTypeById(loanTypeId)
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-3xl">
|
||||
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{isLoading
|
||||
? t('common.loading', 'Ýüklenýär...')
|
||||
: `${t('loanTypes.editTitle', 'Karz görnüşi redaktirle')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center px-4 py-3">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-8 w-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : isError ? (
|
||||
<div className="flex items-center justify-center py-20 text-destructive text-sm">
|
||||
{t('common.error', 'Ýalňyşlyk ýüze çykdy')}
|
||||
</div>
|
||||
) : (
|
||||
<LoanTypeForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
loanTypeId={loanTypeId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
206
src/pages/settings/loan/loanTypesView/index.tsx
Normal file
206
src/pages/settings/loan/loanTypesView/index.tsx
Normal file
@@ -0,0 +1,206 @@
|
||||
// pages/LoanTypeViewPage.tsx
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||
import { useGetLoanTypeById, useDeleteLoanType } from '@/features/loanTypes/hooks/useLoanTypes'
|
||||
|
||||
// ─── LoanTypeViewPage ─────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanTypeViewPage() {
|
||||
const { t, i18n } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const loanTypeId = Number(id)
|
||||
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
||||
|
||||
const { data, isLoading, isError } = useGetLoanTypeById(loanTypeId)
|
||||
const deleteMutation = useDeleteLoanType()
|
||||
|
||||
const lang = (i18n.language ?? 'tk') as 'tk' | 'ru' | 'en'
|
||||
|
||||
const handleDelete = async () => {
|
||||
await deleteMutation.mutateAsync(loanTypeId)
|
||||
navigate('/resources/loan-types')
|
||||
}
|
||||
|
||||
// ── Skeleton ───────────────────────────────────────────────────────────────
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 max-w-3xl">
|
||||
<Skeleton className="h-4 w-64 mb-4" />
|
||||
<Skeleton className="h-7 w-80 mb-6" />
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center px-4 py-3">
|
||||
<Skeleton className="h-4 w-20" />
|
||||
<Skeleton className="h-4 w-40" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Error ──────────────────────────────────────────────────────────────────
|
||||
if (isError || !data) {
|
||||
return (
|
||||
<div className="p-6 flex items-center justify-center py-20 text-destructive text-sm">
|
||||
{t('common.error', 'Ýalňyşlyk ýüze çykdy')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── View ───────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div className="p-6 max-w-3xl">
|
||||
{/* Breadcrumb */}
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground mb-4">
|
||||
<span
|
||||
className="hover:text-foreground cursor-pointer transition-colors"
|
||||
onClick={() => navigate('/resources')}
|
||||
>
|
||||
{t('nav.resources', 'Resurslar')}
|
||||
</span>
|
||||
<span>/</span>
|
||||
<span
|
||||
className="hover:text-foreground cursor-pointer transition-colors text-primary"
|
||||
onClick={() => navigate('/resources/loan-types')}
|
||||
>
|
||||
{t('loanTypes.title', 'Karz görnüşleri')}
|
||||
</span>
|
||||
<span>/</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('loanTypes.viewTitle', 'Karz görnüşi giňişleýin')}: {data.name[lang]}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Page header */}
|
||||
<div className="flex items-start justify-between mb-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('loanTypes.viewTitle', 'Karz görnüşi giňişleýin')}: {data.name[lang]}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => setShowDeleteDialog(true)}
|
||||
className="text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors"
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => navigate(`/resources/loan-types/${loanTypeId}/edit`)}
|
||||
className="text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Redaktirlemek')}
|
||||
>
|
||||
<Pencil size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Detail section */}
|
||||
<Section>
|
||||
<InfoRow label="ID" value={data.id} />
|
||||
|
||||
{/* Multilingual name rows */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-2.5 px-4 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground pt-1">
|
||||
{t('loanTypes.fields.name', 'Ady')}
|
||||
</span>
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-xs font-semibold text-muted-foreground w-6">TK</span>
|
||||
<span className="text-sm text-foreground">{data.name.tk}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-xs font-semibold text-muted-foreground w-6">RU</span>
|
||||
<span className="text-sm text-foreground">{data.name.ru}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-xs font-semibold text-muted-foreground w-6">EN</span>
|
||||
<span className="text-sm text-foreground">{data.name.en}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<InfoRow
|
||||
label={t('loanTypes.fields.tax', 'Salgyt')}
|
||||
value={data.tax}
|
||||
/>
|
||||
|
||||
<InfoRow
|
||||
label={t('loanTypes.fields.loanTerm', 'Karz möhleti')}
|
||||
value={data.loanTerm}
|
||||
/>
|
||||
|
||||
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t('loanTypes.fields.notes', 'Bellikler')}
|
||||
</span>
|
||||
<span className="text-sm text-foreground">
|
||||
{data.notes ? data.notes[lang] || '—' : '—'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t('loanTypes.fields.isActive', 'Işjeň')}
|
||||
</span>
|
||||
{data.isActive ? (
|
||||
<CheckCircle2 size={20} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={20} className="text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('loanTypes.deleteDialog.title', 'Pozmak')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'loanTypes.deleteDialog.description',
|
||||
'Bu karz görnüşini pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylyp bilinmez.'
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={deleteMutation.isPending}>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="bg-destructive hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Pozmak')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
138
src/pages/settings/loan/requiredDocuments/index.tsx
Normal file
138
src/pages/settings/loan/requiredDocuments/index.tsx
Normal file
@@ -0,0 +1,138 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import { useGetRequiredDocuments, useDeleteRequiredDocument } from '@/features/requiredDocuments/hooks/useRequiredDocuments'
|
||||
import type { LoanDocument } from '@/features/requiredDocuments/api/requiredDocumentsApi'
|
||||
import type { VisibilityState } from '@tanstack/react-table'
|
||||
|
||||
// ─── Column visibility defaults ───────────────────────────────────────────────
|
||||
|
||||
const DEFAULT_VISIBILITY: VisibilityState = {}
|
||||
const DEFAULT_ORDER = ['id', 'name', 'actions']
|
||||
|
||||
export default function RequiredDocumentsListPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
// ── Table state ─────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage] = useState(10)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>(DEFAULT_VISIBILITY)
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(DEFAULT_ORDER)
|
||||
|
||||
// ── Data ────────────────────────────────────────────────────────────────────
|
||||
const { data, isLoading } = useGetRequiredDocuments({ page, perPage, search })
|
||||
const deleteMutation = useDeleteRequiredDocument()
|
||||
|
||||
const handleDelete = (id: number) => {
|
||||
if (window.confirm(t('loanDocuments.deleteConfirm', 'Bu resminamany öçürmek isleýärsiňizmi?'))) {
|
||||
deleteMutation.mutate(id)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Columns ─────────────────────────────────────────────────────────────────
|
||||
const columns: ColumnDef<LoanDocument>[] = [
|
||||
{
|
||||
id: 'id',
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
size: 72,
|
||||
cell: ({ row }) => (
|
||||
<span
|
||||
className="text-primary font-semibold cursor-pointer hover:underline"
|
||||
onClick={() => navigate(`/settings/loan/required-documents/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'name',
|
||||
header: t('loanDocuments.columns.name', 'ADY'),
|
||||
accessorFn: (row) => row.name.tk,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name.tk}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
size: 100,
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<button
|
||||
onClick={() => navigate(`/settings/loan/required-documents/${row.original.id}`)}
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.view', 'Görüntüle')}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate(`/settings/loan/required-documents/${row.original.id}/edit`)}
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Düzet')}
|
||||
>
|
||||
<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"
|
||||
title={t('common.delete', 'Öçür')}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
const columnMetas = columns
|
||||
.filter((c) => c.id !== 'actions' && c.id !== 'select')
|
||||
.map((c) => ({ id: c.id as string, label: typeof c.header === 'string' ? c.header : c.id as string }))
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Page heading */}
|
||||
<h1 className="text-xl font-semibold text-foreground mb-4">
|
||||
{t('loanDocuments.title', 'Karz gerekli resminamalary')}
|
||||
</h1>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMetas}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t('loanDocuments.createBtn', 'Karz gerekli resminamalary döretiň')}
|
||||
onAction={() => navigate('/settings/loan/required-documents/create')}
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => String(row.id)}
|
||||
enableRowSelection
|
||||
currentPage={page}
|
||||
totalPages={data?.totalPages ?? 1}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
16
src/pages/settings/loan/requiredDocumentsCreate/index.tsx
Normal file
16
src/pages/settings/loan/requiredDocumentsCreate/index.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { RequiredDocumentForm } from '@/features/requiredDocuments/components/requiredDocumentsForm'
|
||||
|
||||
export default function RequiredDocumentsCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-5xl">
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{t('loanDocuments.createBtn', 'Karz gerekli resminamalary dörediň')}
|
||||
</h1>
|
||||
|
||||
<RequiredDocumentForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
47
src/pages/settings/loan/requiredDocumentsEdit/index.tsx
Normal file
47
src/pages/settings/loan/requiredDocumentsEdit/index.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { RequiredDocumentForm } from '@/features/requiredDocuments/components/requiredDocumentsForm'
|
||||
import { useGetRequiredDocumentById } from '@/features/requiredDocuments/hooks/useRequiredDocuments'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function RequiredDocumentsEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const documentId = Number(id)
|
||||
|
||||
const { data, isLoading, isError } = useGetRequiredDocumentById(documentId)
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-5xl">
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{isLoading
|
||||
? t('common.loading', 'Ýüklenýär...')
|
||||
: `${t('loanDocuments.editTitle', 'Karz gerekli resminamalary redaktirle')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 2 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-start px-4 py-4">
|
||||
<Skeleton className="h-4 w-24 mt-2" />
|
||||
<div>
|
||||
<Skeleton className="h-10 w-full mb-2" />
|
||||
<Skeleton className="h-32 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : isError ? (
|
||||
<div className="flex items-center justify-center py-20 text-destructive text-sm">
|
||||
{t('common.error', 'Ýalňyşlyk ýüze çykdy')}
|
||||
</div>
|
||||
) : (
|
||||
<RequiredDocumentForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
requiredDocumentId={documentId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
117
src/pages/settings/loan/requiredDocumentsView/index.tsx
Normal file
117
src/pages/settings/loan/requiredDocumentsView/index.tsx
Normal file
@@ -0,0 +1,117 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2 } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||
import { useGetRequiredDocumentById, useDeleteRequiredDocument } from '@/features/requiredDocuments/hooks/useRequiredDocuments'
|
||||
|
||||
export default function RequiredDocumentsViewPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const docId = Number(id)
|
||||
const { data, isLoading } = useGetRequiredDocumentById(docId)
|
||||
const deleteMutation = useDeleteRequiredDocument()
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (window.confirm(t('loanDocuments.deleteConfirm', 'Bu resminamany öçürmek isleýärsiňizmi?'))) {
|
||||
await deleteMutation.mutateAsync(docId)
|
||||
navigate('/settings/loan/loan-documents')
|
||||
}
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="h-12 bg-muted rounded-lg animate-pulse" />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-16 text-muted-foreground">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Page heading */}
|
||||
<div className="flex items-start justify-between mb-4 gap-4">
|
||||
<h1 className="text-xl font-semibold text-foreground leading-snug line-clamp-2">
|
||||
{t('loanDocuments.viewTitle', 'Karz gerekli resminamalary giňişleýin')}: {data.name.tk}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={handleDelete}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="text-muted-foreground hover:text-destructive hover:bg-destructive/10"
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => navigate(`/settings/loan/loan-documents/${docId}/edit`)}
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Pencil size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main info */}
|
||||
<Section>
|
||||
<InfoRow label="ID" value={data.id} />
|
||||
|
||||
{/* Name — multilingual */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-2.5 px-4 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground pt-1">
|
||||
{t('loanDocuments.fields.name', 'Ady')}
|
||||
</span>
|
||||
<div className="space-y-3">
|
||||
{(['tk', 'ru', 'en'] as const).map((lang) => (
|
||||
<div key={lang}>
|
||||
<span className="text-xs font-semibold text-muted-foreground uppercase tracking-wider block mb-0.5">
|
||||
{lang === 'tk' ? 'Türkmen' : lang === 'ru' ? 'Русский' : 'English'}
|
||||
</span>
|
||||
<span className="text-sm text-foreground">{data.name[lang] || '—'}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description — multilingual */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-2.5 px-4">
|
||||
<span className="text-sm text-muted-foreground pt-1">
|
||||
{t('loanDocuments.fields.description', 'Yazgy')}
|
||||
</span>
|
||||
<div className="space-y-4">
|
||||
{(['tk', 'ru', 'en'] as const).map((lang) => (
|
||||
<div key={lang}>
|
||||
<span className="text-xs font-semibold text-muted-foreground uppercase tracking-wider block mb-1">
|
||||
{lang === 'tk' ? 'Türkmen' : lang === 'ru' ? 'Русский' : 'English'}
|
||||
</span>
|
||||
{data.description[lang] ? (
|
||||
<div
|
||||
className="text-sm text-foreground prose prose-sm dark:prose-invert max-w-none"
|
||||
dangerouslySetInnerHTML={{ __html: data.description[lang] }}
|
||||
/>
|
||||
) : (
|
||||
<span className="text-muted-foreground/40 text-sm">—</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user