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 { CircleDot, CreditCard, MapPin, User, Wallet, FileText, Phone, Briefcase, ShieldCheck } from "lucide-react"; import type { LucideIcon } from "lucide-react"; import { FormInput, type SelectOption } from "@/components/formInput"; import { FormActions } from "@/components/formActions"; import { DocumentUpload } from "@/components/documentUpload"; import { InfiniteSelect, type InfiniteSelectOption } from "@/components/infiniteSelect"; import { StepBarCards, type StepCardItem } from "@/components/stepBarV2"; import { BentoGrid, BentoCard } from "@/components/bento"; import { useCreateLoanOrder, useUpdateLoanOrder } from "@/features/loanOrders/hooks/useLoanOrders"; import type { LoanOrder } from "@/features/loanOrders/api/loanOrdersApi"; import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "@/features/loanOrders/schemas/loanOrder.schema"; import type { LoanOrderFormData } from "@/features/loanOrders/schemas/loanOrder.schema"; import { useInfiniteLoanTypes } from "@/features/loanTypes/hooks/useLoanTypes"; import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers"; import { useInfiniteProvinces } from "@/features/branches/hooks/useBranches"; import type { LocalizedText } from "@/features/branches/api/branchesApi"; import { formatFromApiDate, formatFromApiPhone } from "@/lib/utils"; import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants"; // ─── Static options ─────────────────────────────────────────────────────────── const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const; function resolveLocalizedName(name: LocalizedText | string | null | undefined, lang = "en"): string { if (!name) return ""; if (typeof name === "string") return name; return name[lang as keyof LocalizedText] ?? name.tm ?? name.en ?? name.ru ?? ""; } function getRegionOptions(t: TFunction): SelectOption[] { return REGION_CODES.map((code) => ({ value: code, label: t(`loanOrders.regions.${code}`, code), })); } const EDUCATION_OPTIONS = [ { value: "high", label: "Ýokary bilim" }, { value: "unfinished_high", label: "Gutarylmadyk ýokary bilim" }, { value: "masters", label: "Magistr" }, { value: "phd", label: "Ylymlaryň doktory" }, { value: "middle", label: "Orta mekdep" }, { value: "school", label: "Orta bilim" }, { value: "school_dropout", label: "Gutarylmadyk orta bilim" }, ]; const MARRIAGE_OPTIONS = [ { value: "MARRIED", label: "Öýlenen / Durmuşa çykan" }, { value: "SINGLE", label: "Öýlenmedik / Durmuşa çykmadyk" }, { value: "DIVORCED", label: "Aýrylşan" }, { value: "WIDOW", label: "Adamsy ýa-da aýaly aradan çykan" }, { value: "LEGAL", label: "Raýat nika" }, ]; const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({ value: String(i + 1).padStart(2, "0"), label: String(i + 1).padStart(2, "0"), })); const YEAR_OPTIONS = Array.from({ length: 15 }, (_, i) => ({ value: String(new Date().getFullYear() + i), label: String(new Date().getFullYear() + i), })); // ─── Form errors helper ────────────────────────────────────────────────────── type FlatErrors = Partial>; function flattenErrors(errors: Record): FlatErrors { const result: FlatErrors = {}; for (const key of Object.keys(errors)) { const msg = errors[key]?.message; if (msg) result[key as keyof LoanOrderFormData] = msg; } return result; } // ─── Step definitions ───────────────────────────────────────────────────────── interface StepDef { id: string; titleKey: string; titleFallback: string; subtitleKey: string; subtitleFallback: string; icon: LucideIcon; validate: (form: LoanOrderFormData, mode: "create" | "edit") => FlatErrors; } const STEPS: StepDef[] = [ { id: "status", titleKey: "Status", titleFallback: "Status", subtitleKey: "loanOrderForm.steps.status.subtitle", subtitleFallback: "Ýagdaý we bellik", icon: CircleDot, validate: (form, mode) => validateStep(0, form, mode), }, { id: "loan", titleKey: "Loan", titleFallback: "Karz", 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", 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", 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)", 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", subtitleKey: "loanOrderForm.steps.passport.subtitle", subtitleFallback: "Seriýa, belgisi, senesi, suratlar", icon: FileText, validate: (form, mode) => validateStep(5, form, mode), }, { id: "contact", titleKey: "Contact data", titleFallback: "Habarlaşmak", 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ş", subtitleKey: "loanOrderForm.steps.job.subtitle", subtitleFallback: "Kärhana we wezipe", icon: Briefcase, validate: (form, mode) => validateStep(7, form, mode), }, { id: "guarantor", titleKey: "1. Guarantor", titleFallback: "1. Zamun", subtitleKey: "loanOrderForm.steps.guarantor.subtitle", subtitleFallback: "Zamun maglumatlary", icon: ShieldCheck, validate: (form, mode) => validateStep(8, form, mode), }, { id: "guarantor2", titleKey: "2. Guarantor", titleFallback: "2. Zamun", subtitleKey: "loanOrderForm.steps.guarantor2.subtitle", subtitleFallback: "2. Zamun maglumatlary", icon: ShieldCheck, validate: (form, mode) => validateStep(9, form, mode), }, ]; // ─── Shared step content props ──────────────────────────────────────────────── interface StepContentProps { form: LoanOrderFormData; errors: FlatErrors; set: (k: K, v: LoanOrderFormData[K]) => void; t: TFunction; } // ─── Step panels ────────────────────────────────────────────────────────────── function StepStatus({ form, errors, set, t }: StepContentProps) { const statusOptions = useMemo(() => getStatusOptions(t, "loanOrderStatus"), [t]); return ( set("status", v)} options={statusOptions} error={errors.status} placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"} /> set("note", v)} placeholder={t("loanOrderForm.placeholders.note") || "Bellik..."} rows={3} /> ); } function StepLoan({ form, errors, set, t, initialData }: StepContentProps & { initialData?: LoanOrder }) { const { i18n } = useTranslation(); const [loanTypeSearch, setLoanTypeSearch] = useState(""); const loanTypesQuery = useInfiniteLoanTypes(loanTypeSearch); const loanTypeOptions: InfiniteSelectOption[] = useMemo(() => { const lang = i18n.language ?? "en"; const opts: InfiniteSelectOption[] = (loanTypesQuery.data?.pages ?? []) .flatMap((p) => p.loanTypes) .map((lt) => ({ value: String(lt.id), label: resolveLocalizedName(lt.title, lang) || String(lt.id) })); if (initialData?.loanTypeId && !opts.some((o) => o.value === String(initialData.loanTypeId))) { opts.unshift({ value: String(initialData.loanTypeId), label: initialData.loanType || String(initialData.loanTypeId) }); } return opts; }, [loanTypesQuery, i18n.language, initialData]); return ( set("loanType", v)} options={loanTypeOptions} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.loanType} loading={loanTypesQuery.isLoading} isLoadingMore={loanTypesQuery.isFetchingNextPage} hasNextPage={!!loanTypesQuery.hasNextPage} onLoadMore={() => loanTypesQuery.fetchNextPage()} searchValue={loanTypeSearch} onSearchChange={setLoanTypeSearch} /> set("loanAmount", v)} placeholder={t("loanOrderForm.placeholders.amount") || "0.00"} error={errors.loanAmount} /> ); } function StepLocation({ form, errors, set, t, initialData }: StepContentProps & { initialData?: LoanOrder }) { const { i18n } = useTranslation(); const [branchSearch, setBranchSearch] = useState(""); const branchQuery = useInfiniteBranches(branchSearch); const regionOptions = useMemo(() => getRegionOptions(t), [t]); const branchOptions: InfiniteSelectOption[] = useMemo(() => { const lang = i18n.language ?? "en"; const opts: InfiniteSelectOption[] = (branchQuery.data?.pages ?? []) .flatMap((p) => p.branches) .map((b) => ({ value: String(b.id), label: resolveLocalizedName(b.name, lang) || b.uniqueCode || String(b.id), })); if (initialData?.branchId && !opts.some((o) => o.value === String(initialData.branchId))) { opts.unshift({ value: String(initialData.branchId), label: initialData.branch || String(initialData.branchId) }); } return opts; }, [branchQuery, i18n.language, initialData]); return ( { set("region", v); set("branch", ""); }} options={regionOptions} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.region} /> set("branch", v)} options={branchOptions} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} disabled={!form.region} error={errors.branch} loading={branchQuery.isLoading} isLoadingMore={branchQuery.isFetchingNextPage} hasNextPage={!!branchQuery.hasNextPage} onLoadMore={() => branchQuery.fetchNextPage()} searchValue={branchSearch} onSearchChange={setBranchSearch} /> ); } function StepPersonal({ form, errors, set, t }: StepContentProps) { return (
set("firstName", v)} placeholder={t("Name") || "Ady"} error={errors.firstName} /> set("lastName", v)} placeholder={t("Surname") || "Familiýasy"} error={errors.lastName} /> set("patronicName", v)} placeholder={t("Patronic name") || "Atasynyň ady"} /> set("education", v)} options={EDUCATION_OPTIONS} placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"} error={errors.education} /> set("marriageStatus", v)} options={MARRIAGE_OPTIONS} placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"} error={errors.marriageStatus} /> set("dateOfBirth", v)} error={errors.dateOfBirth} /> set("residence", v)} placeholder={t("loanOrderForm.placeholders.residence") || "Ýazgy edilen salgy"} error={errors.residence} /> set("currentResidence", v)} placeholder={t("loanOrderForm.placeholders.currentResidence") || "Häzirki ýaşaýyş ýeri"} /> set("loanHistory", v)} options={[]} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} />
); } function StepCard({ form, errors, set, t }: StepContentProps) { return ( set("cardNumber", v)} placeholder={t("Card number") || "Kart belgisi"} error={errors.cardNumber} /> set("cardName", v)} placeholder={t("Name on card") || "Kartdaky ady"} error={errors.cardName} /> set("cardExpMonth", v)} options={MONTH_OPTIONS} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.cardExpMonth} /> set("cardExpYear", v)} options={YEAR_OPTIONS} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.cardExpYear} /> ); } function StepPassport({ form, errors, set, t, mode }: StepContentProps & { mode: "create" | "edit" }) { return (
set("passportSerie", v)} options={PASSPORT_SERIES_OPTIONS} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.passportSerie} /> set("passportNumber", v)} placeholder={t("Passport id") || "Pasport belgisi"} error={errors.passportNumber} /> set("passportDateOfIssue", v)} error={errors.passportDateOfIssue} /> set("passportGivenBy", v)} placeholder={t("Passport given by") || "Kim tarapyndan berildi"} error={errors.passportGivenBy} /> set("bornPlace", v)} placeholder={t("Born place (passport)") || "Doglan ýeri (pasport)"} /> set("passportOne", v)} error={errors.passportOne} required={mode === "create"} accept="image/*" /> set("passportTwo", v)} error={errors.passportTwo} required={mode === "create"} accept="image/*" /> set("passportThree", v)} accept="image/*" /> set("passportFour", v)} accept="image/*" />
); } function StepContact({ form, errors, set, t }: StepContentProps) { return ( set("phone", v)} placeholder={t("loanOrderForm.placeholders.phone") || "61 097 651"} error={errors.phone} /> set("email", v)} placeholder={t("Email") || "E-poçta"} /> set("phoneAdditional", v)} placeholder={t("loanOrderForm.placeholders.phone") || "61 097 651"} error={errors.phoneAdditional} /> set("homePhone", v)} placeholder={t("loanOrderForm.placeholders.phone") || "61 097 651"} error={errors.homePhone} /> ); } function StepJob({ form, errors, set, t, initialData }: StepContentProps & { initialData?: LoanOrder }) { const { i18n } = useTranslation(); const [provinceSearch, setProvinceSearch] = useState(""); const provinceQuery = useInfiniteProvinces(provinceSearch); const regionOptions = useMemo(() => getRegionOptions(t), [t]); const provinceOptions: InfiniteSelectOption[] = useMemo(() => { const lang = i18n.language ?? "en"; const opts: InfiniteSelectOption[] = (provinceQuery.data?.pages ?? []) .flatMap((p) => p.provinces) .map((prov) => ({ value: String(prov.id), label: resolveLocalizedName(prov.name, lang) || String(prov.id) })); if (initialData?.workCityId && !opts.some((o) => o.value === String(initialData.workCityId))) { opts.unshift({ value: String(initialData.workCityId), label: initialData.workCity || String(initialData.workCityId) }); } return opts; }, [provinceQuery, i18n.language, initialData]); return (
set("workCompany", v)} placeholder={t("loanOrderForm.placeholders.companyName") || "Kärhananyň ady"} error={errors.workCompany} /> set("workHrPhone", v)} placeholder={t("loanOrderForm.placeholders.phone") || "61 097 651"} error={errors.workHrPhone} /> set("workRegion", v)} options={regionOptions} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} /> set("workProvince", v)} options={provinceOptions} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} loading={provinceQuery.isLoading} isLoadingMore={provinceQuery.isFetchingNextPage} hasNextPage={!!provinceQuery.hasNextPage} onLoadMore={() => provinceQuery.fetchNextPage()} searchValue={provinceSearch} onSearchChange={setProvinceSearch} /> set("position", v)} placeholder={t("Position") || "Wezipe"} error={errors.position} /> set("salary", v)} placeholder={t("Salary") || "Zähmet haky"} error={errors.salary} /> set("workStartedAt", v)} error={errors.workStartedAt} />
); } function StepGuarantor({ form, errors, set, t }: StepContentProps) { return (
set("guarantor1Name", v)} placeholder={t("Guarantor name") || "Zamunyň ady"} error={errors.guarantor1Name} /> set("guarantor1Surname", v)} placeholder={t("Guarantor Surname") || "Zamunyň familiýasy"} error={errors.guarantor1Surname} /> set("guarantor1Patronic", v)} placeholder={t("Guarantor Patronic name") || "Zamunyň atasynyň ady"} /> set("guarantor1PassportSerie", v)} options={PASSPORT_SERIES_OPTIONS} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.guarantor1PassportSerie} /> set("guarantor1PassportNumber", v)} placeholder={t("Passport id") || "Pasport belgisi"} error={errors.guarantor1PassportNumber} /> set("guarantor1CardNumber", v)} placeholder={t("Card number") || "Kart belgisi"} error={errors.guarantor1CardNumber} /> set("guarantor1CardName", v)} placeholder={t("Name on card") || "Kartdaky ady"} error={errors.guarantor1CardName} /> set("guarantor1CardExpMonth", v)} options={MONTH_OPTIONS} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.guarantor1CardExpMonth} /> set("guarantor1CardExpYear", v)} options={YEAR_OPTIONS} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.guarantor1CardExpYear} /> set("guarantor1Salary", v)} placeholder={t("loanOrderForm.labels.guarantor1Salary") || "Ortaca zähmet haky"} error={errors.guarantor1Salary} />
); } function StepGuarantor2({ form, errors, set, t }: StepContentProps) { return (
set("guarantor2Name", v)} placeholder={t("Guarantor 2 name") || "2. Zamunyň ady"} error={errors.guarantor2Name} /> set("guarantor2Surname", v)} placeholder={t("Guarantor 2 Surname") || "2. Zamunyň familiýasy"} error={errors.guarantor2Surname} /> set("guarantor2Patronic", v)} placeholder={t("Guarantor 2 Patronic name") || "2. Zamunyň atasynyň ady"} /> set("guarantor2PassportSerie", v)} options={PASSPORT_SERIES_OPTIONS} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.guarantor2PassportSerie} /> set("guarantor2PassportNumber", v)} placeholder={t("Passport id") || "Pasport belgisi"} error={errors.guarantor2PassportNumber} /> set("guarantor2CardNumber", v)} placeholder={t("Card number") || "Kart belgisi"} error={errors.guarantor2CardNumber} /> set("guarantor2CardName", v)} placeholder={t("Name on card") || "Kartdaky ady"} error={errors.guarantor2CardName} /> set("guarantor2CardExpMonth", v)} options={MONTH_OPTIONS} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.guarantor2CardExpMonth} /> set("guarantor2CardExpYear", v)} options={YEAR_OPTIONS} placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"} error={errors.guarantor2CardExpYear} /> set("guarantor2Note", v)} placeholder={t("loanOrderForm.placeholders.note") || "Bellik..."} rows={2} />
); } // ─── Props ──────────────────────────────────────────────────────────────────── interface LoanOrderFormProps { mode: "create" | "edit"; initialData?: LoanOrder; } // ─── Main Component ─────────────────────────────────────────────────────────── export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) { const { t, i18n } = useTranslation(); const navigate = useNavigate(); const createMutation = useCreateLoanOrder(); const updateMutation = useUpdateLoanOrder(); const isPending = createMutation.isPending || updateMutation.isPending; const { watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError, } = useForm({ defaultValues: initialData ? { ...DEFAULT_FORM_VALUES, ...mapInitial(initialData) } : DEFAULT_FORM_VALUES, }); const form = watch(); const [currentStep, setCurrentStep] = useState(0); const [visited, setVisited] = useState>(() => (mode === "edit" ? new Set(STEPS.map((_, i) => i)) : new Set())); const [submittedSteps, setSubmittedSteps] = useState>(new Set()); const stepsWithErrors = useMemo(() => { const out = new Set(); visited.forEach((i) => { if (Object.keys(STEPS[i].validate(form, mode)).length > 0) out.add(i); }); return out; }, [form, mode, visited, i18n.language]); const set = useCallback( (key: K, value: LoanOrderFormData[K]) => { (setValue as (name: K, val: LoanOrderFormData[K]) => void)(key, value); clearErrors(key); }, [setValue, clearErrors], ); 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); 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; } if (currentStep < STEPS.length - 1) { setCurrentStep(currentStep + 1); window.scrollTo({ top: 0, behavior: "smooth" }); } }; const handleBack = () => { if (currentStep > 0) { markVisited(currentStep); setCurrentStep(currentStep - 1); window.scrollTo({ top: 0, behavior: "smooth" }); } }; const handleGoTo = (i: number) => { markVisited(currentStep); setCurrentStep(i); window.scrollTo({ top: 0, behavior: "smooth" }); }; // ── Submit ────────────────────────────────────────────────────────────────── 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) { setCurrentStep(i); break; } } return; } const payload = buildPayload(getValues()); if (mode === "create") { createMutation.mutate(payload, { onSuccess: () => navigate("/loan-orders") }); } else if (initialData) { updateMutation.mutate({ id: initialData.id, payload }, { onSuccess: () => navigate("/loan-orders") }); } }; // ── StepBar items ─────────────────────────────────────────────────────────── const stepBarItems: StepCardItem[] = STEPS.map((s, i) => { const isActive = i === currentStep; const hasErrors = stepsWithErrors.has(i); const isDone = visited.has(i) && !hasErrors; return { id: s.id, title: t(s.titleKey) || s.titleFallback, subtitle: t(s.subtitleKey) || s.subtitleFallback, icon: s.icon, status: isActive ? "active" : hasErrors ? "error" : isDone ? "done" : "idle", }; }); const isLastStep = currentStep === STEPS.length - 1; // ── Render ────────────────────────────────────────────────────────────────── return (
{/* Page header */}

