added lang support to loans
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useState, useCallback, useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { TFunction } from "i18next";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
@@ -146,8 +147,10 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
|
||||
interface StepDef {
|
||||
id: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
titleKey: string;
|
||||
titleFallback: string;
|
||||
subtitleKey: string;
|
||||
subtitleFallback: string;
|
||||
icon: LucideIcon;
|
||||
validate: (form: LoanOrderMobileFormData, mode: "create" | "edit") => FlatErrors;
|
||||
}
|
||||
@@ -155,36 +158,36 @@ interface StepDef {
|
||||
const STEPS: StepDef[] = [
|
||||
{
|
||||
id: "loan",
|
||||
title: "Karz",
|
||||
subtitle: "Görnüş, möçber & lokasiýa",
|
||||
titleKey: "loanOrderMobileForm.steps.loan.title", titleFallback: "Karz",
|
||||
subtitleKey: "loanOrderMobileForm.steps.loan.subtitle", subtitleFallback: "Görnüş, möçber & lokasiýa",
|
||||
icon: FileText,
|
||||
validate: (form, mode) => validateStep(0, form, mode),
|
||||
},
|
||||
{
|
||||
id: "personal",
|
||||
title: "Şahsy & Pasport",
|
||||
subtitle: "Şahsyýet & pasport",
|
||||
titleKey: "loanOrderMobileForm.steps.personal.title", titleFallback: "Şahsy & Pasport",
|
||||
subtitleKey: "loanOrderMobileForm.steps.personal.subtitle", subtitleFallback: "Şahsyýet & pasport",
|
||||
icon: User,
|
||||
validate: (form, mode) => validateStep(1, form, mode),
|
||||
},
|
||||
{
|
||||
id: "contact",
|
||||
title: "Habarlaşmak & Iş",
|
||||
subtitle: "Telefon & iş",
|
||||
titleKey: "loanOrderMobileForm.steps.contact.title", titleFallback: "Habarlaşmak & Iş",
|
||||
subtitleKey: "loanOrderMobileForm.steps.contact.subtitle", subtitleFallback: "Telefon & iş",
|
||||
icon: Phone,
|
||||
validate: (form, mode) => validateStep(2, form, mode),
|
||||
},
|
||||
{
|
||||
id: "card",
|
||||
title: "Kart & Zamun",
|
||||
subtitle: "Töleg & zamun",
|
||||
titleKey: "loanOrderMobileForm.steps.card.title", titleFallback: "Kart & Zamun",
|
||||
subtitleKey: "loanOrderMobileForm.steps.card.subtitle", subtitleFallback: "Töleg & zamun",
|
||||
icon: CreditCard,
|
||||
validate: (form, mode) => validateStep(3, form, mode),
|
||||
},
|
||||
{
|
||||
id: "files",
|
||||
title: "Faýllar & Status",
|
||||
subtitle: "Resminamalar",
|
||||
titleKey: "loanOrderMobileForm.steps.files.title", titleFallback: "Faýllar & Status",
|
||||
subtitleKey: "loanOrderMobileForm.steps.files.subtitle", subtitleFallback: "Resminamalar",
|
||||
icon: Upload,
|
||||
validate: (form, mode) => validateStep(4, form, mode),
|
||||
},
|
||||
@@ -196,67 +199,64 @@ interface StepContentProps {
|
||||
form: LoanOrderMobileFormData;
|
||||
errors: FlatErrors;
|
||||
set: <K extends keyof LoanOrderMobileFormData>(k: K, v: LoanOrderMobileFormData[K]) => void;
|
||||
t: TFunction;
|
||||
}
|
||||
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
|
||||
function StepLoan({ form, errors, set }: StepContentProps) {
|
||||
function StepLoan({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={2}>
|
||||
{/* Loan type — single input, no title */}
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Karz görnüşi"
|
||||
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ň"
|
||||
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
|
||||
error={errors.loanType}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
{/* Loan amount — single input, no title */}
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="number"
|
||||
label="Karz möçberi"
|
||||
label={t('loanOrderForm.labels.loanAmount') || 'Karz möçberi'}
|
||||
required
|
||||
value={form.loanAmount}
|
||||
onChange={(v) => set("loanAmount", v)}
|
||||
placeholder="0.00"
|
||||
placeholder={t('loanOrderForm.placeholders.amount') || '0.00'}
|
||||
error={errors.loanAmount}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
{/* Region — single input, no title */}
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Welaýat"
|
||||
label={t('Region') || 'Welaýat'}
|
||||
required
|
||||
value={form.region}
|
||||
onChange={(v) => { set("region", v); set("branch", ""); }}
|
||||
options={REGION_OPTIONS}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
|
||||
error={errors.region}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
{/* Branch — single input, no title */}
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Şahamça"
|
||||
label={t('Branch') || 'Şahamça'}
|
||||
required
|
||||
value={form.branch}
|
||||
onChange={(v) => set("branch", v)}
|
||||
options={BRANCHES_BY_REGION_MOBILE[form.region] ?? []}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
|
||||
disabled={!form.region}
|
||||
error={errors.branch}
|
||||
/>
|
||||
@@ -266,163 +266,153 @@ function StepLoan({ form, errors, set }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepPersonal({ form, errors, set }: StepContentProps) {
|
||||
function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Name row */}
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Ady" required value={form.firstName} onChange={(v) => set("firstName", v)} placeholder="Ady" error={errors.firstName} />
|
||||
<FormInput type="text" label={t('Name') || 'Ady'} required value={form.firstName} onChange={(v) => set("firstName", v)} placeholder={t('Name') || 'Ady'} error={errors.firstName} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Familiýasy" required value={form.lastName} onChange={(v) => set("lastName", v)} placeholder="Familiýasy" error={errors.lastName} />
|
||||
<FormInput type="text" label={t('Surname') || 'Familiýasy'} required value={form.lastName} onChange={(v) => set("lastName", v)} placeholder={t('Surname') || 'Familiýasy'} error={errors.lastName} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Atasynyň ady" value={form.patronicName} onChange={(v) => set("patronicName", v)} placeholder="Atasynyň ady" />
|
||||
<FormInput type="text" label={t('Patronic name') || 'Atasynyň ady'} value={form.patronicName} onChange={(v) => set("patronicName", v)} placeholder={t('Patronic name') || 'Atasynyň ady'} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Education / Marriage / DOB */}
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput type="select" label="Bilimi" required value={form.education} onChange={(v) => set("education", v)} options={EDUCATION_OPTIONS} placeholder="Saýlaň" error={errors.education} />
|
||||
<FormInput type="select" label={t('Education') || 'Bilimi'} required value={form.education} onChange={(v) => set("education", v)} options={EDUCATION_OPTIONS} placeholder={t('loanOrderForm.placeholders.select') || 'Saýlaň'} error={errors.education} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="select" label="Maşgala ýagdaýy" required value={form.marriageStatus} onChange={(v) => set("marriageStatus", v)} options={MARRIAGE_OPTIONS} placeholder="Saýlaň" error={errors.marriageStatus} />
|
||||
<FormInput type="select" label={t('Marriage status') || 'Maşgala ýagdaýy'} required value={form.marriageStatus} onChange={(v) => set("marriageStatus", v)} options={MARRIAGE_OPTIONS} placeholder={t('loanOrderForm.placeholders.select') || 'Saýlaň'} error={errors.marriageStatus} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="date" label="Doglan güni" required value={form.dateOfBirth} onChange={(v) => set("dateOfBirth", v)} error={errors.dateOfBirth} />
|
||||
<FormInput type="date" label={t('Date of birth') || 'Doglan güni'} required value={form.dateOfBirth} onChange={(v) => set("dateOfBirth", v)} error={errors.dateOfBirth} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Residence */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Ýazgy edilen salgyňyz" required value={form.residence} onChange={(v) => set("residence", v)} placeholder="Ýazgy edilen salgy" error={errors.residence} />
|
||||
<FormInput type="text" label={t('Residence (passport)') || 'Ýazgy edilen salgyňyz'} required value={form.residence} onChange={(v) => set("residence", v)} placeholder={t('loanOrderForm.placeholders.residence') || 'Ýazgy edilen salgy'} error={errors.residence} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Häzirki ýaşaýyş ýeri" value={form.currentResidence} onChange={(v) => set("currentResidence", v)} placeholder="Häzirki ýaşaýyş ýeri" />
|
||||
<FormInput type="text" label={t('Current Residence') || 'Häzirki ýaşaýyş ýeri'} value={form.currentResidence} onChange={(v) => set("currentResidence", v)} placeholder={t('loanOrderForm.placeholders.currentResidence') || 'Häzirki ýaşaýyş ýeri'} />
|
||||
</BentoCard>
|
||||
<BentoCard span="full">
|
||||
<FormInput type="searchable-select" label="Karz taryhy" value={form.loanHistory} onChange={(v) => set("loanHistory", v)} options={[]} placeholder="Saýlamak üçin basyň" />
|
||||
<FormInput type="searchable-select" label={t('Loan history') || 'Karz taryhy'} value={form.loanHistory} onChange={(v) => set("loanHistory", v)} options={[]} placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Passport */}
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput type="searchable-select" label="Pasport seriýasy" required value={form.passportSerie} onChange={(v) => set("passportSerie", v)} options={PASSPORT_SERIES_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.passportSerie} />
|
||||
<FormInput type="searchable-select" label={t('Passport serie') || 'Pasport seriýasy'} required value={form.passportSerie} onChange={(v) => set("passportSerie", v)} options={PASSPORT_SERIES_OPTIONS} placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'} error={errors.passportSerie} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Pasport belgisi" required value={form.passportNumber} onChange={(v) => set("passportNumber", v)} placeholder="Pasport belgisi" error={errors.passportNumber} />
|
||||
<FormInput type="text" label={t('Passport id') || 'Pasport belgisi'} required value={form.passportNumber} onChange={(v) => set("passportNumber", v)} placeholder={t('Passport id') || 'Pasport belgisi'} error={errors.passportNumber} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="date" label="Pasport berlen senesi" required value={form.passportDateOfIssue} onChange={(v) => set("passportDateOfIssue", v)} error={errors.passportDateOfIssue} />
|
||||
<FormInput type="date" label={t('Passport date of issue') || 'Pasport berlen senesi'} required value={form.passportDateOfIssue} onChange={(v) => set("passportDateOfIssue", v)} error={errors.passportDateOfIssue} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Kim tarapyndan berildi" required value={form.passportGivenBy} onChange={(v) => set("passportGivenBy", v)} placeholder="Kim tarapyndan berildi" error={errors.passportGivenBy} />
|
||||
<FormInput type="text" label={t('Passport given by') || 'Kim tarapyndan berildi'} required value={form.passportGivenBy} onChange={(v) => set("passportGivenBy", v)} placeholder={t('Passport given by') || 'Kim tarapyndan berildi'} error={errors.passportGivenBy} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Doglan ýeri (pasport)" value={form.bornPlace} onChange={(v) => set("bornPlace", v)} placeholder="Doglan ýeri (pasport)" />
|
||||
<FormInput type="text" label={t('Born place (passport)') || 'Doglan ýeri (pasport)'} value={form.bornPlace} onChange={(v) => set("bornPlace", v)} placeholder={t('Born place (passport)') || 'Doglan ýeri (pasport)'} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StepContact({ form, errors, set }: StepContentProps) {
|
||||
function StepContact({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Contact */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Esasy">
|
||||
<FormInput type="phone" label="Telefon" required value={form.phone} onChange={(v) => set("phone", v)} placeholder="61 097 651" error={errors.phone} />
|
||||
<FormInput type="email" label="E-poçta" value={form.email} onChange={(v) => set("email", v)} placeholder="E-poçta" />
|
||||
<BentoCard title={t('loanOrderForm.titles.contactMain') || 'Esasy'}>
|
||||
<FormInput type="phone" label={t('Phone') || 'Telefon'} required value={form.phone} onChange={(v) => set("phone", v)} placeholder={t('loanOrderForm.placeholders.phone') || '61 097 651'} error={errors.phone} />
|
||||
<FormInput type="email" label={t('Email') || 'E-poçta'} value={form.email} onChange={(v) => set("email", v)} placeholder={t('Email') || 'E-poçta'} />
|
||||
</BentoCard>
|
||||
<BentoCard title="Goşmaça">
|
||||
<FormInput type="phone" label="Telefon goşmaça" value={form.phoneAdditional} onChange={(v) => set("phoneAdditional", v)} placeholder="61 097 651" />
|
||||
<FormInput type="phone" label="Öý telefony" value={form.homePhone} onChange={(v) => set("homePhone", v)} placeholder="61 097 651" />
|
||||
<BentoCard title={t('loanOrderForm.titles.contactAdditional') || 'Goşmaça'}>
|
||||
<FormInput type="phone" label={t('Phone Additional') || 'Telefon goşmaça'} value={form.phoneAdditional} onChange={(v) => set("phoneAdditional", v)} placeholder={t('loanOrderForm.placeholders.phone') || '61 097 651'} />
|
||||
<FormInput type="phone" label={t('Home phone') || 'Öý telefony'} value={form.homePhone} onChange={(v) => set("homePhone", v)} placeholder={t('loanOrderForm.placeholders.phone') || '61 097 651'} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Job */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Işleýän edaranyň/kärhananyň ady" required value={form.workCompany} onChange={(v) => set("workCompany", v)} placeholder="Kärhananyň ady" error={errors.workCompany} />
|
||||
<FormInput type="phone" label="Işgärler bölüminiň iş belgisi" value={form.workHrPhone} onChange={(v) => set("workHrPhone", v)} placeholder="61 097 651" />
|
||||
<FormInput type="text" label={t('Work company name') || 'Işleýän edaranyň/kärhananyň ady'} required value={form.workCompany} onChange={(v) => set("workCompany", v)} placeholder={t('loanOrderForm.placeholders.companyName') || 'Kärhananyň ady'} error={errors.workCompany} />
|
||||
<FormInput type="phone" label={t('HR department work number') || 'Işgärler bölüminiň iş belgisi'} value={form.workHrPhone} onChange={(v) => set("workHrPhone", v)} placeholder={t('loanOrderForm.placeholders.phone') || '61 097 651'} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="searchable-select" label="Işleýän welaýatyňyz" value={form.workRegion} onChange={(v) => set("workRegion", v)} options={REGION_OPTIONS} placeholder="Saýlamak üçin basyň" />
|
||||
<FormInput type="searchable-select" label="Işleýän etrabyňyz" value={form.workProvince} onChange={(v) => set("workProvince", v)} options={[]} placeholder="Saýlamak üçin basyň" />
|
||||
<FormInput type="searchable-select" label={t('Work region') || 'Işleýän welaýatyňyz'} value={form.workRegion} onChange={(v) => set("workRegion", v)} options={REGION_OPTIONS} placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'} />
|
||||
<FormInput type="searchable-select" label={t('Work province') || 'Işleýän etrabyňyz'} value={form.workProvince} onChange={(v) => set("workProvince", v)} options={[]} placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Wezipe" required value={form.position} onChange={(v) => set("position", v)} placeholder="Wezipe" error={errors.position} />
|
||||
<FormInput type="text" label={t('Position') || 'Wezipe'} required value={form.position} onChange={(v) => set("position", v)} placeholder={t('Position') || 'Wezipe'} error={errors.position} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="number" label="Zähmet haky" required value={form.salary} onChange={(v) => set("salary", v)} placeholder="Zähmet haky" error={errors.salary} />
|
||||
<FormInput type="number" label={t('Salary') || 'Zähmet haky'} required value={form.salary} onChange={(v) => set("salary", v)} placeholder={t('Salary') || 'Zähmet haky'} error={errors.salary} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="date" label="Işe başlan wagtyňyz" required value={form.workStartedAt} onChange={(v) => set("workStartedAt", v)} error={errors.workStartedAt} />
|
||||
<FormInput type="date" label={t('Work started at') || 'Işe başlan wagtyňyz'} required value={form.workStartedAt} onChange={(v) => set("workStartedAt", v)} error={errors.workStartedAt} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StepCard({ form, errors, set }: StepContentProps) {
|
||||
function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Salary card */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Kart maglumatlary">
|
||||
<FormInput type="text" label="Kart belgisi" required value={form.cardNumber} onChange={(v) => set("cardNumber", v)} placeholder="Kart belgisi" error={errors.cardNumber} />
|
||||
<FormInput type="text" label="Kartdaky ady" required value={form.cardName} onChange={(v) => set("cardName", v)} placeholder="Kartdaky ady" error={errors.cardName} />
|
||||
<BentoCard title={t('loanOrderForm.titles.cardInfo') || 'Kart maglumatlary'}>
|
||||
<FormInput type="text" label={t('Card number') || 'Kart belgisi'} required value={form.cardNumber} onChange={(v) => set("cardNumber", v)} placeholder={t('Card number') || 'Kart belgisi'} error={errors.cardNumber} />
|
||||
<FormInput type="text" label={t('Name on card') || 'Kartdaky ady'} required value={form.cardName} onChange={(v) => set("cardName", v)} placeholder={t('Name on card') || 'Kartdaky ady'} error={errors.cardName} />
|
||||
</BentoCard>
|
||||
<BentoCard title="Kart möhleti">
|
||||
<FormInput type="searchable-select" label="Aý" required value={form.cardExpMonth} onChange={(v) => set("cardExpMonth", v)} options={MONTH_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.cardExpMonth} />
|
||||
<FormInput type="searchable-select" label="Ýyl" required value={form.cardExpYear} onChange={(v) => set("cardExpYear", v)} options={YEAR_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.cardExpYear} />
|
||||
<BentoCard title={t('loanOrderForm.titles.cardExpiry') || 'Kart möhleti'}>
|
||||
<FormInput type="searchable-select" label={t('loanOrderForm.labels.cardExpMonth') || 'Aý'} required value={form.cardExpMonth} onChange={(v) => set("cardExpMonth", v)} options={MONTH_OPTIONS} placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'} error={errors.cardExpMonth} />
|
||||
<FormInput type="searchable-select" label={t('loanOrderForm.labels.cardExpYear') || 'Ýyl'} required value={form.cardExpYear} onChange={(v) => set("cardExpYear", v)} options={YEAR_OPTIONS} placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'} error={errors.cardExpYear} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Guarantor identity */}
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Zamunyň ady" required value={form.guarantor1Name} onChange={(v) => set("guarantor1Name", v)} placeholder="Zamunyň ady" error={errors.guarantor1Name} />
|
||||
<FormInput type="text" label={t('Guarantor name') || 'Zamunyň ady'} required value={form.guarantor1Name} onChange={(v) => set("guarantor1Name", v)} placeholder={t('Guarantor name') || 'Zamunyň ady'} error={errors.guarantor1Name} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Zamunyň familiýasy" required value={form.guarantor1Surname} onChange={(v) => set("guarantor1Surname", v)} placeholder="Zamunyň familiýasy" error={errors.guarantor1Surname} />
|
||||
<FormInput type="text" label={t('Guarantor Surname') || 'Zamunyň familiýasy'} required value={form.guarantor1Surname} onChange={(v) => set("guarantor1Surname", v)} placeholder={t('Guarantor Surname') || 'Zamunyň familiýasy'} error={errors.guarantor1Surname} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Zamunyň atasynyň ady" value={form.guarantor1Patronic} onChange={(v) => set("guarantor1Patronic", v)} placeholder="Zamunyň atasynyň ady" />
|
||||
<FormInput type="text" label={t('Guarantor Patronic name') || 'Zamunyň atasynyň ady'} value={form.guarantor1Patronic} onChange={(v) => set("guarantor1Patronic", v)} placeholder={t('Guarantor Patronic name') || 'Zamunyň atasynyň ady'} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Guarantor passport */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput type="searchable-select" label="Pasport seriýasy" required value={form.guarantor1PassportSerie} onChange={(v) => set("guarantor1PassportSerie", v)} options={PASSPORT_SERIES_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.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={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'} error={errors.guarantor1PassportSerie} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="text" label="Pasport belgisi" required value={form.guarantor1PassportNumber} onChange={(v) => set("guarantor1PassportNumber", v)} placeholder="Pasport belgisi" error={errors.guarantor1PassportNumber} />
|
||||
<FormInput type="text" label={t('Passport id') || 'Pasport belgisi'} required value={form.guarantor1PassportNumber} onChange={(v) => set("guarantor1PassportNumber", v)} placeholder={t('Passport id') || 'Pasport belgisi'} error={errors.guarantor1PassportNumber} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Guarantor card */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Zamunyň kart maglumatlary">
|
||||
<FormInput type="text" label="Kart belgisi" required value={form.guarantor1CardNumber} onChange={(v) => set("guarantor1CardNumber", v)} placeholder="Kart belgisi" error={errors.guarantor1CardNumber} />
|
||||
<FormInput type="text" label="Kartdaky ady" required value={form.guarantor1CardName} onChange={(v) => set("guarantor1CardName", v)} placeholder="Kartdaky ady" error={errors.guarantor1CardName} />
|
||||
<BentoCard title={t('loanOrderForm.guarantorCardInfo') || 'Zamunyň kart maglumatlary'}>
|
||||
<FormInput type="text" label={t('Card number') || 'Kart belgisi'} required value={form.guarantor1CardNumber} onChange={(v) => set("guarantor1CardNumber", v)} placeholder={t('Card number') || 'Kart belgisi'} error={errors.guarantor1CardNumber} />
|
||||
<FormInput type="text" label={t('Name on card') || 'Kartdaky ady'} required value={form.guarantor1CardName} onChange={(v) => set("guarantor1CardName", v)} placeholder={t('Name on card') || 'Kartdaky ady'} error={errors.guarantor1CardName} />
|
||||
</BentoCard>
|
||||
<BentoCard title="Zamunyň kart möhleti">
|
||||
<FormInput type="searchable-select" label="Aý" required value={form.guarantor1CardExpMonth} onChange={(v) => set("guarantor1CardExpMonth", v)} options={MONTH_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.guarantor1CardExpMonth} />
|
||||
<FormInput type="searchable-select" label="Ýyl" required value={form.guarantor1CardExpYear} onChange={(v) => set("guarantor1CardExpYear", v)} options={YEAR_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.guarantor1CardExpYear} />
|
||||
<FormInput type="number" label="Ortaca zähmet haky" required value={form.guarantor1Salary} onChange={(v) => set("guarantor1Salary", v)} placeholder="Ortaca zähmet haky" error={errors.guarantor1Salary} />
|
||||
<BentoCard title={t('loanOrderForm.guarantorCardExpiry') || 'Zamunyň kart möhleti'}>
|
||||
<FormInput type="searchable-select" label={t('Expiration month') || 'Aý'} required value={form.guarantor1CardExpMonth} onChange={(v) => set("guarantor1CardExpMonth", v)} options={MONTH_OPTIONS} placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'} error={errors.guarantor1CardExpMonth} />
|
||||
<FormInput type="searchable-select" label={t('Expiration year') || 'Ýyl'} required value={form.guarantor1CardExpYear} onChange={(v) => set("guarantor1CardExpYear", v)} options={YEAR_OPTIONS} placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'} error={errors.guarantor1CardExpYear} />
|
||||
<FormInput type="number" label={t('loanOrderForm.labels.guarantor1Salary') || 'Ortaca zähmet haky'} required value={form.guarantor1Salary} onChange={(v) => set("guarantor1Salary", v)} placeholder={t('loanOrderForm.labels.guarantor1Salary') || 'Ortaca zähmet haky'} error={errors.guarantor1Salary} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
@@ -430,49 +420,46 @@ function StepCard({ form, errors, set }: StepContentProps) {
|
||||
}
|
||||
|
||||
function StepFiles({
|
||||
form, errors, set, mode, initialData,
|
||||
form, errors, set, t, mode, initialData,
|
||||
}: StepContentProps & { mode: "create" | "edit"; initialData?: LoanOrderMobile }) {
|
||||
const existingFiles =
|
||||
mode === "edit" && initialData
|
||||
? [
|
||||
{ url: initialData.passportPage1Url, label: "Pasport (sahypa 1)" },
|
||||
{ url: initialData.passportPage23Url, label: "Pasport (2-3-nji sahypa)" },
|
||||
{ url: initialData.passportPage89Url, label: "Pasport (8-9 sahypa)" },
|
||||
{ url: initialData.passportPage32Url, label: "Pasport (32-nji sahypa)" },
|
||||
{ url: initialData.passportPage1Url, label: t('Passport (page 1)') || "Pasport (sahypa 1)" },
|
||||
{ url: initialData.passportPage23Url, label: t('Passport (page 2-3)') || "Pasport (2-3-nji sahypa)" },
|
||||
{ url: initialData.passportPage89Url, label: t('Passport (page 8-9)') || "Pasport (8-9 sahypa)" },
|
||||
{ url: initialData.passportPage32Url, label: t('Passport (page 32)') || "Pasport (32-nji sahypa)" },
|
||||
].filter((f): f is { url: string; label: string } => !!f.url)
|
||||
: [];
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Status & note */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput type="select" label="Status" required value={form.status} onChange={(v) => set("status", v)} options={STATUS_OPTIONS} placeholder="Saýlaň" error={errors.status} />
|
||||
<FormInput type="select" label={t('loanOrderForm.labels.status') || 'Status'} required value={form.status} onChange={(v) => set("status", v)} options={STATUS_OPTIONS} placeholder={t('loanOrderForm.placeholders.select') || 'Saýlaň'} error={errors.status} />
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput type="textarea" label="Bellik" value={form.note} onChange={(v) => set("note", v)} placeholder="Bellik..." rows={3} />
|
||||
<FormInput type="textarea" label={t('Note') || 'Bellik'} value={form.note} onChange={(v) => set("note", v)} placeholder={t('loanOrderForm.placeholders.note') || 'Bellik...'} rows={3} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Existing files (edit mode) */}
|
||||
{existingFiles.length > 0 && (
|
||||
<BentoGrid cols={4}>
|
||||
{existingFiles.map(({ url, label }) => (
|
||||
<BentoCard key={label} title={label}>
|
||||
<a href={url} target="_blank" rel="noopener noreferrer" className="text-xs text-primary underline truncate block">
|
||||
Faýly gör
|
||||
{t('loanOrderForm.fileLabels.viewFile') || 'Faýly gör'}
|
||||
</a>
|
||||
</BentoCard>
|
||||
))}
|
||||
</BentoGrid>
|
||||
)}
|
||||
|
||||
{/* File uploads */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={mode === "edit" ? "Pasport (sahypa 1) (çalyşmak)" : "Pasport (sahypa 1)"}
|
||||
label={mode === "edit" ? (t('loanOrderForm.fileLabels.replacePage1') || 'Pasport (sahypa 1) (çalyşmak)') : (t('Passport (page 1)') || 'Pasport (sahypa 1)')}
|
||||
required={mode === "create"}
|
||||
accept="image/*"
|
||||
fileValue={form.passportPage1}
|
||||
@@ -483,7 +470,7 @@ function StepFiles({
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={mode === "edit" ? "Pasport (2-3-nji sahypa) (çalyşmak)" : "Pasport (2-3-nji sahypa)"}
|
||||
label={mode === "edit" ? (t('loanOrderForm.fileLabels.replacePage23') || 'Pasport (2-3-nji sahypa) (çalyşmak)') : (t('Passport (page 2-3)') || 'Pasport (2-3-nji sahypa)')}
|
||||
required={mode === "create"}
|
||||
accept="image/*"
|
||||
fileValue={form.passportPage23}
|
||||
@@ -494,7 +481,7 @@ function StepFiles({
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label="Pasport (8-9 sahypa)"
|
||||
label={t('Passport (page 8-9)') || 'Pasport (8-9 sahypa)'}
|
||||
accept="image/*"
|
||||
fileValue={form.passportPage89}
|
||||
onFileChange={(f) => set("passportPage89", f)}
|
||||
@@ -503,7 +490,7 @@ function StepFiles({
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label="Pasport (32-nji sahypa)"
|
||||
label={t('Passport (page 32)') || 'Pasport (32-nji sahypa)'}
|
||||
accept="image/*"
|
||||
fileValue={form.passportPage32}
|
||||
onFileChange={(f) => set("passportPage32", f)}
|
||||
@@ -525,7 +512,7 @@ interface LoanOrderMobileFormProps {
|
||||
// ─── Main Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrderMobileFormProps) {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const createMutation = useCreateLoanOrderMobile();
|
||||
@@ -533,16 +520,15 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
const isPending = createMutation.isPending || updateMutation.isPending;
|
||||
|
||||
const {
|
||||
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors,
|
||||
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError,
|
||||
} = useForm<LoanOrderMobileFormData>({ defaultValues: initialData ? { ...DEFAULT_FORM_VALUES, ...mapInitial(initialData) } : DEFAULT_FORM_VALUES });
|
||||
|
||||
const form = watch();
|
||||
const errors = useMemo(() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>), [rhfErrors]);
|
||||
|
||||
const [currentStep, setCurrentStep] = useState(0);
|
||||
const [visited, setVisited] = useState<Set<number>>(
|
||||
() => mode === "edit" ? new Set(STEPS.map((_, i) => i)) : new Set<number>(),
|
||||
);
|
||||
const [submittedSteps, setSubmittedSteps] = useState<Set<number>>(new Set());
|
||||
|
||||
const stepsWithErrors = useMemo(() => {
|
||||
const out = new Set<number>();
|
||||
@@ -550,24 +536,43 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
if (Object.keys(STEPS[i].validate(form, mode)).length > 0) out.add(i);
|
||||
});
|
||||
return out;
|
||||
}, [form, mode, visited]);
|
||||
}, [form, mode, visited, i18n.language]);
|
||||
|
||||
const set = useCallback(<K extends keyof LoanOrderMobileFormData>(key: K, value: LoanOrderMobileFormData[K]) => {
|
||||
(setValue as (name: K, val: LoanOrderMobileFormData[K]) => void)(key, value);
|
||||
clearErrors(key);
|
||||
}, [setValue, clearErrors]);
|
||||
|
||||
const stepProps = useMemo(() => ({ form, errors, set }), [form, errors, set]);
|
||||
const allSubmittedErrors = useMemo(() => {
|
||||
const result: FlatErrors = {};
|
||||
for (const stepIdx of submittedSteps) {
|
||||
Object.assign(result, STEPS[stepIdx].validate(form, mode));
|
||||
}
|
||||
return result;
|
||||
}, [form, mode, submittedSteps, i18n.language]);
|
||||
const errors = useMemo(() => {
|
||||
const fromRHF = flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>)
|
||||
return { ...fromRHF, ...allSubmittedErrors }
|
||||
}, [rhfErrors, allSubmittedErrors]);
|
||||
|
||||
const stepProps = useMemo(() => ({ form, errors, set, t }), [form, errors, set, t]);
|
||||
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
|
||||
const markVisited = (i: number) =>
|
||||
setVisited((prev) => new Set([...prev, i]));
|
||||
|
||||
const markSubmitted = (i: number) =>
|
||||
setSubmittedSteps((prev) => new Set([...prev, i]));
|
||||
|
||||
const handleNext = () => {
|
||||
markVisited(currentStep);
|
||||
markSubmitted(currentStep);
|
||||
const errs = STEPS[currentStep].validate(form, mode);
|
||||
if (Object.keys(errs).length > 0) {
|
||||
Object.entries(errs).forEach(([key, msg]) => {
|
||||
setError(key as keyof LoanOrderMobileFormData, { type: "manual", message: msg });
|
||||
});
|
||||
toast.error(t("common.errors.fillRequiredCorrectly", "Dogry maglumat girizmegiňizi haýyş edýäris."));
|
||||
return;
|
||||
}
|
||||
@@ -595,11 +600,15 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
|
||||
const doSubmit = () => {
|
||||
setVisited(new Set(STEPS.map((_, i) => i)));
|
||||
setSubmittedSteps(new Set(STEPS.map((_, i) => i)));
|
||||
|
||||
const allErrors: FlatErrors = {};
|
||||
for (const step of STEPS) Object.assign(allErrors, step.validate(form, mode));
|
||||
|
||||
if (Object.keys(allErrors).length > 0) {
|
||||
Object.entries(allErrors).forEach(([key, msg]) => {
|
||||
setError(key as keyof LoanOrderMobileFormData, { type: "manual", message: msg });
|
||||
});
|
||||
toast.error(t("common.errors.requiredFieldsMissing", "Käbir hökmany meýdanlar doldurylan däldir."));
|
||||
for (let i = 0; i < STEPS.length; i++) {
|
||||
if (Object.keys(STEPS[i].validate(form, mode)).length > 0) {
|
||||
@@ -630,8 +639,8 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
const isDone = visited.has(i) && !hasErrors;
|
||||
return {
|
||||
id: s.id,
|
||||
title: t(s.title) || s.title,
|
||||
subtitle: s.subtitle,
|
||||
title: t(s.titleKey) || s.titleFallback,
|
||||
subtitle: t(s.subtitleKey) || s.subtitleFallback,
|
||||
icon: s.icon,
|
||||
status: isActive ? "active" : hasErrors ? "error" : isDone ? "done" : "idle",
|
||||
};
|
||||
@@ -647,11 +656,13 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === "create"
|
||||
? (t("Loan order create") || "Karz sargyt döredüň")
|
||||
: (t("Loan order edit") || "Karz sargydy üýtget")}
|
||||
? (t("loanOrderMobiles.createTitle") || "Karz sargyt döredüň")
|
||||
: (t("loanOrderMobiles.editTitle") || "Karz sargydy üýtget")}
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{t("Fill in all sections step by step") || "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň."}
|
||||
{mode === "create"
|
||||
? (t("loanOrderMobiles.createDescription") || "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.")
|
||||
: (t("loanOrderMobiles.editDescription") || "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,62 +1,60 @@
|
||||
import { z } from 'zod'
|
||||
import i18next from 'i18next'
|
||||
|
||||
const t = i18next.t.bind(i18next)
|
||||
|
||||
const fileRequired = z.custom<File>((val) => val instanceof File, t('validation.requiredFile', ''))
|
||||
const fileRequired = z.custom<File>((val) => val instanceof File, 'validation.requiredFile')
|
||||
|
||||
export const loanOrderMobileFormSchema = z.object({
|
||||
status: z.string().min(1, t('validation.required', '')),
|
||||
loanType: z.string().min(1, t('validation.required', '')),
|
||||
region: z.string().min(1, t('validation.required', '')),
|
||||
branch: z.string().min(1, t('validation.required', '')),
|
||||
firstName: z.string().min(1, t('validation.required', '')),
|
||||
lastName: z.string().min(1, t('validation.required', '')),
|
||||
status: z.string().min(1, 'validation.required'),
|
||||
loanType: z.string().min(1, 'validation.required'),
|
||||
region: z.string().min(1, 'validation.required'),
|
||||
branch: z.string().min(1, 'validation.required'),
|
||||
firstName: z.string().min(1, 'validation.required'),
|
||||
lastName: z.string().min(1, 'validation.required'),
|
||||
patronicName: z.string().optional(),
|
||||
education: z.string().min(1, t('validation.required', '')),
|
||||
marriageStatus: z.string().min(1, t('validation.required', '')),
|
||||
dateOfBirth: z.string().min(1, t('validation.required', '')),
|
||||
residence: z.string().min(1, t('validation.required', '')),
|
||||
education: z.string().min(1, 'validation.required'),
|
||||
marriageStatus: z.string().min(1, 'validation.required'),
|
||||
dateOfBirth: z.string().min(1, 'validation.required'),
|
||||
residence: z.string().min(1, 'validation.required'),
|
||||
currentResidence: z.string().optional(),
|
||||
passportSerie: z.string().min(1, t('validation.required', '')),
|
||||
passportNumber: z.string().min(1, t('validation.required', '')),
|
||||
passportDateOfIssue: z.string().min(1, t('validation.required', '')),
|
||||
passportGivenBy: z.string().min(1, t('validation.required', '')),
|
||||
passportSerie: z.string().min(1, 'validation.required'),
|
||||
passportNumber: z.string().min(1, 'validation.required'),
|
||||
passportDateOfIssue: z.string().min(1, 'validation.required'),
|
||||
passportGivenBy: z.string().min(1, 'validation.required'),
|
||||
bornPlace: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
phone: z.string()
|
||||
.min(1, t('validation.required', ''))
|
||||
.refine((val) => val.replace(/\D/g, '').length >= 8, { message: t('validation.invalidPhone', 'Telefon belgisi nädogry') }),
|
||||
.min(1, 'validation.required')
|
||||
.refine((val) => val.replace(/\D/g, '').length >= 8, { message: 'validation.invalidPhone' }),
|
||||
phoneAdditional: z.string().optional(),
|
||||
homePhone: z.string().optional(),
|
||||
workCompany: z.string().min(1, t('validation.required', '')),
|
||||
workCompany: z.string().min(1, 'validation.required'),
|
||||
workHrPhone: z.string().optional(),
|
||||
workRegion: z.string().optional(),
|
||||
workProvince: z.string().optional(),
|
||||
position: z.string().min(1, t('validation.required', '')),
|
||||
salary: z.string().min(1, t('validation.required', '')),
|
||||
workStartedAt: z.string().min(1, t('validation.required', '')),
|
||||
position: z.string().min(1, 'validation.required'),
|
||||
salary: z.string().min(1, 'validation.required'),
|
||||
workStartedAt: z.string().min(1, 'validation.required'),
|
||||
passportPage1: z.custom<File | null>().nullable(),
|
||||
passportPage23: z.custom<File | null>().nullable(),
|
||||
passportPage89: z.custom<File | null>().nullable(),
|
||||
passportPage32: z.custom<File | null>().nullable(),
|
||||
note: z.string().optional(),
|
||||
loanAmount: z.string().min(1, t('validation.required', '')),
|
||||
loanAmount: z.string().min(1, 'validation.required'),
|
||||
loanHistory: z.string().optional(),
|
||||
cardNumber: z.string().min(1, t('validation.required', '')),
|
||||
cardName: z.string().min(1, t('validation.required', '')),
|
||||
cardExpMonth: z.string().min(1, t('validation.required', '')),
|
||||
cardExpYear: z.string().min(1, t('validation.required', '')),
|
||||
guarantor1Name: z.string().min(1, t('validation.required', '')),
|
||||
guarantor1Surname: z.string().min(1, t('validation.required', '')),
|
||||
cardNumber: z.string().min(1, 'validation.required'),
|
||||
cardName: z.string().min(1, 'validation.required'),
|
||||
cardExpMonth: z.string().min(1, 'validation.required'),
|
||||
cardExpYear: z.string().min(1, 'validation.required'),
|
||||
guarantor1Name: z.string().min(1, 'validation.required'),
|
||||
guarantor1Surname: z.string().min(1, 'validation.required'),
|
||||
guarantor1Patronic: z.string().optional(),
|
||||
guarantor1PassportSerie: z.string().min(1, t('validation.required', '')),
|
||||
guarantor1PassportNumber: z.string().min(1, t('validation.required', '')),
|
||||
guarantor1CardNumber: z.string().min(1, t('validation.required', '')),
|
||||
guarantor1CardName: z.string().min(1, t('validation.required', '')),
|
||||
guarantor1CardExpMonth: z.string().min(1, t('validation.required', '')),
|
||||
guarantor1CardExpYear: z.string().min(1, t('validation.required', '')),
|
||||
guarantor1Salary: z.string().min(1, t('validation.required', '')),
|
||||
guarantor1PassportSerie: z.string().min(1, 'validation.required'),
|
||||
guarantor1PassportNumber: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardNumber: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardName: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardExpMonth: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardExpYear: z.string().min(1, 'validation.required'),
|
||||
guarantor1Salary: z.string().min(1, 'validation.required'),
|
||||
})
|
||||
|
||||
export type LoanOrderMobileFormData = z.infer<typeof loanOrderMobileFormSchema>
|
||||
@@ -94,7 +92,10 @@ export function validateStep(stepIndex: number, form: LoanOrderMobileFormData, m
|
||||
const errors: Partial<Record<keyof LoanOrderMobileFormData, string>> = {}
|
||||
for (const issue of result.error.issues) {
|
||||
const key = issue.path[0] as keyof LoanOrderMobileFormData
|
||||
if (!errors[key]) errors[key] = issue.message
|
||||
if (!errors[key]) {
|
||||
const msg = issue.message
|
||||
errors[key] = msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
||||
}
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user