fixed some missed data, added role based function(user)
This commit is contained in:
1 parent
5884ec831c
commit
9ad86634dd
31 files changed
+1276
-977
No files matched your search
@@ -22,55 +22,26 @@ import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUser
|
||||
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";
|
||||
import {
|
||||
PASSPORT_SERIES_OPTIONS,
|
||||
getStatusOptions,
|
||||
getRegionOptions,
|
||||
EDUCATION_OPTIONS,
|
||||
MARRIAGE_OPTIONS,
|
||||
MONTH_OPTIONS,
|
||||
YEAR_OPTIONS,
|
||||
} from "@/constants";
|
||||
import { useGetRequiredDocuments } from "@/features/requiredDocuments/hooks/useRequiredDocuments";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
|
||||
// ─── 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<Record<keyof LoanOrderFormData, string>>;
|
||||
@@ -222,8 +193,8 @@ function StepStatus({ form, errors, set, t }: StepContentProps) {
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label={t("Note") || "Bellik"}
|
||||
value={form.note}
|
||||
onChange={(v) => set("note", v)}
|
||||
value={form.notes}
|
||||
onChange={(v) => set("notes", v)}
|
||||
placeholder={t("loanOrderForm.placeholders.note") || "Bellik..."}
|
||||
rows={3}
|
||||
/>
|
||||
@@ -234,6 +205,7 @@ function StepStatus({ form, errors, set, t }: StepContentProps) {
|
||||
|
||||
function StepLoan({ form, errors, set, t, initialData }: StepContentProps & { initialData?: LoanOrder }) {
|
||||
const { i18n } = useTranslation();
|
||||
const { data: requiredDocsData } = useGetRequiredDocuments({ page: 1, limit: 100 });
|
||||
const [loanTypeSearch, setLoanTypeSearch] = useState("");
|
||||
const loanTypesQuery = useInfiniteLoanTypes(loanTypeSearch);
|
||||
|
||||
@@ -249,38 +221,98 @@ function StepLoan({ form, errors, set, t, initialData }: StepContentProps & { in
|
||||
return opts;
|
||||
}, [loanTypesQuery, i18n.language, initialData]);
|
||||
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<InfiniteSelect
|
||||
label={t("Loan type") || "Karz görnüşi"}
|
||||
required
|
||||
value={form.loanType}
|
||||
onChange={(v) => 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}
|
||||
/>
|
||||
</BentoCard>
|
||||
const docOptions = useMemo<SelectOption[]>(
|
||||
() =>
|
||||
(requiredDocsData?.loansDocuments ?? []).map((doc) => ({
|
||||
value: String(doc.id),
|
||||
label: doc.name,
|
||||
})),
|
||||
[requiredDocsData],
|
||||
);
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("loanOrderForm.labels.loanAmount") || "Karz möçberi"}
|
||||
required
|
||||
value={form.loanAmount}
|
||||
onChange={(v) => set("loanAmount", v)}
|
||||
placeholder={t("loanOrderForm.placeholders.amount") || "0.00"}
|
||||
error={errors.loanAmount}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<InfiniteSelect
|
||||
label={t("Loan type") || "Karz görnüşi"}
|
||||
required
|
||||
value={form.loanType}
|
||||
onChange={(v) => 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}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("loanOrderForm.labels.loanAmount") || "Karz möçberi"}
|
||||
required
|
||||
value={form.loanAmount}
|
||||
onChange={(v) => set("loanAmount", v)}
|
||||
placeholder={t("loanOrderForm.placeholders.amount") || "0.00"}
|
||||
error={errors.loanAmount}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t("loanOrderForm.labels.requiredDoc") || "Gerekli resminat"}
|
||||
value={form.loanOrderRequiredDocId}
|
||||
onChange={(v) => set("loanOrderRequiredDocId", v)}
|
||||
options={docOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("loanOrderForm.titles.loanCardInfo") || "Karz karty maglumatlary"}>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Loan card number") || "Karz kart belgisi"}
|
||||
value={form.loanCardNumber}
|
||||
onChange={(v) => set("loanCardNumber", v)}
|
||||
placeholder={t("Loan card number") || "Karz kart belgisi"}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Loan card name") || "Karz kartdaky ady"}
|
||||
value={form.loanCardName}
|
||||
onChange={(v) => set("loanCardName", v)}
|
||||
placeholder={t("Loan card name") || "Karz kartdaky ady"}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("loanOrderForm.titles.loanCardExpiry") || "Karz kart möhleti"}>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("loanOrderForm.labels.cardExpMonth") || "Aý"}
|
||||
value={form.loanCardMonth}
|
||||
onChange={(v) => set("loanCardMonth", v)}
|
||||
options={MONTH_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("loanOrderForm.labels.cardExpYear") || "Ýyl"}
|
||||
value={form.loanCardYear}
|
||||
onChange={(v) => set("loanCardYear", v)}
|
||||
options={YEAR_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -316,7 +348,7 @@ function StepLocation({ form, errors, set, t, initialData }: StepContentProps &
|
||||
value={form.region}
|
||||
onChange={(v) => {
|
||||
set("region", v);
|
||||
set("branch", "");
|
||||
set("branchId", "");
|
||||
}}
|
||||
options={regionOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
@@ -328,12 +360,12 @@ function StepLocation({ form, errors, set, t, initialData }: StepContentProps &
|
||||
<InfiniteSelect
|
||||
label={t("Branch") || "Şahamça"}
|
||||
required
|
||||
value={form.branch}
|
||||
onChange={(v) => set("branch", v)}
|
||||
value={form.branchId}
|
||||
onChange={(v) => set("branchId", v)}
|
||||
options={branchOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
disabled={!form.region}
|
||||
error={errors.branch}
|
||||
error={errors.branchId}
|
||||
loading={branchQuery.isLoading}
|
||||
isLoadingMore={branchQuery.isFetchingNextPage}
|
||||
hasNextPage={!!branchQuery.hasNextPage}
|
||||
@@ -347,8 +379,6 @@ function StepLocation({ form, errors, set, t, initialData }: StepContentProps &
|
||||
}
|
||||
|
||||
function StepPersonal({ form, errors, set, t, initialData }: StepContentProps & { initialData?: LoanOrder }) {
|
||||
const { data: requiredDocsData } = useGetRequiredDocuments({ page: 1, limit: 100 });
|
||||
|
||||
const [clientSearch, setClientSearch] = useState("");
|
||||
const clientsQuery = useInfiniteClients(clientSearch);
|
||||
|
||||
@@ -369,15 +399,6 @@ function StepPersonal({ form, errors, set, t, initialData }: StepContentProps &
|
||||
return opts;
|
||||
}, [clientsQuery.data, initialData]);
|
||||
|
||||
const loanHistoryOptions = useMemo<SelectOption[]>(
|
||||
() =>
|
||||
(requiredDocsData?.loansDocuments ?? []).map((doc) => ({
|
||||
value: String(doc.id),
|
||||
label: doc.name,
|
||||
})),
|
||||
[requiredDocsData],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={1}>
|
||||
@@ -402,25 +423,25 @@ function StepPersonal({ form, errors, set, t, initialData }: StepContentProps &
|
||||
type="text"
|
||||
label={t("Name") || "Ady"}
|
||||
required
|
||||
value={form.firstName}
|
||||
onChange={(v) => set("firstName", v)}
|
||||
value={form.customerName}
|
||||
onChange={(v) => set("customerName", v)}
|
||||
placeholder={t("Name") || "Ady"}
|
||||
error={errors.firstName}
|
||||
error={errors.customerName}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Surname") || "Familiýasy"}
|
||||
required
|
||||
value={form.lastName}
|
||||
onChange={(v) => set("lastName", v)}
|
||||
value={form.customerSurname}
|
||||
onChange={(v) => set("customerSurname", v)}
|
||||
placeholder={t("Surname") || "Familiýasy"}
|
||||
error={errors.lastName}
|
||||
error={errors.customerSurname}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Patronic name") || "Atasynyň ady"}
|
||||
value={form.patronicName}
|
||||
onChange={(v) => set("patronicName", v)}
|
||||
value={form.customerPatronicName}
|
||||
onChange={(v) => set("customerPatronicName", v)}
|
||||
placeholder={t("Patronic name") || "Atasynyň ady"}
|
||||
/>
|
||||
</div>
|
||||
@@ -454,9 +475,9 @@ function StepPersonal({ form, errors, set, t, initialData }: StepContentProps &
|
||||
type="date"
|
||||
label={t("Date of birth") || "Doglan güni"}
|
||||
required
|
||||
value={form.dateOfBirth}
|
||||
onChange={(v) => set("dateOfBirth", v)}
|
||||
error={errors.dateOfBirth}
|
||||
value={form.bornAt}
|
||||
onChange={(v) => set("bornAt", v)}
|
||||
error={errors.bornAt}
|
||||
/>
|
||||
</div>
|
||||
</BentoCard>
|
||||
@@ -468,28 +489,27 @@ function StepPersonal({ form, errors, set, t, initialData }: StepContentProps &
|
||||
type="text"
|
||||
label={t("Residence (passport)") || "Ýazgy edilen salgyňyz"}
|
||||
required
|
||||
value={form.residence}
|
||||
onChange={(v) => set("residence", v)}
|
||||
value={form.passportAddress}
|
||||
onChange={(v) => set("passportAddress", v)}
|
||||
placeholder={t("loanOrderForm.placeholders.residence") || "Ýazgy edilen salgy"}
|
||||
error={errors.residence}
|
||||
error={errors.passportAddress}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Current Residence") || "Häzirki ýaşaýyş ýeri"}
|
||||
value={form.currentResidence}
|
||||
onChange={(v) => set("currentResidence", v)}
|
||||
value={form.realAddress}
|
||||
onChange={(v) => set("realAddress", v)}
|
||||
placeholder={t("loanOrderForm.placeholders.currentResidence") || "Häzirki ýaşaýyş ýeri"}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("loanOrderForm.titles.loanHistory") || "Karz taryhy"}>
|
||||
<BentoCard title={t("loanOrderForm.titles.bornPlace") || "Doglan ýeri"}>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t("Loan history") || "Karz taryhy"}
|
||||
value={form.loanHistory}
|
||||
onChange={(v) => set("loanHistory", v)}
|
||||
options={loanHistoryOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
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>
|
||||
@@ -526,21 +546,21 @@ function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
type="searchable-select"
|
||||
label={t("loanOrderForm.labels.cardExpMonth") || "Aý"}
|
||||
required
|
||||
value={form.cardExpMonth}
|
||||
onChange={(v) => set("cardExpMonth", v)}
|
||||
value={form.cardMonth}
|
||||
onChange={(v) => set("cardMonth", v)}
|
||||
options={MONTH_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.cardExpMonth}
|
||||
error={errors.cardMonth}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("loanOrderForm.labels.cardExpYear") || "Ýyl"}
|
||||
required
|
||||
value={form.cardExpYear}
|
||||
onChange={(v) => set("cardExpYear", v)}
|
||||
value={form.cardYear}
|
||||
onChange={(v) => set("cardYear", v)}
|
||||
options={YEAR_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.cardExpYear}
|
||||
error={errors.cardYear}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -568,10 +588,10 @@ function StepPassport({ form, errors, set, t, mode }: StepContentProps & { mode:
|
||||
type="text"
|
||||
label={t("Passport id") || "Pasport belgisi"}
|
||||
required
|
||||
value={form.passportNumber}
|
||||
onChange={(v) => set("passportNumber", v)}
|
||||
value={form.passportId}
|
||||
onChange={(v) => set("passportId", v)}
|
||||
placeholder={t("Passport id") || "Pasport belgisi"}
|
||||
error={errors.passportNumber}
|
||||
error={errors.passportId}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
@@ -579,14 +599,14 @@ function StepPassport({ form, errors, set, t, mode }: StepContentProps & { mode:
|
||||
type="date"
|
||||
label={t("Passport date of issue") || "Pasport berlen senesi"}
|
||||
required
|
||||
value={form.passportDateOfIssue}
|
||||
onChange={(v) => set("passportDateOfIssue", v)}
|
||||
error={errors.passportDateOfIssue}
|
||||
value={form.passportGivenAt}
|
||||
onChange={(v) => set("passportGivenAt", v)}
|
||||
error={errors.passportGivenAt}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
@@ -598,15 +618,6 @@ function StepPassport({ form, errors, set, t, mode }: StepContentProps & { mode:
|
||||
error={errors.passportGivenBy}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<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>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
@@ -696,10 +707,10 @@ function StepContact({ form, errors, set, t }: StepContentProps) {
|
||||
<FormInput
|
||||
type="phone"
|
||||
label={t("Home phone") || "Öý telefony"}
|
||||
value={form.homePhone}
|
||||
onChange={(v) => set("homePhone", v)}
|
||||
value={form.phoneHome}
|
||||
onChange={(v) => set("phoneHome", v)}
|
||||
placeholder={t("loanOrderForm.placeholders.phone") || "61 097 651"}
|
||||
error={errors.homePhone}
|
||||
error={errors.phoneHome}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -719,8 +730,8 @@ function StepJob({ form, errors, set, t, initialData }: StepContentProps & { ini
|
||||
.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) });
|
||||
if (initialData?.workProvinceId && !opts.some((o) => o.value === String(initialData.workProvinceId))) {
|
||||
opts.unshift({ value: String(initialData.workProvinceId), label: initialData.workProvince || String(initialData.workProvinceId) });
|
||||
}
|
||||
return opts;
|
||||
}, [provinceQuery, i18n.language, initialData]);
|
||||
@@ -741,10 +752,10 @@ function StepJob({ form, errors, set, t, initialData }: StepContentProps & { ini
|
||||
<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)}
|
||||
value={form.workCompanyAccountantNumber}
|
||||
onChange={(v) => set("workCompanyAccountantNumber", v)}
|
||||
placeholder={t("loanOrderForm.placeholders.phone") || "61 097 651"}
|
||||
error={errors.workHrPhone}
|
||||
error={errors.workCompanyAccountantNumber}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
@@ -759,8 +770,8 @@ function StepJob({ form, errors, set, t, initialData }: StepContentProps & { ini
|
||||
/>
|
||||
<InfiniteSelect
|
||||
label={t("Work province") || "Işleýän etrabyňyz"}
|
||||
value={form.workProvince}
|
||||
onChange={(v) => set("workProvince", v)}
|
||||
value={form.workProvinceId}
|
||||
onChange={(v) => set("workProvinceId", v)}
|
||||
options={provinceOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
loading={provinceQuery.isLoading}
|
||||
@@ -779,10 +790,10 @@ function StepJob({ form, errors, set, t, initialData }: StepContentProps & { ini
|
||||
type="text"
|
||||
label={t("Position") || "Wezipe"}
|
||||
required
|
||||
value={form.position}
|
||||
onChange={(v) => set("position", v)}
|
||||
value={form.workPosition}
|
||||
onChange={(v) => set("workPosition", v)}
|
||||
placeholder={t("Position") || "Wezipe"}
|
||||
error={errors.position}
|
||||
error={errors.workPosition}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
@@ -790,10 +801,10 @@ function StepJob({ form, errors, set, t, initialData }: StepContentProps & { ini
|
||||
type="number"
|
||||
label={t("Salary") || "Zähmet haky"}
|
||||
required
|
||||
value={form.salary}
|
||||
onChange={(v) => set("salary", v)}
|
||||
value={form.workSalary}
|
||||
onChange={(v) => set("workSalary", v)}
|
||||
placeholder={t("Salary") || "Zähmet haky"}
|
||||
error={errors.salary}
|
||||
error={errors.workSalary}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
@@ -820,10 +831,10 @@ function StepGuarantor({ form, errors, set, t }: StepContentProps) {
|
||||
type="text"
|
||||
label={t("Guarantor name") || "Zamunyň ady"}
|
||||
required
|
||||
value={form.guarantor1Name}
|
||||
onChange={(v) => set("guarantor1Name", v)}
|
||||
value={form.guarantorName}
|
||||
onChange={(v) => set("guarantorName", v)}
|
||||
placeholder={t("Guarantor name") || "Zamunyň ady"}
|
||||
error={errors.guarantor1Name}
|
||||
error={errors.guarantorName}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
@@ -831,18 +842,18 @@ function StepGuarantor({ form, errors, set, t }: StepContentProps) {
|
||||
type="text"
|
||||
label={t("Guarantor Surname") || "Zamunyň familiýasy"}
|
||||
required
|
||||
value={form.guarantor1Surname}
|
||||
onChange={(v) => set("guarantor1Surname", v)}
|
||||
value={form.guarantorSurname}
|
||||
onChange={(v) => set("guarantorSurname", v)}
|
||||
placeholder={t("Guarantor Surname") || "Zamunyň familiýasy"}
|
||||
error={errors.guarantor1Surname}
|
||||
error={errors.guarantorSurname}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Guarantor Patronic name") || "Zamunyň atasynyň ady"}
|
||||
value={form.guarantor1Patronic}
|
||||
onChange={(v) => set("guarantor1Patronic", v)}
|
||||
value={form.guarantorPatronicName}
|
||||
onChange={(v) => set("guarantorPatronicName", v)}
|
||||
placeholder={t("Guarantor Patronic name") || "Zamunyň atasynyň ady"}
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -854,11 +865,11 @@ function StepGuarantor({ form, errors, set, t }: StepContentProps) {
|
||||
type="searchable-select"
|
||||
label={t("Passport serie") || "Pasport seriýasy"}
|
||||
required
|
||||
value={form.guarantor1PassportSerie}
|
||||
onChange={(v) => set("guarantor1PassportSerie", v)}
|
||||
value={form.guarantorPassportSerie}
|
||||
onChange={(v) => set("guarantorPassportSerie", v)}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor1PassportSerie}
|
||||
error={errors.guarantorPassportSerie}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
@@ -866,65 +877,66 @@ function StepGuarantor({ form, errors, set, t }: StepContentProps) {
|
||||
type="text"
|
||||
label={t("Passport id") || "Pasport belgisi"}
|
||||
required
|
||||
value={form.guarantor1PassportNumber}
|
||||
onChange={(v) => set("guarantor1PassportNumber", v)}
|
||||
value={form.guarantorPassportId}
|
||||
onChange={(v) => set("guarantorPassportId", v)}
|
||||
placeholder={t("Passport id") || "Pasport belgisi"}
|
||||
error={errors.guarantor1PassportNumber}
|
||||
error={errors.guarantorPassportId}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<BentoCard title={t("loanOrderForm.titles.cardInfo") || "Kart maglumatlary"}>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Card number") || "Kart belgisi"}
|
||||
required
|
||||
value={form.guarantor1CardNumber}
|
||||
onChange={(v) => set("guarantor1CardNumber", v)}
|
||||
value={form.guarantorCardNumber}
|
||||
onChange={(v) => set("guarantorCardNumber", v)}
|
||||
placeholder={t("Card number") || "Kart belgisi"}
|
||||
error={errors.guarantor1CardNumber}
|
||||
error={errors.guarantorCardNumber}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Name on card") || "Kartdaky ady"}
|
||||
required
|
||||
value={form.guarantor1CardName}
|
||||
onChange={(v) => set("guarantor1CardName", v)}
|
||||
value={form.guarantorCardName}
|
||||
onChange={(v) => set("guarantorCardName", v)}
|
||||
placeholder={t("Name on card") || "Kartdaky ady"}
|
||||
error={errors.guarantor1CardName}
|
||||
error={errors.guarantorCardName}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<BentoCard title={t("loanOrderForm.titles.cardExpiry") || "Kart möhleti we bellik"}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("Expiration month") || "Möhleti (aý)"}
|
||||
required
|
||||
value={form.guarantorCardMonth}
|
||||
onChange={(v) => set("guarantorCardMonth", v)}
|
||||
options={MONTH_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantorCardMonth}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("Expiration year") || "Möhleti (ýyl)"}
|
||||
required
|
||||
value={form.guarantorCardYear}
|
||||
onChange={(v) => set("guarantorCardYear", v)}
|
||||
options={YEAR_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantorCardYear}
|
||||
/>
|
||||
</div>
|
||||
<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}
|
||||
type="textarea"
|
||||
label={t("Guarantor Note") || "Zamun belligi"}
|
||||
value={form.guarantorNote}
|
||||
onChange={(v) => set("guarantorNote", v)}
|
||||
placeholder={t("loanOrderForm.placeholders.note") || "Bellik..."}
|
||||
rows={2}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -960,8 +972,8 @@ function StepGuarantor2({ form, errors, set, t }: StepContentProps) {
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Guarantor 2 Patronic name") || "2. Zamunyň atasynyň ady"}
|
||||
value={form.guarantor2Patronic}
|
||||
onChange={(v) => set("guarantor2Patronic", v)}
|
||||
value={form.guarantor2PatronicName}
|
||||
onChange={(v) => set("guarantor2PatronicName", v)}
|
||||
placeholder={t("Guarantor 2 Patronic name") || "2. Zamunyň atasynyň ady"}
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -983,16 +995,16 @@ function StepGuarantor2({ form, errors, set, t }: StepContentProps) {
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Passport id") || "Pasport belgisi"}
|
||||
value={form.guarantor2PassportNumber}
|
||||
onChange={(v) => set("guarantor2PassportNumber", v)}
|
||||
value={form.guarantor2PassportId}
|
||||
onChange={(v) => set("guarantor2PassportId", v)}
|
||||
placeholder={t("Passport id") || "Pasport belgisi"}
|
||||
error={errors.guarantor2PassportNumber}
|
||||
error={errors.guarantor2PassportId}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<BentoCard title={t("loanOrderForm.titles.cardInfo") || "Kart maglumatlary"}>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Card number") || "Kart belgisi"}
|
||||
@@ -1011,25 +1023,27 @@ function StepGuarantor2({ form, errors, set, t }: StepContentProps) {
|
||||
/>
|
||||
</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}
|
||||
/>
|
||||
<BentoCard title={t("loanOrderForm.titles.cardExpiry") || "Kart möhleti we bellik"}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("Expiration month") || "Möhleti (aý)"}
|
||||
value={form.guarantor2CardMonth}
|
||||
onChange={(v) => set("guarantor2CardMonth", v)}
|
||||
options={MONTH_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor2CardMonth}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("Expiration year") || "Möhleti (ýyl)"}
|
||||
value={form.guarantor2CardYear}
|
||||
onChange={(v) => set("guarantor2CardYear", v)}
|
||||
options={YEAR_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor2CardYear}
|
||||
/>
|
||||
</div>
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label={t("Guarantor Note") || "Zamun belligi"}
|
||||
@@ -1100,6 +1114,7 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
|
||||
}
|
||||
return result;
|
||||
}, [form, mode, submittedSteps, i18n.language]);
|
||||
|
||||
const errors = useMemo(() => {
|
||||
const fromRHF = flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>);
|
||||
return { ...fromRHF, ...allSubmittedErrors };
|
||||
@@ -1247,64 +1262,75 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
|
||||
function mapInitial(order: LoanOrder): Partial<LoanOrderFormData> {
|
||||
return {
|
||||
status: order.status ?? "pending",
|
||||
notes: order.notes ?? order.note ?? "",
|
||||
source: order.source ?? "web",
|
||||
satisfiable: order.satisfiable ?? "yes",
|
||||
loanType: order.loanTypeId != null ? String(order.loanTypeId) : "",
|
||||
loanAmount: order.loanAmount != null ? String(order.loanAmount) : "",
|
||||
loanOrderRequiredDocId:
|
||||
order.loanOrderRequiredDocId != null
|
||||
? String(order.loanOrderRequiredDocId)
|
||||
: order.loanOrderRequiredDoc?.id != null
|
||||
? String(order.loanOrderRequiredDoc.id)
|
||||
: (order.loanHistory ?? ""),
|
||||
loanCardNumber: order.loanCardNumber ?? "",
|
||||
loanCardName: order.loanCardName ?? "",
|
||||
loanCardMonth: order.loanCardMonth ?? "",
|
||||
loanCardYear: order.loanCardYear ?? "",
|
||||
region: order.region ?? "AG",
|
||||
branch: order.branchId != null ? String(order.branchId) : "",
|
||||
userId: order.createdById != null ? String(order.createdById) : "",
|
||||
firstName: order.firstName ?? "",
|
||||
lastName: order.lastName ?? "",
|
||||
patronicName: order.patronicName ?? "",
|
||||
branchId: order.branchId != null ? String(order.branchId) : "",
|
||||
userId: order.createdById != null ? String(order.createdById) : order.user?.id != null ? String(order.user.id) : "",
|
||||
customerName: order.customerName ?? order.firstName ?? "",
|
||||
customerSurname: order.customerSurname ?? order.lastName ?? "",
|
||||
customerPatronicName: order.customerPatronicName ?? 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 ?? "",
|
||||
bornAt: formatFromApiDate(order.bornAt ?? order.dateOfBirth),
|
||||
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 ?? "",
|
||||
passportAddress: order.passportAddress ?? order.residence ?? "",
|
||||
realAddress: order.realAddress ?? order.currentResidence ?? "",
|
||||
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) : "",
|
||||
cardMonth: order.cardMonth ?? order.cardExpMonth ?? "",
|
||||
cardYear: order.cardYear ?? order.cardExpYear ?? "",
|
||||
passportSerie: order.passportSerie ?? "",
|
||||
passportId: order.passportId ?? order.passportNumber ?? "",
|
||||
passportGivenAt: formatFromApiDate(order.passportGivenAt ?? order.passportDateOfIssue),
|
||||
passportGivenBy: order.passportGivenBy ?? "",
|
||||
passportOne: order.passportOne ?? order.passportPage1Url ?? "",
|
||||
passportTwo: order.passportTwo ?? order.passportPage23Url ?? "",
|
||||
passportThree: order.passportThree ?? order.passportPage89Url ?? "",
|
||||
passportFour: order.passportFour ?? order.passportPage32Url ?? "",
|
||||
phone: formatFromApiPhone(order.phone),
|
||||
phoneAdditional: formatFromApiPhone(order.phoneAdditional),
|
||||
phoneHome: formatFromApiPhone(order.phoneHome ?? order.homePhone),
|
||||
email: order.email ?? "",
|
||||
workCompany: order.workCompany ?? "",
|
||||
workCompanyAccountantNumber: formatFromApiPhone(order.workCompanyAccountantNumber ?? order.workHrPhone),
|
||||
workRegion: order.workRegion ?? "AG",
|
||||
workProvinceId: order.workProvinceId != null ? String(order.workProvinceId) : order.workCityId != null ? String(order.workCityId) : "",
|
||||
workPosition: order.workPosition ?? order.position ?? "",
|
||||
workSalary: order.workSalary != null ? String(order.workSalary) : order.salary != null ? String(order.salary) : "",
|
||||
workStartedAt: formatFromApiDate(order.workStartedAt),
|
||||
guarantorName: order.guarantorName ?? order.guarantor1Name ?? "",
|
||||
guarantorSurname: order.guarantorSurname ?? order.guarantor1Surname ?? "",
|
||||
guarantorPatronicName: order.guarantorPatronicName ?? order.guarantor1Patronic ?? "",
|
||||
guarantorPassportSerie: order.guarantorPassportSerie ?? order.guarantor1PassportSerie ?? "",
|
||||
guarantorPassportId: order.guarantorPassportId ?? order.guarantor1PassportNumber ?? "",
|
||||
guarantorCardNumber: order.guarantorCardNumber ?? order.guarantor1CardNumber ?? "",
|
||||
guarantorCardName: order.guarantorCardName ?? order.guarantor1CardName ?? "",
|
||||
guarantorCardMonth: order.guarantorCardMonth ?? order.guarantor1CardExpMonth ?? "",
|
||||
guarantorCardYear: order.guarantorCardYear ?? order.guarantor1CardExpYear ?? "",
|
||||
guarantorNote: order.guarantorNote ?? order.guarantor1Note ?? "",
|
||||
guarantor2Name: order.guarantor2Name ?? "",
|
||||
guarantor2Surname: order.guarantor2Surname ?? "",
|
||||
guarantor2Patronic: order.guarantor2Patronic ?? "",
|
||||
guarantor2PatronicName: order.guarantor2PatronicName ?? order.guarantor2Patronic ?? "",
|
||||
guarantor2PassportSerie: order.guarantor2PassportSerie ?? "",
|
||||
guarantor2PassportNumber: order.guarantor2PassportNumber ?? "",
|
||||
guarantor2PassportId: order.guarantor2PassportId ?? order.guarantor2PassportNumber ?? "",
|
||||
guarantor2CardNumber: order.guarantor2CardNumber ?? "",
|
||||
guarantor2CardName: order.guarantor2CardName ?? "",
|
||||
guarantor2CardExpMonth: order.guarantor2CardExpMonth ?? "",
|
||||
guarantor2CardExpYear: order.guarantor2CardExpYear ?? "",
|
||||
guarantor2CardMonth: order.guarantor2CardMonth ?? order.guarantor2CardExpMonth ?? "",
|
||||
guarantor2CardYear: order.guarantor2CardYear ?? order.guarantor2CardExpYear ?? "",
|
||||
guarantor2Note: order.guarantor2Note ?? "",
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user