added loan remaing pages

This commit is contained in:
@jcarymuhammedow committed 2026-05-05 19:07:59 +05:00
1 parent c612d5bae3
commit c2548280a2
24 files changed
+3182 -307

No files matched your search

+3 -3
View File
@@ -1,5 +1,5 @@
import { LoanOrderForm } from '@/features/loanOrders/components/loanOrderForm'
import { LoanOrderForm } from "@/features/loanOrderMobiles/components/loanOrderForm";
export default function LoanOrderCreatePage() {
return <LoanOrderForm mode="create" />
}
return <LoanOrderForm mode="create" />;
}
+10 -16
View File
@@ -1,18 +1,18 @@
import { useParams } from 'react-router-dom'
import { Loader2 } from 'lucide-react'
import { LoanOrderForm } from '@/features/loanOrders/components/loanOrderForm'
import { useLoanOrderById } from '@/features/loanOrders/hooks/useLoanOrders'
import { useParams } from "react-router-dom";
import { Loader2 } from "lucide-react";
import { LoanOrderForm } from "@/features/loanOrderMobiles/components/loanOrderForm";
import { useLoanOrderById } from "@/features/loanOrders/hooks/useLoanOrders";
export default function LoanOrderEditPage() {
const { id } = useParams<{ id: string }>()
const { data, isLoading, isError } = useLoanOrderById(id ?? '')
const { id } = useParams<{ id: string }>();
const { data, isLoading, isError } = useLoanOrderById(id ?? "");
if (isLoading) {
return (
<div className="flex items-center justify-center min-h-[400px]">
<Loader2 className="animate-spin text-muted-foreground" size={32} />
</div>
)
);
}
if (isError || !data) {
@@ -22,14 +22,8 @@ export default function LoanOrderEditPage() {
Maglumat ýüklenilmedi. Sahypany täzeleläň.
</p>
</div>
)
);
}
return (
<LoanOrderForm
mode="edit"
initialData={data}
loanOrderId={id}
/>
)
}
return <LoanOrderForm mode="edit" initialData={data} loanOrderId={id} />;
}
@@ -1,6 +1,7 @@
import { useState, useMemo, useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { Eye, Pencil, Trash2 } from 'lucide-react'
import { useNavigate } from 'react-router-dom'
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
import { DataTable } from '@/components/dataTable'
@@ -36,6 +37,7 @@ const STATUS_OPTIONS: LoanOrderMobileStatus[] = ['GARAŞYLÝAR', 'KANAGATLANDYRY
export default function LoanOrderMobilesPage() {
const { t } = useTranslation()
const navigate = useNavigate()
const deleteMutation = useDeleteLoanOrderMobile()
// ── State ──────────────────────────────────────────────────────────────────
@@ -175,19 +177,21 @@ export default function LoanOrderMobilesPage() {
header: '',
enableHiding: false,
cell: ({ row }) => (
<div className="flex items-center gap-1.5 justify-end">
<button
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.view', 'Görmek')}
>
<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', 'Üýtgetmek')}
>
<Pencil size={15} />
</button>
<div className="flex items-center gap-1.5 justify-end">
<button
onClick={() => navigate(`/loan-order-mobiles/${row.original.id}`)}
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.view', 'Görmek')}
>
<Eye size={15} />
</button>
<button
onClick={() => navigate(`/loan-order-mobiles/${row.original.id}/edit`)}
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.edit', 'Üýtgetmek')}
>
<Pencil size={15} />
</button>
<button
onClick={() => handleDelete(row.original.id)}
disabled={deleteMutation.isPending}
@@ -201,7 +205,7 @@ export default function LoanOrderMobilesPage() {
size: 100,
},
],
[t, handleDelete, deleteMutation.isPending],
[t, handleDelete, deleteMutation.isPending, navigate],
)
// ── Column meta for toolbar ────────────────────────────────────────────────
@@ -269,7 +273,7 @@ export default function LoanOrderMobilesPage() {
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
actionLabel={t('loanOrderMobiles.createButton', 'Karz sargyt dörediň')}
onAction={() => {
// navigate to create page or open modal
navigate('/loan-order-mobiles/create')
}}
/>
@@ -0,0 +1,5 @@
import { LoanOrderMobileForm } from '@/components/loanOrderMobileForm'
export default function LoanOrderMobilesCreatePage() {
return <LoanOrderMobileForm mode="create" />
}
+35
View File
@@ -0,0 +1,35 @@
import { useParams } from 'react-router-dom'
import { Loader2 } from 'lucide-react'
import { LoanOrderMobileForm } from '@/components/loanOrderMobileForm'
import { useLoanOrderMobileById } from '@/features/loanOrderMobiles/hooks/useLoanOrderMobiles'
export default function LoanOrderMobilesEditPage() {
const { id } = useParams<{ id: string }>()
const { data, isLoading, isError } = useLoanOrderMobileById(id ?? '')
if (isLoading) {
return (
<div className="flex items-center justify-center min-h-[400px]">
<Loader2 className="animate-spin text-muted-foreground" size={32} />
</div>
)
}
if (isError || !data) {
return (
<div className="flex items-center justify-center min-h-[400px]">
<p className="text-sm text-destructive">
Maglumat ýüklenilmedi. Sahypany täzeleläň.
</p>
</div>
)
}
return (
<LoanOrderMobileForm
mode="edit"
initialData={data}
loanOrderId={id}
/>
)
}
+452
View File
@@ -0,0 +1,452 @@
import { useNavigate, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Trash2, Pencil, Download, ChevronRight, Eye } from 'lucide-react'
import { useLoanOrderMobileById, useDeleteLoanOrderMobile } from '@/features/loanOrderMobiles/hooks/useLoanOrderMobiles'
import { LoanOrderStatusBadge } from '@/features/loanOrders/components/loanOrderStatusBadge'
import { CreditCardVisual } from '@/components/creditCardVisual'
import { Skeleton } from '@/components/ui/skeleton'
import { toast } from 'sonner'
// ─── Sub-component Types ──────────────────────────────────────────────────────
interface InfoRowProps {
label: string
value?: string | null
isLink?: boolean
}
interface SectionProps {
title: string
children: React.ReactNode
}
interface PassportImageProps {
label: string
src?: string | null
}
interface AuditRowProps {
id: string
action: string
by: string
target: string
status: string
date: string
}
// ─── InfoRow ─────────────────────────────────────────────────────────────────
function InfoRow({ label, value, isLink }: InfoRowProps) {
return (
<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">{label}</span>
{value ? (
<span className={`text-sm ${isLink ? 'text-primary font-medium' : 'text-foreground'}`}>
{value}
</span>
) : (
<span className="text-muted-foreground/40 text-sm">—</span>
)}
</div>
)
}
// ─── Section ─────────────────────────────────────────────────────────────────
function Section({ title, children }: SectionProps) {
return (
<div className="mb-6">
<h2 className="text-base font-semibold text-foreground mb-2">{title}</h2>
<div className="bg-card border border-border rounded-xl overflow-hidden">{children}</div>
</div>
)
}
// ─── PassportImage ────────────────────────────────────────────────────────────
function PassportImage({ label, src }: PassportImageProps) {
const { t } = useTranslation()
return (
<div className="grid grid-cols-[220px_1fr] items-start py-3 px-4 border-b border-border last:border-0">
<span className="text-sm text-muted-foreground pt-1">{label}</span>
<div className="flex flex-col gap-2">
{src ? (
<img
src={src}
alt={label}
className="w-28 h-20 object-cover rounded-md border border-border"
/>
) : (
<div className="w-28 h-20 bg-muted rounded-md border border-border flex items-center justify-center">
<span className="text-xs text-muted-foreground">—</span>
</div>
)}
<button className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit">
<Download size={12} />
{t('common.download', 'Göçürip al')}
</button>
</div>
</div>
)
}
// ─── AuditRow ─────────────────────────────────────────────────────────────────
function AuditRow({ id, action, by, target, status, date }: AuditRowProps) {
return (
<tr className="border-b border-border last:border-0 hover:bg-muted/30 transition-colors">
<td className="px-4 py-2.5 text-xs font-mono text-primary">{id}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{action}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{by}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{target}</td>
<td className="px-4 py-2.5">
<span className="inline-flex items-center gap-1.5 text-xs font-medium text-emerald-400 bg-emerald-400/10 border border-emerald-400/30 px-2 py-0.5 rounded-full">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-400" />
{status}
</span>
</td>
<td className="px-4 py-2.5 text-xs text-muted-foreground whitespace-nowrap">{date}</td>
<td className="px-4 py-2.5">
<button className="p-1 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors">
<Eye size={13} />
</button>
</td>
</tr>
)
}
// ─── Skeleton ─────────────────────────────────────────────────────────────────
function LoanOrderMobilesViewSkeleton() {
return (
<div className="flex flex-col gap-4">
<Skeleton className="h-7 w-64" />
{[...Array(5)].map((_, i) => (
<div key={i} className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3">
<Skeleton className="h-4 w-32 mb-1" />
{[...Array(3)].map((_, j) => (
<Skeleton key={j} className="h-4 w-full" />
))}
</div>
))}
</div>
)
}
// ─── Page ─────────────────────────────────────────────────────────────────────
export default function LoanOrderMobilesViewPage() {
const { t } = useTranslation()
const navigate = useNavigate()
const { id } = useParams<{ id: string }>()
const deleteMutation = useDeleteLoanOrderMobile()
const { data: order, isLoading } = useLoanOrderMobileById(id!)
const handleDelete = () => {
if (!window.confirm(t('loanOrderMobiles.deleteConfirm', 'Bu sargyt pozulsynmy?'))) return
deleteMutation.mutate(id!, {
onSuccess: () => {
toast.success(t('loanOrderMobiles.deleteSuccess', 'Sargyt pozuldy'))
navigate('/loan-order-mobiles')
},
onError: () => {
toast.error(t('loanOrderMobiles.deleteError', 'Pozma wagty ýalňyşlyk ýüze çykdy'))
},
})
}
if (isLoading) return <LoanOrderMobilesViewSkeleton />
if (!order) {
return (
<div className="flex items-center justify-center h-64 text-muted-foreground text-sm">
{t('common.notFound', 'Tapylmady')}
</div>
)
}
// Replace with real audit data from API when available
const auditLogs: AuditRowProps[] = [
{
id: '44548',
action: t('audit.actions.view', 'Görmek'),
by: order.createdBy ?? '',
target: `${t('loanOrderMobiles.title', 'Karz sargyt')}: ${order.id}`,
status: 'FINISHED',
date: order.createdAt ?? '',
},
]
return (
<div className="flex flex-col">
{/* Page Header */}
<div className="flex items-center justify-between mb-5">
<h1 className="text-xl font-semibold text-foreground">
{t('loanOrderMobiles.view.title', 'Karz sargyt giriş')}: {order.id}
</h1>
<div className="flex items-center gap-1.5">
<button
onClick={handleDelete}
disabled={deleteMutation.isPending}
className="p-2 rounded-md cursor-pointer hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
title={t('common.delete', 'Poz')}
>
<Trash2 size={16} />
</button>
<button
onClick={() => navigate(`/loan-order-mobiles/${order.id}/edit`)}
className="p-2 rounded-md cursor-pointer hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.edit', 'Redaktirle')}
>
<Pencil size={16} />
</button>
</div>
</div>
{/* ── Basic Info ─────────────────────────────────────────────────────── */}
<div className="bg-card border border-border rounded-xl overflow-hidden mb-6">
<InfoRow label="ID" value={order.id} />
{/* Status row — special render */}
<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('loanOrders.columns.status', 'Status')}
</span>
<LoanOrderStatusBadge status={order.status} />
</div>
<InfoRow
label={t('loanOrders.columns.createdAt', 'Döredilen wagty')}
value={order.createdAt}
/>
<InfoRow label={t('loanOrders.columns.branch', 'Şahamça')} value={order.branch} isLink />
<InfoRow label={t('loanOrders.fields.note', 'Bellik')} value={order.note || '-'} />
</div>
{/* ── Card ───────────────────────────────────────────────────────────── */}
{(order.cardNumber || order.cardName) && (
<Section title={t('loanOrders.sections.card', 'Kart')}>
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-b border-border flex items-center justify-center">
<CreditCardVisual
cardNumber={order.cardNumber}
cardName={order.cardName}
expMonth={order.cardExpMonth}
expYear={order.cardExpYear}
variant="primary"
/>
</div>
<InfoRow label={t('loanOrders.fields.cardNumber', 'Kart belgisi')} value={order.cardNumber} />
<InfoRow label={t('loanOrders.fields.cardName', 'Kartdaky ady')} value={order.cardName} />
</Section>
)}
{/* ── Loan ───────────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.loan', 'Karz')}>
<InfoRow
label={t('loanOrders.columns.loanType', 'Karz görnüşi')}
value={order.loanType}
isLink
/>
<InfoRow
label={t('loanOrders.fields.loanAmount', 'Karz möçberi')}
value={order.loanAmount ? String(order.loanAmount) : undefined}
/>
</Section>
{/* ── Location ───────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.location', 'Lokasiýa')}>
<InfoRow label={t('loanOrders.columns.region', 'Welaýat')} value={order.region} />
</Section>
{/* ── Personal Info ──────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.personal', 'Şahsy maglumatlar')}>
<InfoRow
label={t('loanOrders.fields.fullName', 'Doly ady')}
value={`${order.firstName} ${order.lastName} ${order.patronicName || ''}`.trim()}
/>
<InfoRow
label={t('loanOrders.fields.education', 'Bilimi')}
value={order.education ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.maritalStatus', 'Maşgala ýagdaýy')}
value={order.marriageStatus ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.birthDate', 'Doglan güni')}
value={order.dateOfBirth ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.registeredAddress', 'Ýazgy edilen salgyňyz')}
value={order.residence ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.currentAddress', 'Häzirki ýaşaýyş ýeri')}
value={order.currentResidence ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.loanHistory', 'Karz taryhy')}
value={order.loanHistory ?? undefined}
isLink
/>
</Section>
{/* ── Contacts ───────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.contacts', 'Habarlaşmak üçin maglumatlar')}>
<InfoRow
label={t('loanOrders.fields.email', 'E-poçta')}
value={order.email ?? undefined}
/>
<InfoRow label={t('loanOrders.columns.phone', 'Telefon')} value={order.phone} />
<InfoRow
label={t('loanOrders.fields.phoneAlt', 'Telefon goşmaça')}
value={order.phoneAdditional ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.homePhone', 'Öý telefony')}
value={order.homePhone ?? undefined}
/>
</Section>
{/* ── Employment ─────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.employment', 'Iş')}>
<InfoRow
label={t('loanOrders.fields.employer', 'Işleýän edaranyň/kärhananyn ady')}
value={order.workCompany ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.deptPhone', 'Işgärler bölüminiň iş belgisi')}
value={order.workHrPhone ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.workRegion', 'Işleýän welaýatyňyz')}
value={order.workRegion ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.workCity', 'Işleýän etrabyňyz')}
value={order.workProvince ?? undefined}
isLink
/>
<InfoRow
label={t('loanOrders.fields.position', 'Wezipe')}
value={order.position ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.salary', 'Zähmet haky')}
value={order.salary ? String(order.salary) : undefined}
/>
<InfoRow
label={t('loanOrders.fields.employedSince', 'Işe başlan wagtyňyz')}
value={order.workStartedAt ?? undefined}
/>
</Section>
{/* ── Passport ───────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.passport', 'Pasport')}>
<InfoRow
label={t('loanOrders.fields.passportNumber', 'Pasport')}
value={order.passportNumber ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.passportIssuedBy', 'Kim tarapyndan berildi')}
value={order.passportGivenBy ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.passportBirthPlace', 'Doglan ýeri (pasport)')}
value={order.bornPlace ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage1', 'Pasport (sahypa 1)')}
src={order.passportPage1Url ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage23', 'Pasport (2-3-nji sahypa)')}
src={order.passportPage23Url ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage89', 'Pasport (8-9 sahypa)')}
src={order.passportPage89Url ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage32', 'Pasport (32-nji sahypa)')}
src={order.passportPage32Url ?? undefined}
/>
</Section>
{/* ── Guarantor ──────────────────────────────────────────────────────── */}
{(order.guarantor1Name || order.guarantor1CardNumber) && (
<Section title={t('loanOrders.sections.guarantor', '1. Zamun')}>
<InfoRow
label={t('loanOrders.fields.guarantorName', 'Zamunyň doly ady')}
value={`${order.guarantor1Name || ''} ${order.guarantor1Surname || ''} ${order.guarantor1Patronic || ''}`.trim()}
/>
<InfoRow
label={t('loanOrders.fields.guarantorPassport', 'Pasport')}
value={`${order.guarantor1PassportSerie || ''} ${order.guarantor1PassportNumber || ''}`.trim()}
/>
<InfoRow
label={t('loanOrders.fields.guarantorSalary', 'Ortaca zähmet haky')}
value={order.guarantor1Salary ? String(order.guarantor1Salary) : undefined}
/>
{order.guarantor1CardNumber && (
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-t border-border flex items-center justify-center">
<CreditCardVisual
cardNumber={order.guarantor1CardNumber}
cardName={order.guarantor1CardName}
expMonth={order.guarantor1CardExpMonth}
expYear={order.guarantor1CardExpYear}
variant="secondary"
/>
</div>
)}
</Section>
)}
{/* ── Audit Log ──────────────────────────────────────────────────────── */}
<div className="mb-6">
<details open>
<summary className="text-base font-semibold text-foreground mb-2 cursor-pointer select-none list-none flex items-center gap-1.5 w-fit">
{t('loanOrders.sections.audit', 'Ammallar')}
<ChevronRight size={15} className="text-muted-foreground" />
</summary>
<div className="bg-card border border-border rounded-xl overflow-hidden mt-2">
<div className="overflow-x-auto">
<table className="w-full text-sm">
<thead>
<tr className="border-b border-border bg-muted/30">
{[
'ID',
t('audit.columns.action', 'AMALYŇ ADY'),
t('audit.columns.by', 'KIM TARAPYNDAN'),
t('audit.columns.target', 'AMALYŇ NYŞANY (TARIBESI)'),
t('audit.columns.status', 'AMALYŇ STATUSY'),
t('audit.columns.date', 'SENE'),
'',
].map((col, i) => (
<th
key={i}
className="px-4 py-2.5 text-left text-xs font-medium text-muted-foreground uppercase tracking-wide whitespace-nowrap"
>
{col}
</th>
))}
</tr>
</thead>
<tbody>
{auditLogs.map((log) => (
<AuditRow key={log.id} {...log} />
))}
</tbody>
</table>
</div>
<div className="flex items-center justify-between px-4 py-2.5 border-t border-border text-xs text-muted-foreground">
<span>{t('common.prev', 'Öňki')}</span>
<span>1–{auditLogs.length} / {auditLogs.length}</span>
<span>{t('common.next', 'Soňky')}</span>
</div>
</div>
</details>
</div>
</div>
)
}
+3 -3
View File
@@ -219,7 +219,7 @@ export default function LoanOrderViewPage() {
</div>
<InfoRow
label={t('loanOrders.fields.amount', 'Berlik')}
value={order.amount ?? undefined}
value={order.amount ? String(order.amount) : undefined}
/>
<InfoRow
label={t('loanOrders.fields.createdBy', 'Sargyt eden')}
@@ -237,7 +237,7 @@ export default function LoanOrderViewPage() {
/>
<InfoRow
label={t('loanOrders.fields.loanAmount', 'Karz mukdary')}
value={order.loanAmount ?? undefined}
value={order.loanAmount ? String(order.loanAmount) : undefined}
/>
</Section>
@@ -321,7 +321,7 @@ export default function LoanOrderViewPage() {
/>
<InfoRow
label={t('loanOrders.fields.salary', 'Zähmet haky')}
value={order.salary ?? undefined}
value={order.salary ? String(order.salary) : undefined}
/>
<InfoRow
label={t('loanOrders.fields.employedSince', 'Işe başlan wagtyňyz')}
+5 -1
View File
@@ -1,4 +1,5 @@
import { useState, useMemo, useCallback } from 'react'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Eye, Pencil, Trash2 } from 'lucide-react'
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
@@ -16,6 +17,7 @@ const COLUMN_IDS = ['id', 'passportSeries', 'passportNumber', 'loanAccount'] as
export default function LoanRemainingPage() {
const { t } = useTranslation()
const navigate = useNavigate()
const deleteMutation = useDeleteLoanRemaining()
// ── State ──────────────────────────────────────────────────────────────────
@@ -99,12 +101,14 @@ export default function LoanRemainingPage() {
cell: ({ row }) => (
<div className="flex items-center gap-1.5 justify-end">
<button
onClick={() => navigate(`/loan-remaining/${row.original.id}`)}
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.view', 'Görmek')}
>
<Eye size={15} />
</button>
<button
onClick={() => navigate(`/loan-remaining/${row.original.id}/edit`)}
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.edit', 'Üýtgetmek')}
>
@@ -164,7 +168,7 @@ export default function LoanRemainingPage() {
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
actionLabel={t('loanRemaining.createButton', 'Karzyň galyndysy dörediň')}
onAction={() => {
// navigate to create page or open modal
navigate('/loan-remaining/create')
}}
/>
+18
View File
@@ -0,0 +1,18 @@
import { useTranslation } from 'react-i18next'
import { LoanRemainingForm } from '@/features/loanRemaining/components/LoanRemainingForm'
export default function LoanRemainingCreatePage() {
const { t } = useTranslation()
return (
<div className="flex flex-col gap-6">
<div className="flex items-center justify-between">
<h1 className="text-xl font-semibold text-foreground">
{t('loanRemaining.create.title', 'Täze karz galyndysy')}
</h1>
</div>
<LoanRemainingForm mode="create" />
</div>
)
}
+45
View File
@@ -0,0 +1,45 @@
import { useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { LoanRemainingForm } from '@/features/loanRemaining/components/LoanRemainingForm'
import { useLoanRemainingById } from '@/features/loanRemaining/hooks/useLoanRemaining'
import { Skeleton } from '@/components/ui/skeleton'
function LoanRemainingEditSkeleton() {
return (
<div className="flex flex-col gap-6">
<Skeleton className="h-8 w-64" />
<div className="bg-card border border-border rounded-xl p-6 h-[250px]">
<Skeleton className="h-full w-full" />
</div>
</div>
)
}
export default function LoanRemainingEditPage() {
const { t } = useTranslation()
const { id } = useParams<{ id: string }>()
const { data, isLoading } = useLoanRemainingById(id)
if (isLoading) return <LoanRemainingEditSkeleton />
if (!data) {
return (
<div className="flex items-center justify-center h-64 text-muted-foreground">
{t('common.notFound', 'Tapylmady')}
</div>
)
}
return (
<div className="flex flex-col gap-6">
<div className="flex items-center justify-between">
<h1 className="text-xl font-semibold text-foreground">
{t('loanRemaining.edit.title', 'Karz galyndysyny üýtget')}: {data.id}
</h1>
</div>
<LoanRemainingForm mode="edit" initialData={data} loanRemainingId={id} />
</div>
)
}
+140
View File
@@ -0,0 +1,140 @@
import { useNavigate, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Trash2, Pencil } from 'lucide-react'
import { useLoanRemainingById, useDeleteLoanRemaining } from '@/features/loanRemaining/hooks/useLoanRemaining'
import { Skeleton } from '@/components/ui/skeleton'
import { toast } from 'sonner'
// ─── Sub-component Types ──────────────────────────────────────────────────────
interface InfoRowProps {
label: string
value?: string | null
}
interface SectionProps {
title: string
children: React.ReactNode
}
// ─── InfoRow ─────────────────────────────────────────────────────────────────
function InfoRow({ label, value }: InfoRowProps) {
return (
<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">{label}</span>
{value ? (
<span className="text-sm text-foreground">
{value}
</span>
) : (
<span className="text-muted-foreground/40 text-sm">—</span>
)}
</div>
)
}
// ─── Section ─────────────────────────────────────────────────────────────────
function Section({ title, children }: SectionProps) {
return (
<div className="mb-6">
<h2 className="text-base font-semibold text-foreground mb-2">{title}</h2>
<div className="bg-card border border-border rounded-xl overflow-hidden">{children}</div>
</div>
)
}
// ─── Skeleton ─────────────────────────────────────────────────────────────────
function LoanRemainingViewSkeleton() {
return (
<div className="flex flex-col gap-4">
<Skeleton className="h-7 w-64" />
<div className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3">
{[...Array(4)].map((_, j) => (
<Skeleton key={j} className="h-4 w-full" />
))}
</div>
</div>
)
}
// ─── Page ─────────────────────────────────────────────────────────────────────
export default function LoanRemainingViewPage() {
const { t } = useTranslation()
const navigate = useNavigate()
const { id } = useParams<{ id: string }>()
const deleteMutation = useDeleteLoanRemaining()
const { data: record, isLoading } = useLoanRemainingById(id!)
const handleDelete = () => {
if (!window.confirm(t('loanRemaining.deleteConfirm', 'Bu ýazgy pozulsynmy?'))) return
deleteMutation.mutate(Number(id!), {
onSuccess: () => {
toast.success(t('loanRemaining.deleteSuccess', 'Ýazgy üstünlikli pozuldy'))
navigate('/loan-remaining')
},
onError: () => {
toast.error(t('loanRemaining.deleteError', 'Pozmak başartmady, gaýtadan synanyşyň'))
},
})
}
if (isLoading) return <LoanRemainingViewSkeleton />
if (!record) {
return (
<div className="flex items-center justify-center h-64 text-muted-foreground text-sm">
{t('common.notFound', 'Tapylmady')}
</div>
)
}
return (
<div className="flex flex-col">
{/* Page Header */}
<div className="flex items-center justify-between mb-5">
<h1 className="text-xl font-semibold text-foreground">
{t('loanRemaining.view.title', 'Karz galyndysy maglumaty')}: {record.id}
</h1>
<div className="flex items-center gap-1.5">
<button
onClick={handleDelete}
disabled={deleteMutation.isPending}
className="p-2 rounded-md cursor-pointer hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
title={t('common.delete', 'Poz')}
>
<Trash2 size={16} />
</button>
<button
onClick={() => navigate(`/loan-remaining/${record.id}/edit`)}
className="p-2 rounded-md cursor-pointer hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.edit', 'Redaktirle')}
>
<Pencil size={16} />
</button>
</div>
</div>
{/* ── Basic Info ─────────────────────────────────────────────────────── */}
<Section title={t('loanRemaining.sections.info', 'Esasy maglumatlar')}>
<InfoRow label="ID" value={String(record.id)} />
<InfoRow
label={t('loanRemaining.columns.passportSeries', 'Pasport seriýasy')}
value={record.passportSeries}
/>
<InfoRow
label={t('loanRemaining.columns.passportNumber', 'Pasport belgisi')}
value={record.passportNumber}
/>
<InfoRow
label={t('loanRemaining.columns.loanAccount', 'Karz hasaby')}
value={record.loanAccount}
/>
</Section>
</div>
)
}