From c2548280a2d4c61aa5feae6c02505e498924b318 Mon Sep 17 00:00:00 2001 From: "@jcarymuhammedow" Date: Tue, 5 May 2026 19:07:59 +0500 Subject: [PATCH] added loan remaing pages --- PROJECT_STANDARDS.md | 7 +- src/app/router/index.tsx | 57 +- src/components/creditCardVisual.tsx | 85 ++ src/components/loanOrderMobileForm.tsx | 1164 +++++++++++++++++ .../api/loanOrderMobilesApi.ts | 149 +++ .../components/loanOrderForm.tsx | 333 ++++- .../hooks/useLoanOrderMobiles.ts | 48 + src/features/loanOrders/api/loanOrdersApi.ts | 57 + .../loanRemaining/api/loanRemainingApi.ts | 37 + .../components/LoanRemainingForm.tsx | 189 +++ .../loanRemaining/hooks/useLoanRemaining.ts | 47 + src/index.css | 18 - src/layouts/DashboardLayout.tsx | 525 ++++---- src/pages/loanOrderCreate/index.tsx | 6 +- src/pages/loanOrderEdit/index.tsx | 26 +- .../index.tsx | 34 +- src/pages/loanOrderMobileCreate/index.tsx | 5 + src/pages/loanOrderMobileEdit/index.tsx | 35 + src/pages/loanOrderMobileView/index.tsx | 452 +++++++ src/pages/loanOrderView/index.tsx | 6 +- src/pages/loanRemaining/index.tsx | 6 +- src/pages/loanRemainingCreate/index.tsx | 18 + src/pages/loanRemainingEdit/index.tsx | 45 + src/pages/loanRemainingView/index.tsx | 140 ++ 24 files changed, 3182 insertions(+), 307 deletions(-) create mode 100644 src/components/creditCardVisual.tsx create mode 100644 src/components/loanOrderMobileForm.tsx rename src/features/{loanOrders => loanOrderMobiles}/components/loanOrderForm.tsx (71%) create mode 100644 src/features/loanRemaining/components/LoanRemainingForm.tsx rename src/pages/{loanOrderMobiles => loanOrderMobile}/index.tsx (91%) create mode 100644 src/pages/loanOrderMobileCreate/index.tsx create mode 100644 src/pages/loanOrderMobileEdit/index.tsx create mode 100644 src/pages/loanOrderMobileView/index.tsx create mode 100644 src/pages/loanRemainingCreate/index.tsx create mode 100644 src/pages/loanRemainingEdit/index.tsx create mode 100644 src/pages/loanRemainingView/index.tsx diff --git a/PROJECT_STANDARDS.md b/PROJECT_STANDARDS.md index b16e4a0..5006130 100644 --- a/PROJECT_STANDARDS.md +++ b/PROJECT_STANDARDS.md @@ -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} /> \ No newline at end of file + [Feature]EditPage.tsx ← id fetch → <[Feature]Form mode="edit" initialData={data} loanOrderId={id} /> + ``` diff --git a/src/app/router/index.tsx b/src/app/router/index.tsx index ce32191..d1dc568 100644 --- a/src/app/router/index.tsx +++ b/src/app/router/index.tsx @@ -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([ ), - }, { path: "/loan-orders/create", @@ -108,6 +113,30 @@ export const router = createBrowserRouter([ ), }, + { + path: "/loan-order-mobiles/:id", + element: ( + }> + + + ), + }, + { + path: "/loan-order-mobiles/create", + element: ( + }> + + + ), + }, + { + path: "/loan-order-mobiles/:id/edit", + element: ( + }> + + + ), + }, { // Sidebar: /loan-remaining path: "/loan-remaining", @@ -117,6 +146,30 @@ export const router = createBrowserRouter([ ), }, + { + path: "/loan-remaining/create", + element: ( + }> + + + ), + }, + { + path: "/loan-remaining/:id", + element: ( + }> + + + ), + }, + { + path: "/loan-remaining/:id/edit", + element: ( + }> + + + ), + }, { // Sidebar: /loan-paid-off-letters path: "/loan-paid-off-letters", diff --git a/src/components/creditCardVisual.tsx b/src/components/creditCardVisual.tsx new file mode 100644 index 0000000..c29654b --- /dev/null +++ b/src/components/creditCardVisual.tsx @@ -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 ( +
+ {/* Glow effects */} +
+
+ + {/* Top row: Chip and Logo/Bank Name */} +
+
+ {/* Chip lines */} +
+
+
+
+
+
+ + {t('Altyn Asyr') || 'ALTYN ASYR'} + +
+
+ + {/* Middle row: Card Number */} +
+
+ {formatCardNumber(cardNumber)} +
+
+ + {/* Bottom row: Name and Expiry */} +
+
+ + {t('Card Holder') || 'KARTDAKY ADY'} + + + {cardName || 'MÄHRIBAN TÖLEGLI'} + +
+
+ + {t('Valid Thru') || 'MÖHLETI'} + + + {expMonth || '00'}/{expYear ? expYear.slice(-2) : '00'} + +
+
+
+ ) +} diff --git a/src/components/loanOrderMobileForm.tsx b/src/components/loanOrderMobileForm.tsx new file mode 100644 index 0000000..2e148c2 --- /dev/null +++ b/src/components/loanOrderMobileForm.tsx @@ -0,0 +1,1164 @@ +import { useState, useCallback } from 'react' +import { useNavigate } from 'react-router-dom' +import { useTranslation } from 'react-i18next' +import { toast } from 'sonner' +import { FormInput } from '@/components/formInput' +import { Button } from '@/components/ui/button' +import { cn } from '@/lib/utils' +import { useCreateLoanOrderMobile, useUpdateLoanOrderMobile } from '@/features/loanOrderMobiles/hooks/useLoanOrderMobiles' +import type { LoanOrderMobile, LoanOrderMobilePayload } from '@/features/loanOrderMobiles/api/loanOrderMobilesApi' + +// ─── Section Wrapper ────────────────────────────────────────────────────────── + +function Section({ + title, + children, + className, +}: { + title: string + children: React.ReactNode + className?: string +}) { + return ( +
+
+

{title}

+
+
{children}
+
+ ) +} + +// ─── Grid helpers ───────────────────────────────────────────────────────────── + +const grid2 = 'grid grid-cols-1 sm:grid-cols-2 gap-6' +const grid3 = 'grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6' +const grid4 = 'grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6' + +// ─── Static options ─────────────────────────────────────────────────────────── + +const REGION_OPTIONS = [ + { value: 'Aşgabat', label: 'Aşgabat' }, + { value: 'Ahal', label: 'Ahal' }, + { value: 'Balkan', label: 'Balkan' }, + { value: 'Daşoguz', label: 'Daşoguz' }, + { value: 'Lebap', label: 'Lebap' }, + { value: 'Mary', label: 'Mary' }, + { value: 'Arkadag', label: 'Arkadag' }, +] + +const EDUCATION_OPTIONS = [ + { value: 'high', label: 'Ýokary bilim' }, + { value: 'unfinished_high', label: 'Gutarylmadyk ýokary bilim' }, + { value: 'masters', label: 'Magistr' }, + { value: 'phd', label: 'Ylymlaryň doktory' }, + { value: 'middle', label: 'Orta mekdep' }, + { value: 'school', label: 'Orta bilim' }, + { value: 'school_dropout', label: 'Gutarylmadyk orta bilim' }, +] + +const MARRIAGE_OPTIONS = [ + { value: 'MARRIED', label: 'Öýlenen / Durmuşa çykan' }, + { value: 'SINGLE', label: 'Öýlenmedik / Durmuşa çykmadyk' }, + { value: 'DIVORCED', label: 'Aýrylşan' }, + { value: 'WIDOW', label: 'Adamsy ýa-da aýaly aradan çykan' }, + { value: 'LEGAL', label: 'Raýat nika' }, +] + +const STATUS_OPTIONS = [ + { value: 'GARAŞYLÝAR', label: 'Garaşylýar' }, + { value: 'IŞLENÝÄR', label: 'Işlenýär' }, + { value: 'KANAGATLANDYRYLAN', label: 'Kanagatlandyrylan' }, + { value: 'RED_EDILDI', label: 'Red edildi' }, +] + +const LOAN_TYPE_OPTIONS = [ + { value: 'consumer', label: 'Sarp ediş karzy' }, + { value: 'mortgage', label: 'Ipoteka' }, + { value: 'car', label: 'Awtoulag karzy' }, + { value: 'student', label: 'Talyplar üçin' }, + { value: 'business', label: 'Işewürlik karzy' }, +] + +const PASSPORT_SERIES_OPTIONS = [ + { value: 'I', label: 'I' }, + { value: 'II', label: 'II' }, +] + +// ─── Form State ─────────────────────────────────────────────────────────────── + +interface FormState { + 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: string + workStartedAt: string + passportPage1: File | null + 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> + +const INITIAL_STATE: FormState = { + status: 'GARAŞYLÝAR', + loanType: '', + region: 'Aşgabat', + branch: '', + firstName: '', + lastName: '', + patronicName: '', + education: '', + marriageStatus: '', + dateOfBirth: '', + residence: '', + currentResidence: '', + passportSerie: '', + passportNumber: '', + passportDateOfIssue: '', + passportGivenBy: '', + bornPlace: '', + email: '', + phone: '', + phoneAdditional: '', + homePhone: '', + workCompany: '', + workHrPhone: '', + workRegion: 'Aşgabat', + workProvince: '', + position: '', + salary: '', + workStartedAt: '', + passportPage1: null, + 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) ───────────── + +function mapToFormState(order: LoanOrderMobile): FormState { + return { + status: order.status ?? 'GARAŞYLÝAR', + loanType: order.loanType ?? '', + region: order.region ?? 'Aşgabat', + branch: order.branch ?? '', + firstName: order.firstName ?? '', + lastName: order.lastName ?? '', + patronicName: order.patronicName ?? '', + education: order.education ?? '', + marriageStatus: order.marriageStatus ?? '', + dateOfBirth: order.dateOfBirth ?? '', + residence: order.residence ?? '', + currentResidence: order.currentResidence ?? '', + passportSerie: order.passportSerie ?? '', + passportNumber: order.passportNumber ?? '', + passportDateOfIssue: order.passportDateOfIssue ?? '', + passportGivenBy: order.passportGivenBy ?? '', + bornPlace: order.bornPlace ?? '', + email: order.email ?? '', + phone: order.phone ?? '', + phoneAdditional: order.phoneAdditional ?? '', + homePhone: order.homePhone ?? '', + workCompany: order.workCompany ?? '', + workHrPhone: order.workHrPhone ?? '', + workRegion: order.workRegion ?? 'Aşgabat', + workProvince: order.workProvince ?? '', + position: order.position ?? '', + salary: order.salary != null ? String(order.salary) : '', + workStartedAt: order.workStartedAt ?? '', + // File field'ları edit modunda null kalır — mevcut URL'ler ayrı gösterilir + passportPage1: null, + 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) : '', + } +} + +// ─── Validation ─────────────────────────────────────────────────────────────── + +function validate( + form: FormState, + t: (k: string) => string, + mode: 'create' | 'edit' +): FormErrors { + const errors: FormErrors = {} + + const req = (key: keyof FormState, label: string) => { + const val = form[key] + if (!val || (typeof val === 'string' && !val.trim())) { + errors[key] = `${label} — ${t('required') || 'hökmany'}` + } + } + + req('loanType', t('Loan type') || 'Karz görnüşi') + req('region', t('Region') || 'Welaýat') + req('branch', t('Branch') || 'Şahamça') + req('firstName', t('Name') || 'Ady') + req('lastName', t('Surname') || 'Familiýasy') + req('education', t('Education') || 'Bilimi') + req('marriageStatus', t('Marriage status') || 'Maşgala ýagdaýy') + req('dateOfBirth', t('Date of birth') || 'Doglan güni') + req('residence', t('Residence (passport)') || 'Ýazgy edilen salgy') + req('passportSerie', t('Passport serie') || 'Pasport seriýasy') + req('passportNumber', t('Passport number') || 'Pasport belgisi') + req('passportDateOfIssue', t('Passport date of issue') || 'Pasport berlen senesi') + req('passportGivenBy', t('Passport given by') || 'Kim tarapyndan berildi') + req('phone', t('Phone') || 'Telefon') + req('workCompany', t('Work company name') || 'Kärhananyň ady') + req('position', t('Position') || 'Wezipe') + 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' + } + + // File'lar diňe create modunda hökmany + if (mode === 'create') { + if (!form.passportPage1) errors.passportPage1 = 'Pasport (sahypa 1) hökmany' + if (!form.passportPage23) errors.passportPage23 = 'Pasport (sahypa 2-3) hökmany' + } + + return errors +} + +// ─── Props ──────────────────────────────────────────────────────────────────── + +interface LoanOrderMobileFormProps { + mode: 'create' | 'edit' + initialData?: LoanOrderMobile + loanOrderId?: string +} + +// ─── Component ──────────────────────────────────────────────────────────────── + +export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrderMobileFormProps) { + const { t } = useTranslation() + const navigate = useNavigate() + + const createMutation = useCreateLoanOrderMobile() + const updateMutation = useUpdateLoanOrderMobile() + + const isPending = createMutation.isPending || updateMutation.isPending + + const [form, setForm] = useState(() => + initialData ? mapToFormState(initialData) : INITIAL_STATE + ) + const [errors, setErrors] = useState({}) + const [submitted, setSubmitted] = useState(false) + + const set = useCallback( + (key: K, value: FormState[K]) => { + setForm((prev) => ({ ...prev, [key]: value })) + if (submitted) { + setErrors((prev) => ({ ...prev, [key]: undefined })) + } + }, + [submitted] + ) + + const handleSubmit = () => { + setSubmitted(true) + const errs = validate(form, t, mode) + if (Object.keys(errs).length > 0) { + setErrors(errs) + toast.error(t('Write a correct data please') || 'Dogry maglumat girizmegiňizi haýyş edýäris.') + const firstKey = Object.keys(errs)[0] + document.getElementById(`field-${firstKey}`)?.scrollIntoView({ behavior: 'smooth', block: 'center' }) + return + } + + const payload: LoanOrderMobilePayload = { + status: form.status, + loanType: form.loanType, + region: form.region, + branch: form.branch, + firstName: form.firstName, + lastName: form.lastName, + patronicName: form.patronicName || undefined, + education: form.education, + marriageStatus: form.marriageStatus, + dateOfBirth: form.dateOfBirth, + residence: form.residence, + currentResidence: form.currentResidence || undefined, + passportSerie: form.passportSerie, + passportNumber: form.passportNumber, + passportDateOfIssue: form.passportDateOfIssue, + passportGivenBy: form.passportGivenBy, + bornPlace: form.bornPlace || undefined, + email: form.email || undefined, + phone: form.phone, + phoneAdditional: form.phoneAdditional || undefined, + homePhone: form.homePhone || undefined, + workCompany: form.workCompany, + workHrPhone: form.workHrPhone || undefined, + workRegion: form.workRegion || undefined, + workProvince: form.workProvince || undefined, + 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') { + createMutation.mutate(payload, { + onSuccess: () => navigate('/loan-order-mobiles'), + }) + } else { + updateMutation.mutate( + { id: loanOrderId!, payload }, + { onSuccess: () => navigate('/loan-order-mobiles') } + ) + } + } + + // ── Render ────────────────────────────────────────────────────────────────── + return ( +
+ {/* Page title */} +
+

+ {mode === 'create' + ? (t('Loan order create') || 'Karz sargyt döredüň') + : (t('Loan order edit') || 'Karz sargydy üýtget')} +

+
+ + {/* ── Status ─────────────────────────────────────────────────────────── */} +
+
+
+ set('status', v)} + options={STATUS_OPTIONS} + error={errors.status} + placeholder="Saýlaň" + /> +
+
+ set('note', v)} + placeholder={t('Note') || 'Bellik'} + /> +
+
+
+ + {/* ── Loan Type ──────────────────────────────────────────────────────── */} +
+
+
+ set('loanType', v)} + options={LOAN_TYPE_OPTIONS} + placeholder="Saýlamak üçin basyň" + error={errors.loanType} + /> +
+
+ set('loanAmount', v)} + placeholder="Karz möçberi" + error={errors.loanAmount} + /> +
+
+
+ + {/* ── Location ───────────────────────────────────────────────────────── */} +
+
+
+ set('region', v)} + options={REGION_OPTIONS} + placeholder="Saýlamak üçin basyň" + error={errors.region} + /> +
+
+ set('branch', v)} + options={[]} + placeholder="Saýlamak üçin basyň" + error={errors.branch} + /> +
+
+
+ + {/* ── Personal Data ──────────────────────────────────────────────────── */} +
+
+
+
+ set('firstName', v)} + placeholder={t('Name') || 'Ady'} + error={errors.firstName} + /> +
+
+ set('lastName', v)} + placeholder={t('Surname') || 'Familiýasy'} + error={errors.lastName} + /> +
+
+ set('patronicName', v)} + placeholder={t('Patronic name') || 'Atasynyň ady'} + /> +
+
+ +
+
+ set('education', v)} + options={EDUCATION_OPTIONS} + placeholder="Saýlaň" + error={errors.education} + /> +
+
+ set('marriageStatus', v)} + options={MARRIAGE_OPTIONS} + placeholder="Saýlaň" + error={errors.marriageStatus} + /> +
+
+ set('dateOfBirth', v)} + error={errors.dateOfBirth} + /> +
+
+ +
+
+ set('residence', v)} + placeholder={t('Residence (passport)') || 'Ýazgy edilen salgyňyz'} + error={errors.residence} + /> +
+
+ set('currentResidence', v)} + placeholder={t('Current Residence') || 'Häzirki ýaşaýyş ýeri'} + /> +
+
+ +
+ set('loanHistory', v)} + options={[]} + placeholder="Saýlamak üçin basyň" + /> +
+
+
+ + {/* ── Card ───────────────────────────────────────────────────────────── */} +
+
+
+ set('cardNumber', v)} + placeholder="Kart belgisi" + error={errors.cardNumber} + /> +
+
+ set('cardName', v)} + placeholder="Kartdaky ady" + error={errors.cardName} + /> +
+
+ 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} + /> +
+
+ 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} + /> +
+
+
+ + {/* ── Passport ───────────────────────────────────────────────────────── */} +
+
+
+
+ set('passportSerie', v)} + options={PASSPORT_SERIES_OPTIONS} + placeholder="Saýlamak üçin basyň" + error={errors.passportSerie} + /> +
+
+ set('passportNumber', v)} + placeholder={t('Passport number') || 'Pasport belgisi'} + error={errors.passportNumber} + /> +
+
+ set('passportDateOfIssue', v)} + error={errors.passportDateOfIssue} + /> +
+
+ +
+
+ set('passportGivenBy', v)} + placeholder={t('Passport given by') || 'Kim tarapyndan berildi'} + error={errors.passportGivenBy} + /> +
+
+ set('bornPlace', v)} + placeholder={t('Born place (passport)') || 'Doglan ýeri (pasport)'} + /> +
+
+
+
+ + {/* ── Contact ────────────────────────────────────────────────────────── */} +
+
+
+ set('email', v)} + placeholder="E-poçta" + /> +
+
+ set('phone', v)} + placeholder="61 097 651" + error={errors.phone} + /> +
+
+ set('phoneAdditional', v)} + placeholder="61 097 651" + /> +
+
+ set('homePhone', v)} + placeholder="61 097 651" + /> +
+
+
+ + {/* ── Job ────────────────────────────────────────────────────────────── */} +
+
+
+
+ set('workCompany', v)} + placeholder={t('Work company name') || 'Işleýän edaranyň/kärhananyň ady'} + error={errors.workCompany} + /> +
+
+ set('workHrPhone', v)} + placeholder="61 097 651" + /> +
+
+ +
+
+ set('workRegion', v)} + options={REGION_OPTIONS} + placeholder="Saýlamak üçin basyň" + /> +
+
+ set('workProvince', v)} + options={[]} + placeholder="Saýlamak üçin basyň" + /> +
+
+ +
+
+ set('position', v)} + placeholder={t('Position') || 'Wezipe'} + error={errors.position} + /> +
+
+ set('salary', v)} + placeholder={t('Salary') || 'Zähmet haky'} + error={errors.salary} + /> +
+
+ set('workStartedAt', v)} + error={errors.workStartedAt} + /> +
+
+
+
+ + {/* ── Passport Files ─────────────────────────────────────────────────── */} +
+ {/* Edit modunda mevcut resimleri göster */} + {mode === 'edit' && initialData && ( +
+ {initialData.passportPage1Url && ( +
+ + {t('Passport (page 1)') || 'Pasport (sahypa 1)'} — {t('current') || 'häzirki'} + + + {t('View file') || 'Faýly gör'} + +
+ )} + {initialData.passportPage23Url && ( +
+ + {t('Passport (page 2-3)') || 'Pasport (2-3-nji sahypa)'} — {t('current') || 'häzirki'} + + + {t('View file') || 'Faýly gör'} + +
+ )} + {initialData.passportPage89Url && ( +
+ + {t('Passport (page 8-9)') || 'Pasport (8-9 sahypa)'} — {t('current') || 'häzirki'} + + + {t('View file') || 'Faýly gör'} + +
+ )} + {initialData.passportPage32Url && ( +
+ + {t('Passport (page 32)') || 'Pasport (32-nji sahypa)'} — {t('current') || 'häzirki'} + + + {t('View file') || 'Faýly gör'} + +
+ )} +
+ )} + +
+
+ set('passportPage1', f)} + placeholder="Faýl saýlaň ýa-da salmak üçin basyň" + error={errors.passportPage1} + /> +
+
+ set('passportPage23', f)} + placeholder="Faýl saýlaň ýa-da salmak üçin basyň" + error={errors.passportPage23} + /> +
+
+ set('passportPage89', f)} + placeholder="Faýl saýlaň ýa-da salmak üçin basyň" + /> +
+
+ set('passportPage32', f)} + placeholder="Faýl saýlaň ýa-da salmak üçin basyň" + /> +
+
+
+ + {/* ── Zamun ──────────────────────────────────────────────────────────── */} +
+
+
+
+ set('guarantor1Name', v)} + placeholder="Zamunyň ady" + error={errors.guarantor1Name} + /> +
+
+ set('guarantor1Surname', v)} + placeholder="Zamunyň familiýasy" + error={errors.guarantor1Surname} + /> +
+
+ set('guarantor1Patronic', v)} + placeholder="Zamunyň atasynyň ady" + /> +
+
+ +
+
+ set('guarantor1PassportSerie', v)} + options={PASSPORT_SERIES_OPTIONS} + placeholder="Saýlamak üçin basyň" + error={errors.guarantor1PassportSerie} + /> +
+
+ set('guarantor1PassportNumber', v)} + placeholder="Pasport belgisi" + error={errors.guarantor1PassportNumber} + /> +
+
+ +
+
+ set('guarantor1CardNumber', v)} + placeholder="Kart belgisi" + error={errors.guarantor1CardNumber} + /> +
+
+ set('guarantor1CardName', v)} + placeholder="Kartdaky ady" + error={errors.guarantor1CardName} + /> +
+
+ 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} + /> +
+
+ 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} + /> +
+
+ +
+
+ set('guarantor1Salary', v)} + placeholder="Ortaca zähmet haky" + error={errors.guarantor1Salary} + /> +
+
+
+
+ + {/* ── Footer Actions ─────────────────────────────────────────────────── */} +
+ + +
+
+ ) +} \ No newline at end of file diff --git a/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts b/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts index e51f0c1..e5273a8 100644 --- a/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts +++ b/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts @@ -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 { return } await apiClient.delete(`/loan-order-mobiles/${id}`) +} + +export async function getLoanOrderMobileById(id: string): Promise { + 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(`/loan-order-mobiles/${id}`) + return data +} + +export async function createLoanOrderMobile( + payload: LoanOrderMobilePayload +): Promise { + 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('/loan-order-mobiles', payload) + return data +} + +export async function updateLoanOrderMobile( + id: string, + payload: Partial +): Promise { + 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(`/loan-order-mobiles/${id}`, payload) + return data } \ No newline at end of file diff --git a/src/features/loanOrders/components/loanOrderForm.tsx b/src/features/loanOrderMobiles/components/loanOrderForm.tsx similarity index 71% rename from src/features/loanOrders/components/loanOrderForm.tsx rename to src/features/loanOrderMobiles/components/loanOrderForm.tsx index cdcd5bc..e7907a5 100644 --- a/src/features/loanOrders/components/loanOrderForm.tsx +++ b/src/features/loanOrderMobiles/components/loanOrderForm.tsx @@ -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> @@ -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 ─────────────────────────────────────────────────────────── */}
-
-
+
+
+
+ set('note', v)} + placeholder={t('Note') || 'Bellik'} + /> +
{/* ── Loan Type ──────────────────────────────────────────────────────── */}
-
- set('loanType', v)} - options={LOAN_TYPE_OPTIONS} - placeholder="Saýlamak üçin basyň" - error={errors.loanType} - /> +
+
+ set('loanType', v)} + options={LOAN_TYPE_OPTIONS} + placeholder="Saýlamak üçin basyň" + error={errors.loanType} + /> +
+
+ set('loanAmount', v)} + placeholder="Karz möçberi" + error={errors.loanAmount} + /> +
@@ -508,6 +624,69 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP /> + +
+ set('loanHistory', v)} + options={[]} + placeholder="Saýlamak üçin basyň" + /> +
+ + + + {/* ── Card ───────────────────────────────────────────────────────────── */} +
+
+
+ set('cardNumber', v)} + placeholder="Kart belgisi" + error={errors.cardNumber} + /> +
+
+ set('cardName', v)} + placeholder="Kartdaky ady" + error={errors.cardName} + /> +
+
+ 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} + /> +
+
+ 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} + /> +
@@ -829,6 +1008,134 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP + {/* ── Zamun ──────────────────────────────────────────────────────────── */} +
+
+
+
+ set('guarantor1Name', v)} + placeholder="Zamunyň ady" + error={errors.guarantor1Name} + /> +
+
+ set('guarantor1Surname', v)} + placeholder="Zamunyň familiýasy" + error={errors.guarantor1Surname} + /> +
+
+ set('guarantor1Patronic', v)} + placeholder="Zamunyň atasynyň ady" + /> +
+
+ +
+
+ set('guarantor1PassportSerie', v)} + options={PASSPORT_SERIES_OPTIONS} + placeholder="Saýlamak üçin basyň" + error={errors.guarantor1PassportSerie} + /> +
+
+ set('guarantor1PassportNumber', v)} + placeholder="Pasport belgisi" + error={errors.guarantor1PassportNumber} + /> +
+
+ +
+
+ set('guarantor1CardNumber', v)} + placeholder="Kart belgisi" + error={errors.guarantor1CardNumber} + /> +
+
+ set('guarantor1CardName', v)} + placeholder="Kartdaky ady" + error={errors.guarantor1CardName} + /> +
+
+ 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} + /> +
+
+ 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} + /> +
+
+ +
+
+ set('guarantor1Salary', v)} + placeholder="Ortaca zähmet haky" + error={errors.guarantor1Salary} + /> +
+
+
+
+ {/* ── Footer Actions ─────────────────────────────────────────────────── */}
+ +
+ + ) +} diff --git a/src/features/loanRemaining/hooks/useLoanRemaining.ts b/src/features/loanRemaining/hooks/useLoanRemaining.ts index aed1875..2aa0833 100644 --- a/src/features/loanRemaining/hooks/useLoanRemaining.ts +++ b/src/features/loanRemaining/hooks/useLoanRemaining.ts @@ -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')) + }, + }) } \ No newline at end of file diff --git a/src/index.css b/src/index.css index 84cd063..fea4c37 100644 --- a/src/index.css +++ b/src/index.css @@ -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); diff --git a/src/layouts/DashboardLayout.tsx b/src/layouts/DashboardLayout.tsx index 7fb2e96..6211323 100644 --- a/src/layouts/DashboardLayout.tsx +++ b/src/layouts/DashboardLayout.tsx @@ -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 ( - - - {t('Dashboard', 'Baş sahypa')} - - - ) - } - - return ( - - - - Dashboards - - - - {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 ( - - - {isLast ? ( - {title} - ) : ( - - {title} - - )} - - {!isLast && } - - ) - })} - - ) - } - - return ( -
-
- {generateBreadcrumbs()} -
- -
- {/* Language Switcher */} -
- - - {langMenuOpen && ( -
- {languages.map((lang) => ( - - ))} -
- )} -
- - - - - -
- - - {userMenuOpen && ( -
- -
- )} -
-
-
- ) -} - -// ─── 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 ( - {/* No overflow:hidden animation — content renders at natural height */} - - - {subItem.items?.map((subSubItem, i) => ( + + + {subItem.items?.map((item, i) => ( - - - {subSubItem.title} + + + {item.title} @@ -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 ( - + !collapsed && setOpen(v)}> - + {item.title} - + - {item.items?.map((subItem, subIndex) => { - // Sub-item has further children → render as collapsible group + {item.items?.map((subItem, i) => { if (subItem.items) { - return ( - - ) + return } - - // Sub-item is a direct link return ( - + {subItem.title} @@ -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 ( - - -
- - TBBANK -
+ + {/* Logo */} + + + + TBBANK + - - - {navItems.map((item, index) => { - // Leaf item (no children) + {/* Nav */} + + + {navItems.map((item, i) => { + // Leaf item if (!item.items) { return ( - + - {item.title} + {item.title} ) } - return + return })} + + {/* Footer */} + + + TBBANK v2.0 + + + v2 + + ) } +// ─── 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(null) + const langMenuRef = useRef(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 ( + + + {t('Dashboard', 'Baş sahypa')} + + + ) + } + return ( + + + + Dashboard + + + + {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 ( + + + {isLast ? ( + {title} + ) : ( + + {title} + + )} + + {!isLast && } + + ) + })} + + ) + } + + return ( +
+ {/* Left: sidebar trigger + breadcrumb */} +
+ {/* + SidebarTrigger handles BOTH: + - Desktop: toggles collapsed/expanded (collapsible="icon") + - Mobile: opens the Sheet overlay + No custom mobile hamburger needed. + */} + + +
+ {generateBreadcrumbs()} +
+
+ + {/* Right: actions */} +
+ {/* Language */} +
+ +
+ {languages.map((lang) => ( + + ))} +
+
+ + {/* Theme */} + + + {/* Notifications */} + + + {/* User menu */} +
+ + +
+
+

{user?.name ?? 'Admin'}

+

{user?.email ?? ''}

+
+ +
+
+
+
+ ) +} + // ─── Layout ─────────────────────────────────────────────────────────────────── export function DashboardLayout() { return ( -
+
-
+ +
-
+ +
- {/* Footer */} -
- © 2026 TBBANK.GOV.TM. + +
+ © 2026 TBBANK.GOV.TM
diff --git a/src/pages/loanOrderCreate/index.tsx b/src/pages/loanOrderCreate/index.tsx index 2ec2ef4..1fb71b7 100644 --- a/src/pages/loanOrderCreate/index.tsx +++ b/src/pages/loanOrderCreate/index.tsx @@ -1,5 +1,5 @@ -import { LoanOrderForm } from '@/features/loanOrders/components/loanOrderForm' +import { LoanOrderForm } from "@/features/loanOrderMobiles/components/loanOrderForm"; export default function LoanOrderCreatePage() { - return -} \ No newline at end of file + return ; +} diff --git a/src/pages/loanOrderEdit/index.tsx b/src/pages/loanOrderEdit/index.tsx index aea2f90..c56476e 100644 --- a/src/pages/loanOrderEdit/index.tsx +++ b/src/pages/loanOrderEdit/index.tsx @@ -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 (
- ) + ); } if (isError || !data) { @@ -22,14 +22,8 @@ export default function LoanOrderEditPage() { Maglumat ýüklenilmedi. Sahypany täzeleläň.

- ) + ); } - return ( - - ) -} \ No newline at end of file + return ; +} diff --git a/src/pages/loanOrderMobiles/index.tsx b/src/pages/loanOrderMobile/index.tsx similarity index 91% rename from src/pages/loanOrderMobiles/index.tsx rename to src/pages/loanOrderMobile/index.tsx index 9975455..ab01d66 100644 --- a/src/pages/loanOrderMobiles/index.tsx +++ b/src/pages/loanOrderMobile/index.tsx @@ -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 }) => ( -
- - +
+ + +
+
+ ) +} + +// ─── AuditRow ───────────────────────────────────────────────────────────────── + +function AuditRow({ id, action, by, target, status, date }: AuditRowProps) { + return ( + + {id} + {action} + {by} + {target} + + + + {status} + + + {date} + + + + + ) +} + +// ─── Skeleton ───────────────────────────────────────────────────────────────── + +function LoanOrderMobilesViewSkeleton() { + return ( +
+ + {[...Array(5)].map((_, i) => ( +
+ + {[...Array(3)].map((_, j) => ( + + ))} +
+ ))} +
+ ) +} + +// ─── 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 + + if (!order) { + return ( +
+ {t('common.notFound', 'Tapylmady')} +
+ ) + } + + // 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 ( +
+ {/* Page Header */} +
+

+ {t('loanOrderMobiles.view.title', 'Karz sargyt giriş')}: {order.id} +

+
+ + +
+
+ + {/* ── Basic Info ─────────────────────────────────────────────────────── */} +
+ + {/* Status row — special render */} +
+ + {t('loanOrders.columns.status', 'Status')} + + +
+ + + +
+ + {/* ── Card ───────────────────────────────────────────────────────────── */} + {(order.cardNumber || order.cardName) && ( +
+
+ +
+ + +
+ )} + + {/* ── Loan ───────────────────────────────────────────────────────────── */} +
+ + +
+ + {/* ── Location ───────────────────────────────────────────────────────── */} +
+ +
+ + {/* ── Personal Info ──────────────────────────────────────────────────── */} +
+ + + + + + + +
+ + {/* ── Contacts ───────────────────────────────────────────────────────── */} +
+ + + + +
+ + {/* ── Employment ─────────────────────────────────────────────────────── */} +
+ + + + + + + +
+ + {/* ── Passport ───────────────────────────────────────────────────────── */} +
+ + + + + + + +
+ + {/* ── Guarantor ──────────────────────────────────────────────────────── */} + {(order.guarantor1Name || order.guarantor1CardNumber) && ( +
+ + + + {order.guarantor1CardNumber && ( +
+ +
+ )} +
+ )} + + {/* ── Audit Log ──────────────────────────────────────────────────────── */} +
+
+ + {t('loanOrders.sections.audit', 'Ammallar')} + + +
+
+ + + + {[ + '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) => ( + + ))} + + + + {auditLogs.map((log) => ( + + ))} + +
+ {col} +
+
+
+ {t('common.prev', 'Öňki')} + 1–{auditLogs.length} / {auditLogs.length} + {t('common.next', 'Soňky')} +
+
+
+
+ +
+ ) +} \ No newline at end of file diff --git a/src/pages/loanOrderView/index.tsx b/src/pages/loanOrderView/index.tsx index 8b322e6..c6e3441 100644 --- a/src/pages/loanOrderView/index.tsx +++ b/src/pages/loanOrderView/index.tsx @@ -219,7 +219,7 @@ export default function LoanOrderViewPage() {
@@ -321,7 +321,7 @@ export default function LoanOrderViewPage() { /> (
+ +
+
+ + {/* ── Basic Info ─────────────────────────────────────────────────────── */} +
+ + + + +
+ + ) +}