added loan remaing pages
This commit is contained in:
@@ -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'))
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user