added loan remaing pages
This commit is contained in:
@@ -7,11 +7,9 @@ Bu doküman, projenin büyümesiyle yapının bozulmaması ve projede çalışac
|
||||
- **State Management:** `zustand`
|
||||
- **Path:** `src/app/store/` (Örn: `authStore.ts`, `themeStore.ts`, `i18nStore.ts`)
|
||||
- Sadece global state (kullanıcı oturumu, tema, dil vb.) için kullanılmalıdır. Component içi basit stateler için `useState` kullanın.
|
||||
|
||||
- **Data Fetching & Caching:** `@tanstack/react-query`
|
||||
- **Path:** `src/features/[feature-name]/hooks/` (Örn: `src/features/auth/hooks/useLogin.ts`)
|
||||
- Bütün API istekleri custom hook'lar içerisine sarmalanmalı ve doğrudan component içinde `useQuery` veya `useMutation` yazılmamalıdır.
|
||||
|
||||
- **HTTP Client:** `axios`
|
||||
- **Path:** `src/lib/api/client.ts`
|
||||
- Tüm istekler merkezi axios instance'ı üzerinden yapılmalıdır. Interceptor'lar (token ekleme, hata yakalama vb.) bu dosyada yönetilir.
|
||||
@@ -52,6 +50,7 @@ Bu doküman, projenin büyümesiyle yapının bozulmaması ve projede çalışac
|
||||
- İsimlendirmeler açıklayıcı olmalı (Örn: `handleData` yerine `submitLoginForm`).
|
||||
|
||||
## 4. Dosya Yapısı Özeti
|
||||
|
||||
```text
|
||||
src/
|
||||
├── app/ # Global provider'lar, store'lar ve router konfigürasyonları
|
||||
@@ -69,6 +68,7 @@ src/
|
||||
```
|
||||
|
||||
## AI / Agent İçin Katı Talimatlar (System Instructions)
|
||||
|
||||
1. Yeni bir bileşen veya özellik ekleneceğinde her zaman önce `src/features/` altına eklenip eklenmeyeceğini değerlendir.
|
||||
2. UI bileşeni oluştururken önce `src/components/ui/` dizininde mevcut bir yapı olup olmadığını kontrol et.
|
||||
3. Asla `any` tipi tanımlama. TypeScript hatalarını doğru tipler (interface/type) yazarak çöz.
|
||||
@@ -92,4 +92,5 @@ src/
|
||||
[feature]Api.ts ← payload tipleri burada tanımlanır
|
||||
pages/
|
||||
[Feature]CreatePage.tsx ← <[Feature]Form mode="create" />
|
||||
[Feature]EditPage.tsx ← id fetch → <[Feature]Form mode="edit" initialData={data} loanOrderId={id} />
|
||||
[Feature]EditPage.tsx ← id fetch → <[Feature]Form mode="edit" initialData={data} loanOrderId={id} />
|
||||
```
|
||||
|
||||
@@ -8,11 +8,17 @@ import LoanOrderEditPage from "@/pages/loanOrderEdit";
|
||||
const LoginPage = lazy(() => import("@/pages/login"));
|
||||
const DashboardPage = lazy(() => import("@/pages/dashboard"));
|
||||
const LoanOrdersPage = lazy(() => import("@/pages/loanOrders"));
|
||||
const LoanOrderMobilesPage = lazy(() => import("@/pages/loanOrderMobiles"));
|
||||
const LoanOrderMobilesPage = lazy(() => import("@/pages/loanOrderMobile"));
|
||||
const LoanRemainingPage = lazy(() => import("@/pages/loanRemaining"));
|
||||
const LoanRemainingCreatePage = lazy(() => import("@/pages/loanRemainingCreate"));
|
||||
const LoanRemainingViewPage = lazy(() => import("@/pages/loanRemainingView"));
|
||||
const LoanRemainingEditPage = lazy(() => import("@/pages/loanRemainingEdit"));
|
||||
const LoanPaidOffLettersPage = lazy(() => import("@/pages/loanPaidOffLetters"));
|
||||
const LoanOrderCreatePage = lazy(() => import("@/pages/loanOrderCreate"));
|
||||
const LoanOrderViewPage = lazy(() => import("@/pages/loanOrderView"));
|
||||
const LoanOrderMobileViewPage = lazy(() => import("@/pages/loanOrderMobileView"));
|
||||
const LoanOrderMobileEditPage = lazy(() => import("@/pages/loanOrderMobileEdit"));
|
||||
const LoanOrderMobileCreatePage = lazy(() => import("@/pages/loanOrderMobileCreate"));
|
||||
|
||||
function AuthGuard() {
|
||||
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
||||
@@ -81,7 +87,6 @@ export const router = createBrowserRouter([
|
||||
<LoanOrderViewPage />
|
||||
</Suspense>
|
||||
),
|
||||
|
||||
},
|
||||
{
|
||||
path: "/loan-orders/create",
|
||||
@@ -108,6 +113,30 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/loan-order-mobiles/:id",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoanOrderMobileViewPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/loan-order-mobiles/create",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoanOrderMobileCreatePage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/loan-order-mobiles/:id/edit",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoanOrderMobileEditPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
// Sidebar: /loan-remaining
|
||||
path: "/loan-remaining",
|
||||
@@ -117,6 +146,30 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/loan-remaining/create",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoanRemainingCreatePage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/loan-remaining/:id",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoanRemainingViewPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/loan-remaining/:id/edit",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoanRemainingEditPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
// Sidebar: /loan-paid-off-letters
|
||||
path: "/loan-paid-off-letters",
|
||||
|
||||
85
src/components/creditCardVisual.tsx
Normal file
85
src/components/creditCardVisual.tsx
Normal file
@@ -0,0 +1,85 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
interface CreditCardVisualProps {
|
||||
cardNumber?: string | null
|
||||
cardName?: string | null
|
||||
expMonth?: string | null
|
||||
expYear?: string | null
|
||||
variant?: 'primary' | 'secondary'
|
||||
}
|
||||
|
||||
export function CreditCardVisual({
|
||||
cardNumber,
|
||||
cardName,
|
||||
expMonth,
|
||||
expYear,
|
||||
variant = 'primary',
|
||||
}: CreditCardVisualProps) {
|
||||
const { t } = useTranslation()
|
||||
|
||||
// Format the card number to add spaces (e.g., 9934 0019 1234 5678)
|
||||
const formatCardNumber = (num?: string | null) => {
|
||||
if (!num) return '**** **** **** ****'
|
||||
const cleaned = num.replace(/\D/g, '')
|
||||
const match = cleaned.match(/.{1,4}/g)
|
||||
return match ? match.join(' ') : cleaned
|
||||
}
|
||||
|
||||
const bgGradient =
|
||||
variant === 'primary'
|
||||
? 'bg-gradient-to-tr from-slate-900 via-slate-800 to-slate-700'
|
||||
: 'bg-gradient-to-tr from-blue-950 via-indigo-900 to-slate-900'
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${bgGradient} w-full max-w-[340px] h-[210px] rounded-2xl p-6 flex flex-col justify-between text-white shadow-xl relative overflow-hidden`}
|
||||
>
|
||||
{/* Glow effects */}
|
||||
<div className="absolute -top-16 -right-16 w-32 h-32 bg-white/10 rounded-full blur-2xl pointer-events-none"></div>
|
||||
<div className="absolute -bottom-16 -left-16 w-32 h-32 bg-blue-500/10 rounded-full blur-2xl pointer-events-none"></div>
|
||||
|
||||
{/* Top row: Chip and Logo/Bank Name */}
|
||||
<div className="flex justify-between items-center z-10">
|
||||
<div className="w-12 h-9 rounded bg-gradient-to-br from-yellow-200 to-yellow-500 flex items-center justify-center opacity-90 overflow-hidden relative">
|
||||
{/* Chip lines */}
|
||||
<div className="absolute w-full h-full border border-yellow-700/30 rounded"></div>
|
||||
<div className="w-[1px] h-full bg-yellow-700/20 absolute left-3"></div>
|
||||
<div className="w-[1px] h-full bg-yellow-700/20 absolute right-3"></div>
|
||||
<div className="w-full h-[1px] bg-yellow-700/20 absolute top-4"></div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<span className="text-sm font-semibold tracking-wider opacity-80">
|
||||
{t('Altyn Asyr') || 'ALTYN ASYR'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Middle row: Card Number */}
|
||||
<div className="z-10 mt-6">
|
||||
<div className="font-mono text-2xl tracking-widest text-slate-100 drop-shadow-md">
|
||||
{formatCardNumber(cardNumber)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom row: Name and Expiry */}
|
||||
<div className="flex justify-between items-end z-10 mt-4">
|
||||
<div className="flex flex-col uppercase">
|
||||
<span className="text-[10px] text-slate-400 tracking-widest mb-1">
|
||||
{t('Card Holder') || 'KARTDAKY ADY'}
|
||||
</span>
|
||||
<span className="font-medium tracking-wider truncate max-w-[180px]">
|
||||
{cardName || 'MÄHRIBAN TÖLEGLI'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col uppercase items-end">
|
||||
<span className="text-[10px] text-slate-400 tracking-widest mb-1">
|
||||
{t('Valid Thru') || 'MÖHLETI'}
|
||||
</span>
|
||||
<span className="font-medium tracking-wider">
|
||||
{expMonth || '00'}/{expYear ? expYear.slice(-2) : '00'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
1164
src/components/loanOrderMobileForm.tsx
Normal file
1164
src/components/loanOrderMobileForm.tsx
Normal file
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,114 @@ export interface LoanOrderMobile {
|
||||
lastName: string
|
||||
phone: string
|
||||
status: LoanOrderMobileStatus
|
||||
createdBy?: string
|
||||
|
||||
// ── Detail fields ─────────────────────────────────────────────────────────
|
||||
patronicName?: string | null
|
||||
education?: string | null
|
||||
marriageStatus?: string | null
|
||||
dateOfBirth?: string | null
|
||||
residence?: string | null
|
||||
currentResidence?: string | null
|
||||
|
||||
// Passport
|
||||
passportSerie?: string | null
|
||||
passportNumber?: string | null
|
||||
passportDateOfIssue?: string | null
|
||||
passportGivenBy?: string | null
|
||||
bornPlace?: string | null
|
||||
passportPage1Url?: string | null
|
||||
passportPage23Url?: string | null
|
||||
passportPage89Url?: string | null
|
||||
passportPage32Url?: string | null
|
||||
|
||||
// Contact
|
||||
email?: string | null
|
||||
phoneAdditional?: string | null
|
||||
homePhone?: string | null
|
||||
|
||||
// Employment
|
||||
workCompany?: string | null
|
||||
workHrPhone?: string | null
|
||||
workRegion?: string | null
|
||||
workProvince?: string | null
|
||||
position?: string | null
|
||||
salary?: number | null
|
||||
workStartedAt?: string | null
|
||||
|
||||
// New fields
|
||||
note?: string | null
|
||||
loanAmount?: number | null
|
||||
loanHistory?: string | null
|
||||
|
||||
// Card (Zähmet haky)
|
||||
cardNumber?: string | null
|
||||
cardName?: string | null
|
||||
cardExpMonth?: string | null
|
||||
cardExpYear?: string | null
|
||||
|
||||
// Guarantor (Zamun)
|
||||
guarantor1Name?: string | null
|
||||
guarantor1Surname?: string | null
|
||||
guarantor1Patronic?: string | null
|
||||
guarantor1PassportSerie?: string | null
|
||||
guarantor1PassportNumber?: string | null
|
||||
guarantor1CardNumber?: string | null
|
||||
guarantor1CardName?: string | null
|
||||
guarantor1CardExpMonth?: string | null
|
||||
guarantor1CardExpYear?: string | null
|
||||
guarantor1Salary?: number | null
|
||||
}
|
||||
|
||||
export interface LoanOrderMobilePayload {
|
||||
status: string
|
||||
loanType: string
|
||||
region: string
|
||||
branch: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
patronicName?: string
|
||||
education: string
|
||||
marriageStatus: string
|
||||
dateOfBirth: string
|
||||
residence: string
|
||||
currentResidence?: string
|
||||
passportSerie: string
|
||||
passportNumber: string
|
||||
passportDateOfIssue: string
|
||||
passportGivenBy: string
|
||||
bornPlace?: string
|
||||
email?: string
|
||||
phone: string
|
||||
phoneAdditional?: string
|
||||
homePhone?: string
|
||||
workCompany: string
|
||||
workHrPhone?: string
|
||||
workRegion?: string
|
||||
workProvince?: string
|
||||
position: string
|
||||
salary: number
|
||||
workStartedAt: string
|
||||
|
||||
note?: string
|
||||
loanAmount?: number
|
||||
loanHistory?: string
|
||||
|
||||
cardNumber?: string
|
||||
cardName?: string
|
||||
cardExpMonth?: string
|
||||
cardExpYear?: string
|
||||
|
||||
guarantor1Name?: string
|
||||
guarantor1Surname?: string
|
||||
guarantor1Patronic?: string
|
||||
guarantor1PassportSerie?: string
|
||||
guarantor1PassportNumber?: string
|
||||
guarantor1CardNumber?: string
|
||||
guarantor1CardName?: string
|
||||
guarantor1CardExpMonth?: string
|
||||
guarantor1CardExpYear?: string
|
||||
guarantor1Salary?: number
|
||||
}
|
||||
|
||||
export interface LoanOrderMobileListParams {
|
||||
@@ -102,4 +210,45 @@ export async function deleteLoanOrderMobile(id: string): Promise<void> {
|
||||
return
|
||||
}
|
||||
await apiClient.delete(`/loan-order-mobiles/${id}`)
|
||||
}
|
||||
|
||||
export async function getLoanOrderMobileById(id: string): Promise<LoanOrderMobile> {
|
||||
if (USE_MOCK) {
|
||||
const order = MOCK_DATA.find((r) => r.id === id)
|
||||
if (!order) throw new Error('Not found')
|
||||
return order
|
||||
}
|
||||
const { data } = await apiClient.get<LoanOrderMobile>(`/loan-order-mobiles/${id}`)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function createLoanOrderMobile(
|
||||
payload: LoanOrderMobilePayload
|
||||
): Promise<LoanOrderMobile> {
|
||||
if (USE_MOCK) {
|
||||
const newOrder: LoanOrderMobile = {
|
||||
...payload,
|
||||
id: `LOM-${String(MOCK_DATA.length + 1).padStart(4, '0')}`,
|
||||
createdAt: new Date().toISOString().slice(0, 16).replace('T', ' '),
|
||||
status: payload.status as LoanOrderMobileStatus,
|
||||
}
|
||||
MOCK_DATA.unshift(newOrder)
|
||||
return newOrder
|
||||
}
|
||||
const { data } = await apiClient.post<LoanOrderMobile>('/loan-order-mobiles', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function updateLoanOrderMobile(
|
||||
id: string,
|
||||
payload: Partial<LoanOrderMobilePayload>
|
||||
): Promise<LoanOrderMobile> {
|
||||
if (USE_MOCK) {
|
||||
const idx = MOCK_DATA.findIndex((r) => r.id === id)
|
||||
if (idx === -1) throw new Error('Not found')
|
||||
MOCK_DATA[idx] = { ...MOCK_DATA[idx], ...payload } as LoanOrderMobile
|
||||
return MOCK_DATA[idx]
|
||||
}
|
||||
const { data } = await apiClient.put<LoanOrderMobile>(`/loan-order-mobiles/${id}`, payload)
|
||||
return data
|
||||
}
|
||||
@@ -120,6 +120,27 @@ interface FormState {
|
||||
passportPage23: File | null
|
||||
passportPage89: File | null
|
||||
passportPage32: File | null
|
||||
|
||||
// New fields
|
||||
note: string
|
||||
loanAmount: string
|
||||
loanHistory: string
|
||||
|
||||
cardNumber: string
|
||||
cardName: string
|
||||
cardExpMonth: string
|
||||
cardExpYear: string
|
||||
|
||||
guarantor1Name: string
|
||||
guarantor1Surname: string
|
||||
guarantor1Patronic: string
|
||||
guarantor1PassportSerie: string
|
||||
guarantor1PassportNumber: string
|
||||
guarantor1CardNumber: string
|
||||
guarantor1CardName: string
|
||||
guarantor1CardExpMonth: string
|
||||
guarantor1CardExpYear: string
|
||||
guarantor1Salary: string
|
||||
}
|
||||
|
||||
type FormErrors = Partial<Record<keyof FormState, string>>
|
||||
@@ -157,6 +178,26 @@ const INITIAL_STATE: FormState = {
|
||||
passportPage23: null,
|
||||
passportPage89: null,
|
||||
passportPage32: null,
|
||||
|
||||
note: '',
|
||||
loanAmount: '',
|
||||
loanHistory: '',
|
||||
|
||||
cardNumber: '',
|
||||
cardName: '',
|
||||
cardExpMonth: '',
|
||||
cardExpYear: '',
|
||||
|
||||
guarantor1Name: '',
|
||||
guarantor1Surname: '',
|
||||
guarantor1Patronic: '',
|
||||
guarantor1PassportSerie: '',
|
||||
guarantor1PassportNumber: '',
|
||||
guarantor1CardNumber: '',
|
||||
guarantor1CardName: '',
|
||||
guarantor1CardExpMonth: '',
|
||||
guarantor1CardExpYear: '',
|
||||
guarantor1Salary: '',
|
||||
}
|
||||
|
||||
// ─── Map LoanOrder → FormState (edit modunda başlangıç değerleri) ─────────────
|
||||
@@ -196,6 +237,26 @@ function mapToFormState(order: LoanOrder): FormState {
|
||||
passportPage23: null,
|
||||
passportPage89: null,
|
||||
passportPage32: null,
|
||||
|
||||
note: order.note ?? '',
|
||||
loanAmount: order.loanAmount != null ? String(order.loanAmount) : '',
|
||||
loanHistory: order.loanHistory ?? '',
|
||||
|
||||
cardNumber: order.cardNumber ?? '',
|
||||
cardName: order.cardName ?? '',
|
||||
cardExpMonth: order.cardExpMonth ?? '',
|
||||
cardExpYear: order.cardExpYear ?? '',
|
||||
|
||||
guarantor1Name: order.guarantor1Name ?? '',
|
||||
guarantor1Surname: order.guarantor1Surname ?? '',
|
||||
guarantor1Patronic: order.guarantor1Patronic ?? '',
|
||||
guarantor1PassportSerie: order.guarantor1PassportSerie ?? '',
|
||||
guarantor1PassportNumber: order.guarantor1PassportNumber ?? '',
|
||||
guarantor1CardNumber: order.guarantor1CardNumber ?? '',
|
||||
guarantor1CardName: order.guarantor1CardName ?? '',
|
||||
guarantor1CardExpMonth: order.guarantor1CardExpMonth ?? '',
|
||||
guarantor1CardExpYear: order.guarantor1CardExpYear ?? '',
|
||||
guarantor1Salary: order.guarantor1Salary != null ? String(order.guarantor1Salary) : '',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +295,22 @@ function validate(
|
||||
req('salary', t('Salary') || 'Zähmet haky')
|
||||
req('workStartedAt', t('Work started at') || 'Işe başlan wagty')
|
||||
|
||||
req('loanAmount', t('Loan amount') || 'Karz möçberi')
|
||||
req('cardNumber', t('Card number') || 'Kart belgisi')
|
||||
req('cardName', t('Card name') || 'Kartdaky ady')
|
||||
req('cardExpMonth', t('Card exp month') || 'Kart Möhleti (aý)')
|
||||
req('cardExpYear', t('Card exp year') || 'Kart Möhleti (ýyl)')
|
||||
|
||||
req('guarantor1Name', t('Guarantor name') || 'Zamunyň ady')
|
||||
req('guarantor1Surname', t('Guarantor surname') || 'Zamunyň familiýasy')
|
||||
req('guarantor1PassportSerie', t('Guarantor passport serie') || 'Pasport seriýasy (Zamun)')
|
||||
req('guarantor1PassportNumber', t('Guarantor passport number') || 'Pasport belgisi (Zamun)')
|
||||
req('guarantor1CardNumber',t('Guarantor card number') || 'Kart belgisi (Zamun)')
|
||||
req('guarantor1CardName', t('Guarantor card name') || 'Kartdaky ady (Zamun)')
|
||||
req('guarantor1CardExpMonth', t('Guarantor card exp month') || 'Möhleti (aý) (Zamun)')
|
||||
req('guarantor1CardExpYear', t('Guarantor card exp year') || 'Möhleti (ýyl) (Zamun)')
|
||||
req('guarantor1Salary', t('Guarantor salary') || 'Ortaca zähmet haky (Zamun)')
|
||||
|
||||
if (form.phone && form.phone.replace(/\D/g, '').length < 8) {
|
||||
errors.phone = 'Telefon belgisi nädogry'
|
||||
}
|
||||
@@ -322,6 +399,23 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
|
||||
position: form.position,
|
||||
salary: Number(form.salary),
|
||||
workStartedAt: form.workStartedAt,
|
||||
note: form.note || undefined,
|
||||
loanAmount: Number(form.loanAmount) || undefined,
|
||||
loanHistory: form.loanHistory || undefined,
|
||||
cardNumber: form.cardNumber || undefined,
|
||||
cardName: form.cardName || undefined,
|
||||
cardExpMonth: form.cardExpMonth || undefined,
|
||||
cardExpYear: form.cardExpYear || undefined,
|
||||
guarantor1Name: form.guarantor1Name || undefined,
|
||||
guarantor1Surname: form.guarantor1Surname || undefined,
|
||||
guarantor1Patronic: form.guarantor1Patronic || undefined,
|
||||
guarantor1PassportSerie: form.guarantor1PassportSerie || undefined,
|
||||
guarantor1PassportNumber: form.guarantor1PassportNumber || undefined,
|
||||
guarantor1CardNumber: form.guarantor1CardNumber || undefined,
|
||||
guarantor1CardName: form.guarantor1CardName || undefined,
|
||||
guarantor1CardExpMonth: form.guarantor1CardExpMonth || undefined,
|
||||
guarantor1CardExpYear: form.guarantor1CardExpYear || undefined,
|
||||
guarantor1Salary: Number(form.guarantor1Salary) || undefined,
|
||||
}
|
||||
|
||||
if (mode === 'create') {
|
||||
@@ -350,8 +444,8 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
|
||||
|
||||
{/* ── Status ─────────────────────────────────────────────────────────── */}
|
||||
<Section title={t('New Loan Order') || 'Täze Karz sargyt'}>
|
||||
<div className={grid2}>
|
||||
<div id="field-status">
|
||||
<div className="flex flex-col gap-6">
|
||||
<div id="field-status" className="max-w-md">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Status') || 'Status'}
|
||||
@@ -363,22 +457,44 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
|
||||
placeholder="Saýlaň"
|
||||
/>
|
||||
</div>
|
||||
<div id="field-note">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Note') || 'Bellik'}
|
||||
value={form.note}
|
||||
onChange={(v) => set('note', v)}
|
||||
placeholder={t('Note') || 'Bellik'}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* ── Loan Type ──────────────────────────────────────────────────────── */}
|
||||
<Section title={t('Loan') || 'Karz'}>
|
||||
<div id="field-loanType">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Loan type') || 'Karz görnüşi'}
|
||||
required
|
||||
value={form.loanType}
|
||||
onChange={(v) => set('loanType', v)}
|
||||
options={LOAN_TYPE_OPTIONS}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.loanType}
|
||||
/>
|
||||
<div className={grid2}>
|
||||
<div id="field-loanType">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Loan type') || 'Karz görnüşi'}
|
||||
required
|
||||
value={form.loanType}
|
||||
onChange={(v) => set('loanType', v)}
|
||||
options={LOAN_TYPE_OPTIONS}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.loanType}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-loanAmount">
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t('Loan amount') || 'Karz möçberi'}
|
||||
required
|
||||
value={form.loanAmount}
|
||||
onChange={(v) => set('loanAmount', v)}
|
||||
placeholder="Karz möçberi"
|
||||
error={errors.loanAmount}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
@@ -508,6 +624,69 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="field-loanHistory" className="max-w-md">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Loan history') || 'Karz taryhy'}
|
||||
value={form.loanHistory}
|
||||
onChange={(v) => set('loanHistory', v)}
|
||||
options={[]}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* ── Card ───────────────────────────────────────────────────────────── */}
|
||||
<Section title={t('Card (Salary)') || 'Kart (Zähmet haky)'}>
|
||||
<div className={grid4}>
|
||||
<div id="field-cardNumber">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Card number') || 'Kart belgisi'}
|
||||
required
|
||||
value={form.cardNumber}
|
||||
onChange={(v) => set('cardNumber', v)}
|
||||
placeholder="Kart belgisi"
|
||||
error={errors.cardNumber}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-cardName">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Card name') || 'Kartdaky ady'}
|
||||
required
|
||||
value={form.cardName}
|
||||
onChange={(v) => set('cardName', v)}
|
||||
placeholder="Kartdaky ady"
|
||||
error={errors.cardName}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-cardExpMonth">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Card exp month') || 'Kart Möhleti (aý)'}
|
||||
required
|
||||
value={form.cardExpMonth}
|
||||
onChange={(v) => set('cardExpMonth', v)}
|
||||
options={Array.from({ length: 12 }, (_, i) => ({ value: String(i + 1).padStart(2, '0'), label: String(i + 1).padStart(2, '0') }))}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.cardExpMonth}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-cardExpYear">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Card exp year') || 'Kart Möhleti (ýyl)'}
|
||||
required
|
||||
value={form.cardExpYear}
|
||||
onChange={(v) => set('cardExpYear', v)}
|
||||
options={Array.from({ length: 15 }, (_, i) => ({ value: String(new Date().getFullYear() + i), label: String(new Date().getFullYear() + i) }))}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.cardExpYear}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
@@ -829,6 +1008,134 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* ── Zamun ──────────────────────────────────────────────────────────── */}
|
||||
<Section title={t('1. Guarantor') || '1. Zamun'}>
|
||||
<div className="flex flex-col gap-6">
|
||||
<div className={grid3}>
|
||||
<div id="field-guarantor1Name">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Guarantor name') || 'Zamunyň ady'}
|
||||
required
|
||||
value={form.guarantor1Name}
|
||||
onChange={(v) => set('guarantor1Name', v)}
|
||||
placeholder="Zamunyň ady"
|
||||
error={errors.guarantor1Name}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-guarantor1Surname">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Guarantor surname') || 'Zamunyň familiýasy'}
|
||||
required
|
||||
value={form.guarantor1Surname}
|
||||
onChange={(v) => set('guarantor1Surname', v)}
|
||||
placeholder="Zamunyň familiýasy"
|
||||
error={errors.guarantor1Surname}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-guarantor1Patronic">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Guarantor patronic') || 'Zamunyň atasynyň ady'}
|
||||
value={form.guarantor1Patronic}
|
||||
onChange={(v) => set('guarantor1Patronic', v)}
|
||||
placeholder="Zamunyň atasynyň ady"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={grid2}>
|
||||
<div id="field-guarantor1PassportSerie">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Passport serie') || 'Pasport seriýasy'}
|
||||
required
|
||||
value={form.guarantor1PassportSerie}
|
||||
onChange={(v) => set('guarantor1PassportSerie', v)}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.guarantor1PassportSerie}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-guarantor1PassportNumber">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Passport number') || 'Pasport belgisi'}
|
||||
required
|
||||
value={form.guarantor1PassportNumber}
|
||||
onChange={(v) => set('guarantor1PassportNumber', v)}
|
||||
placeholder="Pasport belgisi"
|
||||
error={errors.guarantor1PassportNumber}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={grid4}>
|
||||
<div id="field-guarantor1CardNumber">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Card number') || 'Kart belgisi'}
|
||||
required
|
||||
value={form.guarantor1CardNumber}
|
||||
onChange={(v) => set('guarantor1CardNumber', v)}
|
||||
placeholder="Kart belgisi"
|
||||
error={errors.guarantor1CardNumber}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-guarantor1CardName">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Card name') || 'Kartdaky ady'}
|
||||
required
|
||||
value={form.guarantor1CardName}
|
||||
onChange={(v) => set('guarantor1CardName', v)}
|
||||
placeholder="Kartdaky ady"
|
||||
error={errors.guarantor1CardName}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-guarantor1CardExpMonth">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Card exp month') || 'Möhleti (aý)'}
|
||||
required
|
||||
value={form.guarantor1CardExpMonth}
|
||||
onChange={(v) => set('guarantor1CardExpMonth', v)}
|
||||
options={Array.from({ length: 12 }, (_, i) => ({ value: String(i + 1).padStart(2, '0'), label: String(i + 1).padStart(2, '0') }))}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.guarantor1CardExpMonth}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-guarantor1CardExpYear">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Card exp year') || 'Möhleti (ýyl)'}
|
||||
required
|
||||
value={form.guarantor1CardExpYear}
|
||||
onChange={(v) => set('guarantor1CardExpYear', v)}
|
||||
options={Array.from({ length: 15 }, (_, i) => ({ value: String(new Date().getFullYear() + i), label: String(new Date().getFullYear() + i) }))}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.guarantor1CardExpYear}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={grid2}>
|
||||
<div id="field-guarantor1Salary">
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t('Guarantor salary') || 'Ortaca zähmet haky'}
|
||||
required
|
||||
value={form.guarantor1Salary}
|
||||
onChange={(v) => set('guarantor1Salary', v)}
|
||||
placeholder="Ortaca zähmet haky"
|
||||
error={errors.guarantor1Salary}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* ── Footer Actions ─────────────────────────────────────────────────── */}
|
||||
<div className="flex items-center justify-end gap-3 pb-8">
|
||||
<Button
|
||||
@@ -5,7 +5,11 @@ import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
fetchLoanOrderMobiles,
|
||||
deleteLoanOrderMobile,
|
||||
getLoanOrderMobileById,
|
||||
createLoanOrderMobile,
|
||||
updateLoanOrderMobile,
|
||||
type LoanOrderMobileListParams,
|
||||
type LoanOrderMobilePayload,
|
||||
} from '../api/loanOrderMobilesApi'
|
||||
|
||||
// ─── Query keys ────────────────────────────────────────────────────────────────
|
||||
@@ -14,6 +18,8 @@ export const loanOrderMobileKeys = {
|
||||
all: ['loanOrderMobiles'] as const,
|
||||
lists: () => [...loanOrderMobileKeys.all, 'list'] as const,
|
||||
list: (params: LoanOrderMobileListParams) => [...loanOrderMobileKeys.lists(), params] as const,
|
||||
details: () => [...loanOrderMobileKeys.all, 'detail'] as const,
|
||||
detail: (id: string) => [...loanOrderMobileKeys.details(), id] as const,
|
||||
}
|
||||
|
||||
// ─── Hooks ─────────────────────────────────────────────────────────────────────
|
||||
@@ -39,4 +45,46 @@ export function useDeleteLoanOrderMobile() {
|
||||
toast.error(t('loanOrderMobiles.deleteError', 'Pozmak başartmady, gaýtadan synanyşyň'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useLoanOrderMobileById(id: string) {
|
||||
return useQuery({
|
||||
queryKey: loanOrderMobileKeys.detail(id),
|
||||
queryFn: () => getLoanOrderMobileById(id),
|
||||
enabled: !!id,
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateLoanOrderMobile() {
|
||||
const queryClient = useQueryClient()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: LoanOrderMobilePayload) => createLoanOrderMobile(payload),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: loanOrderMobileKeys.lists() })
|
||||
toast.success(t('loanOrderMobiles.createSuccess', 'Sargyt üstünlikli döredildi'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('loanOrderMobiles.createError', 'Sargyt döretmek başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateLoanOrderMobile() {
|
||||
const queryClient = useQueryClient()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ id, payload }: { id: string; payload: Partial<LoanOrderMobilePayload> }) =>
|
||||
updateLoanOrderMobile(id, payload),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: loanOrderMobileKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: loanOrderMobileKeys.detail(variables.id) })
|
||||
toast.success(t('loanOrderMobiles.updateSuccess', 'Sargyt üstünlikli üýtgedildi'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('loanOrderMobiles.updateError', 'Üýtgetmek başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -19,8 +19,11 @@ export interface LoanOrder {
|
||||
lastName: string
|
||||
phone: string
|
||||
status: LoanOrderStatus
|
||||
note?: string | null
|
||||
|
||||
// ── Detail fields ─────────────────────────────────────────────────────────
|
||||
loanAmount?: number | null
|
||||
loanHistory?: string | null
|
||||
patronicName?: string | null
|
||||
education?: string | null
|
||||
marriageStatus?: string | null
|
||||
@@ -52,6 +55,40 @@ export interface LoanOrder {
|
||||
position?: string | null
|
||||
salary?: number | null
|
||||
workStartedAt?: string | null
|
||||
|
||||
// Card (Zähmet haky)
|
||||
cardNumber?: string | null
|
||||
cardName?: string | null
|
||||
cardExpMonth?: string | null
|
||||
cardExpYear?: string | null
|
||||
|
||||
// Guarantor (Zamun)
|
||||
guarantor1Name?: string | null
|
||||
guarantor1Surname?: string | null
|
||||
guarantor1Patronic?: string | null
|
||||
guarantor1PassportSerie?: string | null
|
||||
guarantor1PassportNumber?: string | null
|
||||
guarantor1CardNumber?: string | null
|
||||
guarantor1CardName?: string | null
|
||||
guarantor1CardExpMonth?: string | null
|
||||
guarantor1CardExpYear?: string | null
|
||||
guarantor1Salary?: number | null
|
||||
|
||||
// ── Restored fields from previous version ───────────────────────────────
|
||||
amount?: number | null
|
||||
createdBy?: string | null
|
||||
fullName?: string | null
|
||||
maritalStatus?: string | null
|
||||
birthDate?: string | null
|
||||
registeredAddress?: string | null
|
||||
currentAddress?: string | null
|
||||
phoneAlt?: string | null
|
||||
employer?: string | null
|
||||
deptPhone?: string | null
|
||||
workCity?: string | null
|
||||
employedSince?: string | null
|
||||
passportIssuedBy?: string | null
|
||||
passportBirthPlace?: string | null
|
||||
}
|
||||
|
||||
export interface LoanOrdersParams {
|
||||
@@ -100,6 +137,26 @@ export interface LoanOrderPayload {
|
||||
position: string
|
||||
salary: number
|
||||
workStartedAt: string
|
||||
|
||||
note?: string
|
||||
loanAmount?: number
|
||||
loanHistory?: string
|
||||
|
||||
cardNumber?: string
|
||||
cardName?: string
|
||||
cardExpMonth?: string
|
||||
cardExpYear?: string
|
||||
|
||||
guarantor1Name?: string
|
||||
guarantor1Surname?: string
|
||||
guarantor1Patronic?: string
|
||||
guarantor1PassportSerie?: string
|
||||
guarantor1PassportNumber?: string
|
||||
guarantor1CardNumber?: string
|
||||
guarantor1CardName?: string
|
||||
guarantor1CardExpMonth?: string
|
||||
guarantor1CardExpYear?: string
|
||||
guarantor1Salary?: number
|
||||
}
|
||||
|
||||
// ─── Mock ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -9,6 +9,8 @@ export interface LoanRemaining {
|
||||
loanAccount: string
|
||||
}
|
||||
|
||||
export type LoanRemainingPayload = Omit<LoanRemaining, 'id'>
|
||||
|
||||
export interface LoanRemainingListParams {
|
||||
search?: string
|
||||
page?: number
|
||||
@@ -80,4 +82,39 @@ export async function deleteLoanRemaining(id: number): Promise<void> {
|
||||
return
|
||||
}
|
||||
await apiClient.delete(`/nova-loan-remaining-orders/${id}`)
|
||||
}
|
||||
|
||||
export async function fetchLoanRemainingById(id: number): Promise<LoanRemaining> {
|
||||
if (USE_MOCK) {
|
||||
const item = MOCK_DATA.find((r) => r.id === id)
|
||||
if (!item) throw new Error('Not found')
|
||||
return item
|
||||
}
|
||||
const { data } = await apiClient.get<LoanRemaining>(`/nova-loan-remaining-orders/${id}`)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function createLoanRemaining(payload: LoanRemainingPayload): Promise<LoanRemaining> {
|
||||
if (USE_MOCK) {
|
||||
const newItem: LoanRemaining = {
|
||||
id: Math.max(0, ...MOCK_DATA.map((d) => d.id)) + 1,
|
||||
...payload,
|
||||
}
|
||||
MOCK_DATA.unshift(newItem)
|
||||
return newItem
|
||||
}
|
||||
const { data } = await apiClient.post<LoanRemaining>('/nova-loan-remaining-orders', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function updateLoanRemaining(id: number, payload: LoanRemainingPayload): Promise<LoanRemaining> {
|
||||
if (USE_MOCK) {
|
||||
const idx = MOCK_DATA.findIndex((r) => r.id === id)
|
||||
if (idx === -1) throw new Error('Not found')
|
||||
const updated = { ...MOCK_DATA[idx], ...payload }
|
||||
MOCK_DATA[idx] = updated
|
||||
return updated
|
||||
}
|
||||
const { data } = await apiClient.put<LoanRemaining>(`/nova-loan-remaining-orders/${id}`, payload)
|
||||
return data
|
||||
}
|
||||
189
src/features/loanRemaining/components/LoanRemainingForm.tsx
Normal file
189
src/features/loanRemaining/components/LoanRemainingForm.tsx
Normal file
@@ -0,0 +1,189 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
|
||||
import {
|
||||
useCreateLoanRemaining,
|
||||
useUpdateLoanRemaining,
|
||||
} from '../hooks/useLoanRemaining'
|
||||
import type {
|
||||
LoanRemaining,
|
||||
LoanRemainingPayload,
|
||||
} from '../api/loanRemainingApi'
|
||||
|
||||
interface LoanRemainingFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: LoanRemaining
|
||||
loanRemainingId?: string
|
||||
}
|
||||
|
||||
interface FormState {
|
||||
passportSeries: string
|
||||
passportNumber: string
|
||||
loanAccount: string
|
||||
}
|
||||
|
||||
type FormErrors = Partial<Record<keyof FormState, string>>
|
||||
|
||||
const INITIAL_STATE: FormState = {
|
||||
passportSeries: '',
|
||||
passportNumber: '',
|
||||
loanAccount: '',
|
||||
}
|
||||
|
||||
export function LoanRemainingForm({
|
||||
mode,
|
||||
initialData,
|
||||
loanRemainingId,
|
||||
}: LoanRemainingFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateLoanRemaining()
|
||||
const updateMutation = useUpdateLoanRemaining(Number(loanRemainingId) || 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const [form, setForm] = useState<FormState>(() =>
|
||||
mode === 'edit' && initialData
|
||||
? {
|
||||
passportSeries: initialData.passportSeries,
|
||||
passportNumber: initialData.passportNumber,
|
||||
loanAccount: initialData.loanAccount,
|
||||
}
|
||||
: INITIAL_STATE
|
||||
)
|
||||
|
||||
const [errors, setErrors] = useState<FormErrors>({})
|
||||
const [submitted, setSubmitted] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === 'edit' && initialData) {
|
||||
setForm({
|
||||
passportSeries: initialData.passportSeries,
|
||||
passportNumber: initialData.passportNumber,
|
||||
loanAccount: initialData.loanAccount,
|
||||
})
|
||||
}
|
||||
}, [mode, initialData])
|
||||
|
||||
const set = useCallback(
|
||||
<K extends keyof FormState>(key: K, value: FormState[K]) => {
|
||||
setForm((prev) => ({ ...prev, [key]: value }))
|
||||
if (submitted) {
|
||||
setErrors((prev) => ({ ...prev, [key]: undefined }))
|
||||
}
|
||||
},
|
||||
[submitted]
|
||||
)
|
||||
|
||||
const validate = (): boolean => {
|
||||
const newErrors: FormErrors = {}
|
||||
|
||||
if (!form.passportSeries.trim()) {
|
||||
newErrors.passportSeries = t('common.required', 'Hökman doldurylmaly')
|
||||
}
|
||||
if (!form.passportNumber.trim()) {
|
||||
newErrors.passportNumber = t('common.required', 'Hökman doldurylmaly')
|
||||
}
|
||||
if (!form.loanAccount.trim()) {
|
||||
newErrors.loanAccount = t('common.required', 'Hökman doldurylmaly')
|
||||
}
|
||||
|
||||
setErrors(newErrors)
|
||||
return Object.keys(newErrors).length === 0
|
||||
}
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setSubmitted(true)
|
||||
|
||||
if (!validate()) {
|
||||
toast.error(t('common.errors.fillRequired', 'Hökman doldurylmaly öýjükleri dolduryň'))
|
||||
return
|
||||
}
|
||||
|
||||
const payload: LoanRemainingPayload = form
|
||||
|
||||
if (mode === 'create') {
|
||||
createMutation.mutate(payload, {
|
||||
onSuccess: () => {
|
||||
toast.success(t('common.success.create', 'Üstünlikli döredildi'))
|
||||
navigate('/loan-remaining')
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('common.errors.somethingWentWrong', 'Näsazlyk ýüze çykdy'))
|
||||
},
|
||||
})
|
||||
} else {
|
||||
updateMutation.mutate(payload, {
|
||||
onSuccess: () => {
|
||||
toast.success(t('common.success.save', 'Üstünlikli ýatda saklandy'))
|
||||
navigate('/loan-remaining')
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('common.errors.somethingWentWrong', 'Näsazlyk ýüze çykdy'))
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
<div className="bg-card border border-border rounded-xl p-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<FormInput
|
||||
label={t('loanRemaining.columns.passportSeries', 'Pasport seriýasy')}
|
||||
required
|
||||
value={form.passportSeries}
|
||||
onChange={(v) => set('passportSeries', v)}
|
||||
placeholder={t('loanRemaining.placeholders.passportSeries', 'TM')}
|
||||
error={errors.passportSeries}
|
||||
/>
|
||||
|
||||
<FormInput
|
||||
label={t('loanRemaining.columns.passportNumber', 'Pasport belgisi')}
|
||||
required
|
||||
value={form.passportNumber}
|
||||
onChange={(v) => set('passportNumber', v)}
|
||||
placeholder="A123456"
|
||||
error={errors.passportNumber}
|
||||
/>
|
||||
|
||||
<div className="md:col-span-2">
|
||||
<FormInput
|
||||
label={t('loanRemaining.columns.loanAccount', 'Karz hasaby')}
|
||||
required
|
||||
value={form.loanAccount}
|
||||
onChange={(v) => set('loanAccount', v)}
|
||||
placeholder="NOVA-..."
|
||||
error={errors.loanAccount}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => navigate('/loan-remaining')}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button type="submit" disabled={isPending}>
|
||||
{isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
{mode === 'create'
|
||||
? t('common.create', 'Döret')
|
||||
: t('common.save', 'Ýatda sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
@@ -5,7 +5,11 @@ import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
fetchLoanRemaining,
|
||||
deleteLoanRemaining,
|
||||
fetchLoanRemainingById,
|
||||
createLoanRemaining,
|
||||
updateLoanRemaining,
|
||||
type LoanRemainingListParams,
|
||||
type LoanRemainingPayload,
|
||||
} from '../api/loanRemainingApi'
|
||||
|
||||
// ─── Query keys ────────────────────────────────────────────────────────────────
|
||||
@@ -14,6 +18,8 @@ export const loanRemainingKeys = {
|
||||
all: ['loanRemaining'] as const,
|
||||
lists: () => [...loanRemainingKeys.all, 'list'] as const,
|
||||
list: (params: LoanRemainingListParams) => [...loanRemainingKeys.lists(), params] as const,
|
||||
details: () => [...loanRemainingKeys.all, 'detail'] as const,
|
||||
detail: (id: number) => [...loanRemainingKeys.details(), id] as const,
|
||||
}
|
||||
|
||||
// ─── Hooks ─────────────────────────────────────────────────────────────────────
|
||||
@@ -39,4 +45,45 @@ export function useDeleteLoanRemaining() {
|
||||
toast.error(t('loanRemaining.deleteError', 'Pozmak başartmady, gaýtadan synanyşyň'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useLoanRemainingById(id?: string) {
|
||||
return useQuery({
|
||||
queryKey: loanRemainingKeys.detail(Number(id)),
|
||||
queryFn: () => fetchLoanRemainingById(Number(id)),
|
||||
enabled: !!id,
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateLoanRemaining() {
|
||||
const queryClient = useQueryClient()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: LoanRemainingPayload) => createLoanRemaining(payload),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: loanRemainingKeys.lists() })
|
||||
toast.success(t('loanRemaining.createSuccess', 'Üstünlikli döredildi'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('loanRemaining.createError', 'Döretmek başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateLoanRemaining(id: number) {
|
||||
const queryClient = useQueryClient()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: LoanRemainingPayload) => updateLoanRemaining(id, payload),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: loanRemainingKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: loanRemainingKeys.detail(id) })
|
||||
toast.success(t('loanRemaining.updateSuccess', 'Üstünlikli üýtgedildi'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('loanRemaining.updateError', 'Üýtgetmek başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -18,24 +18,6 @@
|
||||
--shadow:
|
||||
rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px;
|
||||
|
||||
--sans: system-ui, "Segoe UI", Roboto, sans-serif;
|
||||
--heading: system-ui, "Segoe UI", Roboto, sans-serif;
|
||||
--mono: ui-monospace, Consolas, monospace;
|
||||
|
||||
font: 18px/145% var(--sans);
|
||||
letter-spacing: 0.18px;
|
||||
color-scheme: light dark;
|
||||
color: var(--text);
|
||||
background: var(--bg);
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--card: oklch(1 0 0);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import React, { useState } from 'react'
|
||||
import React, { useState, useEffect, useRef } from 'react'
|
||||
import { Outlet, Link, useLocation } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarHeader,
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
@@ -11,7 +13,8 @@ import {
|
||||
SidebarMenuSubButton,
|
||||
SidebarMenuSubItem,
|
||||
SidebarProvider,
|
||||
SidebarHeader,
|
||||
SidebarTrigger,
|
||||
useSidebar,
|
||||
} from '@/components/ui/sidebar'
|
||||
import { useAuthStore } from '@/app/store/authStore'
|
||||
import { useThemeStore } from '@/app/store/themeStore'
|
||||
@@ -43,7 +46,7 @@ import {
|
||||
BreadcrumbSeparator,
|
||||
} from '@/components/ui/breadcrumb'
|
||||
import { cn } from '@/lib/utils'
|
||||
import Icon from "@/assets/icon.svg"
|
||||
import Icon from '@/assets/icon.svg'
|
||||
|
||||
// ─── Collapsible wrappers ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -51,215 +54,64 @@ const Collapsible = CollapsiblePrimitive.Root
|
||||
const CollapsibleTrigger = CollapsiblePrimitive.Trigger
|
||||
const CollapsibleContent = CollapsiblePrimitive.Content
|
||||
|
||||
// ─── Header ───────────────────────────────────────────────────────────────────
|
||||
|
||||
function DashboardHeader() {
|
||||
const { t } = useTranslation()
|
||||
const location = useLocation()
|
||||
const { theme, toggleTheme } = useThemeStore()
|
||||
const { language, setLanguage } = useI18nStore()
|
||||
const user = useAuthStore((s) => s.user)
|
||||
const logout = useAuthStore((s) => s.clearAuth)
|
||||
const [userMenuOpen, setUserMenuOpen] = useState(false)
|
||||
const [langMenuOpen, setLangMenuOpen] = useState(false)
|
||||
|
||||
const languages = [
|
||||
{ code: 'en', label: 'English' },
|
||||
{ code: 'ru', label: 'Русский' },
|
||||
{ code: 'tk', label: 'Türkmençe' },
|
||||
] as const
|
||||
|
||||
const generateBreadcrumbs = () => {
|
||||
const paths = location.pathname.split('/').filter(Boolean)
|
||||
if (paths.length === 0 || (paths.length === 1 && paths[0] === 'dashboard')) {
|
||||
return (
|
||||
<BreadcrumbList>
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbPage>{t('Dashboard', 'Baş sahypa')}</BreadcrumbPage>
|
||||
</BreadcrumbItem>
|
||||
</BreadcrumbList>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<BreadcrumbList>
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbLink asChild>
|
||||
<Link to="/dashboard">Dashboards</Link>
|
||||
</BreadcrumbLink>
|
||||
</BreadcrumbItem>
|
||||
<BreadcrumbSeparator />
|
||||
{paths.map((path, index) => {
|
||||
const isLast = index === paths.length - 1
|
||||
const url = `/${paths.slice(0, index + 1).join('/')}`
|
||||
const formattedPath = path
|
||||
.replace(/-/g, ' ')
|
||||
.split(' ')
|
||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(' ')
|
||||
const title = t(formattedPath, formattedPath)
|
||||
|
||||
return (
|
||||
<React.Fragment key={url}>
|
||||
<BreadcrumbItem>
|
||||
{isLast ? (
|
||||
<BreadcrumbPage>{title}</BreadcrumbPage>
|
||||
) : (
|
||||
<BreadcrumbLink asChild>
|
||||
<Link to={url}>{title}</Link>
|
||||
</BreadcrumbLink>
|
||||
)}
|
||||
</BreadcrumbItem>
|
||||
{!isLast && <BreadcrumbSeparator />}
|
||||
</React.Fragment>
|
||||
)
|
||||
})}
|
||||
</BreadcrumbList>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<header className="h-14 border-b border-border bg-background flex items-center justify-between px-6 sticky top-0 z-30">
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<Breadcrumb>{generateBreadcrumbs()}</Breadcrumb>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
{/* Language Switcher */}
|
||||
<div className="relative">
|
||||
<button
|
||||
onClick={() => setLangMenuOpen(!langMenuOpen)}
|
||||
className="flex items-center gap-2 p-2 rounded-md hover:bg-accent text-muted-foreground hover:text-foreground transition-colors"
|
||||
aria-label="Toggle language"
|
||||
>
|
||||
<Globe size={18} />
|
||||
<span className="text-sm font-medium uppercase">{language}</span>
|
||||
</button>
|
||||
|
||||
{langMenuOpen && (
|
||||
<div className="absolute right-0 mt-1 w-32 bg-card border border-border rounded-md shadow-md py-1 z-50">
|
||||
{languages.map((lang) => (
|
||||
<button
|
||||
key={lang.code}
|
||||
onClick={() => {
|
||||
setLanguage(lang.code)
|
||||
setLangMenuOpen(false)
|
||||
}}
|
||||
className={`w-full text-left px-4 py-2 text-sm hover:bg-accent transition-colors ${
|
||||
language === lang.code
|
||||
? 'text-primary font-medium bg-accent/50'
|
||||
: 'text-foreground'
|
||||
}`}
|
||||
>
|
||||
{lang.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={toggleTheme}
|
||||
className="p-2 rounded-full hover:bg-accent text-muted-foreground hover:text-foreground transition-colors"
|
||||
aria-label="Toggle theme"
|
||||
>
|
||||
{theme === 'dark' ? <Sun size={18} /> : <Moon size={18} />}
|
||||
</button>
|
||||
|
||||
<button className="p-2 rounded-full hover:bg-accent text-muted-foreground hover:text-foreground transition-colors relative">
|
||||
<Bell size={18} />
|
||||
<span className="absolute top-1.5 right-1.5 w-2 h-2 bg-destructive rounded-full" />
|
||||
</button>
|
||||
|
||||
<div className="relative">
|
||||
<button
|
||||
className="flex items-center gap-2 hover:bg-accent py-1.5 px-3 rounded-md transition-colors"
|
||||
onClick={() => setUserMenuOpen(!userMenuOpen)}
|
||||
>
|
||||
<span className="text-sm font-medium text-foreground">{user?.name || 'Admin'}</span>
|
||||
<ChevronDown size={14} className="text-muted-foreground" />
|
||||
</button>
|
||||
|
||||
{userMenuOpen && (
|
||||
<div className="absolute right-0 mt-1 w-48 bg-card border border-border rounded-md shadow-md py-1 z-50">
|
||||
<button
|
||||
onClick={logout}
|
||||
className="w-full text-left px-4 py-2 text-sm text-destructive hover:bg-accent transition-colors"
|
||||
>
|
||||
{t('Logout', 'Çykmak')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Sidebar ──────────────────────────────────────────────────────────────────
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
type NavSubSubItem = { title: string; url: string }
|
||||
type NavSubItem = { title: string; url?: string; items?: NavSubSubItem[] }
|
||||
type NavItem = { title: string; url?: string; icon: React.ElementType; items?: NavSubItem[] }
|
||||
type NavItem = {
|
||||
title: string
|
||||
url?: string
|
||||
icon: React.ElementType
|
||||
items?: NavSubItem[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a nav item (or any of its children) matches the current path.
|
||||
*/
|
||||
function isNavItemActive(item: NavItem | NavSubItem, pathname: string): boolean {
|
||||
if ('url' in item && item.url) {
|
||||
if (pathname === item.url) return true
|
||||
}
|
||||
if (item.items) {
|
||||
return item.items.some((child) => isNavItemActive(child, pathname))
|
||||
}
|
||||
// ─── Nav helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
function isActiveItem(item: NavItem | NavSubItem, pathname: string): boolean {
|
||||
if ('url' in item && item.url && pathname === item.url) return true
|
||||
if (item.items) return item.items.some((c) => isActiveItem(c, pathname))
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Sub-sub-level collapsible: renders a category header (non-link)
|
||||
* with its leaf link items inside a Radix Collapsible.
|
||||
*
|
||||
* Using Radix Collapsible instead of Accordion eliminates the
|
||||
* --radix-accordion-content-height measurement bug that causes
|
||||
* nested accordions to show incorrect heights.
|
||||
*/
|
||||
function NavSubGroup({
|
||||
subItem,
|
||||
pathname,
|
||||
}: {
|
||||
subItem: NavSubItem
|
||||
pathname: string
|
||||
}) {
|
||||
const isActive = subItem.items?.some((s) => pathname === s.url) ?? false
|
||||
const [open, setOpen] = useState(isActive)
|
||||
// ─── Sub-sub collapsible (3rd level) ──────────────────────────────────────────
|
||||
|
||||
function NavSubGroup({ subItem, pathname }: { subItem: NavSubItem; pathname: string }) {
|
||||
const active = subItem.items?.some((s) => pathname === s.url) ?? false
|
||||
const [open, setOpen] = useState(active)
|
||||
|
||||
useEffect(() => {
|
||||
if (active) setOpen(true)
|
||||
}, [active])
|
||||
|
||||
return (
|
||||
<Collapsible open={open} onOpenChange={setOpen}>
|
||||
<CollapsibleTrigger asChild>
|
||||
<button
|
||||
className={cn(
|
||||
'group flex w-full items-center justify-between px-2 py-1.5',
|
||||
'text-xs font-semibold uppercase tracking-wider',
|
||||
'text-sidebar-foreground/60 hover:text-sidebar-foreground',
|
||||
'transition-colors rounded-sm',
|
||||
'flex w-full items-center justify-between px-2 py-1.5 mt-1',
|
||||
'text-[10px] font-bold uppercase tracking-widest select-none',
|
||||
'text-sidebar-foreground/40 hover:text-sidebar-foreground/70 transition-colors duration-150 rounded-sm',
|
||||
)}
|
||||
>
|
||||
<span>{subItem.title}</span>
|
||||
<ChevronRight
|
||||
size={12}
|
||||
size={10}
|
||||
className={cn('transition-transform duration-200', open && 'rotate-90')}
|
||||
/>
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
{/* No overflow:hidden animation — content renders at natural height */}
|
||||
<CollapsibleContent>
|
||||
<SidebarMenuSub className="border-l-0 pl-2 pr-0 mt-0">
|
||||
{subItem.items?.map((subSubItem, i) => (
|
||||
<CollapsibleContent
|
||||
className={cn(
|
||||
'overflow-hidden data-[state=open]:animate-collapsible-down data-[state=closed]:animate-collapsible-up',
|
||||
)}
|
||||
>
|
||||
<SidebarMenuSub className="border-l border-sidebar-border/50 ml-2 pl-2 mt-0.5 gap-0.5">
|
||||
{subItem.items?.map((item, i) => (
|
||||
<SidebarMenuSubItem key={i}>
|
||||
<SidebarMenuSubButton asChild isActive={pathname === subSubItem.url} size='sm'>
|
||||
<Link to={subSubItem.url}>
|
||||
<span>{subSubItem.title}</span>
|
||||
<SidebarMenuSubButton asChild isActive={pathname === item.url} size="sm">
|
||||
<Link to={item.url}>
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
@@ -270,45 +122,46 @@ function NavSubGroup({
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Top-level nav item that has children (both sub-groups and direct links).
|
||||
*/
|
||||
// ─── Top-level collapsible nav item ──────────────────────────────────────────
|
||||
|
||||
function NavGroupItem({ item }: { item: NavItem }) {
|
||||
const pathname = useLocation().pathname
|
||||
const isActive = isNavItemActive(item, pathname)
|
||||
const [open, setOpen] = useState(isActive)
|
||||
const { pathname } = useLocation()
|
||||
const { state } = useSidebar() // 'expanded' | 'collapsed'
|
||||
const collapsed = state === 'collapsed'
|
||||
const active = isActiveItem(item, pathname)
|
||||
const [open, setOpen] = useState(active)
|
||||
|
||||
useEffect(() => {
|
||||
if (active && !collapsed) setOpen(true)
|
||||
}, [active, collapsed])
|
||||
|
||||
return (
|
||||
<Collapsible open={open} onOpenChange={setOpen}>
|
||||
<Collapsible open={!collapsed && open} onOpenChange={(v) => !collapsed && setOpen(v)}>
|
||||
<SidebarMenuItem>
|
||||
<CollapsibleTrigger asChild>
|
||||
<SidebarMenuButton isActive={isActive} tooltip={item.title}>
|
||||
<SidebarMenuButton isActive={active} tooltip={item.title}>
|
||||
<item.icon />
|
||||
<span>{item.title}</span>
|
||||
<ChevronRight
|
||||
size={12}
|
||||
size={14}
|
||||
className={cn(
|
||||
'ml-auto transition-transform duration-200',
|
||||
open && 'rotate-90',
|
||||
'ml-auto shrink-0 transition-transform duration-200',
|
||||
'group-data-[collapsible=icon]:hidden', // hide when icon-only
|
||||
open && !collapsed && 'rotate-90',
|
||||
)}
|
||||
/>
|
||||
</SidebarMenuButton>
|
||||
</CollapsibleTrigger>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<CollapsibleContent>
|
||||
<CollapsibleContent className="overflow-hidden data-[state=open]:animate-collapsible-down data-[state=closed]:animate-collapsible-up">
|
||||
<SidebarMenuSub>
|
||||
{item.items?.map((subItem, subIndex) => {
|
||||
// Sub-item has further children → render as collapsible group
|
||||
{item.items?.map((subItem, i) => {
|
||||
if (subItem.items) {
|
||||
return (
|
||||
<NavSubGroup key={subIndex} subItem={subItem} pathname={pathname} />
|
||||
)
|
||||
return <NavSubGroup key={i} subItem={subItem} pathname={pathname} />
|
||||
}
|
||||
|
||||
// Sub-item is a direct link
|
||||
return (
|
||||
<SidebarMenuSubItem key={subIndex}>
|
||||
<SidebarMenuSubItem key={i}>
|
||||
<SidebarMenuSubButton asChild isActive={pathname === subItem.url}>
|
||||
<Link to={subItem.url ?? '#'}>
|
||||
<span>{subItem.title}</span>
|
||||
@@ -323,9 +176,11 @@ function NavGroupItem({ item }: { item: NavItem }) {
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Sidebar ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function AppSidebar() {
|
||||
const { t } = useTranslation()
|
||||
const location = useLocation()
|
||||
const { pathname } = useLocation()
|
||||
|
||||
const navItems: NavItem[] = [
|
||||
{
|
||||
@@ -343,7 +198,7 @@ function AppSidebar() {
|
||||
{ title: t('Loan orders', 'Karz sargytlary'), url: '/loan-orders' },
|
||||
{ title: t('Loan order (Mobile)', 'Karz sargyt (Mobile)'), url: '/loan-order-mobiles' },
|
||||
{ title: t('Loan balance', 'Karzyň galyndysy'), url: '/loan-remaining' },
|
||||
{ title: t('Certificates of loan repayment', 'Karzyň ýapylandygy barada güwanamalar'), url: '/loan-paid-off-letters' },
|
||||
{ title: t('Certificates', 'Karzyň ýapylandygy barada güwanamalar'), url: '/loan-paid-off-letters' },
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -389,7 +244,7 @@ function AppSidebar() {
|
||||
title: t('Loan', 'KARZ'),
|
||||
items: [
|
||||
{ title: t('Loan types', 'Karz görnüşleri'), url: '/settings/loan/types' },
|
||||
{ title: t('Required Documents', 'Karz gerekli resminamalary'), url: '/settings/loan/documents' },
|
||||
{ title: t('Required Documents', 'Gerekli resminamalar'), url: '/settings/loan/documents' },
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -441,60 +296,264 @@ function AppSidebar() {
|
||||
]
|
||||
|
||||
return (
|
||||
<Sidebar className="border-r border-sidebar-border">
|
||||
<SidebarHeader className="h-14 flex items-center px-4 border-b border-sidebar-border">
|
||||
<div className="flex items-center gap-2 font-bold text-lg text-sidebar-primary">
|
||||
<img className='h-10' src={Icon} alt="" />
|
||||
<span>TBBANK</span>
|
||||
</div>
|
||||
<Sidebar collapsible="icon" className="border-r border-sidebar-border">
|
||||
{/* Logo */}
|
||||
<SidebarHeader className="h-14 flex-row items-center px-4 border-b border-sidebar-border gap-2.5 overflow-hidden">
|
||||
<img className="h-8 w-8 shrink-0" src={Icon} alt="" />
|
||||
<span className="font-bold text-base tracking-tight text-sidebar-foreground whitespace-nowrap group-data-[collapsible=icon]:hidden transition-opacity duration-200">
|
||||
TBBANK
|
||||
</span>
|
||||
</SidebarHeader>
|
||||
|
||||
<SidebarContent>
|
||||
<SidebarMenu className="mt-4 gap-1 px-2 text-sm">
|
||||
{navItems.map((item, index) => {
|
||||
// Leaf item (no children)
|
||||
{/* Nav */}
|
||||
<SidebarContent className="px-2 py-3">
|
||||
<SidebarMenu className="gap-0.5">
|
||||
{navItems.map((item, i) => {
|
||||
// Leaf item
|
||||
if (!item.items) {
|
||||
return (
|
||||
<SidebarMenuItem key={index}>
|
||||
<SidebarMenuItem key={i}>
|
||||
<SidebarMenuButton
|
||||
asChild
|
||||
isActive={location.pathname === item.url}
|
||||
isActive={pathname === item.url}
|
||||
tooltip={item.title}
|
||||
className='text-sm'
|
||||
>
|
||||
<Link to={item.url ?? '#'}>
|
||||
<item.icon />
|
||||
<span className='text-sm'>{item.title}</span>
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
)
|
||||
}
|
||||
|
||||
return <NavGroupItem key={index} item={item} />
|
||||
return <NavGroupItem key={i} item={item} />
|
||||
})}
|
||||
</SidebarMenu>
|
||||
</SidebarContent>
|
||||
|
||||
{/* Footer */}
|
||||
<SidebarFooter className="border-t border-sidebar-border px-4 py-3">
|
||||
<span className="text-[10px] text-sidebar-foreground/25 group-data-[collapsible=icon]:hidden">
|
||||
TBBANK v2.0
|
||||
</span>
|
||||
<span className="text-[10px] text-sidebar-foreground/25 hidden group-data-[collapsible=icon]:block text-center">
|
||||
v2
|
||||
</span>
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Header ───────────────────────────────────────────────────────────────────
|
||||
|
||||
function DashboardHeader() {
|
||||
const { t } = useTranslation()
|
||||
const location = useLocation()
|
||||
const { theme, toggleTheme } = useThemeStore()
|
||||
const { language, setLanguage } = useI18nStore()
|
||||
const user = useAuthStore((s) => s.user)
|
||||
const logout = useAuthStore((s) => s.clearAuth)
|
||||
|
||||
const [userMenuOpen, setUserMenuOpen] = useState(false)
|
||||
const [langMenuOpen, setLangMenuOpen] = useState(false)
|
||||
const userMenuRef = useRef<HTMLDivElement>(null)
|
||||
const langMenuRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
function handler(e: MouseEvent) {
|
||||
if (userMenuRef.current && !userMenuRef.current.contains(e.target as Node)) setUserMenuOpen(false)
|
||||
if (langMenuRef.current && !langMenuRef.current.contains(e.target as Node)) setLangMenuOpen(false)
|
||||
}
|
||||
document.addEventListener('mousedown', handler)
|
||||
return () => document.removeEventListener('mousedown', handler)
|
||||
}, [])
|
||||
|
||||
const languages = [
|
||||
{ code: 'en', label: 'English' },
|
||||
{ code: 'ru', label: 'Русский' },
|
||||
{ code: 'tk', label: 'Türkmençe' },
|
||||
] as const
|
||||
|
||||
const generateBreadcrumbs = () => {
|
||||
const paths = location.pathname.split('/').filter(Boolean)
|
||||
if (paths.length === 0 || (paths.length === 1 && paths[0] === 'dashboard')) {
|
||||
return (
|
||||
<BreadcrumbList>
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbPage>{t('Dashboard', 'Baş sahypa')}</BreadcrumbPage>
|
||||
</BreadcrumbItem>
|
||||
</BreadcrumbList>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<BreadcrumbList>
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbLink asChild>
|
||||
<Link to="/dashboard">Dashboard</Link>
|
||||
</BreadcrumbLink>
|
||||
</BreadcrumbItem>
|
||||
<BreadcrumbSeparator />
|
||||
{paths.map((path, index) => {
|
||||
const isLast = index === paths.length - 1
|
||||
const url = `/${paths.slice(0, index + 1).join('/')}`
|
||||
const formatted = path
|
||||
.replace(/-/g, ' ')
|
||||
.split(' ')
|
||||
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
||||
.join(' ')
|
||||
const title = t(formatted, formatted)
|
||||
return (
|
||||
<React.Fragment key={url}>
|
||||
<BreadcrumbItem>
|
||||
{isLast ? (
|
||||
<BreadcrumbPage>{title}</BreadcrumbPage>
|
||||
) : (
|
||||
<BreadcrumbLink asChild>
|
||||
<Link to={url}>{title}</Link>
|
||||
</BreadcrumbLink>
|
||||
)}
|
||||
</BreadcrumbItem>
|
||||
{!isLast && <BreadcrumbSeparator />}
|
||||
</React.Fragment>
|
||||
)
|
||||
})}
|
||||
</BreadcrumbList>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<header className="h-14 border-b border-border bg-background/80 backdrop-blur-md flex items-center justify-between px-4 sticky top-0 z-30 gap-3">
|
||||
{/* Left: sidebar trigger + breadcrumb */}
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
{/*
|
||||
SidebarTrigger handles BOTH:
|
||||
- Desktop: toggles collapsed/expanded (collapsible="icon")
|
||||
- Mobile: opens the Sheet overlay
|
||||
No custom mobile hamburger needed.
|
||||
*/}
|
||||
<SidebarTrigger className="text-muted-foreground hover:text-foreground hover:bg-accent -ml-1 transition-colors" />
|
||||
|
||||
<div className="text-sm text-muted-foreground min-w-0 truncate">
|
||||
<Breadcrumb>{generateBreadcrumbs()}</Breadcrumb>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right: actions */}
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
{/* Language */}
|
||||
<div className="relative" ref={langMenuRef}>
|
||||
<button
|
||||
onClick={() => setLangMenuOpen((p) => !p)}
|
||||
className="flex items-center gap-1.5 h-8 px-2.5 rounded-md hover:bg-accent text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<Globe size={16} />
|
||||
<span className="uppercase font-medium text-xs hidden sm:block">{language}</span>
|
||||
</button>
|
||||
<div
|
||||
className={cn(
|
||||
'absolute right-0 mt-1.5 w-36 bg-popover border border-border rounded-lg shadow-lg py-1 z-50',
|
||||
'transition-all duration-150 origin-top-right',
|
||||
langMenuOpen
|
||||
? 'opacity-100 scale-100 pointer-events-auto'
|
||||
: 'opacity-0 scale-95 pointer-events-none',
|
||||
)}
|
||||
>
|
||||
{languages.map((lang) => (
|
||||
<button
|
||||
key={lang.code}
|
||||
onClick={() => { setLanguage(lang.code); setLangMenuOpen(false) }}
|
||||
className={cn(
|
||||
'w-full text-left px-3 py-2 text-sm hover:bg-accent transition-colors',
|
||||
language === lang.code ? 'text-primary font-medium' : 'text-foreground',
|
||||
)}
|
||||
>
|
||||
{lang.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Theme */}
|
||||
<button
|
||||
onClick={toggleTheme}
|
||||
className="flex items-center justify-center w-8 h-8 rounded-md hover:bg-accent text-muted-foreground hover:text-foreground transition-colors"
|
||||
aria-label="Toggle theme"
|
||||
>
|
||||
{theme === 'dark' ? <Sun size={16} /> : <Moon size={16} />}
|
||||
</button>
|
||||
|
||||
{/* Notifications */}
|
||||
<button className="relative flex items-center justify-center w-8 h-8 rounded-md hover:bg-accent text-muted-foreground hover:text-foreground transition-colors">
|
||||
<Bell size={16} />
|
||||
<span className="absolute top-1.5 right-1.5 w-1.5 h-1.5 bg-destructive rounded-full ring-1 ring-background" />
|
||||
</button>
|
||||
|
||||
{/* User menu */}
|
||||
<div className="relative" ref={userMenuRef}>
|
||||
<button
|
||||
onClick={() => setUserMenuOpen((p) => !p)}
|
||||
className="flex items-center gap-2 h-8 pl-2 pr-2.5 rounded-md hover:bg-accent transition-colors ml-1"
|
||||
>
|
||||
<div className="w-6 h-6 rounded-full bg-primary/20 flex items-center justify-center text-[10px] font-bold text-primary shrink-0">
|
||||
{(user?.name ?? 'A').charAt(0).toUpperCase()}
|
||||
</div>
|
||||
<span className="text-sm font-medium text-foreground hidden sm:block max-w-[100px] truncate">
|
||||
{user?.name ?? 'Admin'}
|
||||
</span>
|
||||
<ChevronDown
|
||||
size={13}
|
||||
className={cn(
|
||||
'text-muted-foreground transition-transform duration-200',
|
||||
userMenuOpen && 'rotate-180',
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
'absolute right-0 mt-1.5 w-44 bg-popover border border-border rounded-lg shadow-lg py-1 z-50',
|
||||
'transition-all duration-150 origin-top-right',
|
||||
userMenuOpen
|
||||
? 'opacity-100 scale-100 pointer-events-auto'
|
||||
: 'opacity-0 scale-95 pointer-events-none',
|
||||
)}
|
||||
>
|
||||
<div className="px-3 py-2 border-b border-border mb-1">
|
||||
<p className="text-xs font-medium text-foreground truncate">{user?.name ?? 'Admin'}</p>
|
||||
<p className="text-[11px] text-muted-foreground truncate">{user?.email ?? ''}</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={logout}
|
||||
className="w-full text-left flex items-center gap-2 px-3 py-2 text-sm text-destructive hover:bg-accent transition-colors"
|
||||
>
|
||||
{t('Logout', 'Çykmak')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Layout ───────────────────────────────────────────────────────────────────
|
||||
|
||||
export function DashboardLayout() {
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<SidebarProvider>
|
||||
<div className="flex min-h-screen w-full bg-background text-foreground">
|
||||
<div className="flex h-screen w-full bg-background text-foreground overflow-hidden">
|
||||
<AppSidebar />
|
||||
<div className="flex-1 flex flex-col min-w-0">
|
||||
|
||||
<div className="flex-1 flex flex-col min-w-0 overflow-hidden">
|
||||
<DashboardHeader />
|
||||
<main className="flex-1 p-6 overflow-auto">
|
||||
|
||||
<main className="flex-1 p-4 md:p-6 overflow-auto">
|
||||
<Outlet />
|
||||
</main>
|
||||
{/* Footer */}
|
||||
<div className="text-center text-xs text-muted-foreground/40 pt-2 pb-6">
|
||||
© 2026 TBBANK.GOV.TM.
|
||||
|
||||
<div className="text-center text-[11px] text-muted-foreground/30 py-3 border-t border-border/50">
|
||||
© 2026 TBBANK.GOV.TM
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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" />;
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
}}
|
||||
/>
|
||||
|
||||
5
src/pages/loanOrderMobileCreate/index.tsx
Normal file
5
src/pages/loanOrderMobileCreate/index.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { LoanOrderMobileForm } from '@/components/loanOrderMobileForm'
|
||||
|
||||
export default function LoanOrderMobilesCreatePage() {
|
||||
return <LoanOrderMobileForm mode="create" />
|
||||
}
|
||||
35
src/pages/loanOrderMobileEdit/index.tsx
Normal file
35
src/pages/loanOrderMobileEdit/index.tsx
Normal 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
src/pages/loanOrderMobileView/index.tsx
Normal file
452
src/pages/loanOrderMobileView/index.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
@@ -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')}
|
||||
|
||||
@@ -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
src/pages/loanRemainingCreate/index.tsx
Normal file
18
src/pages/loanRemainingCreate/index.tsx
Normal 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
src/pages/loanRemainingEdit/index.tsx
Normal file
45
src/pages/loanRemainingEdit/index.tsx
Normal 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
src/pages/loanRemainingView/index.tsx
Normal file
140
src/pages/loanRemainingView/index.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user