{mode === "create" ? t("loanOrders.create") || "Karz sargyt dörediň" : t("loanOrders.edit") || "Karz sargydy üýtget"}

{mode === "create" ? t("loanOrders.createDescription") || "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň." : t("loanOrders.editDescription") || "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň."}

{/* Step bar */}
{/* Step content */} {currentStep === 0 && } {currentStep === 1 && } {currentStep === 2 && } {currentStep === 3 && } {currentStep === 4 && } {currentStep === 5 && } {currentStep === 6 && } {currentStep === 7 && } {currentStep === 8 && } {currentStep === 9 && } {/* Actions */} navigate(-1) : undefined} onPrev={currentStep > 0 ? handleBack : undefined} onNext={!isLastStep ? handleNext : undefined} showSubmit={isLastStep} onSubmit={isLastStep ? doSubmit : undefined} submitLabel={mode === "create" ? t("loanOrders.create") || "Karz sargyt döredüň" : t("common.save") || "Ýatda sakla"} loadingLabel={t("common.loading") || "Ýüklenilýär..."} cancelLabel={t("common.cancel") || "Ýatyr"} prevLabel={t("common.back") || "Yza"} nextLabel={t("common.next") || "Indiki"} />
); } function mapInitial(order: LoanOrder): Partial { return { status: order.status ?? "pending", loanType: order.loanTypeId != null ? String(order.loanTypeId) : "", region: order.region ?? "AG", branch: order.branchId != null ? String(order.branchId) : "", firstName: order.firstName ?? "", lastName: order.lastName ?? "", patronicName: order.patronicName ?? "", education: order.education ?? "", marriageStatus: order.marriageStatus ?? "", dateOfBirth: formatFromApiDate(order.dateOfBirth), residence: order.residence ?? "", currentResidence: order.currentResidence ?? "", passportSerie: order.passportSerie ?? "", passportNumber: order.passportNumber ?? "", passportDateOfIssue: formatFromApiDate(order.passportDateOfIssue), passportGivenBy: order.passportGivenBy ?? "", passportOne: order.passportPage1Url ?? "", passportTwo: order.passportPage23Url ?? "", passportThree: order.passportPage89Url ?? "", passportFour: order.passportPage32Url ?? "", bornPlace: order.bornPlace ?? "", email: order.email ?? "", phone: formatFromApiPhone(order.phone), phoneAdditional: formatFromApiPhone(order.phoneAdditional), homePhone: formatFromApiPhone(order.homePhone), workCompany: order.workCompany ?? "", workHrPhone: formatFromApiPhone(order.workHrPhone), workRegion: order.workRegion ?? "AG", workProvince: order.workCityId != null ? String(order.workCityId) : "", position: order.position ?? "", salary: order.salary != null ? String(order.salary) : "", workStartedAt: formatFromApiDate(order.workStartedAt), note: order.note ?? "", loanAmount: order.loanAmount != null ? String(order.loanAmount) : "", loanHistory: order.loanHistory ?? "", cardNumber: order.cardNumber ?? "", cardName: order.cardName ?? "", cardExpMonth: order.cardExpMonth ?? "", cardExpYear: order.cardExpYear ?? "", guarantor1Name: order.guarantor1Name ?? "", guarantor1Surname: order.guarantor1Surname ?? "", guarantor1Patronic: order.guarantor1Patronic ?? "", guarantor1PassportSerie: order.guarantor1PassportSerie ?? "", guarantor1PassportNumber: order.guarantor1PassportNumber ?? "", guarantor1CardNumber: order.guarantor1CardNumber ?? "", guarantor1CardName: order.guarantor1CardName ?? "", guarantor1CardExpMonth: order.guarantor1CardExpMonth ?? "", guarantor1CardExpYear: order.guarantor1CardExpYear ?? "", guarantor1Salary: order.guarantor1Salary != null ? String(order.guarantor1Salary) : "", guarantor2Name: order.guarantor2Name ?? "", guarantor2Surname: order.guarantor2Surname ?? "", guarantor2Patronic: order.guarantor2Patronic ?? "", guarantor2PassportSerie: order.guarantor2PassportSerie ?? "", guarantor2PassportNumber: order.guarantor2PassportNumber ?? "", guarantor2CardNumber: order.guarantor2CardNumber ?? "", guarantor2CardName: order.guarantor2CardName ?? "", guarantor2CardExpMonth: order.guarantor2CardExpMonth ?? "", guarantor2CardExpYear: order.guarantor2CardExpYear ?? "", guarantor2Note: order.guarantor2Note ?? "", }; }