added lang support to loans

This commit is contained in:
@jcarymuhammedow
2026-05-16 17:06:04 +05:00
parent d832949746
commit 35164d16d3
24 changed files with 1254 additions and 668 deletions

View File

@@ -6,7 +6,7 @@ import { FormInput } from '@/components/formInput'
import { FormActions } from '@/components/formActions'
import { type CardBalance } from '@/features/cardBalance/api/cardBalanceApi'
import { useCreateCardBalance, useUpdateCardBalance } from '@/features/cardBalance/hooks/useCardBalance'
import { DEFAULT_FORM_VALUES, buildPayload } from '@/features/cardBalance/schemas/cardBalance.schema'
import { cardBalanceFormSchema, DEFAULT_FORM_VALUES, buildPayload } from '@/features/cardBalance/schemas/cardBalance.schema'
import type { CardBalanceFormData } from '@/features/cardBalance/schemas/cardBalance.schema'
interface CardBalanceFormProps {
@@ -65,7 +65,7 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
const isPending = createMutation.isPending || updateMutation.isPending
const {
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors,
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError,
} = useForm<CardBalanceFormData>({
defaultValues: initialData ? { ...DEFAULT_FORM_VALUES, ...initialData } : DEFAULT_FORM_VALUES,
})
@@ -78,8 +78,19 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
clearErrors(field)
}, [setValue, clearErrors])
const errMsg = (msg: string | undefined) =>
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
const handleSubmit = async () => {
const payload = buildPayload(getValues())
const result = cardBalanceFormSchema.safeParse(getValues())
if (!result.success) {
for (const issue of result.error.issues) {
const key = issue.path[0] as keyof CardBalanceFormData
setError(key, { message: issue.message })
}
return
}
const payload = buildPayload(result.data)
if (mode === 'create') {
await createMutation.mutateAsync(payload)
navigate('/card-balances')
@@ -105,7 +116,7 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
onChange={setField('passport_series')}
options={PASSPORT_SERIES_OPTIONS}
placeholder={t('Select to choose', 'Saýlamak üçin basyň')}
error={errors.passport_series}
error={errMsg(errors.passport_series)}
required
/>
<FormInput
@@ -114,7 +125,7 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
value={form.passport_number}
onChange={setField('passport_number')}
placeholder={t('Passport number', 'Pasport belgisi')}
error={errors.passport_number}
error={errMsg(errors.passport_number)}
required
/>
@@ -125,7 +136,7 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
value={form.card_number}
onChange={setField('card_number')}
placeholder={t('Card number', 'Kart belgisi')}
error={errors.card_number}
error={errMsg(errors.card_number)}
required
/>
@@ -137,7 +148,7 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
onChange={setField('card_expiry_month')}
options={MONTH_OPTIONS}
placeholder={t('Select', 'Saýlamak üçin basyň')}
error={errors.card_expiry_month}
error={errMsg(errors.card_expiry_month)}
required
/>
<FormInput
@@ -147,7 +158,7 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
onChange={setField('card_expiry_year')}
options={YEAR_OPTIONS}
placeholder={t('Select', 'Saýlamak üçin basyň')}
error={errors.card_expiry_year}
error={errMsg(errors.card_expiry_year)}
required
/>
</div>

View File

@@ -1,15 +1,12 @@
import { z } from 'zod'
import i18next from 'i18next'
import type { CreateCardBalancePayload } from '../api/cardBalanceApi'
const t = i18next.t.bind(i18next)
export const cardBalanceFormSchema = z.object({
passport_series: z.string().min(1, t('validation.required', '')),
passport_number: z.string().min(1, t('validation.required', '')),
card_number: z.string().min(1, t('validation.required', '')),
card_expiry_month: z.string().min(1, t('validation.required', '')),
card_expiry_year: z.string().min(1, t('validation.required', '')),
passport_series: z.string().min(1, 'validation.required'),
passport_number: z.string().min(1, 'validation.required'),
card_number: z.string().min(1, 'validation.required'),
card_expiry_month: z.string().min(1, 'validation.required'),
card_expiry_year: z.string().min(1, 'validation.required'),
})
export type CardBalanceFormData = z.infer<typeof cardBalanceFormSchema>

View File

@@ -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 { CreditCard, User, FileText } from 'lucide-react'
@@ -71,7 +72,8 @@ interface StepDef {
id: string
titleKey: string
titleFallback: string
subtitle: string
subtitleKey: string
subtitleFallback: string
icon: LucideIcon
validate: (form: CardPinFormData, mode: 'create' | 'edit') => FlatErrors
}
@@ -81,7 +83,8 @@ const STEPS: StepDef[] = [
id: 'card',
titleKey: 'cardPin.step.card',
titleFallback: 'Kart',
subtitle: 'Görnüş & lokasiýa',
subtitleKey: 'cardPinForm.steps.card.subtitle',
subtitleFallback: 'Görnüş & lokasiýa',
icon: CreditCard,
validate: (form, mode) => validateStep(0, form, mode),
},
@@ -89,7 +92,8 @@ const STEPS: StepDef[] = [
id: 'personal',
titleKey: 'cardPin.step.personal',
titleFallback: 'Şahsy',
subtitle: 'Maglumatlar',
subtitleKey: 'cardPinForm.steps.personal.subtitle',
subtitleFallback: 'Maglumatlar',
icon: User,
validate: (form, mode) => validateStep(1, form, mode),
},
@@ -97,7 +101,8 @@ const STEPS: StepDef[] = [
id: 'passport',
titleKey: 'cardPin.step.passport',
titleFallback: 'Pasport',
subtitle: 'Resminamalar',
subtitleKey: 'cardPinForm.steps.passport.subtitle',
subtitleFallback: 'Resminamalar',
icon: FileText,
validate: (form, mode) => validateStep(2, form, mode),
},
@@ -153,79 +158,80 @@ interface StepContentProps {
form: CardPinFormData
errors: FlatErrors
set: <K extends keyof CardPinFormData>(k: K, v: CardPinFormData[K]) => void
t: TFunction
}
// ─── Step panels ──────────────────────────────────────────────────────────────
function StepCard({ form, errors, set }: StepContentProps) {
function StepCard({ form, errors, set, t }: StepContentProps) {
return (
<div className="space-y-4">
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="select"
label="Status"
label={t('loanOrderForm.labels.status') || 'Status'}
required
value={form.status}
onChange={(v) => set('status', v)}
options={STATUS_OPTIONS}
error={errors.status}
placeholder="Saýlaň"
placeholder={t('loanOrderForm.placeholders.select') || 'Saýlaň'}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label="Bellik"
label={t('Note') || 'Bellik'}
value={form.note}
onChange={(v) => set('note', v)}
placeholder="Bellik..."
placeholder={t('loanOrderForm.placeholders.note') || 'Bellik...'}
/>
</BentoCard>
</BentoGrid>
<BentoGrid cols={2}>
<BentoCard title="Kart maglumatlary">
<BentoCard title={t('loanOrderForm.titles.cardInfo') || 'Kart maglumatlary'}>
<FormInput
type="searchable-select"
label="Kart görnüşi"
label={t('Loan type') || 'Kart görnüşi'}
required
value={form.card_type}
onChange={(v) => set('card_type', v)}
options={CARD_TYPE_OPTIONS}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errors.card_type}
/>
<FormInput
type="text"
label="Kart belgisi"
label={t('Card number') || 'Kart belgisi'}
required
value={form.card_number}
onChange={(v) => set('card_number', v)}
placeholder="Kart belgisi"
placeholder={t('Card number') || 'Kart belgisi'}
error={errors.card_number}
/>
</BentoCard>
<BentoCard title="Lokasiýa">
<BentoCard title={t('cardPinForm.titles.location') || 'Lokasiýa'}>
<FormInput
type="searchable-select"
label="Welaýat"
label={t('Region') || 'Welaýat'}
required
value={form.province}
onChange={(v) => { set('province', v); set('branch', '') }}
options={PROVINCE_OPTIONS}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errors.province}
/>
<FormInput
type="searchable-select"
label="Şahamça"
label={t('Branch') || 'Şahamça'}
required
value={form.branch}
onChange={(v) => set('branch', v)}
options={[]}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
disabled={!form.province}
error={errors.branch}
/>
@@ -235,29 +241,29 @@ function StepCard({ form, errors, set }: StepContentProps) {
)
}
function StepPersonal({ form, errors, set }: StepContentProps) {
function StepPersonal({ form, errors, set, t }: StepContentProps) {
return (
<div className="space-y-4">
<BentoGrid cols={3}>
<BentoCard>
<FormInput
type="text" label="Ady" required
type="text" label={t('Name') || 'Ady'} required
value={form.first_name} onChange={(v) => set('first_name', v)}
placeholder="Ady" error={errors.first_name}
placeholder={t('Name') || 'Ady'} error={errors.first_name}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text" label="Familiýasy" required
type="text" label={t('Surname') || 'Familiýasy'} required
value={form.last_name} onChange={(v) => set('last_name', v)}
placeholder="Familiýasy" error={errors.last_name}
placeholder={t('Surname') || 'Familiýasy'} error={errors.last_name}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text" label="Atasynyň ady"
type="text" label={t('Patronic name') || 'Atasynyň ady'}
value={form.father_name} onChange={(v) => set('father_name', v)}
placeholder="Atasynyň ady"
placeholder={t('Patronic name') || 'Atasynyň ady'}
/>
</BentoCard>
</BentoGrid>
@@ -265,14 +271,14 @@ function StepPersonal({ form, errors, set }: StepContentProps) {
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="date" label="Doglan güni" required
type="date" label={t('Date of birth') || 'Doglan güni'} required
value={form.birth_date} onChange={(v) => set('birth_date', v)}
error={errors.birth_date}
/>
</BentoCard>
<BentoCard>
<FormInput
type="phone" label="Telefon" required
type="phone" label={t('Phone') || 'Telefon'} required
value={form.phone} onChange={(v) => set('phone', v)}
error={errors.phone}
/>
@@ -282,17 +288,17 @@ function StepPersonal({ form, errors, set }: StepContentProps) {
)
}
function StepPassport({ form, errors, set, mode, initialData }: StepContentProps & {
function StepPassport({ form, errors, set, t, mode, initialData }: StepContentProps & {
mode: 'create' | 'edit'
initialData?: CardPinItem
}) {
const existingFiles =
mode === 'edit' && initialData
? [
{ url: initialData.passport_file_1, label: 'Pasport (sahypa 1)' },
{ url: initialData.passport_file_2, label: 'Pasport (2-3-nji sahypa)' },
{ url: initialData.passport_file_3, label: 'Pasport (8-9 sahypa)' },
{ url: initialData.passport_file_4, label: 'Pasport (32-nji sahypa)' },
{ url: initialData.passport_file_1, label: t('Passport (page 1)') || 'Pasport (sahypa 1)' },
{ url: initialData.passport_file_2, label: t('Passport (page 2-3)') || 'Pasport (2-3-nji sahypa)' },
{ url: initialData.passport_file_3, label: t('Passport (page 8-9)') || 'Pasport (8-9 sahypa)' },
{ url: initialData.passport_file_4, label: t('Passport (page 32)') || 'Pasport (32-nji sahypa)' },
].filter((f): f is { url: string; label: string } => !!f.url)
: []
@@ -302,23 +308,23 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<BentoCard>
<FormInput
type="searchable-select"
label="Pasport seriýasy"
label={t('Passport serie') || 'Pasport seriýasy'}
required
value={form.passport_series}
onChange={(v) => set('passport_series', v)}
options={PASSPORT_SERIES_OPTIONS}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errors.passport_series}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label="Pasport belgisi"
label={t('Passport id') || 'Pasport belgisi'}
required
value={form.passport_number}
onChange={(v) => set('passport_number', v)}
placeholder="Pasport belgisi"
placeholder={t('Passport id') || 'Pasport belgisi'}
error={errors.passport_number}
/>
</BentoCard>
@@ -334,7 +340,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
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>
))}
@@ -345,7 +351,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<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/*,.pdf"
fileValue={form.passport_file_1}
@@ -356,7 +362,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<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/*,.pdf"
fileValue={form.passport_file_2}
@@ -367,7 +373,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<BentoCard>
<FormInput
type="file"
label={mode === 'edit' ? 'Pasport (8-9 sahypa) (çalyşmak)' : 'Pasport (8-9 sahypa)'}
label={t('Passport (page 8-9)') || 'Pasport (8-9 sahypa)'}
required={mode === 'create'}
accept="image/*,.pdf"
fileValue={form.passport_file_3}
@@ -378,7 +384,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<BentoCard>
<FormInput
type="file"
label={mode === 'edit' ? 'Pasport (32-nji sahypa) (çalyşmak)' : 'Pasport (32-nji sahypa)'}
label={t('Passport (page 32)') || 'Pasport (32-nji sahypa)'}
required={mode === 'create'}
accept="image/*,.pdf"
fileValue={form.passport_file_4}
@@ -394,11 +400,11 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
// ─── Main Component ───────────────────────────────────────────────────────────
export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardPinFormProps) {
const { t } = useTranslation()
const { t, i18n } = useTranslation()
const navigate = useNavigate()
const {
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors,
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError,
} = useForm<CardPinFormData>({
defaultValues: initialData
? { ...DEFAULT_FORM_VALUES, ...mapInitial(initialData) }
@@ -406,12 +412,11 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
})
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())
// ── Computed step errors ───────────────────────────────────────────────────
@@ -421,7 +426,7 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
if (Object.keys(STEPS[i].validate(form, mode)).length > 0) out.add(i)
})
return out
}, [form, mode, visited])
}, [form, mode, visited, i18n.language])
// ── set helper ─────────────────────────────────────────────────────────────
@@ -430,17 +435,36 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
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 CardPinFormData, { type: 'manual', message: msg })
})
toast.error(t('common.errors.fillRequiredCorrectly', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
return
}
@@ -464,12 +488,16 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
const handleSubmit = () => {
setVisited(new Set(STEPS.map((_, i) => i)))
setSubmittedSteps(new Set(STEPS.map((_, i) => i)))
const values = getValues()
const allErrors: FlatErrors = {}
for (const step of STEPS) Object.assign(allErrors, step.validate(values, mode))
if (Object.keys(allErrors).length > 0) {
Object.entries(allErrors).forEach(([key, msg]) => {
setError(key as keyof CardPinFormData, { 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(values, mode)).length > 0) {
@@ -510,7 +538,7 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
return {
id: s.id,
title: t(s.titleKey) || s.titleFallback,
subtitle: s.subtitle,
subtitle: t(s.subtitleKey) || s.subtitleFallback,
icon: s.icon,
status: isActive ? 'active' : hasErrors ? 'error' : isDone ? 'done' : 'idle',
}

View File

@@ -1,24 +1,22 @@
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 cardPinFormSchema = z.object({
status: z.string().min(1, t('validation.required', '')),
status: z.string().min(1, 'validation.required'),
note: z.string().optional(),
card_type: z.string().min(1, t('validation.required', '')),
card_number: z.string().min(1, t('validation.required', '')),
province: z.string().min(1, t('validation.required', '')),
branch: z.string().min(1, t('validation.required', '')),
first_name: z.string().min(1, t('validation.required', '')),
last_name: z.string().min(1, t('validation.required', '')),
card_type: z.string().min(1, 'validation.required'),
card_number: z.string().min(1, 'validation.required'),
province: z.string().min(1, 'validation.required'),
branch: z.string().min(1, 'validation.required'),
first_name: z.string().min(1, 'validation.required'),
last_name: z.string().min(1, 'validation.required'),
father_name: z.string().optional(),
birth_date: z.string().min(1, t('validation.required', '')),
phone: z.string().min(1, t('validation.required', '')),
passport_series: z.string().min(1, t('validation.required', '')),
passport_number: z.string().min(1, t('validation.required', '')),
birth_date: z.string().min(1, 'validation.required'),
phone: z.string().min(1, 'validation.required'),
passport_series: z.string().min(1, 'validation.required'),
passport_number: z.string().min(1, 'validation.required'),
passport_file_1: z.custom<File | null>().nullable(),
passport_file_2: z.custom<File | null>().nullable(),
passport_file_3: z.custom<File | null>().nullable(),
@@ -55,8 +53,8 @@ export const stepSchemas: Record<number, z.ZodType<Partial<CardPinFormData>>> =
first_name: true, last_name: true, birth_date: true, phone: true,
}),
2: z.object({
passport_series: z.string().min(1, t('validation.required', '')),
passport_number: z.string().min(1, t('validation.required', '')),
passport_series: z.string().min(1, 'validation.required'),
passport_number: z.string().min(1, 'validation.required'),
passport_file_1: fileRequired,
passport_file_2: fileRequired,
passport_file_3: fileRequired,
@@ -64,6 +62,10 @@ export const stepSchemas: Record<number, z.ZodType<Partial<CardPinFormData>>> =
}),
}
function translateMsg(msg: string): string {
return msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
}
export function validateStep(
stepIndex: number,
form: CardPinFormData,
@@ -76,7 +78,7 @@ export function validateStep(
const errors: Partial<Record<keyof CardPinFormData, string>> = {}
for (const issue of result.error.issues) {
const key = issue.path[0] as keyof CardPinFormData
if (!errors[key]) errors[key] = issue.message
if (!errors[key]) errors[key] = translateMsg(issue.message)
}
return errors
}
@@ -88,7 +90,7 @@ export function validateStep(
const errors: Partial<Record<keyof CardPinFormData, string>> = {}
for (const issue of result.error.issues) {
const key = issue.path[0] as keyof CardPinFormData
if (!errors[key]) errors[key] = issue.message
if (!errors[key]) errors[key] = translateMsg(issue.message)
}
return errors
}

View File

@@ -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 { CreditCard, User, FileText } from 'lucide-react'
@@ -113,7 +114,8 @@ interface StepDef {
id: string
titleKey: string
titleFallback: string
subtitle: string
subtitleKey: string
subtitleFallback: string
icon: LucideIcon
validate: (form: CardRequisiteFormData, mode: 'create' | 'edit') => FlatErrors
}
@@ -123,7 +125,8 @@ const STEPS: StepDef[] = [
id: 'card',
titleKey: 'Card',
titleFallback: 'Kart',
subtitle: 'Görnüş & lokasiýa',
subtitleKey: 'cardRequisiteForm.steps.card.subtitle',
subtitleFallback: 'Görnüş & lokasiýa',
icon: CreditCard,
validate: (form, mode) => validateStep(0, form, mode),
},
@@ -131,7 +134,8 @@ const STEPS: StepDef[] = [
id: 'personal',
titleKey: 'Personal',
titleFallback: 'Şahsy',
subtitle: 'At & telefon',
subtitleKey: 'cardRequisiteForm.steps.personal.subtitle',
subtitleFallback: 'At & telefon',
icon: User,
validate: (form, mode) => validateStep(1, form, mode),
},
@@ -139,7 +143,8 @@ const STEPS: StepDef[] = [
id: 'passport',
titleKey: 'Passport',
titleFallback: 'Pasport',
subtitle: 'Resminamalar',
subtitleKey: 'cardRequisiteForm.steps.passport.subtitle',
subtitleFallback: 'Resminamalar',
icon: FileText,
validate: (form, mode) => validateStep(2, form, mode),
},
@@ -195,11 +200,12 @@ interface StepContentProps {
form: CardRequisiteFormData
errors: FlatErrors
set: <K extends keyof CardRequisiteFormData>(k: K, v: CardRequisiteFormData[K]) => void
t: TFunction
}
// ─── Step panels ──────────────────────────────────────────────────────────────
function StepCard({ form, errors, set }: StepContentProps) {
function StepCard({ form, errors, set, t }: StepContentProps) {
const branchOptions = BRANCH_OPTIONS[form.province_id] ?? []
return (
@@ -208,31 +214,31 @@ function StepCard({ form, errors, set }: StepContentProps) {
<BentoCard>
<FormInput
type="select"
label="Status"
label={t('loanOrderForm.labels.status') || 'Status'}
required
value={form.status}
onChange={(v) => set('status', v)}
options={STATUS_OPTIONS}
error={errors.status}
placeholder="Saýlaň"
placeholder={t('loanOrderForm.placeholders.select') || 'Saýlaň'}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label="Bellik"
label={t('Note') || 'Bellik'}
value={form.note}
onChange={(v) => set('note', v)}
placeholder="Bellik..."
placeholder={t('loanOrderForm.placeholders.note') || 'Bellik...'}
/>
</BentoCard>
</BentoGrid>
<BentoGrid cols={2}>
<BentoCard title="Kart maglumatlary">
<BentoCard title={t('loanOrderForm.titles.cardInfo') || 'Kart maglumatlary'}>
<FormInput
type="select"
label="Görnüşi"
label={t('cardRequisiteForm.labels.cardType') || 'Görnüşi'}
required
value={form.card_type}
onChange={(v) => set('card_type', v)}
@@ -242,34 +248,34 @@ function StepCard({ form, errors, set }: StepContentProps) {
/>
<FormInput
type="text"
label="Kart belgisi"
label={t('Card number') || 'Kart belgisi'}
required
value={form.card_number}
onChange={(v) => set('card_number', v)}
placeholder="Kart belgisi"
placeholder={t('Card number') || 'Kart belgisi'}
error={errors.card_number}
/>
</BentoCard>
<BentoCard title="Kart möhleti">
<BentoCard title={t('loanOrderForm.titles.cardExpiry') || 'Kart möhleti'}>
<FormInput
type="select"
label="Möhleti (aý)"
label={t('Expiration month') || 'Möhleti (aý)'}
required
value={form.card_expiry_month}
onChange={(v) => set('card_expiry_month', v)}
options={MONTH_OPTIONS}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errors.card_expiry_month}
/>
<FormInput
type="select"
label="Möhleti (ýyl)"
label={t('Expiration year') || 'Möhleti (ýyl)'}
required
value={form.card_expiry_year}
onChange={(v) => set('card_expiry_year', v)}
options={YEAR_OPTIONS}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errors.card_expiry_year}
/>
</BentoCard>
@@ -279,24 +285,24 @@ function StepCard({ form, errors, set }: StepContentProps) {
<BentoCard>
<FormInput
type="select"
label="Welaýat"
label={t('Region') || 'Welaýat'}
required
value={form.province_id}
onChange={(v) => { set('province_id', v); set('branch_id', '') }}
options={PROVINCE_OPTIONS}
placeholder="Aşgabat"
placeholder={t('Region') || 'Aşgabat'}
error={errors.province_id}
/>
</BentoCard>
<BentoCard>
<FormInput
type="searchable-select"
label="Şahamça"
label={t('Branch') || 'Şahamça'}
required
value={form.branch_id}
onChange={(v) => set('branch_id', v)}
options={branchOptions}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
disabled={!form.province_id}
error={errors.branch_id}
/>
@@ -306,29 +312,29 @@ function StepCard({ form, errors, set }: StepContentProps) {
)
}
function StepPersonal({ form, errors, set }: StepContentProps) {
function StepPersonal({ form, errors, set, t }: StepContentProps) {
return (
<div className="space-y-4">
<BentoGrid cols={3}>
<BentoCard>
<FormInput
type="text" label="Ady" required
type="text" label={t('Name') || 'Ady'} required
value={form.first_name} onChange={(v) => set('first_name', v)}
placeholder="Ady" error={errors.first_name}
placeholder={t('Name') || 'Ady'} error={errors.first_name}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text" label="Familiýasy" required
type="text" label={t('Surname') || 'Familiýasy'} required
value={form.last_name} onChange={(v) => set('last_name', v)}
placeholder="Familiýasy" error={errors.last_name}
placeholder={t('Surname') || 'Familiýasy'} error={errors.last_name}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text" label="Atasynyň ady"
type="text" label={t('Patronic name') || 'Atasynyň ady'}
value={form.middle_name} onChange={(v) => set('middle_name', v)}
placeholder="Atasynyň ady"
placeholder={t('Patronic name') || 'Atasynyň ady'}
/>
</BentoCard>
</BentoGrid>
@@ -336,14 +342,14 @@ function StepPersonal({ form, errors, set }: StepContentProps) {
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="date" label="Doglan güni" required
type="date" label={t('Date of birth') || 'Doglan güni'} required
value={form.birth_date} onChange={(v) => set('birth_date', v)}
error={errors.birth_date}
/>
</BentoCard>
<BentoCard>
<FormInput
type="phone" label="Telefon" required
type="phone" label={t('Phone') || 'Telefon'} required
value={form.phone} onChange={(v) => set('phone', v)}
placeholder="63 21 87 04"
error={errors.phone}
@@ -354,17 +360,17 @@ function StepPersonal({ form, errors, set }: StepContentProps) {
)
}
function StepPassport({ form, errors, set, mode, initialData }: StepContentProps & {
function StepPassport({ form, errors, set, t, mode, initialData }: StepContentProps & {
mode: 'create' | 'edit'
initialData?: CardRequisite
}) {
const existingFiles =
mode === 'edit' && initialData
? [
{ url: initialData.passport_page1_url, label: 'Pasport (sahypa 1)' },
{ url: initialData.passport_page2_3_url, label: 'Pasport (2-3-nji sahypa)' },
{ url: initialData.passport_page8_9_url, label: 'Pasport (8-9 sahypa)' },
{ url: initialData.passport_page32_url, label: 'Pasport (32-nji sahypa)' },
{ url: initialData.passport_page1_url, label: t('Passport (page 1)') || 'Pasport (sahypa 1)' },
{ url: initialData.passport_page2_3_url, label: t('Passport (page 2-3)') || 'Pasport (2-3-nji sahypa)' },
{ url: initialData.passport_page8_9_url, label: t('Passport (page 8-9)') || 'Pasport (8-9 sahypa)' },
{ url: initialData.passport_page32_url, label: t('Passport (page 32)') || 'Pasport (32-nji sahypa)' },
].filter((f): f is { url: string; label: string } => !!f.url)
: []
@@ -374,23 +380,23 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<BentoCard>
<FormInput
type="searchable-select"
label="Pasport seriýasy"
label={t('Passport serie') || 'Pasport seriýasy'}
required
value={form.passport_series}
onChange={(v) => set('passport_series', v)}
options={PASSPORT_SERIES_OPTIONS}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errors.passport_series}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label="Pasport belgisi"
label={t('Passport id') || 'Pasport belgisi'}
required
value={form.passport_number}
onChange={(v) => set('passport_number', v)}
placeholder="Pasport belgisi"
placeholder={t('Passport id') || 'Pasport belgisi'}
error={errors.passport_number}
/>
</BentoCard>
@@ -406,7 +412,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
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>
))}
@@ -417,7 +423,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<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/*,.pdf"
fileValue={form.passport_page1}
@@ -428,7 +434,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<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/*,.pdf"
fileValue={form.passport_page2_3}
@@ -439,7 +445,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<BentoCard>
<FormInput
type="file"
label={mode === 'edit' ? 'Pasport (8-9 sahypa) (çalyşmak)' : 'Pasport (8-9 sahypa)'}
label={t('Passport (page 8-9)') || 'Pasport (8-9 sahypa)'}
required={mode === 'create'}
accept="image/*,.pdf"
fileValue={form.passport_page8_9}
@@ -450,7 +456,7 @@ function StepPassport({ form, errors, set, mode, initialData }: StepContentProps
<BentoCard>
<FormInput
type="file"
label={mode === 'edit' ? 'Pasport (32-nji sahypa) (çalyşmak)' : 'Pasport (32-nji sahypa)'}
label={t('Passport (page 32)') || 'Pasport (32-nji sahypa)'}
required={mode === 'create'}
accept="image/*,.pdf"
fileValue={form.passport_page32}
@@ -470,7 +476,7 @@ export function CardRequisiteForm({
initialData,
cardRequisiteId,
}: CardRequisiteFormProps) {
const { t } = useTranslation()
const { t, i18n } = useTranslation()
const navigate = useNavigate()
const createMutation = useCreateCardRequisite()
@@ -478,18 +484,17 @@ export function CardRequisiteForm({
const isPending = createMutation.isPending || updateMutation.isPending
const {
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors,
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError,
} = useForm<CardRequisiteFormData>({
defaultValues: initialData ? 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())
// ── Computed step errors ───────────────────────────────────────────────────
@@ -499,7 +504,7 @@ export function CardRequisiteForm({
if (Object.keys(STEPS[i].validate(form, mode)).length > 0) out.add(i)
})
return out
}, [form, mode, visited])
}, [form, mode, visited, i18n.language])
// ── set helper ─────────────────────────────────────────────────────────────
@@ -508,17 +513,36 @@ export function CardRequisiteForm({
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 CardRequisiteFormData, { type: 'manual', message: msg })
})
toast.error(t('Fix errors', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
return
}
@@ -547,11 +571,15 @@ export function CardRequisiteForm({
const handleSubmit = async () => {
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 CardRequisiteFormData, { type: 'manual', message: msg })
})
toast.error(t('Fix errors', '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) {
@@ -582,7 +610,7 @@ export function CardRequisiteForm({
return {
id: s.id,
title: t(s.titleKey) || s.titleFallback,
subtitle: s.subtitle,
subtitle: t(s.subtitleKey) || s.subtitleFallback,
icon: s.icon,
status: isActive ? 'active' : hasErrors ? 'error' : isDone ? 'done' : 'idle',
}

View File

@@ -2,26 +2,24 @@ import { z } from 'zod'
import i18next from 'i18next'
import type { CardRequisiteStatus, CreateCardRequisitePayload } from '../api/cardRequisitesApi'
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 cardRequisiteFormSchema = z.object({
status: z.string().min(1, t('validation.required', '')),
status: z.string().min(1, 'validation.required'),
note: z.string().optional(),
card_type: z.string().min(1, t('validation.required', '')),
card_number: z.string().min(1, t('validation.required', '')),
card_expiry_month: z.string().min(1, t('validation.required', '')),
card_expiry_year: z.string().min(1, t('validation.required', '')),
province_id: z.string().min(1, t('validation.required', '')),
branch_id: z.string().min(1, t('validation.required', '')),
first_name: z.string().min(1, t('validation.required', '')),
last_name: z.string().min(1, t('validation.required', '')),
card_type: z.string().min(1, 'validation.required'),
card_number: z.string().min(1, 'validation.required'),
card_expiry_month: z.string().min(1, 'validation.required'),
card_expiry_year: z.string().min(1, 'validation.required'),
province_id: z.string().min(1, 'validation.required'),
branch_id: z.string().min(1, 'validation.required'),
first_name: z.string().min(1, 'validation.required'),
last_name: z.string().min(1, 'validation.required'),
middle_name: z.string().optional(),
birth_date: z.string().min(1, t('validation.required', '')),
phone: z.string().min(1, t('validation.required', '')),
passport_series: z.string().min(1, t('validation.required', '')),
passport_number: z.string().min(1, t('validation.required', '')),
birth_date: z.string().min(1, 'validation.required'),
phone: z.string().min(1, 'validation.required'),
passport_series: z.string().min(1, 'validation.required'),
passport_number: z.string().min(1, 'validation.required'),
passport_page1: z.custom<File | null>().nullable(),
passport_page2_3: z.custom<File | null>().nullable(),
passport_page8_9: z.custom<File | null>().nullable(),
@@ -40,8 +38,8 @@ export const stepSchemas: Record<number, z.ZodType<Partial<CardRequisiteFormData
first_name: true, last_name: true, birth_date: true, phone: true,
}),
2: z.object({
passport_series: z.string().min(1, t('validation.required', '')),
passport_number: z.string().min(1, t('validation.required', '')),
passport_series: z.string().min(1, 'validation.required'),
passport_number: z.string().min(1, 'validation.required'),
passport_page1: fileRequired,
passport_page2_3: fileRequired,
passport_page8_9: fileRequired,
@@ -49,6 +47,10 @@ export const stepSchemas: Record<number, z.ZodType<Partial<CardRequisiteFormData
}),
}
function translateMsg(msg: string): string {
return msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
}
export function validateStep(
stepIndex: number,
form: CardRequisiteFormData,
@@ -56,15 +58,15 @@ export function validateStep(
): Partial<Record<keyof CardRequisiteFormData, string>> {
if (stepIndex === 2 && mode === 'edit') {
const schema = z.object({
passport_series: z.string().min(1, t('validation.required', '')),
passport_number: z.string().min(1, t('validation.required', '')),
passport_series: z.string().min(1, 'validation.required'),
passport_number: z.string().min(1, 'validation.required'),
})
const result = schema.safeParse(form)
if (result.success) return {}
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {}
for (const issue of result.error.issues) {
const key = issue.path[0] as keyof CardRequisiteFormData
if (!errors[key]) errors[key] = issue.message
if (!errors[key]) errors[key] = translateMsg(issue.message)
}
return errors
}
@@ -76,7 +78,7 @@ export function validateStep(
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {}
for (const issue of result.error.issues) {
const key = issue.path[0] as keyof CardRequisiteFormData
if (!errors[key]) errors[key] = issue.message
if (!errors[key]) errors[key] = translateMsg(issue.message)
}
return errors
}

View File

@@ -81,6 +81,9 @@ export function CardTransactionForm({
clearErrors(field)
}
const errMsg = (msg: string | undefined) =>
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
const handleSubmit = async () => {
const result = cardTransactionFormSchema.safeParse(getValues())
if (!result.success) {
@@ -119,7 +122,7 @@ export function CardTransactionForm({
onChange={setField('passport_series')}
options={PASSPORT_SERIES_OPTIONS}
placeholder={t('Select to choose', 'Saýlamak üçin basyň')}
error={errors.passport_series}
error={errMsg(errors.passport_series)}
required
/>
@@ -130,7 +133,7 @@ export function CardTransactionForm({
value={form.passport_number}
onChange={setField('passport_number')}
placeholder={t('Passport number', 'Pasport belgisi')}
error={errors.passport_number}
error={errMsg(errors.passport_number)}
required
/>
@@ -141,7 +144,7 @@ export function CardTransactionForm({
value={form.card_number}
onChange={setField('card_number')}
placeholder={t('Card number', 'Kart belgisi')}
error={errors.card_number}
error={errMsg(errors.card_number)}
required
/>
@@ -154,7 +157,7 @@ export function CardTransactionForm({
onChange={setField('card_expiry_month')}
options={MONTH_OPTIONS}
placeholder={t('Select to choose', 'Saýlamak üçin basyň')}
error={errors.card_expiry_month}
error={errMsg(errors.card_expiry_month)}
required
/>
@@ -165,7 +168,7 @@ export function CardTransactionForm({
onChange={setField('card_expiry_year')}
options={YEAR_OPTIONS}
placeholder={t('Select to choose', 'Saýlamak üçin basyň')}
error={errors.card_expiry_year}
error={errMsg(errors.card_expiry_year)}
required
/>
</div>

View File

@@ -1,15 +1,12 @@
import { z } from 'zod'
import i18next from 'i18next'
import type { CreateCardTransactionPayload } from '../api/cardTransactionsApi'
const t = i18next.t.bind(i18next)
export const cardTransactionFormSchema = z.object({
passport_series: z.string().min(1, t('validation.required', '')),
passport_number: z.string().min(1, t('validation.required', '')),
card_number: z.string().min(1, t('validation.required', '')),
card_expiry_month: z.string().min(1, t('validation.required', '')),
card_expiry_year: z.string().min(1, t('validation.required', '')),
passport_series: z.string().min(1, 'validation.required'),
passport_number: z.string().min(1, 'validation.required'),
card_number: z.string().min(1, 'validation.required'),
card_expiry_month: z.string().min(1, 'validation.required'),
card_expiry_year: z.string().min(1, 'validation.required'),
})
export type CardTransactionFormData = z.infer<typeof cardTransactionFormSchema>

View File

@@ -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>

View File

@@ -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
}

View File

@@ -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 {
@@ -97,7 +98,8 @@ interface StepDef {
id: string
titleKey: string
titleFallback: string
subtitle: string
subtitleKey: string
subtitleFallback: string
icon: LucideIcon
validate: (form: LoanOrderFormData, mode: 'create' | 'edit') => FlatErrors
}
@@ -105,52 +107,62 @@ interface StepDef {
const STEPS: StepDef[] = [
{
id: 'status', titleKey: 'Status', titleFallback: 'Status',
subtitle: 'Ýagdaý we bellik', icon: CircleDot,
subtitleKey: 'loanOrderForm.steps.status.subtitle', subtitleFallback: 'Ýagdaý we bellik',
icon: CircleDot,
validate: (form, mode) => validateStep(0, form, mode),
},
{
id: 'loan', titleKey: 'Loan', titleFallback: 'Karz',
subtitle: 'Görnüş we möçber', icon: Wallet,
subtitleKey: 'loanOrderForm.steps.loan.subtitle', subtitleFallback: 'Görnüş we möçber',
icon: Wallet,
validate: (form, mode) => validateStep(1, form, mode),
},
{
id: 'location', titleKey: 'Location', titleFallback: 'Lokasiýa',
subtitle: 'Welaýat we şahamça', icon: MapPin,
subtitleKey: 'loanOrderForm.steps.location.subtitle', subtitleFallback: 'Welaýat we şahamça',
icon: MapPin,
validate: (form, mode) => validateStep(2, form, mode),
},
{
id: 'personal', titleKey: 'Personal data', titleFallback: 'Şahsy maglumatlar',
subtitle: 'At, bilim, maşgala', icon: User,
subtitleKey: 'loanOrderForm.steps.personal.subtitle', subtitleFallback: 'At, bilim, maşgala',
icon: User,
validate: (form, mode) => validateStep(3, form, mode),
},
{
id: 'card', titleKey: 'Card (Salary)', titleFallback: 'Kart (Zähmet haky)',
subtitle: 'Zähmet haky karty', icon: CreditCard,
subtitleKey: 'loanOrderForm.steps.card.subtitle', subtitleFallback: 'Zähmet haky karty',
icon: CreditCard,
validate: (form, mode) => validateStep(4, form, mode),
},
{
id: 'passport', titleKey: 'Passport', titleFallback: 'Pasport',
subtitle: 'Seriýa, belgisi, senesi', icon: FileText,
subtitleKey: 'loanOrderForm.steps.passport.subtitle', subtitleFallback: 'Seriýa, belgisi, senesi',
icon: FileText,
validate: (form, mode) => validateStep(5, form, mode),
},
{
id: 'contact', titleKey: 'Contact data', titleFallback: 'Habarlaşmak',
subtitle: 'Telefon we e-poçta', icon: Phone,
subtitleKey: 'loanOrderForm.steps.contact.subtitle', subtitleFallback: 'Telefon we e-poçta',
icon: Phone,
validate: (form, mode) => validateStep(6, form, mode),
},
{
id: 'job', titleKey: 'Job', titleFallback: 'Iş',
subtitle: 'Kärhana we wezipe', icon: Briefcase,
subtitleKey: 'loanOrderForm.steps.job.subtitle', subtitleFallback: 'Kärhana we wezipe',
icon: Briefcase,
validate: (form, mode) => validateStep(7, form, mode),
},
{
id: 'files', titleKey: 'Passport files', titleFallback: 'Pasport faýllar',
subtitle: 'Pasport suratlary', icon: FolderOpen,
subtitleKey: 'loanOrderForm.steps.files.subtitle', subtitleFallback: 'Pasport suratlary',
icon: FolderOpen,
validate: (form, mode) => validateStep(8, form, mode),
},
{
id: 'guarantor', titleKey: '1. Guarantor', titleFallback: '1. Zamun',
subtitle: 'Zamun maglumatlary', icon: ShieldCheck,
subtitleKey: 'loanOrderForm.steps.guarantor.subtitle', subtitleFallback: 'Zamun maglumatlary',
icon: ShieldCheck,
validate: (form, mode) => validateStep(9, form, mode),
},
]
@@ -205,33 +217,34 @@ interface StepContentProps {
form: LoanOrderFormData
errors: FlatErrors
set: <K extends keyof LoanOrderFormData>(k: K, v: LoanOrderFormData[K]) => void
t: TFunction
}
// ─── Step panels ──────────────────────────────────────────────────────────────
function StepStatus({ form, errors, set }: StepContentProps) {
function StepStatus({ form, errors, set, t }: StepContentProps) {
return (
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="select"
label="Status"
label={t('loanOrderForm.labels.status') || 'Status'}
required
value={form.status}
onChange={(v) => set('status', v)}
options={STATUS_OPTIONS}
error={errors.status}
placeholder="Saýlaň"
placeholder={t('loanOrderForm.placeholders.select') || 'Saýlaň'}
/>
</BentoCard>
<BentoCard>
<FormInput
type="textarea"
label="Bellik"
label={t('Note') || 'Bellik'}
value={form.note}
onChange={(v) => set('note', v)}
placeholder="Bellik..."
placeholder={t('loanOrderForm.placeholders.note') || 'Bellik...'}
rows={3}
/>
</BentoCard>
@@ -239,18 +252,18 @@ function StepStatus({ form, errors, set }: StepContentProps) {
)
}
function StepLoan({ form, errors, set }: StepContentProps) {
function StepLoan({ form, errors, set, t }: StepContentProps) {
return (
<BentoGrid cols={2}>
<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>
@@ -258,11 +271,11 @@ function StepLoan({ form, errors, set }: StepContentProps) {
<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>
@@ -270,7 +283,7 @@ function StepLoan({ form, errors, set }: StepContentProps) {
)
}
function StepLocation({ form, errors, set }: StepContentProps) {
function StepLocation({ form, errors, set, t }: StepContentProps) {
const branchOptions = BRANCHES_BY_REGION[form.region] ?? []
return (
@@ -278,12 +291,12 @@ function StepLocation({ form, errors, set }: StepContentProps) {
<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>
@@ -291,12 +304,12 @@ function StepLocation({ form, errors, set }: StepContentProps) {
<BentoCard>
<FormInput
type="searchable-select"
label="Şahamça"
label={t('Branch') || 'Şahamça'}
required
value={form.branch}
onChange={(v) => set('branch', v)}
options={branchOptions}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
disabled={!form.region}
error={errors.branch}
/>
@@ -305,131 +318,131 @@ function StepLocation({ form, errors, set }: StepContentProps) {
)
}
function StepPersonal({ form, errors, set }: StepContentProps) {
function StepPersonal({ form, errors, set, t }: StepContentProps) {
return (
<div className="space-y-4">
<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>
<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>
<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>
</div>
)
}
function StepCard({ form, errors, set }: StepContentProps) {
function StepCard({ form, errors, set, t }: StepContentProps) {
return (
<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>
)
}
function StepPassport({ form, errors, set }: StepContentProps) {
function StepPassport({ form, errors, set, t }: StepContentProps) {
return (
<div className="space-y-4">
<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 (
<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>
)
}
function StepJob({ form, errors, set }: StepContentProps) {
function StepJob({ form, errors, set, t }: StepContentProps) {
return (
<div className="space-y-4">
<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>
@@ -437,14 +450,14 @@ function StepJob({ form, errors, set }: StepContentProps) {
}
function StepFiles({
form, errors, set, mode, initialData,
form, errors, set, t, mode, initialData,
}: StepContentProps & { mode: 'create' | 'edit'; initialData?: LoanOrder }) {
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)
: []
@@ -460,7 +473,7 @@ function StepFiles({
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>
))}
@@ -471,7 +484,7 @@ function StepFiles({
<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 +496,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}
@@ -495,7 +508,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)}
@@ -505,7 +518,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)}
@@ -516,40 +529,40 @@ function StepFiles({
)
}
function StepGuarantor({ form, errors, set }: StepContentProps) {
function StepGuarantor({ form, errors, set, t }: StepContentProps) {
return (
<div className="space-y-4">
<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>
<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>
<BentoGrid cols={2}>
<BentoCard >
<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} />
<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>
<FormInput type="searchable-select" label="Möhleti (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="Möhleti (ý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} />
<FormInput type="searchable-select" label={t('Expiration month') || 'Möhleti (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') || 'Möhleti (ý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>
@@ -567,7 +580,7 @@ interface LoanOrderFormProps {
// ─── Main Component ───────────────────────────────────────────────────────────
export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormProps) {
const { t } = useTranslation()
const { t, i18n } = useTranslation()
const navigate = useNavigate()
const createMutation = useCreateLoanOrder()
@@ -575,16 +588,15 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
const isPending = createMutation.isPending || updateMutation.isPending
const {
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors,
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError,
} = useForm<LoanOrderFormData>({ 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>()
@@ -592,24 +604,43 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
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 LoanOrderFormData>(key: K, value: LoanOrderFormData[K]) => {
(setValue as (name: K, val: LoanOrderFormData[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 LoanOrderFormData, { type: 'manual', message: msg })
})
toast.error(t('common.errors.fillRequiredCorrectly', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
return
}
@@ -637,11 +668,15 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
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 LoanOrderFormData, { 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) {
@@ -672,7 +707,7 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
return {
id: s.id,
title: t(s.titleKey) || s.titleFallback,
subtitle: s.subtitle,
subtitle: t(s.subtitleKey) || s.subtitleFallback,
icon: s.icon,
status: isActive ? 'active' : hasErrors ? 'error' : isDone ? 'done' : 'idle',
}
@@ -688,11 +723,13 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
<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('loanOrders.create') || 'Karz sargyt döredüň')
: (t('loanOrders.edit') || '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('loanOrders.createDescription') || 'Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.')
: (t('loanOrders.editDescription') || 'Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.')}
</p>
</div>
@@ -724,12 +761,12 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
submitLabel={
mode === 'create'
? (t('loanOrderMobiles.createButton') || 'Karz sargyt döredüň')
: (t('loanOrders.saveButton') || 'Ýatda sakla')
: (t('common.save') || 'Ýatda sakla')
}
loadingLabel={t('Loading') || 'Ýüklenilýär...'}
cancelLabel={t('Cancel') || 'Ýatyr'}
prevLabel={t('Back') || 'Yza'}
nextLabel={t('Next') || 'Indiki'}
loadingLabel={t('common.loading') || 'Ýüklenilýär...'}
cancelLabel={t('common.cancel') || 'Ýatyr'}
prevLabel={t('common.back') || 'Yza'}
nextLabel={t('common.next') || 'Indiki'}
/>
</div>
)

View File

@@ -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 loanOrderFormSchema = 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 LoanOrderFormData = z.infer<typeof loanOrderFormSchema>
@@ -101,7 +99,10 @@ export function validateStep(stepIndex: number, form: LoanOrderFormData, mode: '
const errors: Partial<Record<keyof LoanOrderFormData, string>> = {}
for (const issue of result.error.issues) {
const key = issue.path[0] as keyof LoanOrderFormData
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
}

View File

@@ -81,6 +81,9 @@ export function LoanRemainingForm({
}
}
const errMsg = (msg: string | undefined) =>
msg?.startsWith('validation.') ? t(msg, msg) : msg
const onError = () => {
toast.error(t('common.errors.fillRequired', 'Hökman doldurylmaly öýjükleri dolduryň'))
}
@@ -95,7 +98,7 @@ export function LoanRemainingForm({
value={watch('passportSeries')}
onChange={(v) => setValue('passportSeries', v)}
placeholder={t('loanRemaining.placeholders.passportSeries', 'TM')}
error={errors.passportSeries?.message}
error={errMsg(errors.passportSeries?.message)}
/>
<FormInput
@@ -104,7 +107,7 @@ export function LoanRemainingForm({
value={watch('passportNumber')}
onChange={(v) => setValue('passportNumber', v)}
placeholder="A123456"
error={errors.passportNumber?.message}
error={errMsg(errors.passportNumber?.message)}
/>
<div className="md:col-span-2">
@@ -114,7 +117,7 @@ export function LoanRemainingForm({
value={watch('loanAccount')}
onChange={(v) => setValue('loanAccount', v)}
placeholder="NOVA-..."
error={errors.loanAccount?.message}
error={errMsg(errors.loanAccount?.message)}
/>
</div>
</div>

View File

@@ -1,12 +1,9 @@
import { z } from 'zod'
import i18next from 'i18next'
const t = i18next.t.bind(i18next)
export const loanRemainingFormSchema = z.object({
passportSeries: z.string().min(1, t('validation.required', '')),
passportNumber: z.string().min(1, t('validation.required', '')),
loanAccount: z.string().min(1, t('validation.required', '')),
passportSeries: z.string().min(1, 'validation.required'),
passportNumber: z.string().min(1, 'validation.required'),
loanAccount: z.string().min(1, 'validation.required'),
})
export type LoanRemainingFormData = z.infer<typeof loanRemainingFormSchema>

View File

@@ -1,5 +1,6 @@
import { useState, useCallback, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import type { TFunction } from 'i18next'
import { toast } from 'sonner'
import { CreditCard, User, FileText, Upload } from 'lucide-react'
import type { LucideIcon } from 'lucide-react'
@@ -54,7 +55,8 @@ interface StepDef {
id: string
titleKey: string
titleFallback: string
subtitle: string
subtitleKey: string
subtitleFallback: string
icon: LucideIcon
validate: (form: OrderNewCardFormData, mode: 'create' | 'edit') => FlatErrors
}
@@ -64,7 +66,8 @@ const STEPS: StepDef[] = [
id: 'card',
titleKey: 'cardOrder.step.card',
titleFallback: 'Kart',
subtitle: 'Görnüş & lokasiýa',
subtitleKey: 'orderNewCardForm.steps.card.subtitle',
subtitleFallback: 'Görnüş & lokasiýa',
icon: CreditCard,
validate: (form, mode) => validateStep(0, form, mode),
},
@@ -72,7 +75,8 @@ const STEPS: StepDef[] = [
id: 'personal',
titleKey: 'cardOrder.step.personal',
titleFallback: 'Şahsy',
subtitle: 'Maglumatlar',
subtitleKey: 'orderNewCardForm.steps.personal.subtitle',
subtitleFallback: 'Maglumatlar',
icon: User,
validate: (form, mode) => validateStep(1, form, mode),
},
@@ -80,7 +84,8 @@ const STEPS: StepDef[] = [
id: 'passport',
titleKey: 'cardOrder.step.passport',
titleFallback: 'Pasport',
subtitle: 'Resmi maglumat',
subtitleKey: 'orderNewCardForm.steps.passport.subtitle',
subtitleFallback: 'Resmi maglumat',
icon: FileText,
validate: (form, mode) => validateStep(2, form, mode),
},
@@ -88,7 +93,8 @@ const STEPS: StepDef[] = [
id: 'files',
titleKey: 'cardOrder.step.files',
titleFallback: 'Faýllar',
subtitle: 'Ýüklemek & Tassyklamak',
subtitleKey: 'orderNewCardForm.steps.files.subtitle',
subtitleFallback: 'Ýüklemek & Tassyklamak',
icon: Upload,
validate: (form, mode) => validateStep(3, form, mode),
},
@@ -144,12 +150,13 @@ interface StepContentProps {
form: OrderNewCardFormData
errors: FlatErrors
set: <K extends keyof OrderNewCardFormData>(k: K, v: OrderNewCardFormData[K]) => void
t: TFunction
}
// ─── Step panels ──────────────────────────────────────────────────────────────
function StepCard({
form, errors, set,
form, errors, set, t,
statusOptions, issuanceReasonOptions, cardTypeOptions, provinceOptions, branchOptions,
}: StepContentProps & {
statusOptions: SelectOption[]
@@ -164,20 +171,20 @@ function StepCard({
<BentoCard>
<FormInput
type="select"
label="Status"
label={t('loanOrderForm.labels.status') || 'Status'}
required
value={form.status}
onChange={(v) => set('status', v as CardOrderStatus)}
options={statusOptions}
placeholder="Saýlaň"
placeholder={t('loanOrderForm.placeholders.select') || 'Saýlaň'}
error={errors.status}
/>
<FormInput
type="textarea"
label="Bellik"
label={t('Note') || 'Bellik'}
value={form.note}
onChange={(v) => set('note', v)}
placeholder="Bellik..."
placeholder={t('loanOrderForm.placeholders.note') || 'Bellik...'}
rows={3}
/>
</BentoCard>
@@ -195,7 +202,7 @@ function StepCard({
htmlFor="isPaid"
className="text-xs font-semibold text-muted-foreground uppercase tracking-wider cursor-pointer select-none"
>
Tölenen
{t('orderNewCardForm.isPaid') || 'Tölenen'}
</label>
</div>
</BentoCard>
@@ -205,24 +212,24 @@ function StepCard({
<BentoCard>
<FormInput
type="searchable-select"
label="Kartyň çykarylmagynyň sebäbi"
label={t('Reason for issuing the card') || 'Kartyň çykarylmagynyň sebäbi'}
required
value={form.issuanceReasonId}
onChange={(v) => set('issuanceReasonId', v)}
options={issuanceReasonOptions}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errors.issuanceReasonId}
/>
</BentoCard>
<BentoCard>
<FormInput
type="searchable-select"
label="Kart görnüşi"
label={t('Card type') || 'Kart görnüşi'}
required
value={form.cardTypeId}
onChange={(v) => set('cardTypeId', v)}
options={cardTypeOptions}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errors.cardTypeId}
/>
</BentoCard>
@@ -232,25 +239,25 @@ function StepCard({
<BentoCard>
<FormInput
type="select"
label="Welaýat"
label={t('Region') || 'Welaýat'}
required
value={form.provinceId}
onChange={(v) => { set('provinceId', v); set('branchId', '') }}
options={provinceOptions}
placeholder="Saýlaň"
placeholder={t('loanOrderForm.placeholders.select') || 'Saýlaň'}
error={errors.provinceId}
/>
</BentoCard>
<BentoCard>
<FormInput
type="searchable-select"
label="Şahamça"
label={t('Branch') || 'Şahamça'}
required
value={form.branchId}
onChange={(v) => set('branchId', v)}
options={branchOptions}
disabled={!form.provinceId}
placeholder="Saýlamak üçin basyň"
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errors.branchId}
/>
</BentoCard>
@@ -259,7 +266,7 @@ function StepCard({
)
}
function StepPersonal({ form, errors, set, citizenshipOptions }: StepContentProps & {
function StepPersonal({ form, errors, set, t, citizenshipOptions }: StepContentProps & {
citizenshipOptions: SelectOption[]
}) {
return (
@@ -267,23 +274,23 @@ function StepPersonal({ form, errors, set, citizenshipOptions }: StepContentProp
<BentoGrid cols={3}>
<BentoCard>
<FormInput
type="text" label="Ady" required
type="text" label={t('Name') || 'Ady'} required
value={form.firstName} onChange={(v) => set('firstName', v)}
placeholder="Ady" error={errors.firstName}
placeholder={t('Name') || 'Ady'} error={errors.firstName}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text" label="Familiýasy" required
type="text" label={t('Surname') || 'Familiýasy'} required
value={form.lastName} onChange={(v) => set('lastName', v)}
placeholder="Familiýasy" error={errors.lastName}
placeholder={t('Surname') || 'Familiýasy'} error={errors.lastName}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text" label="Atasynyň ady"
type="text" label={t('Patronic name') || 'Atasynyň ady'}
value={form.middleName} onChange={(v) => set('middleName', v)}
placeholder="Atasynyň ady"
placeholder={t('Patronic name') || 'Atasynyň ady'}
/>
</BentoCard>
</BentoGrid>
@@ -291,14 +298,14 @@ function StepPersonal({ form, errors, set, citizenshipOptions }: StepContentProp
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="text" label="Köne familiýaňyz (eger üýtgän bolsa)"
type="text" label={t('Old surname (if changed)') || 'Köne familiýaňyz (eger üýtgän bolsa)'}
value={form.formerLastName} onChange={(v) => set('formerLastName', v)}
placeholder="Köne familiýaňyz"
placeholder={t('orderNewCardForm.placeholders.formerLastName') || 'Köne familiýaňyz'}
/>
</BentoCard>
<BentoCard>
<FormInput
type="date" label="Doglan güni" required
type="date" label={t('Date of birth') || 'Doglan güni'} required
value={form.birthDate} onChange={(v) => set('birthDate', v)}
error={errors.birthDate}
/>
@@ -308,20 +315,20 @@ function StepPersonal({ form, errors, set, citizenshipOptions }: StepContentProp
<BentoGrid cols={3}>
<BentoCard>
<FormInput
type="phone" label="Telefon" required
type="phone" label={t('Phone') || 'Telefon'} required
value={form.phone} onChange={(v) => set('phone', v)}
error={errors.phone}
/>
</BentoCard>
<BentoCard>
<FormInput
type="phone" label="Telefon goşmaça"
type="phone" label={t('Phone Additional') || 'Telefon goşmaça'}
value={form.phoneExtra} onChange={(v) => set('phoneExtra', v)}
/>
</BentoCard>
<BentoCard>
<FormInput
type="select" label="Raýatlyk" required
type="select" label={t('Citizenship') || 'Raýatlyk'} required
value={form.citizenship} onChange={(v) => set('citizenship', v)}
options={citizenshipOptions}
error={errors.citizenship}
@@ -332,17 +339,17 @@ function StepPersonal({ form, errors, set, citizenshipOptions }: StepContentProp
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="text" label="Ýazgy edilen salgyňyz" required
type="text" label={t('orderNewCardForm.labels.registeredAddress') || 'Ýazgy edilen salgyňyz'} required
value={form.registeredAddress} onChange={(v) => set('registeredAddress', v)}
placeholder="Ýazgy edilen salgyňyz"
placeholder={t('orderNewCardForm.labels.registeredAddress') || 'Ýazgy edilen salgyňyz'}
error={errors.registeredAddress}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text" label="Häzirki ýaşaýyş ýeri" required
type="text" label={t('orderNewCardForm.labels.currentAddress') || 'Häzirki ýaşaýyş ýeri'} required
value={form.currentAddress} onChange={(v) => set('currentAddress', v)}
placeholder="Häzirki ýaşaýyş ýeri"
placeholder={t('orderNewCardForm.labels.currentAddress') || 'Häzirki ýaşaýyş ýeri'}
error={errors.currentAddress}
/>
</BentoCard>
@@ -351,9 +358,9 @@ function StepPersonal({ form, errors, set, citizenshipOptions }: StepContentProp
<BentoGrid cols={1}>
<BentoCard>
<FormInput
type="text" label="Işleýän ýeriňiz we wezipäňiz" required
type="text" label={t('orderNewCardForm.labels.workplace') || 'Işleýän ýeriňiz we wezipäňiz'} required
value={form.workplace} onChange={(v) => set('workplace', v)}
placeholder="Işleýän ýeriňiz we wezipäňiz"
placeholder={t('orderNewCardForm.labels.workplace') || 'Işleýän ýeriňiz we wezipäňiz'}
error={errors.workplace}
/>
</BentoCard>
@@ -362,7 +369,7 @@ function StepPersonal({ form, errors, set, citizenshipOptions }: StepContentProp
)
}
function StepPassport({ form, errors, set, passportSeriesOptions }: StepContentProps & {
function StepPassport({ form, errors, set, t, passportSeriesOptions }: StepContentProps & {
passportSeriesOptions: SelectOption[]
}) {
return (
@@ -370,24 +377,24 @@ function StepPassport({ form, errors, set, passportSeriesOptions }: StepContentP
<BentoGrid cols={3}>
<BentoCard>
<FormInput
type="select" label="Pasport seriýasy" required
type="select" label={t('Passport serie') || 'Pasport seriýasy'} required
value={form.passportSeriesId} onChange={(v) => set('passportSeriesId', v)}
options={passportSeriesOptions}
placeholder="Saýlaň"
placeholder={t('loanOrderForm.placeholders.select') || 'Saýlaň'}
error={errors.passportSeriesId}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text" label="Pasport belgisi" required
type="text" label={t('Passport id') || 'Pasport belgisi'} required
value={form.passportNumber} onChange={(v) => set('passportNumber', v)}
placeholder="Pasport belgisi"
placeholder={t('Passport id') || 'Pasport belgisi'}
error={errors.passportNumber}
/>
</BentoCard>
<BentoCard>
<FormInput
type="date" label="Pasport berlen senesi" required
type="date" label={t('Passport date of issue') || 'Pasport berlen senesi'} required
value={form.passportIssueDate} onChange={(v) => set('passportIssueDate', v)}
error={errors.passportIssueDate}
/>
@@ -397,17 +404,17 @@ function StepPassport({ form, errors, set, passportSeriesOptions }: StepContentP
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="text" label="Kim tarapyndan berildi" required
type="text" label={t('Passport given by') || 'Kim tarapyndan berildi'} required
value={form.passportIssuedBy} onChange={(v) => set('passportIssuedBy', v)}
placeholder="Kim tarapyndan berildi"
placeholder={t('Passport given by') || 'Kim tarapyndan berildi'}
error={errors.passportIssuedBy}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text" label="Doglan ýeri (pasport)" required
type="text" label={t('Born place (passport)') || 'Doglan ýeri (pasport)'} required
value={form.passportBirthPlace} onChange={(v) => set('passportBirthPlace', v)}
placeholder="Doglan ýeri (pasport)"
placeholder={t('Born place (passport)') || 'Doglan ýeri (pasport)'}
error={errors.passportBirthPlace}
/>
</BentoCard>
@@ -417,15 +424,15 @@ function StepPassport({ form, errors, set, passportSeriesOptions }: StepContentP
}
function StepFiles({
form, errors, set, mode, initialData,
form, errors, set, t, mode, initialData,
}: StepContentProps & { mode: 'create' | 'edit'; initialData?: CardOrder }) {
const existingFiles =
mode === 'edit' && initialData
? [
{ url: initialData.passportFiles.page1, label: 'Pasport (sahypa 1)' },
{ url: initialData.passportFiles.page23, label: 'Pasport (2-3-nji sahypa)' },
{ url: initialData.passportFiles.page89, label: 'Pasport (8-9 sahypa)' },
{ url: initialData.passportFiles.page32, label: 'Pasport (32-nji sahypa)' },
{ url: initialData.passportFiles.page1, label: t('Passport (page 1)') || 'Pasport (sahypa 1)' },
{ url: initialData.passportFiles.page23, label: t('Passport (page 2-3)') || 'Pasport (2-3-nji sahypa)' },
{ url: initialData.passportFiles.page89, label: t('Passport (page 8-9)') || 'Pasport (8-9 sahypa)' },
{ url: initialData.passportFiles.page32, label: t('Passport (page 32)') || 'Pasport (32-nji sahypa)' },
].filter((f): f is { url: string; label: string } => !!f.url)
: []
@@ -441,7 +448,7 @@ function StepFiles({
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>
))}
@@ -452,7 +459,7 @@ function StepFiles({
<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/*,.pdf"
fileValue={form.passportPage1}
@@ -463,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/*,.pdf"
fileValue={form.passportPage23}
@@ -474,7 +481,7 @@ function StepFiles({
<BentoCard>
<FormInput
type="file"
label="Pasport (8-9 sahypa)"
label={t('Passport (page 8-9)') || 'Pasport (8-9 sahypa)'}
required={mode === 'create'}
accept="image/*,.pdf"
fileValue={form.passportPage89}
@@ -485,7 +492,7 @@ function StepFiles({
<BentoCard>
<FormInput
type="file"
label="Pasport (32-nji sahypa)"
label={t('Passport (page 32)') || 'Pasport (32-nji sahypa)'}
required={mode === 'create'}
accept="image/*,.pdf"
fileValue={form.passportPage32}
@@ -528,7 +535,7 @@ function StepFiles({
<span
className={`text-sm font-medium ${errors.termsAccepted ? 'text-destructive' : 'text-primary'}`}
>
Şertnama bilen razylaşýaryn (Okamak üçin bas)
{t('I accept terms of contract') || 'Şertnama bilen razylaşýaryn (Okamak üçin bas)'}
</span>
</div>
</BentoCard>
@@ -554,18 +561,17 @@ export function CardOrderForm({
const isPending = createMutation.isPending || updateMutation.isPending
const {
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors,
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError,
} = useForm<OrderNewCardFormData>({
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())
// ── Lookup data ────────────────────────────────────────────────────────────
@@ -614,18 +620,34 @@ export function CardOrderForm({
clearErrors(key)
}, [setValue, clearErrors])
const stepProps = useMemo(() => ({ form, errors, set }), [form, errors, set])
const currentStepErrors = useMemo(
() => submittedSteps.has(currentStep) ? STEPS[currentStep].validate(form, mode) : {},
[currentStep, form, mode, submittedSteps],
)
const errors = useMemo(() => {
const fromRHF = flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>)
return { ...fromRHF, ...currentStepErrors }
}, [rhfErrors, currentStepErrors])
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) {
toast.error(t('validation.fixErrors', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
Object.entries(errs).forEach(([key, msg]) => {
setError(key as keyof OrderNewCardFormData, { type: 'manual', message: msg })
})
toast.error(t('common.errors.fillRequiredCorrectly', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
return
}
if (currentStep < STEPS.length - 1) {
@@ -652,11 +674,15 @@ export function CardOrderForm({
const doSubmit = async () => {
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 OrderNewCardFormData, { type: 'manual', message: msg })
})
toast.error(t('validation.fixErrors', '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) {
@@ -690,7 +716,7 @@ export function CardOrderForm({
return {
id: s.id,
title: t(s.titleKey) || s.titleFallback,
subtitle: s.subtitle,
subtitle: t(s.subtitleKey) || s.subtitleFallback,
icon: s.icon,
status: isActive ? 'active' : hasErrors ? 'error' : isDone ? 'done' : 'idle',
}

View File

@@ -2,34 +2,32 @@ import { z } from 'zod'
import i18next from 'i18next'
import type { CardOrderStatus } from '../api/orderNewCardApi'
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 orderNewCardFormSchema = z.object({
isPaid: z.boolean(),
status: z.string().min(1, t('validation.required', '')),
status: z.string().min(1, 'validation.required'),
note: z.string().optional(),
issuanceReasonId: z.string().min(1, t('validation.required', '')),
cardTypeId: z.string().min(1, t('validation.required', '')),
provinceId: z.string().min(1, t('validation.required', '')),
branchId: z.string().min(1, t('validation.required', '')),
firstName: z.string().min(1, t('validation.required', '')),
lastName: z.string().min(1, t('validation.required', '')),
issuanceReasonId: z.string().min(1, 'validation.required'),
cardTypeId: z.string().min(1, 'validation.required'),
provinceId: z.string().min(1, 'validation.required'),
branchId: z.string().min(1, 'validation.required'),
firstName: z.string().min(1, 'validation.required'),
lastName: z.string().min(1, 'validation.required'),
middleName: z.string().optional(),
formerLastName: z.string().optional(),
birthDate: z.string().min(1, t('validation.required', '')),
phone: z.string().min(1, t('validation.required', '')),
birthDate: z.string().min(1, 'validation.required'),
phone: z.string().min(1, 'validation.required'),
phoneExtra: z.string().optional(),
citizenship: z.string().min(1, t('validation.required', '')),
registeredAddress: z.string().min(1, t('validation.required', '')),
currentAddress: z.string().min(1, t('validation.required', '')),
workplace: z.string().min(1, t('validation.required', '')),
passportSeriesId: z.string().min(1, t('validation.required', '')),
passportNumber: z.string().min(1, t('validation.required', '')),
passportIssueDate: z.string().min(1, t('validation.required', '')),
passportIssuedBy: z.string().min(1, t('validation.required', '')),
passportBirthPlace: z.string().min(1, t('validation.required', '')),
citizenship: z.string().min(1, 'validation.required'),
registeredAddress: z.string().min(1, 'validation.required'),
currentAddress: z.string().min(1, 'validation.required'),
workplace: z.string().min(1, 'validation.required'),
passportSeriesId: z.string().min(1, 'validation.required'),
passportNumber: z.string().min(1, 'validation.required'),
passportIssueDate: z.string().min(1, 'validation.required'),
passportIssuedBy: z.string().min(1, 'validation.required'),
passportBirthPlace: z.string().min(1, 'validation.required'),
passportPage1: z.custom<File | null>().nullable(),
passportPage23: z.custom<File | null>().nullable(),
passportPage89: z.custom<File | null>().nullable(),
@@ -56,7 +54,7 @@ export const stepSchemas: Record<number, z.ZodType<Partial<OrderNewCardFormData>
passportPage23: fileRequired,
passportPage89: fileRequired,
passportPage32: fileRequired,
termsAccepted: z.literal(true, { message: t('validation.requiredTerms', '') }),
termsAccepted: z.literal(true, { message: 'validation.requiredTerms' }),
}),
}
@@ -72,7 +70,10 @@ export function validateStep(
const errors: Partial<Record<keyof OrderNewCardFormData, string>> = {}
for (const issue of result.error.issues) {
const key = issue.path[0] as keyof OrderNewCardFormData
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
}

View File

@@ -1,6 +1,8 @@
import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import type { TFunction } from 'i18next'
import { toast } from 'sonner'
import {
User, MapPin, IdCard, CreditCard, Files,
} from 'lucide-react'
@@ -123,16 +125,18 @@ type StepId = 'general' | 'location' | 'personal' | 'payment' | 'docs'
interface Step {
id: StepId
title: string
subtitle: string
titleKey: string
titleFallback: string
subtitleKey: string
subtitleFallback: string
}
const STEPS: Step[] = [
{ id: 'general', title: 'Esasy', subtitle: 'Status, müşderi' },
{ id: 'location', title: 'Lokasiýa', subtitle: 'Welaýat, şahamça' },
{ id: 'personal', title: 'Şahsy', subtitle: 'Pasport, kontakt' },
{ id: 'payment', title: 'Töleg', subtitle: 'Töleýji, kabul ediji' },
{ id: 'docs', title: 'Resminamalar', subtitle: '15 resminama' },
{ id: 'general', titleKey: 'intlPaymentForm.steps.general.title', titleFallback: 'Esasy', subtitleKey: 'intlPaymentForm.steps.general.subtitle', subtitleFallback: 'Status, müşderi' },
{ id: 'location', titleKey: 'intlPaymentForm.steps.location.title', titleFallback: 'Lokasiýa', subtitleKey: 'intlPaymentForm.steps.location.subtitle', subtitleFallback: 'Welaýat, şahamça' },
{ id: 'personal', titleKey: 'intlPaymentForm.steps.personal.title', titleFallback: 'Şahsy', subtitleKey: 'intlPaymentForm.steps.personal.subtitle', subtitleFallback: 'Pasport, kontakt' },
{ id: 'payment', titleKey: 'intlPaymentForm.steps.payment.title', titleFallback: 'Töleg', subtitleKey: 'intlPaymentForm.steps.payment.subtitle', subtitleFallback: 'Töleýji, kabul ediji' },
{ id: 'docs', titleKey: 'intlPaymentForm.steps.docs.title', titleFallback: 'Resminamalar', subtitleKey: 'intlPaymentForm.steps.docs.subtitle', subtitleFallback: '15 resminama' },
]
// Per-step required fields for incremental validation
@@ -144,19 +148,19 @@ const STEP_REQUIRED_FIELDS: Partial<Record<StepId, (keyof FormState)[]>> = {
}
const STEP_ERROR_LABELS: Partial<Record<keyof FormState, string>> = {
client_id: 'Ulanyjy hökmany',
status: 'Status hökmany',
currency_type: 'Ýüztumanyň görnüşi hökmany',
province: 'Welaýat hökmany',
branch: 'Şahamça hökmany',
passport_first_name: 'Ady hökmany',
passport_last_name: 'Familiýasy hökmany',
phone: 'Telefon hökmany',
passport_series: 'Pasport seriýasy hökmany',
passport_number: 'Pasport nomeri hökmany',
payer_full_name: 'Doly ady hökmany',
payer_account_number: 'Goşun hasaby hökmany',
receiver_info: 'Kabul edijiniň maglumatlary hökmany',
client_id: 'validation.required',
status: 'validation.required',
currency_type: 'validation.required',
province: 'validation.required',
branch: 'validation.required',
passport_first_name: 'validation.required',
passport_last_name: 'validation.required',
phone: 'validation.required',
passport_series: 'validation.required',
passport_number: 'validation.required',
payer_full_name: 'validation.required',
payer_account_number: 'validation.required',
receiver_info: 'validation.required',
}
// ─── Default state ────────────────────────────────────────────────────────────
@@ -241,58 +245,62 @@ function BentoCard({
// ─── Step content panels ──────────────────────────────────────────────────────
function StepGeneral({
form, errors, set,
form, errors, set, t,
}: {
form: FormState
errors: FormErrors
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
t: TFunction
}) {
const errMsg = (msg: string | undefined) =>
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
return (
<BentoGrid cols={2}>
<BentoCard title="Müşderi">
<BentoCard title={t('intlPaymentForm.titles.general.client') || 'Müşderi'}>
<FormInput
type="searchable-select"
label="Ulanyjy"
label={t('User') || 'Ulanyjy'}
value={form.client_id}
onChange={(v) => set('client_id', v)}
options={[]}
placeholder="Saýlamak üçin basyň"
error={errors.client_id}
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errMsg(errors.client_id)}
required
/>
</BentoCard>
<BentoCard title="Status">
<BentoCard title={t('loanOrderForm.labels.status') || 'Status'}>
<FormInput
type="select"
label="Status"
label={t('loanOrderForm.labels.status') || 'Status'}
value={form.status}
onChange={(v) => set('status', v)}
options={STATUS_OPTIONS}
error={errors.status}
error={errMsg(errors.status)}
required
/>
</BentoCard>
<BentoCard title="Kart görnüşi" span="full">
<BentoCard title={t('Card type') || 'Kart görnüşi'} span="full">
<FormInput
type="select"
label="Ýüztumanyň görnüşi"
label={t('Application type') || 'Ýüztumanyň görnüşi'}
value={form.currency_type}
onChange={(v) => set('currency_type', v)}
options={CURRENCY_OPTIONS}
error={errors.currency_type}
error={errMsg(errors.currency_type)}
required
/>
</BentoCard>
<BentoCard title="Bellik" span="full">
<BentoCard title={t('Note') || 'Bellik'} span="full">
<FormInput
type="textarea"
label="Bellik"
label={t('Note') || 'Bellik'}
value={form.note}
onChange={(v) => set('note', v)}
placeholder="Bellik..."
placeholder={t('loanOrderForm.placeholders.note') || 'Bellik...'}
rows={2}
/>
</BentoCard>
@@ -301,38 +309,42 @@ function StepGeneral({
}
function StepLocation({
form, errors, set,
form, errors, set, t,
}: {
form: FormState
errors: FormErrors
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
t: TFunction
}) {
const errMsg = (msg: string | undefined) =>
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
return (
<BentoGrid cols={2}>
<BentoCard title="Welaýat">
<BentoCard title={t('Region') || 'Welaýat'}>
<FormInput
type="searchable-select"
label="Welaýat"
label={t('Region') || 'Welaýat'}
value={form.province}
onChange={(v) => { set('province', v); set('branch', '') }}
options={PROVINCE_OPTIONS}
error={errors.province}
error={errMsg(errors.province)}
required
/>
<p className="text-xs text-muted-foreground">
Welaýaty saýlasaňyz şahamçalar güncellenar.
{t('intlPaymentForm.hints.selectRegion') || 'Welaýaty saýlasaňyz şahamçalar güncellenar.'}
</p>
</BentoCard>
<BentoCard title="Şahamça">
<BentoCard title={t('Branch') || 'Şahamça'}>
<FormInput
type="searchable-select"
label="Şahamça"
label={t('Branch') || 'Şahamça'}
value={form.branch}
onChange={(v) => set('branch', v)}
options={[]} // filtered by province
placeholder="Saýlamak üçin basyň"
error={errors.branch}
options={[]}
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
error={errMsg(errors.branch)}
required
/>
</BentoCard>
@@ -341,60 +353,64 @@ function StepLocation({
}
function StepPersonal({
form, errors, set,
form, errors, set, t,
}: {
form: FormState
errors: FormErrors
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
t: TFunction
}) {
const errMsg = (msg: string | undefined) =>
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
return (
<BentoGrid cols={2}>
<BentoCard title="At-familýa">
<BentoCard title={t('intlPaymentForm.titles.personal.name') || 'At-familýa'}>
<FormInput
type="text"
label="Pasportdaky familýa"
label={t('Passport surname') || 'Pasportdaky familiýa'}
value={form.passport_last_name}
onChange={(v) => set('passport_last_name', v)}
placeholder="NURYYEW"
error={errors.passport_last_name}
error={errMsg(errors.passport_last_name)}
required
/>
<FormInput
type="text"
label="Pasportdaky ady"
label={t('Passport name') || 'Pasportdaky ady'}
value={form.passport_first_name}
onChange={(v) => set('passport_first_name', v)}
placeholder="HAÝDAR"
error={errors.passport_first_name}
error={errMsg(errors.passport_first_name)}
required
/>
</BentoCard>
<BentoCard title="Kontakt">
<BentoCard title={t('Contact data') || 'Kontakt'}>
<FormInput
type="phone"
label="Telefon"
label={t('Phone') || 'Telefon'}
value={form.phone}
onChange={(v) => set('phone', v)}
error={errors.phone}
error={errMsg(errors.phone)}
required
/>
<FormInput
type="email"
label="E-poçta"
label={t('Email') || 'E-poçta'}
value={form.email}
onChange={(v) => set('email', v)}
placeholder="email@example.com"
/>
</BentoCard>
<BentoCard title="Häzirki ýaşyş ýeri" span="full">
<BentoCard title={t('Current Residence') || 'Häzirki ýaşaýyş ýeri'} span="full">
<FormInput
type="text"
label="Häzirki ýaşyş ýeri"
label={t('Current Residence') || 'Häzirki ýaşaýyş ýeri'}
value={form.home_address}
onChange={(v) => set('home_address', v)}
placeholder="Köçe, jaý belgisi..."
placeholder={t('intlPaymentForm.placeholders.address') || 'Köçe, jaý belgisi...'}
/>
</BentoCard>
</BentoGrid>
@@ -402,65 +418,69 @@ function StepPersonal({
}
function StepPayment({
form, errors, set,
form, errors, set, t,
}: {
form: FormState
errors: FormErrors
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
t: TFunction
}) {
const errMsg = (msg: string | undefined) =>
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
return (
<BentoGrid cols={2}>
<BentoCard title="Pasport maglumatlary">
<BentoCard title={t('Passport') || 'Pasport maglumatlary'}>
<FormInput
type="select"
label="Pasport seriýasy"
label={t('Passport serie') || 'Pasport seriýasy'}
value={form.passport_series}
onChange={(v) => set('passport_series', v)}
options={PASSPORT_SERIES_OPTIONS}
error={errors.passport_series}
error={errMsg(errors.passport_series)}
required
/>
<FormInput
type="text"
label="Pasport nomeri"
label={t('Passport id') || 'Pasport belgisi'}
value={form.passport_number}
onChange={(v) => set('passport_number', v)}
placeholder="A123456"
error={errors.passport_number}
error={errMsg(errors.passport_number)}
required
/>
</BentoCard>
<BentoCard title="Töleýji">
<BentoCard title={t('intlPaymentForm.titles.payment.payer') || 'Töleýji'}>
<FormInput
type="text"
label="Ady Familiýasy Atasynyň ady"
label={t('intlPaymentForm.labels.payerFullName') || 'Ady Familiýasy Atasynyň ady'}
value={form.payer_full_name}
onChange={(v) => set('payer_full_name', v)}
placeholder="Doly ady..."
error={errors.payer_full_name}
placeholder={t('intlPaymentForm.placeholders.payerFullName') || 'Doly ady...'}
error={errMsg(errors.payer_full_name)}
required
/>
<FormInput
type="text"
label="Goşun hasaby"
label={t('intlPaymentForm.labels.payerAccount') || 'Goşun hasaby'}
value={form.payer_account_number}
onChange={(v) => set('payer_account_number', v)}
placeholder="1234 5678 ..."
error={errors.payer_account_number}
placeholder={t('intlPaymentForm.placeholders.payerAccount') || '1234 5678 ...'}
error={errMsg(errors.payer_account_number)}
required
/>
</BentoCard>
<BentoCard title="Kabul edijiniň maglumatlary" span="full">
<BentoCard title={t('Payee information') || 'Kabul edijiniň maglumatlary'} span="full">
<FormInput
type="textarea"
label="Töleg kabul edijiniň maglumatlary"
label={t('intlPaymentForm.labels.receiverInfo') || 'Töleg kabul edijiniň maglumatlary'}
value={form.receiver_info}
onChange={(v) => set('receiver_info', v)}
placeholder="Kabul ediji bank, hasap, Swift..."
placeholder={t('intlPaymentForm.placeholders.receiverInfo') || 'Kabul ediji bank, hasap, Swift...'}
rows={3}
error={errors.receiver_info}
error={errMsg(errors.receiver_info)}
required
/>
</BentoCard>
@@ -469,14 +489,15 @@ function StepPayment({
}
function StepDocs({
form, set,
form, set, t,
}: {
form: FormState
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
t: TFunction
}) {
return (
<BentoGrid cols={2}>
<BentoCard title="Kabul ediji talyp — 9 resminama">
<BentoCard title={t('intlPaymentForm.titles.docs.kabul') || 'Kabul ediji talyp — 9 resminama'}>
<div className="space-y-3">
{KABUL_DOCS.map(({ key, label }) => (
<FormInput
@@ -491,7 +512,7 @@ function StepDocs({
</div>
</BentoCard>
<BentoCard title="Upgradyý — 6 resminama">
<BentoCard title={t('intlPaymentForm.titles.docs.upgrad') || 'Upgradyý — 6 resminama'}>
<div className="space-y-3">
{UPGRAD_DOCS.map(({ key, label }) => (
<FormInput
@@ -592,6 +613,7 @@ export function IntlPaymentForm({
const stepErrors = validateStep(form, stepId)
if (Object.keys(stepErrors).length > 0) {
setErrors(stepErrors)
toast.error(t('common.errors.fillRequiredCorrectly', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
setStepStatuses((prev) => {
const next = [...prev]
next[currentStep] = 'error'
@@ -610,6 +632,7 @@ export function IntlPaymentForm({
const allErrors = validateAll(form)
if (Object.keys(allErrors).length > 0) {
setErrors(allErrors)
toast.error(t('common.errors.requiredFieldsMissing', 'Käbir hökmany meýdanlar doldurylan däldir.'))
return
}
onSubmit({
@@ -622,8 +645,8 @@ export function IntlPaymentForm({
// ── StepBarCards data ──
const stepCardItems: StepCardItem[] = STEPS.map((s, i) => ({
id: s.id,
title: s.title,
subtitle: s.subtitle,
title: t(s.titleKey) || s.titleFallback,
subtitle: t(s.subtitleKey) || s.subtitleFallback,
status: stepStatuses[i],
icon: [User, MapPin, IdCard, CreditCard, Files][i],
}))
@@ -656,11 +679,11 @@ export function IntlPaymentForm({
</div>
{/* ── Step content ─────────────────────────────────────────────────── */}
{STEPS[currentStep].id === 'general' && <StepGeneral form={form} errors={errors} set={set} />}
{STEPS[currentStep].id === 'location' && <StepLocation form={form} errors={errors} set={set} />}
{STEPS[currentStep].id === 'personal' && <StepPersonal form={form} errors={errors} set={set} />}
{STEPS[currentStep].id === 'payment' && <StepPayment form={form} errors={errors} set={set} />}
{STEPS[currentStep].id === 'docs' && <StepDocs form={form} set={set} />}
{STEPS[currentStep].id === 'general' && <StepGeneral form={form} errors={errors} set={set} t={t} />}
{STEPS[currentStep].id === 'location' && <StepLocation form={form} errors={errors} set={set} t={t} />}
{STEPS[currentStep].id === 'personal' && <StepPersonal form={form} errors={errors} set={set} t={t} />}
{STEPS[currentStep].id === 'payment' && <StepPayment form={form} errors={errors} set={set} t={t} />}
{STEPS[currentStep].id === 'docs' && <StepDocs form={form} set={set} t={t} />}
{/* ── Actions ───────────────────────────────────────────────────────── */}
<FormActions

View File

@@ -2,27 +2,25 @@ import { z } from 'zod'
import i18next from 'i18next'
import type { IntlPaymentCreatePayload, IntlPaymentStatus, CurrencyType } from '../api/visaMasterPaymentsApi'
const t = i18next.t.bind(i18next)
const fileField = z.custom<File | null>().nullable()
export const visaMasterPaymentFormSchema = z.object({
client_id: z.string().min(1, t('validation.required', '')),
status: z.string().min(1, t('validation.required', '')),
client_id: z.string().min(1, 'validation.required'),
status: z.string().min(1, 'validation.required'),
note: z.string().optional().default(''),
currency_type: z.string().min(1, t('validation.required', '')),
province: z.string().min(1, t('validation.required', '')),
branch: z.string().min(1, t('validation.required', '')),
passport_first_name: z.string().min(1, t('validation.required', '')),
passport_last_name: z.string().min(1, t('validation.required', '')),
phone: z.string().min(1, t('validation.required', '')),
currency_type: z.string().min(1, 'validation.required'),
province: z.string().min(1, 'validation.required'),
branch: z.string().min(1, 'validation.required'),
passport_first_name: z.string().min(1, 'validation.required'),
passport_last_name: z.string().min(1, 'validation.required'),
phone: z.string().min(1, 'validation.required'),
email: z.string().optional().default(''),
home_address: z.string().optional().default(''),
passport_series: z.string().min(1, t('validation.required', '')),
passport_number: z.string().min(1, t('validation.required', '')),
payer_full_name: z.string().min(1, t('validation.required', '')),
payer_account_number: z.string().min(1, t('validation.required', '')),
receiver_info: z.string().min(1, t('validation.required', '')),
passport_series: z.string().min(1, 'validation.required'),
passport_number: z.string().min(1, 'validation.required'),
payer_full_name: z.string().min(1, 'validation.required'),
payer_account_number: z.string().min(1, 'validation.required'),
receiver_info: z.string().min(1, 'validation.required'),
doc_sberbank_account: fileField,
doc_school_enrollment: fileField,
doc_summons: fileField,
@@ -65,7 +63,10 @@ export function validateStep(
const errors: Partial<Record<keyof IntlPaymentFormData, string>> = {}
for (const issue of result.error.issues) {
const key = issue.path[0] as keyof IntlPaymentFormData
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
}

View File

@@ -2,6 +2,7 @@ import { useCallback, useMemo } from 'react'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import { zodResolver } from '@hookform/resolvers/zod'
import { FormInput } from '@/components/formInput'
import { FormActions } from '@/components/formActions'
@@ -55,7 +56,10 @@ export function VisaMasterSettingForm({
initialData,
settingId,
}: VisaMasterSettingFormProps) {
const { t } = useTranslation()
const { t } = useTranslation()
const errMsg = (msg: string | undefined) =>
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
const navigate = useNavigate()
const createMutation = useCreateVisaMasterSetting()
@@ -93,7 +97,10 @@ export function VisaMasterSettingForm({
const handleSubmit = useCallback(async () => {
const isValid = await trigger()
if (!isValid) return
if (!isValid) {
toast.error(t('common.errors.fillRequiredCorrectly', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
return
}
const payload = buildPayload(getValues())
@@ -123,7 +130,7 @@ export function VisaMasterSettingForm({
value={form.kod}
onChange={set('kod')}
placeholder={t('visaMasterSettings.fields.kod', 'Kod')}
error={errors.kod}
error={errMsg(errors.kod)}
disabled={isPending}
/>
</div>
@@ -139,7 +146,7 @@ export function VisaMasterSettingForm({
value={form.ady}
onChange={set('ady')}
placeholder={t('visaMasterSettings.fields.ady', 'Ady')}
error={errors.ady}
error={errMsg(errors.ady)}
disabled={isPending}
/>
</div>
@@ -155,7 +162,7 @@ export function VisaMasterSettingForm({
value={form.yazgy}
onChange={set('yazgy')}
placeholder={t('visaMasterSettings.fields.yazgy', 'Yazgy')}
error={errors.yazgy}
error={errMsg(errors.yazgy)}
disabled={isPending}
rows={3}
/>

View File

@@ -1,13 +1,10 @@
import { z } from 'zod'
import i18next from 'i18next'
import type { VisaMasterSettingPayload } from '../api/visaMasterSberSettingsApi'
const t = i18next.t.bind(i18next)
export const visaMasterSettingFormSchema = z.object({
kod: z.string().min(1, t('validation.required', '')),
ady: z.string().min(1, t('validation.required', '')),
yazgy: z.string().min(1, t('validation.required', '')),
kod: z.string().min(1, 'validation.required'),
ady: z.string().min(1, 'validation.required'),
yazgy: z.string().min(1, 'validation.required'),
})
export type VisaMasterSettingFormData = z.infer<typeof visaMasterSettingFormSchema>

View File

@@ -373,7 +373,18 @@
"common.search": "Search",
"common.yes": "Yes",
"common.no": "No",
"loanRemaining.create.title": "New Loan Remaining Balance",
"loanRemaining.edit.title": "Edit Loan Remaining Balance",
"loanOrders.title": "Loan Orders",
"loanOrders.create": "Create Loan Order",
"loanOrders.edit": "Edit Loan Order",
"loanOrders.createDescription": "Fill in all fields step by step.",
"loanOrders.editDescription": "Fill in all fields step by step.",
"loanOrderMobiles.title": "Loan Orders (Mobile)",
"loanOrderMobiles.createTitle": "Create Loan Order (Mobile)",
"loanOrderMobiles.editTitle": "Edit Loan Order",
"loanOrderMobiles.createDescription": "Fill in all fields step by step.",
"loanOrderMobiles.editDescription": "Fill in all fields step by step.",
"loanOrderMobiles.searchPlaceholder": "Search...",
"loanOrderMobiles.createButton": "Create Loan Order",
"loanOrderMobiles.deleteConfirm": "Are you sure you want to delete this order?",
@@ -418,6 +429,11 @@
"Loan balance": "Loan balance",
"common.cancel": "Cancel",
"common.confirm": "Confirm",
"common.back": "Back",
"common.next": "Next",
"common.save": "Save",
"common.create": "Create",
"common.loading": "Loading...",
"common.errors.fillRequiredCorrectly": "Please enter correct data.",
"common.errors.requiredFieldsMissing": "Some required fields are missing.",
"validation.required": "Required field",
@@ -428,5 +444,126 @@
"validation.requiredTerms": "You must agree to the terms",
"validation.valuePositive": "Value must be greater than 0",
"validation.minLength": "At least {length} characters",
"validation.invalidEmail": "Invalid email format"
"validation.invalidEmail": "Invalid email format",
"Status": "Status",
"Card (Salary)": "Card (Salary)",
"1. Guarantor": "1. Guarantor",
"Loan history": "Loan history",
"loanOrderForm.labels.status": "Status",
"loanOrderForm.labels.loanAmount": "Loan amount",
"loanOrderForm.labels.cardExpMonth": "Month",
"loanOrderForm.labels.cardExpYear": "Year",
"loanOrderForm.labels.guarantor1Salary": "Average salary",
"loanOrderForm.steps.status.subtitle": "Status & Note",
"loanOrderForm.steps.loan.subtitle": "Type & Amount",
"loanOrderForm.steps.location.subtitle": "Region & Branch",
"loanOrderForm.steps.personal.subtitle": "Name, Education, Family",
"loanOrderForm.steps.card.subtitle": "Salary Card",
"loanOrderForm.steps.passport.subtitle": "Series, Number, Date",
"loanOrderForm.steps.contact.subtitle": "Phone & Email",
"loanOrderForm.steps.job.subtitle": "Company & Position",
"loanOrderForm.steps.files.subtitle": "Passport Photos",
"loanOrderForm.steps.guarantor.subtitle": "Guarantor Info",
"loanOrderForm.placeholders.select": "Select",
"loanOrderForm.placeholders.searchableSelect": "Click to select",
"loanOrderForm.placeholders.note": "Note...",
"loanOrderForm.placeholders.amount": "0.00",
"loanOrderForm.placeholders.phone": "61 097 651",
"loanOrderForm.placeholders.companyName": "Company name",
"loanOrderForm.placeholders.residence": "Registered address",
"loanOrderForm.placeholders.currentResidence": "Current residence",
"loanOrderForm.titles.cardInfo": "Card details",
"loanOrderForm.titles.cardExpiry": "Card expiry",
"loanOrderForm.titles.contactMain": "Main",
"loanOrderForm.titles.contactAdditional": "Additional",
"loanOrderForm.fileLabels.replacePage1": "Passport (page 1) (replace)",
"loanOrderForm.fileLabels.replacePage23": "Passport (pages 2-3) (replace)",
"loanOrderForm.fileLabels.viewFile": "View file",
"loanOrderForm.guarantorCardInfo": "Guarantor card details",
"loanOrderForm.guarantorCardExpiry": "Guarantor card expiry",
"loanOrderMobileForm.steps.loan.title": "Loan",
"loanOrderMobileForm.steps.loan.subtitle": "Type, Amount & Location",
"loanOrderMobileForm.steps.personal.title": "Personal & Passport",
"loanOrderMobileForm.steps.personal.subtitle": "Identity & passport",
"loanOrderMobileForm.steps.contact.title": "Contact & Job",
"loanOrderMobileForm.steps.contact.subtitle": "Phone & work",
"loanOrderMobileForm.steps.card.title": "Card & Guarantor",
"loanOrderMobileForm.steps.card.subtitle": "Payment & guarantor",
"loanOrderMobileForm.steps.files.title": "Files & Status",
"loanOrderMobileForm.steps.files.subtitle": "Documents",
"Card type": "Card type",
"orderNewCardForm.steps.card.subtitle": "Type & Location",
"orderNewCardForm.steps.personal.subtitle": "Personal info",
"orderNewCardForm.steps.passport.subtitle": "Official data",
"orderNewCardForm.steps.files.subtitle": "Upload & Confirm",
"orderNewCardForm.isPaid": "Paid",
"orderNewCardForm.placeholders.formerLastName": "Former surname",
"orderNewCardForm.labels.registeredAddress": "Registered address",
"orderNewCardForm.labels.currentAddress": "Current address",
"orderNewCardForm.labels.workplace": "Workplace & position",
"common.prev": "Back",
"common.saving": "Saving...",
"common.success.create": "Successfully created",
"common.success.save": "Successfully saved",
"common.errors.fillRequired": "Please fill required fields",
"validation.fixErrors": "Please fix the errors",
"cardOrder.step.card": "Card",
"cardOrder.step.personal": "Personal",
"cardOrder.step.passport": "Passport",
"cardOrder.step.files": "Files",
"cardOrder.submit": "Create card order",
"cardOrder.status.pending": "Pending",
"cardOrder.status.approved": "Approved",
"cardOrder.status.rejected": "Rejected",
"citizenship.tm": "Turkmenistan",
"citizenship.ru": "Russia",
"citizenship.other": "Other",
"loanOrders.saveButton": "Save",
"loanRemaining.placeholders.passportSeries": "TM",
"Passport series": "Passport series",
"Card expiry month": "Card expiry (month)",
"Card expiry year": "Card expiry (year)",
"Select to choose": "Click to select",
"Saving...": "Saving...",
"Create card transaction": "Create card transaction",
"Create card balance": "Create card balance",
"Select": "Select",
"Save changes": "Save changes",
"cardRequisiteForm.steps.card.subtitle": "Type & Location",
"cardRequisiteForm.steps.personal.subtitle": "Name & Phone",
"cardRequisiteForm.steps.passport.subtitle": "Documents",
"cardRequisiteForm.labels.cardType": "Card type",
"cardPinForm.steps.card.subtitle": "Type & Location",
"cardPinForm.steps.personal.subtitle": "Info",
"cardPinForm.steps.passport.subtitle": "Documents",
"cardPinForm.titles.location": "Location",
"cardPin.step.card": "Card",
"cardPin.step.personal": "Personal",
"cardPin.step.passport": "Passport",
"cardPin.createBtn": "Create PIN envelope",
"cardPin.editBtn": "Edit PIN envelope",
"intlPaymentForm.steps.general.title": "General",
"intlPaymentForm.steps.general.subtitle": "Status, client",
"intlPaymentForm.steps.location.title": "Location",
"intlPaymentForm.steps.location.subtitle": "Region, branch",
"intlPaymentForm.steps.personal.title": "Personal",
"intlPaymentForm.steps.personal.subtitle": "Passport, contact",
"intlPaymentForm.steps.payment.title": "Payment",
"intlPaymentForm.steps.payment.subtitle": "Payer, receiver",
"intlPaymentForm.steps.docs.title": "Documents",
"intlPaymentForm.steps.docs.subtitle": "15 documents",
"intlPaymentForm.titles.general.client": "Client",
"intlPaymentForm.titles.personal.name": "Name & Surname",
"intlPaymentForm.titles.payment.payer": "Payer",
"intlPaymentForm.titles.docs.kabul": "Receiver student — 9 docs",
"intlPaymentForm.titles.docs.upgrad": "Upgrade — 6 docs",
"intlPaymentForm.labels.payerFullName": "Full name",
"intlPaymentForm.labels.payerAccount": "Account number",
"intlPaymentForm.labels.receiverInfo": "Receiver info",
"intlPaymentForm.placeholders.payerFullName": "Full name...",
"intlPaymentForm.placeholders.payerAccount": "1234 5678 ...",
"intlPaymentForm.placeholders.receiverInfo": "Receiver bank, account, Swift...",
"intlPaymentForm.placeholders.address": "Street, house number...",
"intlPaymentForm.hints.selectRegion": "Branches update when region is selected.",
"Fix errors": "Please fix the errors"
}

View File

@@ -373,7 +373,18 @@
"common.search": "Поиск",
"common.yes": "Да",
"common.no": "Нет",
"loanRemaining.create.title": "Новая задолженность по кредиту",
"loanRemaining.edit.title": "Изменить задолженность по кредиту",
"loanOrders.title": "Заявки на кредит",
"loanOrders.create": "Создать заявку на кредит",
"loanOrders.edit": "Редактировать заявку на кредит",
"loanOrders.createDescription": "Заполните все поля, чтобы создать новую заявку на кредит.",
"loanOrders.editDescription": "Измените данные существующей заявки на кредит.",
"loanOrderMobiles.title": "Заявки на кредит (Мобильные)",
"loanOrderMobiles.createTitle": "Создать заявку на кредит (Мобильные)",
"loanOrderMobiles.editTitle": "Редактировать заявку на кредит (Мобильные)",
"loanOrderMobiles.createDescription": "Заполните все поля, чтобы создать новую заявку на кредит.",
"loanOrderMobiles.editDescription": "Измените данные существующей заявки на кредит.",
"loanOrderMobiles.searchPlaceholder": "Поиск...",
"loanOrderMobiles.createButton": "Создать заявку на кредит",
"loanOrderMobiles.deleteConfirm": "Вы уверены, что хотите удалить этот заказ?",
@@ -418,6 +429,11 @@
"Loan balance": "Остаток кредита",
"common.cancel": "Отмена",
"common.confirm": "Подтвердить",
"common.back": "Назад",
"common.next": "Дальше",
"common.save": "Сохранить",
"common.create": "Создать",
"common.loading": "Загрузка...",
"common.errors.fillRequiredCorrectly": "Пожалуйста, введите корректные данные.",
"common.errors.requiredFieldsMissing": "Некоторые обязательные поля не заполнены.",
"validation.required": "Обязательное поле",
@@ -428,5 +444,127 @@
"validation.requiredTerms": "Необходимо согласиться с условиями",
"validation.valuePositive": "Значение должно быть больше 0",
"validation.minLength": "Минимум {length} символов",
"validation.invalidEmail": "Неверный формат email"
"validation.invalidEmail": "Неверный формат email",
"Status": "Статус",
"Card (Salary)": "Карта (Зарплата)",
"1. Guarantor": "1. Поручитель",
"Loan history": "Кредитная история",
"loanOrderForm.labels.status": "Статус",
"loanOrderForm.labels.loanAmount": "Сумма кредита",
"loanOrderForm.labels.cardExpMonth": "Месяц",
"loanOrderForm.labels.cardExpYear": "Год",
"loanOrderForm.labels.guarantor1Salary": "Средняя зарплата",
"loanOrderForm.steps.status.subtitle": "Статус и заметка",
"loanOrderForm.steps.loan.subtitle": "Тип и сумма",
"loanOrderForm.steps.location.subtitle": "Велаят и филиал",
"loanOrderForm.steps.personal.subtitle": "Имя, образование, семья",
"loanOrderForm.steps.card.subtitle": "Зарплатная карта",
"loanOrderForm.steps.passport.subtitle": "Серия, номер, дата",
"loanOrderForm.steps.contact.subtitle": "Телефон и email",
"loanOrderForm.steps.job.subtitle": "Компания и должность",
"loanOrderForm.steps.files.subtitle": "Фото паспорта",
"loanOrderForm.steps.guarantor.subtitle": "Информация о поручителе",
"loanOrderForm.placeholders.select": "Выберите",
"loanOrderForm.placeholders.searchableSelect": "Нажмите для выбора",
"loanOrderForm.placeholders.note": "Примечание...",
"loanOrderForm.placeholders.amount": "0.00",
"loanOrderForm.placeholders.phone": "61 097 651",
"loanOrderForm.placeholders.companyName": "Название компании",
"loanOrderForm.placeholders.residence": "Адрес прописки",
"loanOrderForm.placeholders.currentResidence": "Фактический адрес",
"loanOrderForm.titles.cardInfo": "Данные карты",
"loanOrderForm.titles.cardExpiry": "Срок карты",
"loanOrderForm.titles.contactMain": "Основной",
"loanOrderForm.titles.contactAdditional": "Дополнительный",
"loanOrderForm.fileLabels.replacePage1": "Паспорт (страница 1) (заменить)",
"loanOrderForm.fileLabels.replacePage23": "Паспорт (страницы 2-3) (заменить)",
"loanOrderForm.fileLabels.viewFile": "Просмотреть файл",
"loanOrderForm.guarantorCardInfo": "Данные карты поручителя",
"loanOrderForm.guarantorCardExpiry": "Срок карты поручителя",
"loanOrderMobileForm.steps.loan.title": "Кредит",
"loanOrderMobileForm.steps.loan.subtitle": "Тип, сумма и местоположение",
"loanOrderMobileForm.steps.personal.title": "Личные данные и паспорт",
"loanOrderMobileForm.steps.personal.subtitle": "Личность и паспорт",
"loanOrderMobileForm.steps.contact.title": "Контакты и работа",
"loanOrderMobileForm.steps.contact.subtitle": "Телефон и работа",
"loanOrderMobileForm.steps.card.title": "Карта и поручитель",
"loanOrderMobileForm.steps.card.subtitle": "Платёж и поручитель",
"loanOrderMobileForm.steps.files.title": "Файлы и статус",
"loanOrderMobileForm.steps.files.subtitle": "Документы",
"Card type": "Тип карты",
"orderNewCardForm.steps.card.subtitle": "Тип и местоположение",
"orderNewCardForm.steps.personal.subtitle": "Личные данные",
"orderNewCardForm.steps.passport.subtitle": "Официальные данные",
"orderNewCardForm.steps.files.subtitle": "Загрузка и подтверждение",
"orderNewCardForm.isPaid": "Оплачено",
"orderNewCardForm.placeholders.formerLastName": "Прежняя фамилия",
"orderNewCardForm.labels.registeredAddress": "Адрес прописки",
"orderNewCardForm.labels.currentAddress": "Фактический адрес",
"orderNewCardForm.labels.workplace": "Место работы и должность",
"common.prev": "Назад",
"common.saving": "Сохранение...",
"common.success.create": "Успешно создано",
"common.success.save": "Успешно сохранено",
"common.errors.fillRequired": "Заполните обязательные поля",
"validation.fixErrors": "Пожалуйста, исправьте ошибки",
"cardOrder.step.card": "Карта",
"cardOrder.step.personal": "Личные данные",
"cardOrder.step.passport": "Паспорт",
"cardOrder.step.files": "Файлы",
"cardOrder.submit": "Создать заявку на карту",
"cardOrder.status.pending": "В ожидании",
"cardOrder.status.approved": "Одобрено",
"cardOrder.status.rejected": "Отклонено",
"citizenship.tm": "Туркменистан",
"citizenship.ru": "Россия",
"citizenship.other": "Другое",
"loanOrders.saveButton": "Сохранить",
"loanRemaining.placeholders.passportSeries": "TM",
"Passport series": "Серия паспорта",
"Card expiry month": "Срок карты (месяц)",
"Card expiry year": "Срок карты (год)",
"Select to choose": "Нажмите для выбора",
"Saving...": "Сохранение...",
"Create card transaction": "Создать транзакцию",
"Create card balance": "Создать запись об остатке",
"Select": "Выберите",
"Save changes": "Сохранить изменения",
"cardRequisiteForm.steps.card.subtitle": "Тип и местоположение",
"cardRequisiteForm.steps.personal.subtitle": "Имя и телефон",
"cardRequisiteForm.steps.passport.subtitle": "Документы",
"cardRequisiteForm.labels.cardType": "Тип карты",
"Fix errors": "Пожалуйста, исправьте ошибки",
"Personal": "Личные данные",
"cardPinForm.steps.card.subtitle": "Тип и местоположение",
"cardPinForm.steps.personal.subtitle": "Информация",
"cardPinForm.steps.passport.subtitle": "Документы",
"cardPinForm.titles.location": "Местоположение",
"cardPin.step.card": "Карта",
"cardPin.step.personal": "Личные данные",
"cardPin.step.passport": "Паспорт",
"cardPin.createBtn": "Создать ПИН-конверт",
"cardPin.editBtn": "Редактировать ПИН-конверт",
"intlPaymentForm.steps.general.title": "Основное",
"intlPaymentForm.steps.general.subtitle": "Статус, клиент",
"intlPaymentForm.steps.location.title": "Местоположение",
"intlPaymentForm.steps.location.subtitle": "Велаят, филиал",
"intlPaymentForm.steps.personal.title": "Личные данные",
"intlPaymentForm.steps.personal.subtitle": "Паспорт, контакт",
"intlPaymentForm.steps.payment.title": "Платёж",
"intlPaymentForm.steps.payment.subtitle": "Плательщик, получатель",
"intlPaymentForm.steps.docs.title": "Документы",
"intlPaymentForm.steps.docs.subtitle": "15 документов",
"intlPaymentForm.titles.general.client": "Клиент",
"intlPaymentForm.titles.personal.name": "Имя и фамилия",
"intlPaymentForm.titles.payment.payer": "Плательщик",
"intlPaymentForm.titles.docs.kabul": "Студент-получатель — 9 док.",
"intlPaymentForm.titles.docs.upgrad": "Апгрейд — 6 док.",
"intlPaymentForm.labels.payerFullName": "Полное имя",
"intlPaymentForm.labels.payerAccount": "Номер счета",
"intlPaymentForm.labels.receiverInfo": "Информация о получателе",
"intlPaymentForm.placeholders.payerFullName": "Полное имя...",
"intlPaymentForm.placeholders.payerAccount": "1234 5678 ...",
"intlPaymentForm.placeholders.receiverInfo": "Банк получателя, счет, Swift...",
"intlPaymentForm.placeholders.address": "Улица, номер дома...",
"intlPaymentForm.hints.selectRegion": "Филиалы обновятся после выбора велаята."
}

View File

@@ -202,7 +202,7 @@
"Passport (page 32)": "Pasport (32-nji sahypa)",
"Passport (page 8-9)": "Pasport (8-9 sahypa)",
"Passport date of issue": "Pasport berlen senesi",
"Passport files": "Pasport faýýlar",
"Passport files": "Pasport faýllar",
"Passport given by": "Kim tarapyndan berildi",
"Passport id": "Pasport belgisi",
"Passport name": "Pasportdaky ady",
@@ -373,7 +373,18 @@
"common.search": "Gözlemek",
"common.yes": "Hawa",
"common.no": "Ýok",
"loanRemaining.create.title": "Täze karz galyndysy",
"loanRemaining.edit.title": "Karz galyndysyny üýtget",
"loanOrders.title": "Karz sargytlary",
"loanOrders.create": "Karz sargyt dörediň",
"loanOrders.edit": "Karz sargydy üýtget",
"loanOrders.createDescription": "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.",
"loanOrders.editDescription": "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.",
"loanOrderMobiles.title": "Karz sargytlary",
"loanOrderMobiles.editTitle": "Karz sargydy üýtget",
"loanOrderMobiles.createTitle": "Karz sargydy dörediň (Mobile)",
"loanOrderMobiles.createDescription": "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.",
"loanOrderMobiles.editDescription": "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.",
"loanOrderMobiles.searchPlaceholder": "Gözlemek",
"loanOrderMobiles.createButton": "Karz sargyt dörediň",
"loanOrderMobiles.deleteConfirm": "Bu sargyt pozulsynmy?",
@@ -434,6 +445,11 @@
"loanDocuments.toast.deleteError": "Resminama öçürilende ýalňyşlyk ýüze çykdy!",
"common.cancel": "Ýatyrmak",
"common.confirm": "Tassykla",
"common.back": "Yza gaýtmak",
"common.next": "Indiki",
"common.save": "Ýatda sakla",
"common.create": "Döretmek",
"common.loading": "Ýüklenilýär...",
"common.errors.fillRequiredCorrectly": "Dogry maglumat girizmegiňizi haýyş edýäris.",
"common.errors.requiredFieldsMissing": "Käbir hökmany meýdanlar doldurylan däldir.",
"validation.required": "Hökmany meýdan",
@@ -444,5 +460,127 @@
"validation.requiredTerms": "Şertnama bilen razylaşmaly",
"validation.valuePositive": "Baha 0-dan uly bolmaly",
"validation.minLength": "Iň az {length} harp giriziň",
"validation.invalidEmail": "Nädogry e-poçta formaty"
"validation.invalidEmail": "Nädogry e-poçta formaty",
"Status": "Ýagdaý",
"Card (Salary)": "Kart (Zähmet haky)",
"1. Guarantor": "1. Zamun",
"Loan history": "Karz taryhy",
"loanOrderForm.labels.status": "Status",
"loanOrderForm.labels.loanAmount": "Karz möçberi",
"loanOrderForm.labels.cardExpMonth": "Aý",
"loanOrderForm.labels.cardExpYear": "Ýyl",
"loanOrderForm.labels.guarantor1Salary": "Ortaca zähmet haky",
"loanOrderForm.steps.status.subtitle": "Ýagdaý we bellik",
"loanOrderForm.steps.loan.subtitle": "Görnüş we möçber",
"loanOrderForm.steps.location.subtitle": "Welaýat we şahamça",
"loanOrderForm.steps.personal.subtitle": "At, bilim, maşgala",
"loanOrderForm.steps.card.subtitle": "Zähmet haky karty",
"loanOrderForm.steps.passport.subtitle": "Seriýa, belgisi, senesi",
"loanOrderForm.steps.contact.subtitle": "Telefon we e-poçta",
"loanOrderForm.steps.job.subtitle": "Kärhana we wezipe",
"loanOrderForm.steps.files.subtitle": "Pasport suratlary",
"loanOrderForm.steps.guarantor.subtitle": "Zamun maglumatlary",
"loanOrderForm.placeholders.select": "Saýlaň",
"loanOrderForm.placeholders.searchableSelect": "Saýlamak üçin basyň",
"loanOrderForm.placeholders.note": "Bellik...",
"loanOrderForm.placeholders.amount": "0.00",
"loanOrderForm.placeholders.phone": "61 097 651",
"loanOrderForm.placeholders.companyName": "Kärhananyň ady",
"loanOrderForm.placeholders.residence": "Ýazgy edilen salgy",
"loanOrderForm.placeholders.currentResidence": "Häzirki ýaşaýyş ýeri",
"loanOrderForm.titles.cardInfo": "Kart maglumatlary",
"loanOrderForm.titles.cardExpiry": "Kart möhleti",
"loanOrderForm.titles.contactMain": "Esasy",
"loanOrderForm.titles.contactAdditional": "Goşmaça",
"loanOrderForm.fileLabels.replacePage1": "Pasport (sahypa 1) (çalyşmak)",
"loanOrderForm.fileLabels.replacePage23": "Pasport (2-3-nji sahypa) (çalyşmak)",
"loanOrderForm.fileLabels.viewFile": "Faýly gör",
"loanOrderForm.guarantorCardInfo": "Zamunyň kart maglumatlary",
"loanOrderForm.guarantorCardExpiry": "Zamunyň kart möhleti",
"loanOrderMobileForm.steps.loan.title": "Karz",
"loanOrderMobileForm.steps.loan.subtitle": "Görnüş, möçber & lokasiýa",
"loanOrderMobileForm.steps.personal.title": "Şahsy & Pasport",
"loanOrderMobileForm.steps.personal.subtitle": "Şahsyýet & pasport",
"loanOrderMobileForm.steps.contact.title": "Habarlaşmak & Iş",
"loanOrderMobileForm.steps.contact.subtitle": "Telefon & iş",
"loanOrderMobileForm.steps.card.title": "Kart & Zamun",
"loanOrderMobileForm.steps.card.subtitle": "Töleg & zamun",
"loanOrderMobileForm.steps.files.title": "Faýllar & Status",
"loanOrderMobileForm.steps.files.subtitle": "Resminamalar",
"Card type": "Kart görnüşi",
"orderNewCardForm.steps.card.subtitle": "Görnüş & lokasiýa",
"orderNewCardForm.steps.personal.subtitle": "Maglumatlar",
"orderNewCardForm.steps.passport.subtitle": "Resmi maglumat",
"orderNewCardForm.steps.files.subtitle": "Ýüklemek & Tassyklamak",
"orderNewCardForm.isPaid": "Tölenen",
"orderNewCardForm.placeholders.formerLastName": "Köne familiýaňyz",
"orderNewCardForm.labels.registeredAddress": "Ýazgy edilen salgyňyz",
"orderNewCardForm.labels.currentAddress": "Häzirki ýaşaýyş ýeri",
"orderNewCardForm.labels.workplace": "Işleýän ýeriňiz we wezipäňiz",
"common.prev": "Yza",
"common.saving": "Ýüklenilýär...",
"common.success.create": "Üstünlikli döredildi",
"common.success.save": "Üstünlikli ýatda saklandy",
"common.errors.fillRequired": "Hökman doldurylmaly öýjükleri dolduryň",
"validation.fixErrors": "Dogry maglumat girizmegiňizi haýyş edýäris.",
"cardOrder.step.card": "Kart",
"cardOrder.step.personal": "Şahsy",
"cardOrder.step.passport": "Pasport",
"cardOrder.step.files": "Faýllar",
"cardOrder.submit": "Kart sargyt dörediň",
"cardOrder.status.pending": "Garaşylýar",
"cardOrder.status.approved": "Tassyklandy",
"cardOrder.status.rejected": "Ýatyryldy",
"citizenship.tm": "Türkmenistan",
"citizenship.ru": "Russiýa",
"citizenship.other": "Beýlekiler",
"loanOrders.saveButton": "Ýatda sakla",
"loanRemaining.placeholders.passportSeries": "TM",
"Passport series": "Pasport seriýasy",
"Card expiry month": "Kart möhleti (aý)",
"Card expiry year": "Kart möhleti (ýyl)",
"Select to choose": "Saýlamak üçin basyň",
"Saving...": "Saklanýar...",
"Create card transaction": "Kart herekedi dörediň",
"Create card balance": "Kart galyndysy dörediň",
"Select": "Saýlamak üçin basyň",
"Save changes": "Üýtgetmeleri sakla",
"cardRequisiteForm.steps.card.subtitle": "Görnüş & lokasiýa",
"cardRequisiteForm.steps.personal.subtitle": "At & telefon",
"cardRequisiteForm.steps.passport.subtitle": "Resminamalar",
"cardRequisiteForm.labels.cardType": "Kart görnüşi",
"Fix errors": "Dogry maglumat girizmegiňizi haýyş edýäris.",
"Personal": "Şahsy",
"cardPinForm.steps.card.subtitle": "Görnüş & lokasiýa",
"cardPinForm.steps.personal.subtitle": "Maglumatlar",
"cardPinForm.steps.passport.subtitle": "Resminamalar",
"cardPinForm.titles.location": "Lokasiýa",
"cardPin.step.card": "Kart",
"cardPin.step.personal": "Şahsy",
"cardPin.step.passport": "Pasport",
"cardPin.createBtn": "Kart pin bukja dörediň",
"cardPin.editBtn": "Kart pin bukja redaktirläň",
"intlPaymentForm.steps.general.title": "Esasy",
"intlPaymentForm.steps.general.subtitle": "Status, müşderi",
"intlPaymentForm.steps.location.title": "Lokasiýa",
"intlPaymentForm.steps.location.subtitle": "Welaýat, şahamça",
"intlPaymentForm.steps.personal.title": "Şahsy",
"intlPaymentForm.steps.personal.subtitle": "Pasport, kontakt",
"intlPaymentForm.steps.payment.title": "Töleg",
"intlPaymentForm.steps.payment.subtitle": "Töleýji, kabul ediji",
"intlPaymentForm.steps.docs.title": "Resminamalar",
"intlPaymentForm.steps.docs.subtitle": "15 resminama",
"intlPaymentForm.titles.general.client": "Müşderi",
"intlPaymentForm.titles.personal.name": "At-familýa",
"intlPaymentForm.titles.payment.payer": "Töleýji",
"intlPaymentForm.titles.docs.kabul": "Kabul ediji talyp — 9 resminama",
"intlPaymentForm.titles.docs.upgrad": "Upgradyý — 6 resminama",
"intlPaymentForm.labels.payerFullName": "Ady Familiýasy Atasynyň ady",
"intlPaymentForm.labels.payerAccount": "Goşun hasaby",
"intlPaymentForm.labels.receiverInfo": "Töleg kabul edijiniň maglumatlary",
"intlPaymentForm.placeholders.payerFullName": "Doly ady...",
"intlPaymentForm.placeholders.payerAccount": "1234 5678 ...",
"intlPaymentForm.placeholders.receiverInfo": "Kabul ediji bank, hasap, Swift...",
"intlPaymentForm.placeholders.address": "Köçe, jaý belgisi...",
"intlPaymentForm.hints.selectRegion": "Welaýaty saýlasaňyz şahamçalar güncellenar."
}

View File

@@ -271,7 +271,7 @@ export default function LoanOrdersPage() {
<DataTableToolbar
searchValue={search}
onSearchChange={(v) => { setSearch(v); setPage(1) }}
searchPlaceholder={t('loanOrders.searchPlaceholder', 'Gözlemek')}
searchPlaceholder={t('loanOrderMobiles.searchPlaceholder', 'Gözlemek')}
columns={toggleableColumns}
columnVisibility={columnVisibility}
onColumnVisibilityChange={setColumnVisibility}