connected with loan order api
This commit is contained in:
@@ -4,31 +4,42 @@ 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, FolderOpen, ShieldCheck } from "lucide-react";
|
||||
import { CircleDot, CreditCard, MapPin, User, Wallet, FileText, Phone, Briefcase, ShieldCheck } from "lucide-react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
|
||||
import { FormInput } from "@/components/formInput";
|
||||
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 { BRANCHES_BY_REGION } 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_OPTIONS = [
|
||||
{ value: "Aşgabat", label: "Aşgabat" },
|
||||
{ value: "Ahal", label: "Ahal" },
|
||||
{ value: "Balkan", label: "Balkan" },
|
||||
{ value: "Daşoguz", label: "Daşoguz" },
|
||||
{ value: "Lebap", label: "Lebap" },
|
||||
{ value: "Mary", label: "Mary" },
|
||||
{ value: "Arkadag", label: "Arkadag" },
|
||||
];
|
||||
const 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" },
|
||||
@@ -48,14 +59,6 @@ const MARRIAGE_OPTIONS = [
|
||||
{ value: "LEGAL", label: "Raýat nika" },
|
||||
];
|
||||
|
||||
const LOAN_TYPE_OPTIONS = [
|
||||
{ value: "consumer", label: "Sarp ediş karzy" },
|
||||
{ value: "mortgage", label: "Ipoteka" },
|
||||
{ value: "car", label: "Awtoulag karzy" },
|
||||
{ value: "student", label: "Talyplar üçin" },
|
||||
{ value: "business", label: "Işewürlik karzy" },
|
||||
];
|
||||
|
||||
const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({
|
||||
value: String(i + 1).padStart(2, "0"),
|
||||
label: String(i + 1).padStart(2, "0"),
|
||||
@@ -142,7 +145,7 @@ const STEPS: StepDef[] = [
|
||||
titleKey: "Passport",
|
||||
titleFallback: "Pasport",
|
||||
subtitleKey: "loanOrderForm.steps.passport.subtitle",
|
||||
subtitleFallback: "Seriýa, belgisi, senesi",
|
||||
subtitleFallback: "Seriýa, belgisi, senesi, suratlar",
|
||||
icon: FileText,
|
||||
validate: (form, mode) => validateStep(5, form, mode),
|
||||
},
|
||||
@@ -164,15 +167,6 @@ const STEPS: StepDef[] = [
|
||||
icon: Briefcase,
|
||||
validate: (form, mode) => validateStep(7, form, mode),
|
||||
},
|
||||
{
|
||||
id: "files",
|
||||
titleKey: "Passport files",
|
||||
titleFallback: "Pasport faýllar",
|
||||
subtitleKey: "loanOrderForm.steps.files.subtitle",
|
||||
subtitleFallback: "Pasport suratlary",
|
||||
icon: FolderOpen,
|
||||
validate: (form, mode) => validateStep(8, form, mode),
|
||||
},
|
||||
{
|
||||
id: "guarantor",
|
||||
titleKey: "1. Guarantor",
|
||||
@@ -180,6 +174,15 @@ const STEPS: StepDef[] = [
|
||||
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),
|
||||
},
|
||||
];
|
||||
@@ -227,19 +230,40 @@ function StepStatus({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepLoan({ form, errors, set, t }: StepContentProps) {
|
||||
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 (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
<InfiniteSelect
|
||||
label={t("Loan type") || "Karz görnüşi"}
|
||||
required
|
||||
value={form.loanType}
|
||||
onChange={(v) => set("loanType", v)}
|
||||
options={LOAN_TYPE_OPTIONS}
|
||||
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}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
@@ -258,8 +282,27 @@ function StepLoan({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepLocation({ form, errors, set, t }: StepContentProps) {
|
||||
const branchOptions = BRANCHES_BY_REGION[form.region] ?? [];
|
||||
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 (
|
||||
<BentoGrid cols={2}>
|
||||
@@ -273,15 +316,14 @@ function StepLocation({ form, errors, set, t }: StepContentProps) {
|
||||
set("region", v);
|
||||
set("branch", "");
|
||||
}}
|
||||
options={REGION_OPTIONS}
|
||||
options={regionOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.region}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
<InfiniteSelect
|
||||
label={t("Branch") || "Şahamça"}
|
||||
required
|
||||
value={form.branch}
|
||||
@@ -290,6 +332,12 @@ function StepLocation({ form, errors, set, t }: StepContentProps) {
|
||||
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}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -369,7 +417,6 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
@@ -456,7 +503,7 @@ function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
function StepPassport({ form, errors, set, t, mode }: StepContentProps & { mode: "create" | "edit" }) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={3}>
|
||||
@@ -517,6 +564,56 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<DocumentUpload
|
||||
label={
|
||||
mode === "edit"
|
||||
? t("loanOrderForm.fileLabels.replacePage1") || "Pasport (sahypa 1) (çalyşmak)"
|
||||
: t("Passport (page 1)") || "Pasport (sahypa 1)"
|
||||
}
|
||||
value={form.passportOne}
|
||||
onChange={(v) => set("passportOne", v)}
|
||||
error={errors.passportOne}
|
||||
required={mode === "create"}
|
||||
accept="image/*"
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<DocumentUpload
|
||||
label={
|
||||
mode === "edit"
|
||||
? t("loanOrderForm.fileLabels.replacePage23") || "Pasport (2-3-nji sahypa) (çalyşmak)"
|
||||
: t("Passport (page 2-3)") || "Pasport (2-3-nji sahypa)"
|
||||
}
|
||||
value={form.passportTwo}
|
||||
onChange={(v) => set("passportTwo", v)}
|
||||
error={errors.passportTwo}
|
||||
required={mode === "create"}
|
||||
accept="image/*"
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<DocumentUpload
|
||||
label={t("Passport (page 8-9)") || "Pasport (8-9 sahypa)"}
|
||||
value={form.passportThree}
|
||||
onChange={(v) => set("passportThree", v)}
|
||||
accept="image/*"
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<DocumentUpload
|
||||
label={t("Passport (page 32)") || "Pasport (32-nji sahypa)"}
|
||||
value={form.passportFour}
|
||||
onChange={(v) => set("passportFour", v)}
|
||||
accept="image/*"
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -565,7 +662,25 @@ function StepContact({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepJob({ form, errors, set, t }: StepContentProps) {
|
||||
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 (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={2}>
|
||||
@@ -595,16 +710,21 @@ function StepJob({ form, errors, set, t }: StepContentProps) {
|
||||
label={t("Work region") || "Işleýän welaýatyňyz"}
|
||||
value={form.workRegion}
|
||||
onChange={(v) => set("workRegion", v)}
|
||||
options={REGION_OPTIONS}
|
||||
options={regionOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
<InfiniteSelect
|
||||
label={t("Work province") || "Işleýän etrabyňyz"}
|
||||
value={form.workProvince}
|
||||
onChange={(v) => set("workProvince", v)}
|
||||
options={[]}
|
||||
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}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -647,88 +767,6 @@ function StepJob({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepFiles({ form, errors, set, t, mode, initialData }: StepContentProps & { mode: "create" | "edit"; initialData?: LoanOrder }) {
|
||||
const existingFiles =
|
||||
mode === "edit" && initialData
|
||||
? [
|
||||
{ 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">
|
||||
{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">
|
||||
{t("loanOrderForm.fileLabels.viewFile") || "Faýly gör"}
|
||||
</a>
|
||||
</BentoCard>
|
||||
))}
|
||||
</BentoGrid>
|
||||
)}
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
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}
|
||||
onFileChange={(f) => set("passportPage1", f)}
|
||||
error={errors.passportPage1}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
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}
|
||||
onFileChange={(f) => set("passportPage23", f)}
|
||||
error={errors.passportPage23}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t("Passport (page 8-9)") || "Pasport (8-9 sahypa)"}
|
||||
accept="image/*"
|
||||
fileValue={form.passportPage89}
|
||||
onFileChange={(f) => set("passportPage89", f)}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t("Passport (page 32)") || "Pasport (32-nji sahypa)"}
|
||||
accept="image/*"
|
||||
fileValue={form.passportPage32}
|
||||
onFileChange={(f) => set("passportPage32", f)}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StepGuarantor({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
@@ -850,6 +888,118 @@ function StepGuarantor({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepGuarantor2({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Guarantor 2 name") || "2. Zamunyň ady"}
|
||||
value={form.guarantor2Name}
|
||||
onChange={(v) => set("guarantor2Name", v)}
|
||||
placeholder={t("Guarantor 2 name") || "2. Zamunyň ady"}
|
||||
error={errors.guarantor2Name}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Guarantor 2 Surname") || "2. Zamunyň familiýasy"}
|
||||
value={form.guarantor2Surname}
|
||||
onChange={(v) => set("guarantor2Surname", v)}
|
||||
placeholder={t("Guarantor 2 Surname") || "2. Zamunyň familiýasy"}
|
||||
error={errors.guarantor2Surname}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Guarantor 2 Patronic name") || "2. Zamunyň atasynyň ady"}
|
||||
value={form.guarantor2Patronic}
|
||||
onChange={(v) => set("guarantor2Patronic", v)}
|
||||
placeholder={t("Guarantor 2 Patronic name") || "2. Zamunyň atasynyň ady"}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("Passport serie") || "Pasport seriýasy"}
|
||||
value={form.guarantor2PassportSerie}
|
||||
onChange={(v) => set("guarantor2PassportSerie", v)}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor2PassportSerie}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Passport id") || "Pasport belgisi"}
|
||||
value={form.guarantor2PassportNumber}
|
||||
onChange={(v) => set("guarantor2PassportNumber", v)}
|
||||
placeholder={t("Passport id") || "Pasport belgisi"}
|
||||
error={errors.guarantor2PassportNumber}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Card number") || "Kart belgisi"}
|
||||
value={form.guarantor2CardNumber}
|
||||
onChange={(v) => set("guarantor2CardNumber", v)}
|
||||
placeholder={t("Card number") || "Kart belgisi"}
|
||||
error={errors.guarantor2CardNumber}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Name on card") || "Kartdaky ady"}
|
||||
value={form.guarantor2CardName}
|
||||
onChange={(v) => set("guarantor2CardName", v)}
|
||||
placeholder={t("Name on card") || "Kartdaky ady"}
|
||||
error={errors.guarantor2CardName}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("Expiration month") || "Möhleti (aý)"}
|
||||
value={form.guarantor2CardExpMonth}
|
||||
onChange={(v) => set("guarantor2CardExpMonth", v)}
|
||||
options={MONTH_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor2CardExpMonth}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("Expiration year") || "Möhleti (ýyl)"}
|
||||
value={form.guarantor2CardExpYear}
|
||||
onChange={(v) => set("guarantor2CardExpYear", v)}
|
||||
options={YEAR_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor2CardExpYear}
|
||||
/>
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label={t("Guarantor Note") || "Zamun belligi"}
|
||||
value={form.guarantor2Note}
|
||||
onChange={(v) => set("guarantor2Note", v)}
|
||||
placeholder={t("loanOrderForm.placeholders.note") || "Bellik..."}
|
||||
rows={2}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Props ────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface LoanOrderFormProps {
|
||||
@@ -1006,7 +1156,7 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
|
||||
{/* Page header */}
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === "create" ? t("loanOrders.create") || "Karz sargyt döredüň" : t("loanOrders.edit") || "Karz sargydy üýtget"}
|
||||
{mode === "create" ? t("loanOrders.create") || "Karz sargyt dörediň" : t("loanOrders.edit") || "Karz sargydy üýtget"}
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{mode === "create"
|
||||
@@ -1022,15 +1172,15 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
|
||||
|
||||
{/* Step content */}
|
||||
{currentStep === 0 && <StepStatus {...stepProps} />}
|
||||
{currentStep === 1 && <StepLoan {...stepProps} />}
|
||||
{currentStep === 2 && <StepLocation {...stepProps} />}
|
||||
{currentStep === 1 && <StepLoan {...stepProps} initialData={initialData} />}
|
||||
{currentStep === 2 && <StepLocation {...stepProps} initialData={initialData} />}
|
||||
{currentStep === 3 && <StepPersonal {...stepProps} />}
|
||||
{currentStep === 4 && <StepCard {...stepProps} />}
|
||||
{currentStep === 5 && <StepPassport {...stepProps} />}
|
||||
{currentStep === 5 && <StepPassport {...stepProps} mode={mode} />}
|
||||
{currentStep === 6 && <StepContact {...stepProps} />}
|
||||
{currentStep === 7 && <StepJob {...stepProps} />}
|
||||
{currentStep === 8 && <StepFiles {...stepProps} mode={mode} initialData={initialData} />}
|
||||
{currentStep === 9 && <StepGuarantor {...stepProps} />}
|
||||
{currentStep === 7 && <StepJob {...stepProps} initialData={initialData} />}
|
||||
{currentStep === 8 && <StepGuarantor {...stepProps} />}
|
||||
{currentStep === 9 && <StepGuarantor2 {...stepProps} />}
|
||||
|
||||
{/* Actions */}
|
||||
<FormActions
|
||||
@@ -1040,7 +1190,7 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={isLastStep ? doSubmit : undefined}
|
||||
submitLabel={mode === "create" ? t("loanOrders.createButton") || "Karz sargyt döredüň" : t("common.save") || "Ýatda sakla"}
|
||||
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"}
|
||||
@@ -1053,33 +1203,37 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
|
||||
function mapInitial(order: LoanOrder): Partial<LoanOrderFormData> {
|
||||
return {
|
||||
status: order.status ?? "pending",
|
||||
loanType: order.loanType ?? "",
|
||||
region: order.region ?? "Aşgabat",
|
||||
branch: order.branch ?? "",
|
||||
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: order.dateOfBirth ?? "",
|
||||
dateOfBirth: formatFromApiDate(order.dateOfBirth),
|
||||
residence: order.residence ?? "",
|
||||
currentResidence: order.currentResidence ?? "",
|
||||
passportSerie: order.passportSerie ?? "",
|
||||
passportNumber: order.passportNumber ?? "",
|
||||
passportDateOfIssue: order.passportDateOfIssue ?? "",
|
||||
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: order.phone ?? "",
|
||||
phoneAdditional: order.phoneAdditional ?? "",
|
||||
homePhone: order.homePhone ?? "",
|
||||
phone: formatFromApiPhone(order.phone),
|
||||
phoneAdditional: formatFromApiPhone(order.phoneAdditional),
|
||||
homePhone: formatFromApiPhone(order.homePhone),
|
||||
workCompany: order.workCompany ?? "",
|
||||
workHrPhone: order.workHrPhone ?? "",
|
||||
workRegion: order.workRegion ?? "Aşgabat",
|
||||
workProvince: order.workProvince ?? "",
|
||||
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: order.workStartedAt ?? "",
|
||||
workStartedAt: formatFromApiDate(order.workStartedAt),
|
||||
note: order.note ?? "",
|
||||
loanAmount: order.loanAmount != null ? String(order.loanAmount) : "",
|
||||
loanHistory: order.loanHistory ?? "",
|
||||
@@ -1097,5 +1251,15 @@ function mapInitial(order: LoanOrder): Partial<LoanOrderFormData> {
|
||||
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 ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user