fixed some missed data, added role based function(user)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { lazy, Suspense } from "react";
|
||||
import { createBrowserRouter, Navigate, Outlet } from "react-router-dom";
|
||||
import type { RouteObject } from "react-router-dom";
|
||||
import { useAuthStore } from "../store/authStore";
|
||||
import { useAuthStore, getHomePath } from "../store/authStore";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { DashboardLayout } from "@/layouts/DashboardLayout";
|
||||
import { AuthLayout } from "@/layouts/AuthLayout";
|
||||
@@ -123,7 +123,14 @@ function AuthGuard() {
|
||||
|
||||
function PublicGuard() {
|
||||
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
||||
if (isAuthenticated) return <Navigate to="/dashboard" replace />;
|
||||
if (isAuthenticated) return <Navigate to={getHomePath()} replace />;
|
||||
return <Outlet />;
|
||||
}
|
||||
|
||||
function DashboardGuard() {
|
||||
const user = useAuthStore((s) => s.user);
|
||||
const isAdmin = user?.role?.code === "admin";
|
||||
if (!isAdmin) return <Navigate to="/loan-orders" replace />;
|
||||
return <Outlet />;
|
||||
}
|
||||
|
||||
@@ -192,12 +199,17 @@ const routes: AppRoute[] = [
|
||||
element: <DashboardLayout />,
|
||||
errorElement: <PageErrorFallback />,
|
||||
children: [
|
||||
{ path: "/", element: <Navigate to="/dashboard" replace /> },
|
||||
{ path: "/", element: <Navigate to={getHomePath()} replace /> },
|
||||
|
||||
{
|
||||
path: "/dashboard",
|
||||
handle: { title: (t) => t("nav.dashboard", "Baş sahypa") },
|
||||
element: page(DashboardPage),
|
||||
element: <DashboardGuard />,
|
||||
children: [
|
||||
{
|
||||
path: "/dashboard",
|
||||
handle: { title: (t) => t("nav.dashboard", "Baş sahypa") },
|
||||
element: page(DashboardPage),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ── KARZ SARGYTLARY ───────────────────────────────────────────────
|
||||
|
||||
@@ -36,6 +36,13 @@ export interface AuthUser {
|
||||
createdAt?: string;
|
||||
}
|
||||
|
||||
/** Returns the role-appropriate landing page for the current user. */
|
||||
export function getHomePath(): string {
|
||||
const user = useAuthStore.getState().user;
|
||||
const isAdmin = user?.role?.code === "admin";
|
||||
return isAdmin ? "/dashboard" : "/loan-orders";
|
||||
}
|
||||
|
||||
interface AuthState {
|
||||
token: string | null;
|
||||
refreshTokenValue: string | null;
|
||||
|
||||
35
src/constants/formOptions.ts
Normal file
35
src/constants/formOptions.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { SelectOption } from "@/components/formInput";
|
||||
|
||||
export const EDUCATION_OPTIONS: SelectOption[] = [
|
||||
{ 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" },
|
||||
];
|
||||
|
||||
export const MARRIAGE_OPTIONS: SelectOption[] = [
|
||||
{ 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" },
|
||||
];
|
||||
|
||||
export const MONTH_OPTIONS: SelectOption[] = Array.from({ length: 12 }, (_, i) => {
|
||||
const val = String(i + 1).padStart(2, "0");
|
||||
return { value: val, label: val };
|
||||
});
|
||||
|
||||
export const YEAR_OPTIONS: SelectOption[] = Array.from({ length: 15 }, (_, i) => {
|
||||
const year = String(new Date().getFullYear() + i);
|
||||
return { value: year, label: year };
|
||||
});
|
||||
|
||||
/** Longer expiry range used by card balance / requisites / transaction forms. */
|
||||
export const CARD_YEAR_OPTIONS: SelectOption[] = Array.from({ length: 20 }, (_, i) => {
|
||||
const year = String(new Date().getFullYear() + i);
|
||||
return { value: year, label: year };
|
||||
});
|
||||
@@ -1,2 +1,4 @@
|
||||
export * from "./formOptions";
|
||||
export * from "./passportSeries";
|
||||
export * from "./regionCodes";
|
||||
export * from "./statusOptions";
|
||||
|
||||
34
src/constants/regionCodes.ts
Normal file
34
src/constants/regionCodes.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { TFunction } from "i18next";
|
||||
import type { SelectOption } from "@/components/formInput";
|
||||
|
||||
export const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
export type RegionCode = (typeof REGION_CODES)[number];
|
||||
|
||||
/** Distinct region set used by loan paid-off letters. */
|
||||
export const LOAN_PAID_OFF_REGION_CODES = ["AG", "AH", "BA", "DA", "LE", "MA"] as const;
|
||||
|
||||
export type LoanPaidOffRegionCode = (typeof LOAN_PAID_OFF_REGION_CODES)[number];
|
||||
|
||||
export const REGION_LABELS: Record<string, string> = {
|
||||
AG: "Aşgabat",
|
||||
AH: "Ahal",
|
||||
BN: "Balkan",
|
||||
DZ: "Daşoguz",
|
||||
LB: "Lebap",
|
||||
MR: "Mary",
|
||||
};
|
||||
|
||||
type TranslateFn = TFunction | ((key: string, fallback?: string) => string);
|
||||
|
||||
export function getRegionOptions(
|
||||
t: TranslateFn,
|
||||
prefix = "loanOrders",
|
||||
codes: readonly string[] = REGION_CODES,
|
||||
labels?: Record<string, string>,
|
||||
): SelectOption[] {
|
||||
return codes.map((code) => ({
|
||||
value: code,
|
||||
label: t(`${prefix}.regions.${code}`, labels?.[code] ?? code),
|
||||
}));
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import { useAuthStore } from "@/app/store/authStore";
|
||||
import { useAuthStore, getHomePath } from "@/app/store/authStore";
|
||||
import { extractErrorMessage } from "@/lib/api/client";
|
||||
import { loginApi, getProfileApi, updateProfileApi, type LoginRequest, type UpdateProfileRequest } from "../api/authApi";
|
||||
|
||||
@@ -21,7 +21,7 @@ export function useLogin() {
|
||||
setUser(profile);
|
||||
}
|
||||
|
||||
navigate("/dashboard", { replace: true });
|
||||
navigate(getHomePath(), { replace: true });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { useCreateCardBalance, useUpdateCardBalance } from "@/features/cardBalan
|
||||
import { cardBalanceFormSchema, DEFAULT_FORM_VALUES, mapInitial, buildPayload } from "@/features/cardBalance/schemas/cardBalance.schema";
|
||||
import type { CardBalanceFormData } from "@/features/cardBalance/schemas/cardBalance.schema";
|
||||
import { useInfiniteUsers } from "@/features/allUsers/hooks/useAllUsers";
|
||||
import { MONTH_OPTIONS, CARD_YEAR_OPTIONS } from "@/constants";
|
||||
|
||||
interface CardBalanceFormProps {
|
||||
mode: "create" | "edit";
|
||||
@@ -42,16 +43,6 @@ const CURRENCY_OPTIONS: SelectOption[] = [
|
||||
{ value: "EUR", label: "EUR" },
|
||||
];
|
||||
|
||||
const MONTH_OPTIONS: SelectOption[] = Array.from({ length: 12 }, (_, i) => {
|
||||
const val = String(i + 1).padStart(2, "0");
|
||||
return { value: val, label: val };
|
||||
});
|
||||
|
||||
const YEAR_OPTIONS: SelectOption[] = Array.from({ length: 20 }, (_, i) => {
|
||||
const year = String(new Date().getFullYear() + i);
|
||||
return { value: year, label: year };
|
||||
});
|
||||
|
||||
// ─── Component ────────────────────────────────────────────────────────────────
|
||||
|
||||
export function CardBalanceForm({ mode, initialData }: CardBalanceFormProps) {
|
||||
@@ -182,7 +173,7 @@ export function CardBalanceForm({ mode, initialData }: CardBalanceFormProps) {
|
||||
label={t("Card expiry year", "Kart Möhleti (ýyl)")}
|
||||
value={form.expiryYear}
|
||||
onChange={setString("expiryYear")}
|
||||
options={YEAR_OPTIONS}
|
||||
options={CARD_YEAR_OPTIONS}
|
||||
placeholder={t("Select", "Saýlamak üçin basyň")}
|
||||
error={errMsg(errors.expiryYear)}
|
||||
required
|
||||
|
||||
@@ -21,6 +21,7 @@ import { useInfiniteCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
import { resolveLocalizedName } from "@/features/loanOrders/api/loanOrdersApi";
|
||||
import { getRegionOptions, MONTH_OPTIONS, CARD_YEAR_OPTIONS } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -48,15 +49,6 @@ const STATUS_OPTIONS: SelectOption[] = [
|
||||
{ value: "rejected", label: "Ret edilen" },
|
||||
];
|
||||
|
||||
const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
function getRegionOptions(t: TFunction): SelectOption[] {
|
||||
return REGION_CODES.map((code) => ({
|
||||
value: code,
|
||||
label: t(`cardRequisites.regions.${code}`, code),
|
||||
}));
|
||||
}
|
||||
|
||||
const PASSPORT_SERIES_OPTIONS = [
|
||||
{ value: "I-MR", label: "I-MR" },
|
||||
{ value: "II-MR", label: "II-MR" },
|
||||
@@ -67,16 +59,6 @@ const PASSPORT_SERIES_OPTIONS = [
|
||||
{ value: "B", label: "B" },
|
||||
];
|
||||
|
||||
const MONTH_OPTIONS: SelectOption[] = Array.from({ length: 12 }, (_, i) => {
|
||||
const val = String(i + 1).padStart(2, "0");
|
||||
return { value: val, label: val };
|
||||
});
|
||||
|
||||
const YEAR_OPTIONS: SelectOption[] = Array.from({ length: 20 }, (_, i) => {
|
||||
const year = String(new Date().getFullYear() + i);
|
||||
return { value: year, label: year };
|
||||
});
|
||||
|
||||
function mapInitial(data: CardRequisite): CardRequisiteFormData {
|
||||
return {
|
||||
status: data.status ?? "pending",
|
||||
@@ -166,7 +148,7 @@ function StepCard({ form, errors, set, t, initialData }: StepContentProps) {
|
||||
const branchQuery = useInfiniteBranches(branchSearch);
|
||||
const clientQuery = useInfiniteClients(clientSearch);
|
||||
|
||||
const regionOptions = useMemo(() => getRegionOptions(t), [t]);
|
||||
const regionOptions = useMemo(() => getRegionOptions(t, "cardRequisites"), [t]);
|
||||
|
||||
const cardTypeOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (cardTypeQuery.data?.pages ?? [])
|
||||
@@ -282,7 +264,7 @@ function StepCard({ form, errors, set, t, initialData }: StepContentProps) {
|
||||
required
|
||||
value={form.cardYear}
|
||||
onChange={(v) => set("cardYear", v)}
|
||||
options={YEAR_OPTIONS}
|
||||
options={CARD_YEAR_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.cardYear}
|
||||
/>
|
||||
|
||||
@@ -13,6 +13,7 @@ import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import type { LocalizedTitle } from "@/features/cardTypes/api/cardTypesApi";
|
||||
import { cardTransactionFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/cardTransaction.schema";
|
||||
import type { CardTransactionFormData } from "../schemas/cardTransaction.schema";
|
||||
import { MONTH_OPTIONS, CARD_YEAR_OPTIONS } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -21,18 +22,6 @@ interface CardTransactionFormProps {
|
||||
initialData?: Card;
|
||||
}
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => {
|
||||
const val = String(i + 1).padStart(2, "0");
|
||||
return { value: val, label: val };
|
||||
});
|
||||
|
||||
const YEAR_OPTIONS = Array.from({ length: 20 }, (_, i) => {
|
||||
const year = String(new Date().getFullYear() + i);
|
||||
return { value: year, label: year };
|
||||
});
|
||||
|
||||
// ─── Form errors helper ───────────────────────────────────────────────────────
|
||||
|
||||
type FlatErrors = Partial<Record<keyof CardTransactionFormData, string>>;
|
||||
@@ -224,7 +213,7 @@ export function CardTransactionForm({ mode, initialData }: CardTransactionFormPr
|
||||
label={t("Card expiry year", "Kart möhleti (ýyl)")}
|
||||
value={form.year}
|
||||
onChange={setField("year")}
|
||||
options={YEAR_OPTIONS}
|
||||
options={CARD_YEAR_OPTIONS}
|
||||
placeholder={t("Select to choose", "Saýlamak üçin basyň")}
|
||||
error={errMsg(errors.year)}
|
||||
required
|
||||
|
||||
@@ -48,7 +48,7 @@ export async function createLoanOrderMobile(payload: LoanOrderPayload): Promise<
|
||||
// ─── Mobile-specific List API ──────────────────────────────────────────────────
|
||||
|
||||
export async function fetchLoanOrderMobiles(params: LoanOrdersParams = {}, signal?: AbortSignal): Promise<LoanOrdersResponse> {
|
||||
const { page, perPage, limit, search, region, status, branch, branch_id, createdById, userId, user_id, archived } = params;
|
||||
const { page, perPage, limit, search, region, status, branch, branch_id, createdById, userId, user_id } = params;
|
||||
const branchId = branch || branch_id;
|
||||
const uid = createdById || userId || user_id;
|
||||
|
||||
@@ -61,7 +61,6 @@ export async function fetchLoanOrderMobiles(params: LoanOrdersParams = {}, signa
|
||||
status: status || undefined,
|
||||
branch_id: branchId || undefined,
|
||||
user_id: uid || undefined,
|
||||
archived: archived || undefined,
|
||||
},
|
||||
signal,
|
||||
});
|
||||
|
||||
@@ -29,48 +29,17 @@ import { useInfiniteLoanTypes } from "@/features/loanTypes/hooks/useLoanTypes";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
import { useGetRequiredDocuments } from "@/features/requiredDocuments/hooks/useRequiredDocuments";
|
||||
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
import {
|
||||
PASSPORT_SERIES_OPTIONS,
|
||||
getStatusOptions,
|
||||
getRegionOptions,
|
||||
EDUCATION_OPTIONS,
|
||||
MARRIAGE_OPTIONS,
|
||||
MONTH_OPTIONS,
|
||||
YEAR_OPTIONS,
|
||||
} from "@/constants";
|
||||
import { formatFromApiDate, formatFromApiPhone } from "@/lib/utils";
|
||||
|
||||
// ─── Static options ───────────────────────────────────────────────────────────
|
||||
|
||||
const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
function getRegionOptions(t: TFunction): SelectOption[] {
|
||||
return REGION_CODES.map((code) => ({
|
||||
value: code,
|
||||
label: t(`loanOrders.regions.${code}`, code),
|
||||
}));
|
||||
}
|
||||
|
||||
const EDUCATION_OPTIONS: SelectOption[] = [
|
||||
{ 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: SelectOption[] = [
|
||||
{ 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: SelectOption[] = Array.from({ length: 12 }, (_, i) => ({
|
||||
value: String(i + 1).padStart(2, "0"),
|
||||
label: String(i + 1).padStart(2, "0"),
|
||||
}));
|
||||
|
||||
const YEAR_OPTIONS: SelectOption[] = 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 LoanOrderMobileFormData, string>>;
|
||||
@@ -222,8 +191,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}
|
||||
/>
|
||||
@@ -312,7 +281,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ň"}
|
||||
@@ -324,12 +293,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}
|
||||
@@ -398,25 +367,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>
|
||||
@@ -450,9 +419,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>
|
||||
@@ -464,16 +433,16 @@ 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>
|
||||
@@ -482,8 +451,8 @@ function StepPersonal({ form, errors, set, t, initialData }: StepContentProps &
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t("Loan history") || "Karz taryhy"}
|
||||
value={form.loanHistory}
|
||||
onChange={(v) => set("loanHistory", v)}
|
||||
value={form.loanOrderRequiredDocId}
|
||||
onChange={(v) => set("loanOrderRequiredDocId", v)}
|
||||
options={loanHistoryOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
/>
|
||||
@@ -522,21 +491,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>
|
||||
@@ -564,10 +533,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>
|
||||
@@ -575,9 +544,9 @@ 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>
|
||||
@@ -692,10 +661,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>
|
||||
@@ -735,10 +704,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>
|
||||
|
||||
@@ -753,8 +722,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}
|
||||
@@ -773,10 +742,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>
|
||||
@@ -784,10 +753,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>
|
||||
@@ -814,10 +783,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>
|
||||
@@ -825,18 +794,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>
|
||||
@@ -848,11 +817,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>
|
||||
@@ -860,10 +829,10 @@ 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>
|
||||
@@ -874,19 +843,19 @@ function StepGuarantor({ form, errors, set, t }: StepContentProps) {
|
||||
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>
|
||||
|
||||
@@ -895,35 +864,21 @@ function StepGuarantor({ form, errors, set, t }: StepContentProps) {
|
||||
type="searchable-select"
|
||||
label={t("loanOrderForm.labels.cardExpMonth") || "Aý"}
|
||||
required
|
||||
value={form.guarantor1CardExpMonth}
|
||||
onChange={(v) => set("guarantor1CardExpMonth", v)}
|
||||
value={form.guarantorCardMonth}
|
||||
onChange={(v) => set("guarantorCardMonth", v)}
|
||||
options={MONTH_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor1CardExpMonth}
|
||||
error={errors.guarantorCardMonth}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("loanOrderForm.labels.cardExpYear") || "Ýyl"}
|
||||
required
|
||||
value={form.guarantor1CardExpYear}
|
||||
onChange={(v) => set("guarantor1CardExpYear", v)}
|
||||
value={form.guarantorCardYear}
|
||||
onChange={(v) => set("guarantorCardYear", v)}
|
||||
options={YEAR_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor1CardExpYear}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("Guarantor Salary") || "Zamunyň zähmet haky"}
|
||||
required
|
||||
value={form.guarantor1Salary}
|
||||
onChange={(v) => set("guarantor1Salary", v)}
|
||||
placeholder={t("Guarantor Salary") || "Zamunyň zähmet haky"}
|
||||
error={errors.guarantor1Salary}
|
||||
error={errors.guarantorCardYear}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -959,8 +914,8 @@ function StepGuarantor2({ form, errors, set, t }: StepContentProps) {
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Guarantor Patronic name") || "Zamunyň atasynyň ady"}
|
||||
value={form.guarantor2Patronic}
|
||||
onChange={(v) => set("guarantor2Patronic", v)}
|
||||
value={form.guarantor2PatronicName}
|
||||
onChange={(v) => set("guarantor2PatronicName", v)}
|
||||
placeholder={t("Guarantor Patronic name") || "Zamunyň atasynyň ady"}
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -982,10 +937,10 @@ 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>
|
||||
@@ -1014,20 +969,20 @@ function StepGuarantor2({ form, errors, set, t }: StepContentProps) {
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("loanOrderForm.labels.cardExpMonth") || "Aý"}
|
||||
value={form.guarantor2CardExpMonth}
|
||||
onChange={(v) => set("guarantor2CardExpMonth", v)}
|
||||
value={form.guarantor2CardMonth}
|
||||
onChange={(v) => set("guarantor2CardMonth", v)}
|
||||
options={MONTH_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor2CardExpMonth}
|
||||
error={errors.guarantor2CardMonth}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t("loanOrderForm.labels.cardExpYear") || "Ýyl"}
|
||||
value={form.guarantor2CardExpYear}
|
||||
onChange={(v) => set("guarantor2CardExpYear", v)}
|
||||
value={form.guarantor2CardYear}
|
||||
onChange={(v) => set("guarantor2CardYear", v)}
|
||||
options={YEAR_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.guarantor2CardExpYear}
|
||||
error={errors.guarantor2CardYear}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -1059,8 +1014,7 @@ export function LoanOrderMobileForm({ initialData, mode }: LoanOrderMobileFormPr
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const [currentStep, setCurrentStep] = useState(0);
|
||||
const [visited, setVisited] = useState<Set<number>>(() => new Set([0]));
|
||||
const [submittedSteps, setSubmittedSteps] = useState<Set<number>>(() => new Set());
|
||||
const [visited, setVisited] = useState<Set<number>>(() => (mode === "edit" ? new Set(STEPS.map((_, i) => i)) : new Set([0])));
|
||||
|
||||
const createMutation = useCreateLoanOrderMobile();
|
||||
const updateMutation = useUpdateLoanOrderMobile();
|
||||
@@ -1085,7 +1039,7 @@ export function LoanOrderMobileForm({ initialData, mode }: LoanOrderMobileFormPr
|
||||
(setValue as (name: K, val: LoanOrderMobileFormData[K]) => void)(k, v);
|
||||
clearErrors(k);
|
||||
},
|
||||
[setValue, clearErrors, submittedSteps, currentStep],
|
||||
[setValue, clearErrors],
|
||||
);
|
||||
|
||||
const stepProps: StepContentProps = { form, errors: flatErrors, set, t };
|
||||
@@ -1096,15 +1050,14 @@ export function LoanOrderMobileForm({ initialData, mode }: LoanOrderMobileFormPr
|
||||
|
||||
const stepsWithErrors = useMemo(() => {
|
||||
const errorSet = new Set<number>();
|
||||
submittedSteps.forEach((s) => {
|
||||
visited.forEach((s) => {
|
||||
const stepErrs = STEPS[s].validate(form, mode);
|
||||
if (Object.keys(stepErrs).length > 0) errorSet.add(s);
|
||||
});
|
||||
return errorSet;
|
||||
}, [submittedSteps, form, mode]);
|
||||
}, [visited, form, mode]);
|
||||
|
||||
const handleNext = () => {
|
||||
setSubmittedSteps((prev) => new Set([...prev, currentStep]));
|
||||
const stepErrs = STEPS[currentStep].validate(form, mode);
|
||||
|
||||
if (Object.keys(stepErrs).length > 0) {
|
||||
@@ -1139,7 +1092,6 @@ export function LoanOrderMobileForm({ initialData, mode }: LoanOrderMobileFormPr
|
||||
|
||||
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));
|
||||
@@ -1240,19 +1192,19 @@ function mapInitial(order: LoanOrderMobile): Partial<LoanOrderMobileFormData> {
|
||||
status: order.status ?? "pending",
|
||||
loanType: order.loanTypeId != null ? String(order.loanTypeId) : "",
|
||||
region: order.region ?? "AG",
|
||||
branch: order.branchId != null ? String(order.branchId) : "",
|
||||
branchId: order.branchId != null ? String(order.branchId) : "",
|
||||
userId: order.createdById != null ? String(order.createdById) : "",
|
||||
firstName: order.firstName ?? "",
|
||||
lastName: order.lastName ?? "",
|
||||
patronicName: order.patronicName ?? "",
|
||||
customerName: order.customerName ?? order.firstName ?? "",
|
||||
customerSurname: order.customerSurname ?? order.lastName ?? "",
|
||||
customerPatronicName: order.customerPatronicName ?? "",
|
||||
education: order.education ?? "",
|
||||
marriageStatus: order.marriageStatus ?? "",
|
||||
dateOfBirth: formatFromApiDate(order.dateOfBirth),
|
||||
residence: order.residence ?? "",
|
||||
currentResidence: order.currentResidence ?? "",
|
||||
bornAt: formatFromApiDate(order.bornAt),
|
||||
passportAddress: order.passportAddress ?? order.residence ?? "",
|
||||
realAddress: order.realAddress ?? order.currentResidence ?? "",
|
||||
passportSerie: order.passportSerie ?? "",
|
||||
passportNumber: order.passportNumber ?? "",
|
||||
passportDateOfIssue: formatFromApiDate(order.passportDateOfIssue),
|
||||
passportId: order.passportId ?? "",
|
||||
passportGivenAt: formatFromApiDate(order.passportGivenAt),
|
||||
passportGivenBy: order.passportGivenBy ?? "",
|
||||
passportOne: order.passportPage1Url ?? "",
|
||||
passportTwo: order.passportPage23Url ?? "",
|
||||
@@ -1262,40 +1214,39 @@ function mapInitial(order: LoanOrderMobile): Partial<LoanOrderMobileFormData> {
|
||||
email: order.email ?? "",
|
||||
phone: formatFromApiPhone(order.phone),
|
||||
phoneAdditional: formatFromApiPhone(order.phoneAdditional),
|
||||
homePhone: formatFromApiPhone(order.homePhone),
|
||||
phoneHome: formatFromApiPhone(order.phoneHome),
|
||||
workCompany: order.workCompany ?? "",
|
||||
workHrPhone: formatFromApiPhone(order.workHrPhone),
|
||||
workCompanyAccountantNumber: formatFromApiPhone(order.workCompanyAccountantNumber),
|
||||
workRegion: order.workRegion ?? "AG",
|
||||
workProvince: order.workCityId != null ? String(order.workCityId) : "",
|
||||
position: order.position ?? "",
|
||||
salary: order.salary != null ? String(order.salary) : "",
|
||||
workProvinceId: order.workCityId != null ? String(order.workCityId) : "",
|
||||
workPosition: order.workPosition ?? "",
|
||||
workSalary: order.workSalary != null ? String(order.workSalary) : "",
|
||||
workStartedAt: formatFromApiDate(order.workStartedAt),
|
||||
note: order.note ?? "",
|
||||
notes: order.notes ?? order.note ?? "",
|
||||
loanAmount: order.loanAmount != null ? String(order.loanAmount) : "",
|
||||
loanHistory: order.loanHistory ?? "",
|
||||
loanOrderRequiredDocId: order.loanOrderRequiredDocId != null ? String(order.loanOrderRequiredDocId) : (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) : "",
|
||||
cardMonth: order.cardMonth ?? "",
|
||||
cardYear: order.cardYear ?? "",
|
||||
guarantorName: order.guarantorName ?? "",
|
||||
guarantorSurname: order.guarantorSurname ?? "",
|
||||
guarantorPatronicName: order.guarantorPatronicName ?? "",
|
||||
guarantorPassportSerie: order.guarantorPassportSerie ?? "",
|
||||
guarantorPassportId: order.guarantorPassportId ?? "",
|
||||
guarantorCardNumber: order.guarantorCardNumber ?? "",
|
||||
guarantorCardName: order.guarantorCardName ?? "",
|
||||
guarantorCardMonth: order.guarantorCardMonth ?? "",
|
||||
guarantorCardYear: order.guarantorCardYear ?? "",
|
||||
guarantor2Name: order.guarantor2Name ?? "",
|
||||
guarantor2Surname: order.guarantor2Surname ?? "",
|
||||
guarantor2Patronic: order.guarantor2Patronic ?? "",
|
||||
guarantor2PatronicName: order.guarantor2PatronicName ?? "",
|
||||
guarantor2PassportSerie: order.guarantor2PassportSerie ?? "",
|
||||
guarantor2PassportNumber: order.guarantor2PassportNumber ?? "",
|
||||
guarantor2PassportId: order.guarantor2PassportId ?? "",
|
||||
guarantor2CardNumber: order.guarantor2CardNumber ?? "",
|
||||
guarantor2CardName: order.guarantor2CardName ?? "",
|
||||
guarantor2CardExpMonth: order.guarantor2CardExpMonth ?? "",
|
||||
guarantor2CardExpYear: order.guarantor2CardExpYear ?? "",
|
||||
guarantor2CardMonth: order.guarantor2CardMonth ?? "",
|
||||
guarantor2CardYear: order.guarantor2CardYear ?? "",
|
||||
guarantor2Note: order.guarantor2Note ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -32,39 +32,55 @@ export interface LoanOrder {
|
||||
workProvinceId?: number | string;
|
||||
createdById?: number | string;
|
||||
createdBy?: string | null;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
customerName: string;
|
||||
customerSurname: string;
|
||||
customerPatronicName?: string | null;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
patronicName?: string | null;
|
||||
fullName?: string | null;
|
||||
phone: string;
|
||||
phoneHome?: string | null;
|
||||
homePhone?: string | null;
|
||||
phoneAdditional?: string | null;
|
||||
phoneAlt?: string | null;
|
||||
status: LoanOrderStatus;
|
||||
note?: string | null;
|
||||
notes?: string | null;
|
||||
|
||||
loanAmount?: number | null;
|
||||
amount?: number | null;
|
||||
loanHistory?: string | null;
|
||||
loanOrderRequiredDocId?: number | null;
|
||||
loanOrderRequiredDoc?: { id: number; name: string } | null;
|
||||
satisfiable?: string | null;
|
||||
|
||||
education?: string | null;
|
||||
marriageStatus?: string | null;
|
||||
maritalStatus?: string | null;
|
||||
bornAt?: string | null;
|
||||
dateOfBirth?: string | null;
|
||||
birthDate?: string | null;
|
||||
bornPlace?: string | null;
|
||||
passportBirthPlace?: string | null;
|
||||
passportAddress?: string | null;
|
||||
residence?: string | null;
|
||||
registeredAddress?: string | null;
|
||||
realAddress?: string | null;
|
||||
currentResidence?: string | null;
|
||||
currentAddress?: string | null;
|
||||
|
||||
passportSerie?: string | null;
|
||||
passportId?: string | null;
|
||||
passportNumber?: string | null;
|
||||
passportGivenAt?: string | null;
|
||||
passportDateOfIssue?: string | null;
|
||||
passportGivenBy?: string | null;
|
||||
passportIssuedBy?: string | null;
|
||||
bornPlace?: string | null;
|
||||
passportBirthPlace?: string | null;
|
||||
passportOne?: string | null;
|
||||
passportTwo?: string | null;
|
||||
passportThree?: string | null;
|
||||
passportFour?: string | null;
|
||||
passportPage1Url?: string | null;
|
||||
passportPage23Url?: string | null;
|
||||
passportPage89Url?: string | null;
|
||||
@@ -74,21 +90,42 @@ export interface LoanOrder {
|
||||
|
||||
workCompany?: string | null;
|
||||
employer?: string | null;
|
||||
workCompanyAccountantNumber?: string | null;
|
||||
workHrPhone?: string | null;
|
||||
deptPhone?: string | null;
|
||||
workRegion?: string | null;
|
||||
workProvince?: string | null;
|
||||
workCity?: string | null;
|
||||
workPosition?: string | null;
|
||||
position?: string | null;
|
||||
workSalary?: number | null;
|
||||
salary?: number | null;
|
||||
workStartedAt?: string | null;
|
||||
employedSince?: string | null;
|
||||
|
||||
cardNumber?: string | null;
|
||||
cardName?: string | null;
|
||||
cardMonth?: string | null;
|
||||
cardYear?: string | null;
|
||||
cardExpMonth?: string | null;
|
||||
cardExpYear?: string | null;
|
||||
|
||||
loanCardNumber?: string | null;
|
||||
loanCardName?: string | null;
|
||||
loanCardMonth?: string | null;
|
||||
loanCardYear?: string | null;
|
||||
|
||||
guarantorName?: string | null;
|
||||
guarantorSurname?: string | null;
|
||||
guarantorPatronicName?: string | null;
|
||||
guarantorPassportSerie?: string | null;
|
||||
guarantorPassportId?: string | null;
|
||||
guarantorCardNumber?: string | null;
|
||||
guarantorCardName?: string | null;
|
||||
guarantorCardMonth?: string | null;
|
||||
guarantorCardYear?: string | null;
|
||||
guarantorNote?: string | null;
|
||||
|
||||
guarantor1Name?: string | null;
|
||||
guarantor1Surname?: string | null;
|
||||
guarantor1Patronic?: string | null;
|
||||
@@ -103,22 +140,18 @@ export interface LoanOrder {
|
||||
|
||||
guarantor2Name?: string | null;
|
||||
guarantor2Surname?: string | null;
|
||||
guarantor2PatronicName?: string | null;
|
||||
guarantor2Patronic?: string | null;
|
||||
guarantor2PassportSerie?: string | null;
|
||||
guarantor2PassportId?: string | null;
|
||||
guarantor2PassportNumber?: string | null;
|
||||
guarantor2CardNumber?: string | null;
|
||||
guarantor2CardName?: string | null;
|
||||
guarantor2CardMonth?: string | null;
|
||||
guarantor2CardYear?: string | null;
|
||||
guarantor2CardExpMonth?: string | null;
|
||||
guarantor2CardExpYear?: string | null;
|
||||
guarantor2Note?: string | null;
|
||||
|
||||
loanCardNumber?: string | null;
|
||||
loanCardName?: string | null;
|
||||
loanCardMonth?: string | null;
|
||||
loanCardYear?: string | null;
|
||||
|
||||
amount?: number | null;
|
||||
phoneAlt?: string | null;
|
||||
}
|
||||
|
||||
export interface LoanOrdersParams {
|
||||
@@ -130,7 +163,6 @@ export interface LoanOrdersParams {
|
||||
createdById?: string | number;
|
||||
userId?: string | number;
|
||||
user_id?: string | number;
|
||||
archived?: string;
|
||||
page?: number;
|
||||
perPage?: number;
|
||||
limit?: number;
|
||||
@@ -144,45 +176,79 @@ export interface LoanOrdersResponse {
|
||||
}
|
||||
|
||||
export interface LoanOrderPayload {
|
||||
status: string;
|
||||
loanType: string;
|
||||
region: string;
|
||||
branch: string;
|
||||
status?: string;
|
||||
loanType?: string | number;
|
||||
region?: string;
|
||||
branchId?: string | number;
|
||||
branch?: string | number;
|
||||
userId?: string | number;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
customerName?: string;
|
||||
customerSurname?: string;
|
||||
customerPatronicName?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
patronicName?: string;
|
||||
education: string;
|
||||
marriageStatus: string;
|
||||
dateOfBirth: string;
|
||||
residence: string;
|
||||
education?: string;
|
||||
marriageStatus?: string;
|
||||
bornAt?: string;
|
||||
dateOfBirth?: string;
|
||||
passportAddress?: string;
|
||||
residence?: string;
|
||||
realAddress?: string;
|
||||
currentResidence?: string;
|
||||
passportSerie: string;
|
||||
passportNumber: string;
|
||||
passportDateOfIssue: string;
|
||||
passportGivenBy: string;
|
||||
passportSerie?: string;
|
||||
passportId?: string;
|
||||
passportNumber?: string;
|
||||
passportGivenAt?: string;
|
||||
passportDateOfIssue?: string;
|
||||
passportGivenBy?: string;
|
||||
bornPlace?: string;
|
||||
email?: string;
|
||||
phone: string;
|
||||
phone?: string;
|
||||
phoneAdditional?: string;
|
||||
phoneHome?: string;
|
||||
homePhone?: string;
|
||||
workCompany: string;
|
||||
workCompany?: string;
|
||||
workCompanyAccountantNumber?: string;
|
||||
workHrPhone?: string;
|
||||
workRegion?: string;
|
||||
workProvince?: string;
|
||||
position: string;
|
||||
salary: number;
|
||||
workStartedAt: string;
|
||||
workProvinceId?: string | number;
|
||||
workProvince?: string | number;
|
||||
workPosition?: string;
|
||||
position?: string;
|
||||
workSalary?: string | number;
|
||||
salary?: string | number;
|
||||
workStartedAt?: string;
|
||||
|
||||
notes?: string;
|
||||
note?: string;
|
||||
loanAmount?: number;
|
||||
loanAmount?: string | number;
|
||||
loanOrderRequiredDocId?: string | number;
|
||||
loanHistory?: string;
|
||||
|
||||
cardNumber?: string;
|
||||
cardName?: string;
|
||||
cardMonth?: string;
|
||||
cardYear?: string;
|
||||
cardExpMonth?: string;
|
||||
cardExpYear?: string;
|
||||
|
||||
loanCardNumber?: string;
|
||||
loanCardName?: string;
|
||||
loanCardMonth?: string;
|
||||
loanCardYear?: string;
|
||||
|
||||
guarantorName?: string;
|
||||
guarantorSurname?: string;
|
||||
guarantorPatronicName?: string;
|
||||
guarantorPassportSerie?: string;
|
||||
guarantorPassportId?: string;
|
||||
guarantorCardNumber?: string;
|
||||
guarantorCardName?: string;
|
||||
guarantorCardMonth?: string;
|
||||
guarantorCardYear?: string;
|
||||
guarantorNote?: string;
|
||||
|
||||
guarantor1Name?: string;
|
||||
guarantor1Surname?: string;
|
||||
guarantor1Patronic?: string;
|
||||
@@ -192,15 +258,19 @@ export interface LoanOrderPayload {
|
||||
guarantor1CardName?: string;
|
||||
guarantor1CardExpMonth?: string;
|
||||
guarantor1CardExpYear?: string;
|
||||
guarantor1Salary?: number;
|
||||
guarantor1Note?: string;
|
||||
|
||||
guarantor2Name?: string;
|
||||
guarantor2Surname?: string;
|
||||
guarantor2PatronicName?: string;
|
||||
guarantor2Patronic?: string;
|
||||
guarantor2PassportSerie?: string;
|
||||
guarantor2PassportId?: string;
|
||||
guarantor2PassportNumber?: string;
|
||||
guarantor2CardNumber?: string;
|
||||
guarantor2CardName?: string;
|
||||
guarantor2CardMonth?: string;
|
||||
guarantor2CardYear?: string;
|
||||
guarantor2CardExpMonth?: string;
|
||||
guarantor2CardExpYear?: string;
|
||||
guarantor2Note?: string;
|
||||
@@ -210,6 +280,8 @@ export interface LoanOrderPayload {
|
||||
passportThree?: string;
|
||||
passportFour?: string;
|
||||
source?: string;
|
||||
satisfiable?: string;
|
||||
uniqueId?: string;
|
||||
}
|
||||
|
||||
// ─── Backend types ─────────────────────────────────────────────────────────────
|
||||
@@ -342,6 +414,9 @@ export function toNum(value: string | number | null | undefined): number | null
|
||||
export function mapBackendToUI(order: BackendLoanOrder): LoanOrder {
|
||||
const rawStatus = order.status ?? "";
|
||||
const status: LoanOrderStatus = isStatusValue(rawStatus) ? rawStatus : "pending";
|
||||
const custName = order.customerName ?? "";
|
||||
const custSurname = order.customerSurname ?? "";
|
||||
const custPatronic = order.customerPatronicName ?? "";
|
||||
|
||||
return {
|
||||
id: String(order.id ?? order.uniqueId ?? ""),
|
||||
@@ -359,20 +434,28 @@ export function mapBackendToUI(order: BackendLoanOrder): LoanOrder {
|
||||
workProvinceId: resolveNestedId(order.workProvince) ?? order.workProvinceId ?? undefined,
|
||||
createdById: order.user?.id ?? order.userId ?? undefined,
|
||||
createdBy: order.user?.name ?? order.userName ?? "",
|
||||
firstName: order.customerName ?? "",
|
||||
lastName: order.customerSurname ?? "",
|
||||
patronicName: order.customerPatronicName ?? "",
|
||||
fullName: [order.customerName, order.customerSurname].filter(Boolean).join(" "),
|
||||
customerName: custName,
|
||||
customerSurname: custSurname,
|
||||
customerPatronicName: custPatronic,
|
||||
firstName: custName,
|
||||
lastName: custSurname,
|
||||
patronicName: custPatronic,
|
||||
fullName: [custName, custSurname].filter(Boolean).join(" "),
|
||||
phone: formatFromApiPhone(order.phone ?? order.phoneHome ?? ""),
|
||||
phoneHome: formatFromApiPhone(order.phoneHome),
|
||||
homePhone: formatFromApiPhone(order.phoneHome),
|
||||
phoneAdditional: formatFromApiPhone(order.phoneAdditional),
|
||||
phoneAlt: formatFromApiPhone(order.phoneAdditional),
|
||||
status,
|
||||
note: order.notes ?? "",
|
||||
notes: order.notes ?? "",
|
||||
loanAmount: toNum(order.loanAmount),
|
||||
amount: toNum(order.loanAmount),
|
||||
loanHistory: order.loanOrderRequiredDoc?.name || (order.loanOrderRequiredDocId ? String(order.loanOrderRequiredDocId) : ""),
|
||||
loanOrderRequiredDocId: order.loanOrderRequiredDocId ?? order.loanOrderRequiredDoc?.id ?? undefined,
|
||||
loanOrderRequiredDoc: order.loanOrderRequiredDoc ?? undefined,
|
||||
satisfiable: order.satisfiable ?? "",
|
||||
bornAt: formatFromApiDate(order.bornAt),
|
||||
dateOfBirth: formatFromApiDate(order.bornAt),
|
||||
birthDate: formatFromApiDate(order.bornAt),
|
||||
bornPlace: order.bornPlace ?? "",
|
||||
@@ -380,35 +463,62 @@ export function mapBackendToUI(order: BackendLoanOrder): LoanOrder {
|
||||
education: order.education ?? "",
|
||||
marriageStatus: order.marriageStatus ?? "",
|
||||
maritalStatus: order.marriageStatus ?? "",
|
||||
passportAddress: order.passportAddress ?? "",
|
||||
residence: order.passportAddress ?? "",
|
||||
registeredAddress: order.passportAddress ?? "",
|
||||
realAddress: order.realAddress ?? "",
|
||||
currentResidence: order.realAddress ?? "",
|
||||
currentAddress: order.realAddress ?? "",
|
||||
email: order.email ?? "",
|
||||
passportSerie: order.passportSerie ?? "",
|
||||
passportId: order.passportId ?? "",
|
||||
passportNumber: order.passportId ?? "",
|
||||
passportGivenAt: formatFromApiDate(order.passportGivenAt),
|
||||
passportDateOfIssue: formatFromApiDate(order.passportGivenAt),
|
||||
passportGivenBy: order.passportGivenBy ?? "",
|
||||
passportIssuedBy: order.passportGivenBy ?? "",
|
||||
passportOne: order.passportOne ?? "",
|
||||
passportTwo: order.passportTwo ?? "",
|
||||
passportThree: order.passportThree ?? "",
|
||||
passportFour: order.passportFour ?? "",
|
||||
passportPage1Url: order.passportOne ?? "",
|
||||
passportPage23Url: order.passportTwo ?? "",
|
||||
passportPage89Url: order.passportThree ?? "",
|
||||
passportPage32Url: order.passportFour ?? "",
|
||||
workCompany: order.workCompany ?? "",
|
||||
employer: order.workCompany ?? "",
|
||||
workCompanyAccountantNumber: formatFromApiPhone(order.workCompanyAccountantNumber),
|
||||
workHrPhone: formatFromApiPhone(order.workCompanyAccountantNumber),
|
||||
deptPhone: formatFromApiPhone(order.workCompanyAccountantNumber),
|
||||
workRegion: order.workRegion ?? "",
|
||||
workProvince: resolveNestedName(order.workProvince) || resolveLocalizedName(order.workProvinceName),
|
||||
workCity: resolveNestedName(order.workProvince) || resolveLocalizedName(order.workProvinceName),
|
||||
workSalary: toNum(order.workSalary),
|
||||
salary: toNum(order.workSalary),
|
||||
workPosition: order.workPosition ?? "",
|
||||
position: order.workPosition ?? "",
|
||||
workStartedAt: formatFromApiDate(order.workStartedAt),
|
||||
employedSince: formatFromApiDate(order.workStartedAt),
|
||||
cardNumber: order.cardNumber ?? order.loanCardNumber ?? "",
|
||||
cardName: order.cardName ?? order.loanCardName ?? "",
|
||||
cardExpMonth: order.cardMonth ?? order.loanCardMonth ?? "",
|
||||
cardExpYear: order.cardYear ?? order.loanCardYear ?? "",
|
||||
cardNumber: order.cardNumber ?? "",
|
||||
cardName: order.cardName ?? "",
|
||||
cardMonth: order.cardMonth ?? "",
|
||||
cardYear: order.cardYear ?? "",
|
||||
cardExpMonth: order.cardMonth ?? "",
|
||||
cardExpYear: order.cardYear ?? "",
|
||||
loanCardNumber: order.loanCardNumber ?? "",
|
||||
loanCardName: order.loanCardName ?? "",
|
||||
loanCardMonth: order.loanCardMonth ?? "",
|
||||
loanCardYear: order.loanCardYear ?? "",
|
||||
guarantorName: order.guarantorName ?? "",
|
||||
guarantorSurname: order.guarantorSurname ?? "",
|
||||
guarantorPatronicName: order.guarantorPatronicName ?? "",
|
||||
guarantorPassportSerie: order.guarantorPassportSerie ?? "",
|
||||
guarantorPassportId: order.guarantorPassportId ?? "",
|
||||
guarantorCardNumber: order.guarantorCardNumber ?? "",
|
||||
guarantorCardName: order.guarantorCardName ?? "",
|
||||
guarantorCardMonth: order.guarantorCardMonth ?? "",
|
||||
guarantorCardYear: order.guarantorCardYear ?? "",
|
||||
guarantorNote: order.guarantorNote ?? "",
|
||||
guarantor1Name: order.guarantorName ?? "",
|
||||
guarantor1Surname: order.guarantorSurname ?? "",
|
||||
guarantor1Patronic: order.guarantorPatronicName ?? "",
|
||||
@@ -422,96 +532,106 @@ export function mapBackendToUI(order: BackendLoanOrder): LoanOrder {
|
||||
guarantor1Note: order.guarantorNote ?? "",
|
||||
guarantor2Name: order.guarantor2Name ?? "",
|
||||
guarantor2Surname: order.guarantor2Surname ?? "",
|
||||
guarantor2PatronicName: order.guarantor2PatronicName ?? "",
|
||||
guarantor2Patronic: order.guarantor2PatronicName ?? "",
|
||||
guarantor2PassportSerie: order.guarantor2PassportSerie ?? "",
|
||||
guarantor2PassportId: order.guarantor2PassportId ?? "",
|
||||
guarantor2PassportNumber: order.guarantor2PassportId ?? "",
|
||||
guarantor2CardNumber: order.guarantor2CardNumber ?? "",
|
||||
guarantor2CardName: order.guarantor2CardName ?? "",
|
||||
guarantor2CardMonth: order.guarantor2CardMonth ?? "",
|
||||
guarantor2CardYear: order.guarantor2CardYear ?? "",
|
||||
guarantor2CardExpMonth: order.guarantor2CardMonth ?? "",
|
||||
guarantor2CardExpYear: order.guarantor2CardYear ?? "",
|
||||
guarantor2Note: order.guarantor2Note ?? "",
|
||||
loanCardNumber: order.loanCardNumber ?? "",
|
||||
loanCardName: order.loanCardName ?? "",
|
||||
loanCardMonth: order.loanCardMonth ?? "",
|
||||
loanCardYear: order.loanCardYear ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
export function mapPayloadToBackend(payload: LoanOrderPayload | Partial<LoanOrderPayload>): Record<string, unknown> {
|
||||
const customerName = payload.customerName || payload.firstName || "";
|
||||
const customerSurname = payload.customerSurname || payload.lastName || "";
|
||||
const customerPatronicName = payload.customerPatronicName || payload.patronicName || "";
|
||||
const branchId = toNum(payload.branchId ?? payload.branch);
|
||||
const loanType = toNum(payload.loanType);
|
||||
const userId = toNum(payload.userId) ?? 0;
|
||||
const workProvinceId = toNum(payload.workProvinceId ?? payload.workProvince);
|
||||
const loanOrderRequiredDocId = toNum(payload.loanOrderRequiredDocId ?? payload.loanHistory) ?? 0;
|
||||
|
||||
return {
|
||||
customerName: payload.firstName ?? "",
|
||||
customerSurname: payload.lastName ?? "",
|
||||
customerPatronicName: payload.patronicName || "",
|
||||
branchId: toNum(payload.branch),
|
||||
loanType: toNum(payload.loanType),
|
||||
region: payload.region ?? "",
|
||||
education: payload.education || "",
|
||||
marriageStatus: payload.marriageStatus || "",
|
||||
bornAt: formatToApiDate(payload.dateOfBirth),
|
||||
bornAt: formatToApiDate(payload.bornAt || payload.dateOfBirth),
|
||||
bornPlace: payload.bornPlace || "",
|
||||
passportAddress: payload.residence || "",
|
||||
realAddress: payload.currentResidence || "",
|
||||
passportSerie: payload.passportSerie || "",
|
||||
passportId: payload.passportNumber || "",
|
||||
passportGivenAt: formatToApiDate(payload.passportDateOfIssue),
|
||||
passportGivenBy: payload.passportGivenBy || "",
|
||||
branchId,
|
||||
cardMonth: payload.cardMonth || payload.cardExpMonth || "",
|
||||
cardName: payload.cardName || "",
|
||||
cardNumber: payload.cardNumber || "",
|
||||
cardYear: payload.cardYear || payload.cardExpYear || "",
|
||||
customerName,
|
||||
customerPatronicName,
|
||||
customerSurname,
|
||||
education: payload.education || "",
|
||||
email: payload.email || "",
|
||||
guarantor2CardMonth: payload.guarantor2CardMonth || payload.guarantor2CardExpMonth || "",
|
||||
guarantor2CardName: payload.guarantor2CardName || "",
|
||||
guarantor2CardNumber: payload.guarantor2CardNumber || "",
|
||||
guarantor2CardYear: payload.guarantor2CardYear || payload.guarantor2CardExpYear || "",
|
||||
guarantor2Name: payload.guarantor2Name || "",
|
||||
guarantor2Note: payload.guarantor2Note || "",
|
||||
guarantor2PassportId: payload.guarantor2PassportId || payload.guarantor2PassportNumber || "",
|
||||
guarantor2PassportSerie: payload.guarantor2PassportSerie || "",
|
||||
guarantor2PatronicName: payload.guarantor2PatronicName || payload.guarantor2Patronic || "",
|
||||
guarantor2Surname: payload.guarantor2Surname || "",
|
||||
guarantorCardMonth: payload.guarantorCardMonth || payload.guarantor1CardExpMonth || "",
|
||||
guarantorCardName: payload.guarantorCardName || payload.guarantor1CardName || "",
|
||||
guarantorCardNumber: payload.guarantorCardNumber || payload.guarantor1CardNumber || "",
|
||||
guarantorCardYear: payload.guarantorCardYear || payload.guarantor1CardExpYear || "",
|
||||
guarantorName: payload.guarantorName || payload.guarantor1Name || "",
|
||||
guarantorNote: payload.guarantorNote || payload.guarantor1Note || "",
|
||||
guarantorPassportId: payload.guarantorPassportId || payload.guarantor1PassportNumber || "",
|
||||
guarantorPassportSerie: payload.guarantorPassportSerie || payload.guarantor1PassportSerie || "",
|
||||
guarantorPatronicName: payload.guarantorPatronicName || payload.guarantor1Patronic || "",
|
||||
guarantorSurname: payload.guarantorSurname || payload.guarantor1Surname || "",
|
||||
loanAmount: payload.loanAmount != null ? String(payload.loanAmount) : "",
|
||||
loanCardMonth: payload.loanCardMonth || "",
|
||||
loanCardName: payload.loanCardName || "",
|
||||
loanCardNumber: payload.loanCardNumber || "",
|
||||
loanCardYear: payload.loanCardYear || "",
|
||||
loanOrderRequiredDocId,
|
||||
loanType,
|
||||
marriageStatus: payload.marriageStatus || "",
|
||||
notes: payload.notes || payload.note || "",
|
||||
passportAddress: payload.passportAddress || payload.residence || "",
|
||||
passportFour: payload.passportFour || "",
|
||||
passportGivenAt: formatToApiDate(payload.passportGivenAt || payload.passportDateOfIssue),
|
||||
passportGivenBy: payload.passportGivenBy || "",
|
||||
passportId: payload.passportId || payload.passportNumber || "",
|
||||
passportOne: payload.passportOne || "",
|
||||
passportSerie: payload.passportSerie || "",
|
||||
passportThree: payload.passportThree || "",
|
||||
passportTwo: payload.passportTwo || "",
|
||||
phone: formatToApiPhone(payload.phone),
|
||||
phoneAdditional: formatToApiPhone(payload.phoneAdditional),
|
||||
phoneHome: formatToApiPhone(payload.homePhone),
|
||||
workCompany: payload.workCompany || "",
|
||||
workCompanyAccountantNumber: formatToApiPhone(payload.workHrPhone),
|
||||
workRegion: payload.workRegion || "",
|
||||
workProvinceId: toNum(payload.workProvince),
|
||||
workSalary: payload.salary != null ? String(payload.salary) : "",
|
||||
workPosition: payload.position || "",
|
||||
workStartedAt: formatToApiDate(payload.workStartedAt),
|
||||
loanAmount: payload.loanAmount != null ? String(payload.loanAmount) : "",
|
||||
cardNumber: payload.cardNumber || "",
|
||||
cardName: payload.cardName || "",
|
||||
cardMonth: payload.cardExpMonth || "",
|
||||
cardYear: payload.cardExpYear || "",
|
||||
loanCardNumber: payload.cardNumber || "",
|
||||
loanCardName: payload.cardName || "",
|
||||
loanCardMonth: payload.cardExpMonth || "",
|
||||
loanCardYear: payload.cardExpYear || "",
|
||||
guarantorName: payload.guarantor1Name || "",
|
||||
guarantorSurname: payload.guarantor1Surname || "",
|
||||
guarantorPatronicName: payload.guarantor1Patronic || "",
|
||||
guarantorPassportSerie: payload.guarantor1PassportSerie || "",
|
||||
guarantorPassportId: payload.guarantor1PassportNumber || "",
|
||||
guarantorCardNumber: payload.guarantor1CardNumber || "",
|
||||
guarantorCardName: payload.guarantor1CardName || "",
|
||||
guarantorCardMonth: payload.guarantor1CardExpMonth || "",
|
||||
guarantorCardYear: payload.guarantor1CardExpYear || "",
|
||||
guarantorNote: "",
|
||||
guarantor2Name: payload.guarantor2Name || "",
|
||||
guarantor2Surname: payload.guarantor2Surname || "",
|
||||
guarantor2PatronicName: payload.guarantor2Patronic || "",
|
||||
guarantor2PassportSerie: payload.guarantor2PassportSerie || "",
|
||||
guarantor2PassportId: payload.guarantor2PassportNumber || "",
|
||||
guarantor2CardNumber: payload.guarantor2CardNumber || "",
|
||||
guarantor2CardName: payload.guarantor2CardName || "",
|
||||
guarantor2CardMonth: payload.guarantor2CardExpMonth || "",
|
||||
guarantor2CardYear: payload.guarantor2CardExpYear || "",
|
||||
guarantor2Note: payload.guarantor2Note || "",
|
||||
notes: payload.note || "",
|
||||
passportOne: payload.passportOne || "",
|
||||
passportTwo: payload.passportTwo || "",
|
||||
passportThree: payload.passportThree || "",
|
||||
passportFour: payload.passportFour || "",
|
||||
status: payload.status ?? "pending",
|
||||
satisfiable: "yes",
|
||||
phoneHome: formatToApiPhone(payload.phoneHome || payload.homePhone),
|
||||
realAddress: payload.realAddress || payload.currentResidence || "",
|
||||
region: payload.region ?? "",
|
||||
satisfiable: payload.satisfiable || "yes",
|
||||
source: payload.source ?? "web",
|
||||
loanOrderRequiredDocId: payload.loanHistory ? Number(payload.loanHistory) : 0,
|
||||
userId: toNum(payload.userId) ?? 0,
|
||||
status: payload.status ?? "pending",
|
||||
uniqueId: payload.uniqueId || "",
|
||||
userId,
|
||||
workCompany: payload.workCompany || "",
|
||||
workCompanyAccountantNumber: formatToApiPhone(payload.workCompanyAccountantNumber || payload.workHrPhone),
|
||||
workPosition: payload.workPosition || payload.position || "",
|
||||
workProvinceId,
|
||||
workRegion: payload.workRegion || "",
|
||||
workSalary: payload.workSalary != null ? String(payload.workSalary) : payload.salary != null ? String(payload.salary) : "",
|
||||
workStartedAt: formatToApiDate(payload.workStartedAt),
|
||||
};
|
||||
}
|
||||
|
||||
// ─── API Functions ─────────────────────────────────────────────────────────────
|
||||
|
||||
export async function fetchLoanOrders(params: LoanOrdersParams = {}, signal?: AbortSignal): Promise<LoanOrdersResponse> {
|
||||
const { page, perPage, limit, search, region, status, branch, branch_id, createdById, userId, user_id, archived } = params;
|
||||
const { page, perPage, limit, search, region, status, branch, branch_id, createdById, userId, user_id } = params;
|
||||
const branchId = branch || branch_id;
|
||||
const uid = createdById || userId || user_id;
|
||||
|
||||
@@ -524,7 +644,6 @@ export async function fetchLoanOrders(params: LoanOrdersParams = {}, signal?: Ab
|
||||
status: status || undefined,
|
||||
branch_id: branchId || undefined,
|
||||
user_id: uid || undefined,
|
||||
archived: archived || undefined,
|
||||
},
|
||||
signal,
|
||||
});
|
||||
|
||||
@@ -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 ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,134 +2,120 @@ import { z } from "zod";
|
||||
import i18next from "i18next";
|
||||
|
||||
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||
|
||||
export const loanOrderFormSchema = z.object({
|
||||
// ── Step 0: Status & Notes ────────────────────────
|
||||
status: z.string().min(1, "validation.required"),
|
||||
notes: z.string().optional(),
|
||||
source: z.string().optional(),
|
||||
satisfiable: z.string().optional(),
|
||||
|
||||
// ── Step 1: Loan & Loan Card ──────────────────────
|
||||
loanType: z.string().min(1, "validation.required"),
|
||||
loanAmount: z.string().min(1, "validation.required"),
|
||||
loanOrderRequiredDocId: z.string().optional(),
|
||||
loanCardNumber: z.string().optional(),
|
||||
loanCardName: z.string().optional(),
|
||||
loanCardMonth: z.string().optional(),
|
||||
loanCardYear: z.string().optional(),
|
||||
|
||||
// ── Step 2: Location ──────────────────────────────
|
||||
region: z.string().min(1, "validation.required"),
|
||||
branch: z.string().min(1, "validation.required"),
|
||||
branchId: z.string().min(1, "validation.required"),
|
||||
|
||||
// ── Step 3: Personal ──────────────────────────────
|
||||
userId: z.string().min(1, "validation.required"),
|
||||
firstName: z.string().min(1, "validation.required"),
|
||||
lastName: z.string().min(1, "validation.required"),
|
||||
patronicName: z.string().optional(),
|
||||
customerName: z.string().min(1, "validation.required"),
|
||||
customerSurname: z.string().min(1, "validation.required"),
|
||||
customerPatronicName: z.string().optional(),
|
||||
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, "validation.required"),
|
||||
passportNumber: z.string().min(1, "validation.required"),
|
||||
passportDateOfIssue: z.string().min(1, "validation.required"),
|
||||
passportGivenBy: z.string().min(1, "validation.required"),
|
||||
bornAt: z.string().min(1, "validation.required"),
|
||||
bornPlace: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
phone: z
|
||||
.string()
|
||||
.min(1, "validation.required")
|
||||
.refine(
|
||||
(val) => {
|
||||
const digits = val.replace(/\D/g, "");
|
||||
return digits.length === 8;
|
||||
},
|
||||
{ message: "validation.invalidPhone" },
|
||||
)
|
||||
.refine(
|
||||
(val) => {
|
||||
const digits = val.replace(/\D/g, "");
|
||||
const prefix = digits.slice(0, 2);
|
||||
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||
},
|
||||
{ message: "validation.invalidPhonePrefix" },
|
||||
),
|
||||
phoneAdditional: z
|
||||
.string()
|
||||
.refine(
|
||||
(val) => {
|
||||
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||
const digits = val.replace(/\D/g, "");
|
||||
return digits.length === 8;
|
||||
},
|
||||
{ message: "validation.invalidPhone" },
|
||||
)
|
||||
.refine(
|
||||
(val) => {
|
||||
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||
const digits = val.replace(/\D/g, "");
|
||||
return VALID_PHONE_PREFIXES.includes(digits.slice(0, 2));
|
||||
},
|
||||
{ message: "validation.invalidPhonePrefix" },
|
||||
)
|
||||
.optional(),
|
||||
passportAddress: z.string().min(1, "validation.required"),
|
||||
realAddress: z.string().optional(),
|
||||
|
||||
homePhone: z
|
||||
.string()
|
||||
.refine(
|
||||
(val) => {
|
||||
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||
return val.replace(/\D/g, "").length === 8;
|
||||
},
|
||||
{ message: "validation.invalidPhone" },
|
||||
)
|
||||
.refine(
|
||||
(val) => {
|
||||
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||
return VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2));
|
||||
},
|
||||
{ message: "validation.invalidPhonePrefix" },
|
||||
)
|
||||
.optional(),
|
||||
workCompany: z.string().min(1, "validation.required"),
|
||||
workHrPhone: z
|
||||
.string()
|
||||
.refine(
|
||||
(val) => {
|
||||
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||
return val.replace(/\D/g, "").length === 8;
|
||||
},
|
||||
{ message: "validation.invalidPhone" },
|
||||
)
|
||||
.refine(
|
||||
(val) => {
|
||||
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||
return VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2));
|
||||
},
|
||||
{ message: "validation.invalidPhonePrefix" },
|
||||
)
|
||||
.optional(),
|
||||
workRegion: z.string().optional(),
|
||||
workProvince: z.string().optional(),
|
||||
position: z.string().min(1, "validation.required"),
|
||||
salary: z.string().min(1, "validation.required"),
|
||||
workStartedAt: z.string().min(1, "validation.required"),
|
||||
// ── Step 4: Salary Card ───────────────────────────
|
||||
cardNumber: z.string().min(1, "validation.required"),
|
||||
cardName: z.string().min(1, "validation.required"),
|
||||
cardMonth: z.string().min(1, "validation.required"),
|
||||
cardYear: z.string().min(1, "validation.required"),
|
||||
|
||||
// ── Step 5: Passport ──────────────────────────────
|
||||
passportSerie: z.string().min(1, "validation.required"),
|
||||
passportId: z.string().min(1, "validation.required"),
|
||||
passportGivenAt: z.string().min(1, "validation.required"),
|
||||
passportGivenBy: z.string().min(1, "validation.required"),
|
||||
passportOne: z.string().optional(),
|
||||
passportTwo: z.string().optional(),
|
||||
passportThree: z.string().optional(),
|
||||
passportFour: z.string().optional(),
|
||||
note: z.string().optional(),
|
||||
loanAmount: z.string().min(1, "validation.required"),
|
||||
loanHistory: z.string().optional(),
|
||||
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, "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"),
|
||||
|
||||
// ── Step 6: Contacts ──────────────────────────────
|
||||
phone: z
|
||||
.string()
|
||||
.min(1, "validation.required")
|
||||
.refine((val) => val.replace(/\D/g, "").length === 8, { message: "validation.invalidPhone" })
|
||||
.refine((val) => VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2)), { message: "validation.invalidPhonePrefix" }),
|
||||
phoneAdditional: z
|
||||
.string()
|
||||
.refine((val) => !val || val.replace(/\D/g, "").length === 0 || val.replace(/\D/g, "").length === 8, {
|
||||
message: "validation.invalidPhone",
|
||||
})
|
||||
.refine((val) => !val || val.replace(/\D/g, "").length === 0 || VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2)), {
|
||||
message: "validation.invalidPhonePrefix",
|
||||
})
|
||||
.optional(),
|
||||
phoneHome: z
|
||||
.string()
|
||||
.refine((val) => !val || val.replace(/\D/g, "").length === 0 || val.replace(/\D/g, "").length === 8, {
|
||||
message: "validation.invalidPhone",
|
||||
})
|
||||
.refine((val) => !val || val.replace(/\D/g, "").length === 0 || VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2)), {
|
||||
message: "validation.invalidPhonePrefix",
|
||||
})
|
||||
.optional(),
|
||||
email: z.string().optional(),
|
||||
|
||||
// ── Step 7: Employment ────────────────────────────
|
||||
workCompany: z.string().min(1, "validation.required"),
|
||||
workCompanyAccountantNumber: z
|
||||
.string()
|
||||
.refine((val) => !val || val.replace(/\D/g, "").length === 0 || val.replace(/\D/g, "").length === 8, {
|
||||
message: "validation.invalidPhone",
|
||||
})
|
||||
.refine((val) => !val || val.replace(/\D/g, "").length === 0 || VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2)), {
|
||||
message: "validation.invalidPhonePrefix",
|
||||
})
|
||||
.optional(),
|
||||
workRegion: z.string().optional(),
|
||||
workProvinceId: z.string().optional(),
|
||||
workPosition: z.string().min(1, "validation.required"),
|
||||
workSalary: z.string().min(1, "validation.required"),
|
||||
workStartedAt: z.string().min(1, "validation.required"),
|
||||
|
||||
// ── Step 8: Guarantor 1 ───────────────────────────
|
||||
guarantorName: z.string().min(1, "validation.required"),
|
||||
guarantorSurname: z.string().min(1, "validation.required"),
|
||||
guarantorPatronicName: z.string().optional(),
|
||||
guarantorPassportSerie: z.string().min(1, "validation.required"),
|
||||
guarantorPassportId: z.string().min(1, "validation.required"),
|
||||
guarantorCardNumber: z.string().min(1, "validation.required"),
|
||||
guarantorCardName: z.string().min(1, "validation.required"),
|
||||
guarantorCardMonth: z.string().min(1, "validation.required"),
|
||||
guarantorCardYear: z.string().min(1, "validation.required"),
|
||||
guarantorNote: z.string().optional(),
|
||||
|
||||
// ── Step 9: Guarantor 2 ───────────────────────────
|
||||
guarantor2Name: z.string().optional(),
|
||||
guarantor2Surname: z.string().optional(),
|
||||
guarantor2Patronic: z.string().optional(),
|
||||
guarantor2PatronicName: z.string().optional(),
|
||||
guarantor2PassportSerie: z.string().optional(),
|
||||
guarantor2PassportNumber: z.string().optional(),
|
||||
guarantor2PassportId: z.string().optional(),
|
||||
guarantor2CardNumber: z.string().optional(),
|
||||
guarantor2CardName: z.string().optional(),
|
||||
guarantor2CardExpMonth: z.string().optional(),
|
||||
guarantor2CardExpYear: z.string().optional(),
|
||||
guarantor2CardMonth: z.string().optional(),
|
||||
guarantor2CardYear: z.string().optional(),
|
||||
guarantor2Note: z.string().optional(),
|
||||
});
|
||||
|
||||
@@ -138,59 +124,58 @@ export type LoanOrderFormData = z.infer<typeof loanOrderFormSchema>;
|
||||
export const stepSchemas: Record<number, z.ZodType<Partial<LoanOrderFormData>>> = {
|
||||
0: loanOrderFormSchema.pick({ status: true }),
|
||||
1: loanOrderFormSchema.pick({ loanType: true, loanAmount: true }),
|
||||
2: loanOrderFormSchema.pick({ region: true, branch: true }),
|
||||
2: loanOrderFormSchema.pick({ region: true, branchId: true }),
|
||||
3: loanOrderFormSchema.pick({
|
||||
userId: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
customerName: true,
|
||||
customerSurname: true,
|
||||
education: true,
|
||||
marriageStatus: true,
|
||||
dateOfBirth: true,
|
||||
residence: true,
|
||||
bornAt: true,
|
||||
passportAddress: true,
|
||||
}),
|
||||
4: loanOrderFormSchema.pick({
|
||||
cardNumber: true,
|
||||
cardName: true,
|
||||
cardExpMonth: true,
|
||||
cardExpYear: true,
|
||||
cardMonth: true,
|
||||
cardYear: true,
|
||||
}),
|
||||
5: loanOrderFormSchema.pick({
|
||||
passportSerie: true,
|
||||
passportNumber: true,
|
||||
passportDateOfIssue: true,
|
||||
passportId: true,
|
||||
passportGivenAt: true,
|
||||
passportGivenBy: true,
|
||||
passportOne: true,
|
||||
passportTwo: true,
|
||||
}),
|
||||
6: loanOrderFormSchema.pick({ phone: true, phoneAdditional: true, homePhone: true }),
|
||||
6: loanOrderFormSchema.pick({ phone: true, phoneAdditional: true, phoneHome: true }),
|
||||
7: loanOrderFormSchema.pick({
|
||||
workCompany: true,
|
||||
position: true,
|
||||
salary: true,
|
||||
workPosition: true,
|
||||
workSalary: true,
|
||||
workStartedAt: true,
|
||||
workHrPhone: true,
|
||||
workCompanyAccountantNumber: true,
|
||||
}),
|
||||
8: loanOrderFormSchema.pick({
|
||||
guarantor1Name: true,
|
||||
guarantor1Surname: true,
|
||||
guarantor1PassportSerie: true,
|
||||
guarantor1PassportNumber: true,
|
||||
guarantor1CardNumber: true,
|
||||
guarantor1CardName: true,
|
||||
guarantor1CardExpMonth: true,
|
||||
guarantor1CardExpYear: true,
|
||||
guarantor1Salary: true,
|
||||
guarantorName: true,
|
||||
guarantorSurname: true,
|
||||
guarantorPassportSerie: true,
|
||||
guarantorPassportId: true,
|
||||
guarantorCardNumber: true,
|
||||
guarantorCardName: true,
|
||||
guarantorCardMonth: true,
|
||||
guarantorCardYear: true,
|
||||
}),
|
||||
9: loanOrderFormSchema.pick({
|
||||
guarantor2Name: true,
|
||||
guarantor2Surname: true,
|
||||
guarantor2Patronic: true,
|
||||
guarantor2PatronicName: true,
|
||||
guarantor2PassportSerie: true,
|
||||
guarantor2PassportNumber: true,
|
||||
guarantor2PassportId: true,
|
||||
guarantor2CardNumber: true,
|
||||
guarantor2CardName: true,
|
||||
guarantor2CardExpMonth: true,
|
||||
guarantor2CardExpYear: true,
|
||||
guarantor2CardMonth: true,
|
||||
guarantor2CardYear: true,
|
||||
guarantor2Note: true,
|
||||
}),
|
||||
};
|
||||
@@ -206,8 +191,8 @@ export function validateStep(
|
||||
stepIndex === 5 && mode === "edit"
|
||||
? loanOrderFormSchema.pick({
|
||||
passportSerie: true,
|
||||
passportNumber: true,
|
||||
passportDateOfIssue: true,
|
||||
passportId: true,
|
||||
passportGivenAt: true,
|
||||
passportGivenBy: true,
|
||||
})
|
||||
: stepSchemas[stepIndex];
|
||||
@@ -227,128 +212,140 @@ export function validateStep(
|
||||
|
||||
export const DEFAULT_FORM_VALUES: LoanOrderFormData = {
|
||||
status: "pending",
|
||||
notes: "",
|
||||
source: "web",
|
||||
satisfiable: "yes",
|
||||
loanType: "",
|
||||
loanAmount: "",
|
||||
loanOrderRequiredDocId: "",
|
||||
loanCardNumber: "",
|
||||
loanCardName: "",
|
||||
loanCardMonth: "",
|
||||
loanCardYear: "",
|
||||
region: "AG",
|
||||
branch: "",
|
||||
branchId: "",
|
||||
userId: "",
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
patronicName: "",
|
||||
customerName: "",
|
||||
customerSurname: "",
|
||||
customerPatronicName: "",
|
||||
education: "",
|
||||
marriageStatus: "",
|
||||
dateOfBirth: "",
|
||||
residence: "",
|
||||
currentResidence: "",
|
||||
passportSerie: "",
|
||||
passportNumber: "",
|
||||
passportDateOfIssue: "",
|
||||
passportGivenBy: "",
|
||||
bornAt: "",
|
||||
bornPlace: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
phoneAdditional: "",
|
||||
homePhone: "",
|
||||
workCompany: "",
|
||||
workHrPhone: "",
|
||||
workRegion: "AG",
|
||||
workProvince: "",
|
||||
position: "",
|
||||
salary: "",
|
||||
workStartedAt: "",
|
||||
passportAddress: "",
|
||||
realAddress: "",
|
||||
cardNumber: "",
|
||||
cardName: "",
|
||||
cardMonth: "",
|
||||
cardYear: "",
|
||||
passportSerie: "",
|
||||
passportId: "",
|
||||
passportGivenAt: "",
|
||||
passportGivenBy: "",
|
||||
passportOne: "",
|
||||
passportTwo: "",
|
||||
passportThree: "",
|
||||
passportFour: "",
|
||||
note: "",
|
||||
loanAmount: "",
|
||||
loanHistory: "",
|
||||
cardNumber: "",
|
||||
cardName: "",
|
||||
cardExpMonth: "",
|
||||
cardExpYear: "",
|
||||
guarantor1Name: "",
|
||||
guarantor1Surname: "",
|
||||
guarantor1Patronic: "",
|
||||
guarantor1PassportSerie: "",
|
||||
guarantor1PassportNumber: "",
|
||||
guarantor1CardNumber: "",
|
||||
guarantor1CardName: "",
|
||||
guarantor1CardExpMonth: "",
|
||||
guarantor1CardExpYear: "",
|
||||
guarantor1Salary: "",
|
||||
phone: "",
|
||||
phoneAdditional: "",
|
||||
phoneHome: "",
|
||||
email: "",
|
||||
workCompany: "",
|
||||
workCompanyAccountantNumber: "",
|
||||
workRegion: "AG",
|
||||
workProvinceId: "",
|
||||
workPosition: "",
|
||||
workSalary: "",
|
||||
workStartedAt: "",
|
||||
guarantorName: "",
|
||||
guarantorSurname: "",
|
||||
guarantorPatronicName: "",
|
||||
guarantorPassportSerie: "",
|
||||
guarantorPassportId: "",
|
||||
guarantorCardNumber: "",
|
||||
guarantorCardName: "",
|
||||
guarantorCardMonth: "",
|
||||
guarantorCardYear: "",
|
||||
guarantorNote: "",
|
||||
guarantor2Name: "",
|
||||
guarantor2Surname: "",
|
||||
guarantor2Patronic: "",
|
||||
guarantor2PatronicName: "",
|
||||
guarantor2PassportSerie: "",
|
||||
guarantor2PassportNumber: "",
|
||||
guarantor2PassportId: "",
|
||||
guarantor2CardNumber: "",
|
||||
guarantor2CardName: "",
|
||||
guarantor2CardExpMonth: "",
|
||||
guarantor2CardExpYear: "",
|
||||
guarantor2CardMonth: "",
|
||||
guarantor2CardYear: "",
|
||||
guarantor2Note: "",
|
||||
};
|
||||
|
||||
export function buildPayload(data: LoanOrderFormData) {
|
||||
return {
|
||||
status: data.status,
|
||||
notes: data.notes || undefined,
|
||||
source: data.source || "web",
|
||||
satisfiable: data.satisfiable || "yes",
|
||||
loanType: data.loanType,
|
||||
loanAmount: data.loanAmount,
|
||||
loanOrderRequiredDocId: data.loanOrderRequiredDocId || undefined,
|
||||
loanCardNumber: data.loanCardNumber || undefined,
|
||||
loanCardName: data.loanCardName || undefined,
|
||||
loanCardMonth: data.loanCardMonth || undefined,
|
||||
loanCardYear: data.loanCardYear || undefined,
|
||||
region: data.region,
|
||||
branch: data.branch,
|
||||
branchId: data.branchId,
|
||||
userId: data.userId,
|
||||
firstName: data.firstName,
|
||||
lastName: data.lastName,
|
||||
patronicName: data.patronicName || undefined,
|
||||
customerName: data.customerName,
|
||||
customerSurname: data.customerSurname,
|
||||
customerPatronicName: data.customerPatronicName || undefined,
|
||||
education: data.education,
|
||||
marriageStatus: data.marriageStatus,
|
||||
dateOfBirth: data.dateOfBirth,
|
||||
residence: data.residence,
|
||||
currentResidence: data.currentResidence || undefined,
|
||||
passportSerie: data.passportSerie,
|
||||
passportNumber: data.passportNumber,
|
||||
passportDateOfIssue: data.passportDateOfIssue,
|
||||
passportGivenBy: data.passportGivenBy,
|
||||
bornAt: data.bornAt,
|
||||
bornPlace: data.bornPlace || undefined,
|
||||
email: data.email || undefined,
|
||||
phone: data.phone,
|
||||
phoneAdditional: data.phoneAdditional || undefined,
|
||||
homePhone: data.homePhone || undefined,
|
||||
workCompany: data.workCompany,
|
||||
workHrPhone: data.workHrPhone || undefined,
|
||||
workRegion: data.workRegion || undefined,
|
||||
workProvince: data.workProvince || undefined,
|
||||
position: data.position,
|
||||
salary: Number(data.salary),
|
||||
workStartedAt: data.workStartedAt,
|
||||
note: data.note || undefined,
|
||||
loanAmount: Number(data.loanAmount) || undefined,
|
||||
loanHistory: data.loanHistory || undefined,
|
||||
cardNumber: data.cardNumber || undefined,
|
||||
cardName: data.cardName || undefined,
|
||||
cardExpMonth: data.cardExpMonth || undefined,
|
||||
cardExpYear: data.cardExpYear || undefined,
|
||||
guarantor1Name: data.guarantor1Name || undefined,
|
||||
guarantor1Surname: data.guarantor1Surname || undefined,
|
||||
guarantor1Patronic: data.guarantor1Patronic || undefined,
|
||||
guarantor1PassportSerie: data.guarantor1PassportSerie || undefined,
|
||||
guarantor1PassportNumber: data.guarantor1PassportNumber || undefined,
|
||||
guarantor1CardNumber: data.guarantor1CardNumber || undefined,
|
||||
guarantor1CardName: data.guarantor1CardName || undefined,
|
||||
guarantor1CardExpMonth: data.guarantor1CardExpMonth || undefined,
|
||||
guarantor1CardExpYear: data.guarantor1CardExpYear || undefined,
|
||||
guarantor1Salary: Number(data.guarantor1Salary) || undefined,
|
||||
guarantor2Name: data.guarantor2Name || undefined,
|
||||
guarantor2Surname: data.guarantor2Surname || undefined,
|
||||
guarantor2Patronic: data.guarantor2Patronic || undefined,
|
||||
guarantor2PassportSerie: data.guarantor2PassportSerie || undefined,
|
||||
guarantor2PassportNumber: data.guarantor2PassportNumber || undefined,
|
||||
guarantor2CardNumber: data.guarantor2CardNumber || undefined,
|
||||
guarantor2CardName: data.guarantor2CardName || undefined,
|
||||
guarantor2CardExpMonth: data.guarantor2CardExpMonth || undefined,
|
||||
guarantor2CardExpYear: data.guarantor2CardExpYear || undefined,
|
||||
guarantor2Note: data.guarantor2Note || undefined,
|
||||
passportAddress: data.passportAddress,
|
||||
realAddress: data.realAddress || undefined,
|
||||
cardNumber: data.cardNumber,
|
||||
cardName: data.cardName,
|
||||
cardMonth: data.cardMonth,
|
||||
cardYear: data.cardYear,
|
||||
passportSerie: data.passportSerie,
|
||||
passportId: data.passportId,
|
||||
passportGivenAt: data.passportGivenAt,
|
||||
passportGivenBy: data.passportGivenBy,
|
||||
passportOne: data.passportOne || undefined,
|
||||
passportTwo: data.passportTwo || undefined,
|
||||
passportThree: data.passportThree || undefined,
|
||||
passportFour: data.passportFour || undefined,
|
||||
phone: data.phone,
|
||||
phoneAdditional: data.phoneAdditional || undefined,
|
||||
phoneHome: data.phoneHome || undefined,
|
||||
email: data.email || undefined,
|
||||
workCompany: data.workCompany,
|
||||
workCompanyAccountantNumber: data.workCompanyAccountantNumber || undefined,
|
||||
workRegion: data.workRegion || undefined,
|
||||
workProvinceId: data.workProvinceId || undefined,
|
||||
workPosition: data.workPosition,
|
||||
workSalary: data.workSalary,
|
||||
workStartedAt: data.workStartedAt,
|
||||
guarantorName: data.guarantorName,
|
||||
guarantorSurname: data.guarantorSurname,
|
||||
guarantorPatronicName: data.guarantorPatronicName || undefined,
|
||||
guarantorPassportSerie: data.guarantorPassportSerie,
|
||||
guarantorPassportId: data.guarantorPassportId,
|
||||
guarantorCardNumber: data.guarantorCardNumber,
|
||||
guarantorCardName: data.guarantorCardName,
|
||||
guarantorCardMonth: data.guarantorCardMonth,
|
||||
guarantorCardYear: data.guarantorCardYear,
|
||||
guarantorNote: data.guarantorNote || undefined,
|
||||
guarantor2Name: data.guarantor2Name || undefined,
|
||||
guarantor2Surname: data.guarantor2Surname || undefined,
|
||||
guarantor2PatronicName: data.guarantor2PatronicName || undefined,
|
||||
guarantor2PassportSerie: data.guarantor2PassportSerie || undefined,
|
||||
guarantor2PassportId: data.guarantor2PassportId || undefined,
|
||||
guarantor2CardNumber: data.guarantor2CardNumber || undefined,
|
||||
guarantor2CardName: data.guarantor2CardName || undefined,
|
||||
guarantor2CardMonth: data.guarantor2CardMonth || undefined,
|
||||
guarantor2CardYear: data.guarantor2CardYear || undefined,
|
||||
guarantor2Note: data.guarantor2Note || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { InfiniteSelect, type InfiniteSelectOption, type InfiniteSelectProps } f
|
||||
import { DocumentUpload } from "@/components/documentUpload";
|
||||
import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions, getRegionOptions, LOAN_PAID_OFF_REGION_CODES } from "@/constants";
|
||||
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
|
||||
import { useInfiniteUsers } from "@/features/allUsers/hooks/useAllUsers";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
@@ -56,8 +56,6 @@ function resolveLocalizedName(name: LocalizedText | string | undefined | null, l
|
||||
|
||||
// ─── Static options ───────────────────────────────────────────────────────────
|
||||
|
||||
const REGION_CODES = ["AG", "AH", "BA", "DA", "LE", "MA"] as const;
|
||||
|
||||
// ─── Step definitions ─────────────────────────────────────────────────────────
|
||||
|
||||
interface StepDef {
|
||||
@@ -429,14 +427,7 @@ export function LoanPaidOffLetterForm({ mode, initialData }: LoanPaidOffLetterFo
|
||||
|
||||
const statusOptions = useMemo<SelectOption[]>(() => getStatusOptions(t, "loanPaidOffLetters.status"), [t]);
|
||||
|
||||
const regionOptions = useMemo<SelectOption[]>(
|
||||
() =>
|
||||
REGION_CODES.map((code) => ({
|
||||
value: code,
|
||||
label: t(`loanPaidOffLetters.regions.${code}`, code),
|
||||
})),
|
||||
[t],
|
||||
);
|
||||
const regionOptions = useMemo<SelectOption[]>(() => getRegionOptions(t, "loanPaidOffLetters", LOAN_PAID_OFF_REGION_CODES), [t]);
|
||||
|
||||
// ── Step validation state ───────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -2,10 +2,19 @@ import apiClient from "@/lib/api/client";
|
||||
|
||||
// ─── Types ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface LoanRemainingUser {
|
||||
id: number;
|
||||
name: string;
|
||||
username?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
}
|
||||
|
||||
export interface LoanRemaining {
|
||||
id: number;
|
||||
userId: number;
|
||||
userName: string;
|
||||
user?: LoanRemainingUser | null;
|
||||
userId?: number;
|
||||
userName?: string;
|
||||
passportSerie: string;
|
||||
passportId: string;
|
||||
accountNumber: string;
|
||||
|
||||
@@ -45,12 +45,13 @@ export function LoanRemainingForm({ mode, initialData }: LoanRemainingFormProps)
|
||||
};
|
||||
});
|
||||
|
||||
if (initialData?.userId) {
|
||||
const currentVal = String(initialData.userId);
|
||||
const effectiveUserId = initialData?.user?.id ?? initialData?.userId;
|
||||
if (effectiveUserId) {
|
||||
const currentVal = String(effectiveUserId);
|
||||
if (!opts.some((o) => o.value === currentVal)) {
|
||||
opts.unshift({
|
||||
value: currentVal,
|
||||
label: initialData.userName || currentVal,
|
||||
label: initialData?.user?.name || initialData?.user?.username || initialData?.userName || currentVal,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -80,11 +81,12 @@ export function LoanRemainingForm({ mode, initialData }: LoanRemainingFormProps)
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === "edit" && initialData) {
|
||||
const uId = initialData.user?.id ?? initialData.userId;
|
||||
reset({
|
||||
passportSerie: initialData.passportSerie,
|
||||
passportId: initialData.passportId,
|
||||
accountNumber: initialData.accountNumber,
|
||||
userId: String(initialData.userId),
|
||||
userId: uId != null ? String(uId) : "",
|
||||
});
|
||||
}
|
||||
}, [mode, initialData, reset]);
|
||||
|
||||
@@ -20,7 +20,7 @@ import type { IntlPaymentFormData } from "../schemas/visaMasterPayment.schema";
|
||||
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions, getRegionOptions, REGION_CODES, REGION_LABELS } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -38,17 +38,6 @@ const CURRENCY_OPTIONS = [
|
||||
{ value: "mastercard", label: "MasterCard" },
|
||||
];
|
||||
|
||||
const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
const REGION_LABELS: Record<string, string> = {
|
||||
AG: "Aşgabat",
|
||||
AH: "Ahal",
|
||||
BN: "Balkan",
|
||||
DZ: "Daşoguz",
|
||||
LB: "Lebap",
|
||||
MR: "Mary",
|
||||
};
|
||||
|
||||
function resolveLocalizedName(name: LocalizedText | string | null | undefined, lang = "en"): string {
|
||||
if (!name) return "";
|
||||
if (typeof name === "string") return name;
|
||||
@@ -56,13 +45,6 @@ function resolveLocalizedName(name: LocalizedText | string | null | undefined, l
|
||||
return name[key as keyof LocalizedText] ?? name.tm ?? name.en ?? name.ru ?? "";
|
||||
}
|
||||
|
||||
function getRegionOptions(t: TFunction): { value: string; label: string }[] {
|
||||
return REGION_CODES.map((code) => ({
|
||||
value: code,
|
||||
label: t(`intlPayment.regions.${code}`, REGION_LABELS[code] ?? code),
|
||||
}));
|
||||
}
|
||||
|
||||
const KABUL_DOCS: { key: keyof IntlPaymentFormData; label: string }[] = [
|
||||
{ key: "doc_sberbank_account", label: "Talypyň SBERBANK kartynyň rekwizitleri" },
|
||||
{ key: "doc_school_enrollment", label: "Daşary ýurt ÝOM-da okaýandygy barada güwänamasy" },
|
||||
@@ -251,7 +233,7 @@ function StepLocation({ form, errors, set, t, initialData }: StepContentProps) {
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const branchQuery = useInfiniteBranches(branchSearch);
|
||||
|
||||
const regionOptions = useMemo(() => getRegionOptions(t), [t]);
|
||||
const regionOptions = useMemo(() => getRegionOptions(t, "intlPayment", REGION_CODES, REGION_LABELS), [t]);
|
||||
|
||||
const branchOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (branchQuery.data?.pages ?? [])
|
||||
|
||||
@@ -423,6 +423,12 @@ function AppSidebar() {
|
||||
},
|
||||
];
|
||||
|
||||
const isAdmin = user?.role?.code === "admin";
|
||||
|
||||
const filteredNavGroups = isAdmin
|
||||
? navGroups
|
||||
: (navGroups.filter((_, i) => i === 1).map((group) => ({ ...group, items: [group.items[0]] })) as NavGroup[]);
|
||||
|
||||
return (
|
||||
<Sidebar collapsible="icon">
|
||||
{/* Logo */}
|
||||
@@ -438,7 +444,7 @@ function AppSidebar() {
|
||||
|
||||
{/* Nav */}
|
||||
<SidebarContent className="px-2 py-2">
|
||||
{navGroups.map((group, gi) => (
|
||||
{filteredNavGroups.map((group, gi) => (
|
||||
<div key={gi}>
|
||||
{group.label && <NavGroupLabel label={group.label} />}
|
||||
<SidebarMenu className="gap-0.5">
|
||||
|
||||
@@ -377,6 +377,7 @@
|
||||
"common.backToHome": "Go to home",
|
||||
"errors.pageNotFoundTitle": "Page not found",
|
||||
"errors.pageNotFoundDescription": "The page you are looking for does not exist or has been moved.",
|
||||
"errors.forbidden": "You do not have permission to perform this action.",
|
||||
"Phone or username": "Phone or username",
|
||||
"featureNotImplemented": "Not implemented",
|
||||
"common.search": "Search",
|
||||
|
||||
@@ -377,6 +377,7 @@
|
||||
"common.backToHome": "На главную",
|
||||
"errors.pageNotFoundTitle": "Страница не найдена",
|
||||
"errors.pageNotFoundDescription": "Страница, которую вы ищете, не существует или была перемещена.",
|
||||
"errors.forbidden": "У вас нет разрешения на выполнение этого действия.",
|
||||
"Phone or username": "Телефон или имя пользователя",
|
||||
"featureNotImplemented": "Эта функция еще не реализована",
|
||||
"common.search": "Поиск",
|
||||
|
||||
@@ -377,6 +377,7 @@
|
||||
"common.backToHome": "Baş sahypa",
|
||||
"errors.pageNotFoundTitle": "Sahypa tapylmady",
|
||||
"errors.pageNotFoundDescription": "Gözleýän sahypaňyz ýok ýa-da başga ýere geçirilen bolup biler.",
|
||||
"errors.forbidden": "Bu amaly ýerine ýetirmäge rugsadyňyz ýok.",
|
||||
"Phone or username": "Telefon ýada ulanyjy ady",
|
||||
"featureNotImplemented": "Bu funksiýa entek durmuşa geçirilmedi",
|
||||
"common.search": "Gözlemek",
|
||||
|
||||
@@ -17,6 +17,7 @@ import { resolveLocalizedName } from "@/features/cardRequisites/api/cardRequisit
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useInfiniteCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
import { getRegionOptions } from "@/constants";
|
||||
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -42,8 +43,6 @@ const COLUMN_IDS = ["id", "uniqueId", "cardType", "customer", "user", "region",
|
||||
|
||||
// ─── Filter constants ─────────────────────────────────────────────────────────
|
||||
|
||||
const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
export default function CardRequisitesPage() {
|
||||
const { t, i18n } = useTranslation();
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as "tm" | "ru" | "en";
|
||||
@@ -147,7 +146,7 @@ export default function CardRequisitesPage() {
|
||||
const total = data?.count ?? 0;
|
||||
const totalPages = Math.max(1, Math.ceil(total / perPage));
|
||||
|
||||
const regionOptions = useMemo(() => REGION_CODES.map((code) => ({ value: code, label: t(`loanOrders.regions.${code}`, code) })), [t]);
|
||||
const regionOptions = useMemo(() => getRegionOptions(t), [t]);
|
||||
|
||||
const statusOptions = useMemo(
|
||||
() => [
|
||||
|
||||
@@ -17,20 +17,10 @@ import type { IntlPaymentStatus, IntlPaymentItem } from "@/features/visaMasterPa
|
||||
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
|
||||
import { useInfiniteUsers } from "@/features/allUsers/hooks/useAllUsers";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
import { REGION_CODES, REGION_LABELS } from "@/constants";
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
const REGION_LABELS: Record<string, string> = {
|
||||
AG: "Aşgabat",
|
||||
AH: "Ahal",
|
||||
BN: "Balkan",
|
||||
DZ: "Daşoguz",
|
||||
LB: "Lebap",
|
||||
MR: "Mary",
|
||||
};
|
||||
|
||||
function resolveLocalizedName(name: LocalizedText | string | null | undefined, lang: string): string {
|
||||
if (!name) return "";
|
||||
if (typeof name === "string") return name;
|
||||
|
||||
@@ -14,8 +14,8 @@ import { useLoanOrderMobiles, useDeleteLoanOrderMobile } from "@/features/loanOr
|
||||
import type { LoanOrderMobile, LoanOrderMobileStatus } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi";
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { getStatusLabel, getStatusOptions, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
import { getStatusLabel, getStatusOptions, getRegionOptions, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
import { formatFromApiDate } from "@/lib/utils";
|
||||
// ─── Status Badge (inline) ────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_ICONS: Record<StatusValue, React.ElementType> = {
|
||||
@@ -38,8 +38,6 @@ const COLUMN_IDS = ["id", "loanType", "createdAt", "region", "branch", "firstNam
|
||||
|
||||
// ─── Filter fields ────────────────────────────────────────────────────────────
|
||||
|
||||
const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
// ─── Page Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanOrderMobilesPage() {
|
||||
@@ -97,7 +95,7 @@ export default function LoanOrderMobilesPage() {
|
||||
const { data, isLoading } = useLoanOrderMobiles(queryParams);
|
||||
const totalPages = data ? Math.ceil(data.total / perPage) : 1;
|
||||
|
||||
const regionOptions = useMemo(() => REGION_CODES.map((code) => ({ value: code, label: t(`loanOrders.regions.${code}`, code) })), [t]);
|
||||
const regionOptions = useMemo(() => getRegionOptions(t), [t]);
|
||||
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)));
|
||||
@@ -138,7 +136,7 @@ export default function LoanOrderMobilesPage() {
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("Created at", "DÖREDILEN WAGTY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground whitespace-nowrap">{row.original.createdAt}</span>,
|
||||
cell: ({ row }) => <span className="text-sm text-foreground whitespace-nowrap">{formatFromApiDate(row.original.createdAt)}</span>,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import { BentoGrid, BentoCard, InfoRow, PassportImage, AuditLog, type AuditRowProps } from "@/components/viewPageComponents";
|
||||
import { ConfirmDialog } from "@/components/confirmDialog";
|
||||
import { getStatusLabel, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
import { formatFromApiDate } from "@/lib/utils";
|
||||
|
||||
// ─── Status config ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -87,7 +88,9 @@ export default function LoanOrderMobilesViewPage() {
|
||||
];
|
||||
|
||||
const hasCard = !!(order.cardNumber || order.cardName);
|
||||
const hasLoanCard = !!(order.loanCardNumber || order.loanCardName);
|
||||
const hasGuarantor = !!(order.guarantor1Name || order.guarantor1CardNumber);
|
||||
const hasGuarantor2 = !!(order.guarantor2Name || order.guarantor2Surname || order.guarantor2CardNumber);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
@@ -119,11 +122,17 @@ export default function LoanOrderMobilesViewPage() {
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard title={t("loanOrders.sections.meta", "Esasy maglumatlar")}>
|
||||
<InfoRow label={t("common.id", "ID")} value={order.id} />
|
||||
<InfoRow label={t("loanOrders.fields.uniqueId", "Ýeke-täk ID")} value={order.uniqueId || undefined} />
|
||||
<InfoRow label={t("loanOrders.columns.status", "Status")}>
|
||||
<LoanOrderMobileStatusBadge status={order.status} />
|
||||
</InfoRow>
|
||||
<InfoRow label={t("loanOrders.columns.createdAt", "Döredilen wagty")} value={order.createdAt} />
|
||||
|
||||
<InfoRow label={t("loanOrders.columns.createdAt", "Döredilen wagty")} value={formatFromApiDate(order.createdAt)} />
|
||||
<InfoRow label={t("loanOrders.fields.updatedAt", "Üýtgedilen wagty")} value={formatFromApiDate(order.updatedAt) || undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.source", "Çeşme")} value={order.source ?? undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.satisfiable", "Kanagatlandyrylan")}
|
||||
value={order.satisfiable ? t(`loanOrders.satisfiable.${order.satisfiable}`, order.satisfiable) : undefined}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.note", "Bellik")} value={order.note || undefined} />
|
||||
<InfoRow label={t("loanOrders.columns.createdBy", "Döreden")} value={order.createdBy} />
|
||||
</BentoCard>
|
||||
@@ -169,37 +178,44 @@ export default function LoanOrderMobilesViewPage() {
|
||||
<InfoRow label={t("loanOrders.fields.cardName", "Kartdaky ady")} value={order.cardName} />
|
||||
</BentoCard>
|
||||
|
||||
{/* Guarantor card — shown side-by-side with main card when both exist */}
|
||||
{hasGuarantor && (
|
||||
<BentoCard title={t("loanOrders.sections.guarantor", "1. Zamun")} noPadding>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorName", "Zamunyň doly ady")}
|
||||
value={`${order.guarantor1Name || ""} ${order.guarantor1Surname || ""} ${order.guarantor1Patronic || ""}`.trim()}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorPassport", "Pasport")}
|
||||
value={`${order.guarantor1PassportSerie || ""} ${order.guarantor1PassportNumber || ""}`.trim()}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorSalary", "Ortaca zähmet haky")}
|
||||
value={order.guarantor1Salary ? String(order.guarantor1Salary) : undefined}
|
||||
/>
|
||||
{order.guarantor1CardNumber && (
|
||||
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-t border-border flex items-center justify-center">
|
||||
<CreditCardVisual
|
||||
cardNumber={order.guarantor1CardNumber}
|
||||
cardName={order.guarantor1CardName}
|
||||
expMonth={order.guarantor1CardExpMonth}
|
||||
expYear={order.guarantor1CardExpYear}
|
||||
variant="secondary"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{/* Loan disbursement card — shown side-by-side with personal card */}
|
||||
{hasLoanCard && (
|
||||
<BentoCard title={t("loanOrders.sections.loanCard", "Karz geçiriljek kartoçka")} noPadding>
|
||||
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-b border-border flex items-center justify-center">
|
||||
<CreditCardVisual
|
||||
cardNumber={order.loanCardNumber}
|
||||
cardName={order.loanCardName}
|
||||
expMonth={order.loanCardMonth}
|
||||
expYear={order.loanCardYear}
|
||||
variant="primary"
|
||||
/>
|
||||
</div>
|
||||
<InfoRow label={t("loanOrders.fields.loanCardNumber", "Kart belgisi")} value={order.loanCardNumber ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.loanCardName", "Kartdaky ady")} value={order.loanCardName ?? undefined} />
|
||||
</BentoCard>
|
||||
)}
|
||||
</BentoGrid>
|
||||
)}
|
||||
|
||||
{/* If there's no personal card but a loan card exists, still show it on its own row */}
|
||||
{!hasCard && hasLoanCard && (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("loanOrders.sections.loanCard", "Karz geçiriljek kartoçka")} noPadding>
|
||||
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-b border-border flex items-center justify-center">
|
||||
<CreditCardVisual
|
||||
cardNumber={order.loanCardNumber}
|
||||
cardName={order.loanCardName}
|
||||
expMonth={order.loanCardMonth}
|
||||
expYear={order.loanCardYear}
|
||||
variant="primary"
|
||||
/>
|
||||
</div>
|
||||
<InfoRow label={t("loanOrders.fields.loanCardNumber", "Kart belgisi")} value={order.loanCardNumber ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.loanCardName", "Kartdaky ady")} value={order.loanCardName ?? undefined} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)}
|
||||
|
||||
{/* ── Row 3: Personal + Contacts ──────────────────────────────────── */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("loanOrders.sections.personal", "Şahsy maglumatlar")}>
|
||||
@@ -241,7 +257,9 @@ export default function LoanOrderMobilesViewPage() {
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("loanOrders.sections.passport", "Pasport")}>
|
||||
<InfoRow label={t("loanOrders.fields.passportSerie", "Pasport seriýasy")} value={order.passportSerie ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.passportNumber", "Pasport")} value={order.passportNumber ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.passportGivenAt", "Berlen senesi")} value={order.passportDateOfIssue ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.passportIssuedBy", "Kim tarapyndan berildi")} value={order.passportGivenBy ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.passportBirthPlace", "Doglan ýeri (pasport)")} value={order.bornPlace ?? undefined} />
|
||||
</BentoCard>
|
||||
@@ -269,9 +287,9 @@ export default function LoanOrderMobilesViewPage() {
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Guarantor (standalone — only when no card to pair with) ─────── */}
|
||||
{/* ── Guarantor 1 (standalone — only when no personal card to pair with) ── */}
|
||||
{hasGuarantor && !hasCard && (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoGrid cols={hasGuarantor2 ? 2 : 1}>
|
||||
<BentoCard title={t("loanOrders.sections.guarantor", "1. Zamun")}>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorName", "Zamunyň doly ady")}
|
||||
@@ -285,6 +303,7 @@ export default function LoanOrderMobilesViewPage() {
|
||||
label={t("loanOrders.fields.guarantorSalary", "Ortaca zähmet haky")}
|
||||
value={order.guarantor1Salary ? String(order.guarantor1Salary) : undefined}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorNote", "Bellik")} value={order.guarantor1Note ?? undefined} />
|
||||
{order.guarantor1CardNumber && (
|
||||
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-t border-border flex items-center justify-center">
|
||||
<CreditCardVisual
|
||||
@@ -297,6 +316,69 @@ export default function LoanOrderMobilesViewPage() {
|
||||
</div>
|
||||
)}
|
||||
</BentoCard>
|
||||
|
||||
{/* Guarantor 2 — paired with guarantor 1 here since no personal card row is shown */}
|
||||
{hasGuarantor2 && (
|
||||
<BentoCard title={t("loanOrders.sections.guarantor2", "2. Zamun")}>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorName", "Zamunyň doly ady")}
|
||||
value={`${order.guarantor2Name || ""} ${order.guarantor2Surname || ""} ${order.guarantor2Patronic || ""}`.trim()}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorPassport", "Pasport")}
|
||||
value={`${order.guarantor2PassportSerie || ""} ${order.guarantor2PassportNumber || ""}`.trim()}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorNote", "Bellik")} value={order.guarantor2Note ?? undefined} />
|
||||
{order.guarantor2CardNumber && (
|
||||
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-t border-border flex items-center justify-center">
|
||||
<CreditCardVisual
|
||||
cardNumber={order.guarantor2CardNumber}
|
||||
cardName={order.guarantor2CardName}
|
||||
expMonth={order.guarantor2CardExpMonth}
|
||||
expYear={order.guarantor2CardExpYear}
|
||||
variant="secondary"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</BentoCard>
|
||||
)}
|
||||
</BentoGrid>
|
||||
)}
|
||||
|
||||
{/* ── Guarantor 1 + 2 (standalone — when a personal card already paired guarantor1 above) ── */}
|
||||
{hasGuarantor && hasCard && hasGuarantor2 && (
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title={t("loanOrders.sections.guarantor2", "2. Zamun")}>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorName", "Zamunyň doly ady")}
|
||||
value={`${order.guarantor2Name || ""} ${order.guarantor2Surname || ""} ${order.guarantor2Patronic || ""}`.trim()}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorPassport", "Pasport")}
|
||||
value={`${order.guarantor2PassportSerie || ""} ${order.guarantor2PassportNumber || ""}`.trim()}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorNote", "Bellik")} value={order.guarantor2Note ?? undefined} />
|
||||
{order.guarantor2CardNumber && (
|
||||
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-t border-border flex items-center justify-center">
|
||||
<CreditCardVisual
|
||||
cardNumber={order.guarantor2CardNumber}
|
||||
cardName={order.guarantor2CardName}
|
||||
expMonth={order.guarantor2CardExpMonth}
|
||||
expYear={order.guarantor2CardExpYear}
|
||||
variant="secondary"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)}
|
||||
|
||||
{/* ── Guarantor 1 note when it was paired with the personal card above (Row 2) ── */}
|
||||
{hasGuarantor && hasCard && order.guarantor1Note && (
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title={t("loanOrders.fields.guarantorNote", "1. Zamunyň bellik")}>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorNote", "Bellik")} value={order.guarantor1Note ?? undefined} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { LoanOrderStatus } from "@/features/loanOrders/api/loanOrdersApi";
|
||||
import { BentoGrid, BentoCard, InfoRow, PassportImage, AuditLog, type AuditRowProps } from "@/components/viewPageComponents";
|
||||
import { ConfirmDialog } from "@/components/confirmDialog";
|
||||
import { getStatusLabel, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
import { formatFromApiDate } from "@/lib/utils";
|
||||
|
||||
// ─── Status config ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -27,6 +28,14 @@ function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderStatus }) {
|
||||
return <StatusBadge label={getStatusLabel(status, t, "loanOrderStatus")} variant={variant} icon={Icon} />;
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Combine expiry month/year into a single "MM/YYYY" string, or undefined if both are empty. */
|
||||
function formatCardExpiry(month?: string | null, year?: string | null): string | undefined {
|
||||
if (!month && !year) return undefined;
|
||||
return [month, year].filter(Boolean).join("/");
|
||||
}
|
||||
|
||||
// ─── Skeleton ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function LoanOrderViewSkeleton() {
|
||||
@@ -81,10 +90,15 @@ export default function LoanOrderViewPage() {
|
||||
by: order.createdBy ?? "",
|
||||
target: `${t("loanOrders.title", "Karz sargyt")}: ${order.id}`,
|
||||
status: "FINISHED",
|
||||
date: order.createdAt ?? "",
|
||||
date: formatFromApiDate(order.createdAt),
|
||||
},
|
||||
];
|
||||
|
||||
const guarantor1Name = [order.guarantorName, order.guarantorSurname, order.guarantorPatronicName].filter(Boolean).join(" ");
|
||||
const guarantor2Name = [order.guarantor2Name, order.guarantor2Surname, order.guarantor2PatronicName].filter(Boolean).join(" ");
|
||||
|
||||
const hasGuarantor2 = order.guarantor2Name || order.guarantor2Surname || order.guarantor2PassportId || order.guarantor2CardNumber;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
{/* ── Page header ──────────────────────────────────────────────────── */}
|
||||
@@ -116,10 +130,17 @@ export default function LoanOrderViewPage() {
|
||||
{/* Meta */}
|
||||
<BentoCard title={t("loanOrders.sections.meta", "Esasy maglumatlar")}>
|
||||
<InfoRow label={t("common.id", "ID")} value={order.id} />
|
||||
<InfoRow label={t("loanOrders.columns.createdAt", "Döredilen wagty")} value={order.createdAt} />
|
||||
<InfoRow label={t("loanOrders.fields.uniqueId", "Ýeke-täk ID")} value={order.uniqueId || undefined} />
|
||||
<InfoRow label={t("loanOrders.columns.createdAt", "Döredilen wagty")} value={formatFromApiDate(order.createdAt) || undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.updatedAt", "Üýtgedilen wagty")} value={formatFromApiDate(order.updatedAt) || undefined} />
|
||||
<InfoRow label={t("loanOrders.columns.status", "Status")}>
|
||||
<LoanOrderMobileStatusBadge status={order.status} />
|
||||
</InfoRow>
|
||||
<InfoRow label={t("loanOrders.fields.source", "Çeşme")} value={order.source ?? undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.satisfiable", "Kanagatlandyrylan")}
|
||||
value={order.satisfiable ? t(`loanOrders.satisfiable.${order.satisfiable}`, order.satisfiable) : undefined}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.amount", "Berlik")} value={order.amount ? String(order.amount) : undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.createdBy", "Sargyt eden")}
|
||||
@@ -127,6 +148,7 @@ export default function LoanOrderViewPage() {
|
||||
isLink
|
||||
href={order.createdById ? `/all-users/${order.createdById}` : "/all-users"}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.notes", "Bellik")} value={order.notes ?? undefined} />
|
||||
</BentoCard>
|
||||
|
||||
{/* Loan */}
|
||||
@@ -141,6 +163,7 @@ export default function LoanOrderViewPage() {
|
||||
label={t("loanOrders.fields.loanAmount", "Karz mukdary")}
|
||||
value={order.loanAmount ? String(order.loanAmount) : undefined}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.loanHistory", "Talap edilýän resminama")} value={order.loanHistory || undefined} />
|
||||
</BentoCard>
|
||||
|
||||
{/* Location */}
|
||||
@@ -160,9 +183,10 @@ export default function LoanOrderViewPage() {
|
||||
{/* Personal */}
|
||||
<BentoCard title={t("loanOrders.sections.personal", "Şahsy maglumatlar")}>
|
||||
<InfoRow label={t("loanOrders.fields.fullName", "Doly ady")} value={order.fullName ?? `${order.firstName} ${order.lastName}`} />
|
||||
<InfoRow label={t("loanOrders.fields.patronicName", "Atasynyň ady")} value={order.patronicName ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.education", "Bilimi")} value={order.education ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.maritalStatus", "Maşgala ýagdaýy")} value={order.maritalStatus ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.birthDate", "Doglan güni")} value={order.birthDate ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.birthDate", "Doglan güni")} value={formatFromApiDate(order.birthDate) || undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.registeredAddress", "Ýazgy edilen salgy")} value={order.registeredAddress ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.currentAddress", "Häzirki ýaşaýyş ýeri")} value={order.currentAddress ?? undefined} />
|
||||
</BentoCard>
|
||||
@@ -191,12 +215,20 @@ export default function LoanOrderViewPage() {
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.position", "Wezipe")} value={order.position ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.salary", "Zähmet haky")} value={order.salary ? String(order.salary) : undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.employedSince", "Işe başlan wagty")} value={order.employedSince ?? undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.employedSince", "Işe başlan wagty")}
|
||||
value={formatFromApiDate(order.employedSince) || undefined}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
{/* Passport info */}
|
||||
<BentoCard title={t("loanOrders.sections.passport", "Pasport")}>
|
||||
<InfoRow label={t("loanOrders.fields.passportNumber", "Pasport")} value={order.passportNumber ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.passportSerie", "Pasport seriýasy")} value={order.passportSerie ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.passportNumber", "Pasport belgisi")} value={order.passportNumber ?? undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.passportGivenAt", "Berlen senesi")}
|
||||
value={formatFromApiDate(order.passportDateOfIssue) || undefined}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.passportIssuedBy", "Kim tarapyndan berildi")} value={order.passportIssuedBy ?? undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.passportBirthPlace", "Doglan ýeri (pasport)")}
|
||||
@@ -227,6 +259,71 @@ export default function LoanOrderViewPage() {
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Row 5: Salary Card + Loan Card ──────────────────────────────── */}
|
||||
<BentoGrid cols={2}>
|
||||
{/* Salary / personal card */}
|
||||
<BentoCard title={t("loanOrders.sections.salaryCard", "Zähmet haky kartoçkasy")}>
|
||||
<InfoRow label={t("loanOrders.fields.cardNumber", "Karta belgisi")} value={order.cardNumber ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.cardName", "Kartdaky ady")} value={order.cardName ?? undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.cardExpiry", "Möhleti")}
|
||||
value={formatCardExpiry(order.cardExpMonth ?? order.cardMonth, order.cardExpYear ?? order.cardYear)}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
{/* Loan card (disbursement card) */}
|
||||
<BentoCard title={t("loanOrders.sections.loanCard", "Karz geçiriljek kartoçka")}>
|
||||
<InfoRow label={t("loanOrders.fields.loanCardNumber", "Karta belgisi")} value={order.loanCardNumber ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.loanCardName", "Kartdaky ady")} value={order.loanCardName ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.cardExpiry", "Möhleti")} value={formatCardExpiry(order.loanCardMonth, order.loanCardYear)} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Row 6: Guarantors ───────────────────────────────────────────── */}
|
||||
<BentoGrid cols={hasGuarantor2 ? 2 : 1}>
|
||||
{/* Guarantor 1 */}
|
||||
<BentoCard title={t("loanOrders.sections.guarantor1", "1-nji zamun")}>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorFullName", "Doly ady")} value={guarantor1Name || undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorPassportSerie", "Pasport seriýasy")}
|
||||
value={order.guarantor1PassportSerie ?? undefined}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorPassportNumber", "Pasport belgisi")}
|
||||
value={order.guarantor1PassportNumber ?? undefined}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorCardNumber", "Karta belgisi")} value={order.guarantor1CardNumber ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.guarantorCardName", "Kartdaky ady")} value={order.guarantor1CardName ?? undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.cardExpiry", "Möhleti")}
|
||||
value={formatCardExpiry(order.guarantor1CardExpMonth, order.guarantor1CardExpYear)}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorNote", "Bellik")} value={order.guarantor1Note ?? undefined} />
|
||||
</BentoCard>
|
||||
|
||||
{/* Guarantor 2 (optional) */}
|
||||
{hasGuarantor2 && (
|
||||
<BentoCard title={t("loanOrders.sections.guarantor2", "2-nji zamun")}>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorFullName", "Doly ady")} value={guarantor2Name || undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorPassportSerie", "Pasport seriýasy")}
|
||||
value={order.guarantor2PassportSerie ?? undefined}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.guarantorPassportNumber", "Pasport belgisi")}
|
||||
value={order.guarantor2PassportNumber ?? undefined}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorCardNumber", "Karta belgisi")} value={order.guarantor2CardNumber ?? undefined} />
|
||||
<InfoRow label={t("loanOrders.fields.guarantorCardName", "Kartdaky ady")} value={order.guarantor2CardName ?? undefined} />
|
||||
<InfoRow
|
||||
label={t("loanOrders.fields.cardExpiry", "Möhleti")}
|
||||
value={formatCardExpiry(order.guarantor2CardExpMonth, order.guarantor2CardExpYear)}
|
||||
/>
|
||||
<InfoRow label={t("loanOrders.fields.guarantorNote", "Bellik")} value={order.guarantor2Note ?? undefined} />
|
||||
</BentoCard>
|
||||
)}
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Audit log ────────────────────────────────────────────────────── */}
|
||||
<AuditLog logs={auditLogs} />
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ import { useLoanOrders, useDeleteLoanOrder } from "@/features/loanOrders/hooks/u
|
||||
import type { LoanOrder, LoanOrderStatus } from "@/features/loanOrders/api/loanOrdersApi";
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { getStatusLabel, getStatusOptions, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
import { getStatusLabel, getStatusOptions, getRegionOptions, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
import { formatFromApiDate } from "@/lib/utils";
|
||||
// ─── Status Badge (inline) ────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_ICONS: Record<StatusValue, React.ElementType> = {
|
||||
@@ -38,8 +38,6 @@ const COLUMN_IDS = ["id", "loanType", "createdAt", "region", "branch", "firstNam
|
||||
|
||||
// ─── Filter fields ────────────────────────────────────────────────────────────
|
||||
|
||||
const REGION_CODES = ["AG", "AH", "BN", "DZ", "LB", "MR"] as const;
|
||||
|
||||
// ─── Page Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanOrdersPage() {
|
||||
@@ -78,7 +76,6 @@ export default function LoanOrdersPage() {
|
||||
{ fieldId: "region", value: "" },
|
||||
{ fieldId: "status", value: "" },
|
||||
{ fieldId: "branch", value: "" },
|
||||
{ fieldId: "archived", value: "" },
|
||||
]);
|
||||
|
||||
const queryParams = useMemo(() => {
|
||||
@@ -88,7 +85,6 @@ export default function LoanOrdersPage() {
|
||||
region: filterMap.region || undefined,
|
||||
status: (filterMap.status as LoanOrderStatus) || undefined,
|
||||
branch: filterMap.branch || undefined,
|
||||
archived: filterMap.archived || undefined,
|
||||
page,
|
||||
perPage,
|
||||
};
|
||||
@@ -97,7 +93,7 @@ export default function LoanOrdersPage() {
|
||||
const { data, isLoading } = useLoanOrders(queryParams);
|
||||
const totalPages = data ? Math.ceil(data.total / perPage) : 1;
|
||||
|
||||
const regionOptions = useMemo(() => REGION_CODES.map((code) => ({ value: code, label: t(`loanOrders.regions.${code}`, code) })), [t]);
|
||||
const regionOptions = useMemo(() => getRegionOptions(t), [t]);
|
||||
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)));
|
||||
@@ -138,7 +134,7 @@ export default function LoanOrdersPage() {
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("Created at", "DÖREDILEN WAGTY"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground whitespace-nowrap">{row.original.createdAt}</span>,
|
||||
cell: ({ row }) => <span className="text-sm text-foreground whitespace-nowrap">{formatFromApiDate(row.original.createdAt)}</span>,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
@@ -229,14 +225,6 @@ export default function LoanOrdersPage() {
|
||||
searchValue: branchSearch,
|
||||
onSearchChange: setBranchSearch,
|
||||
},
|
||||
{
|
||||
id: "archived",
|
||||
label: t("loanOrders.filters.archived", "ARHIWLENEN"),
|
||||
options: [
|
||||
{ value: "true", label: t("common.yes", "Hawa") },
|
||||
{ value: "false", label: t("common.no", "Ýok") },
|
||||
],
|
||||
},
|
||||
],
|
||||
[t, regionOptions, branchOptions, isBranchesLoading, isFetchingNextBranches, hasNextBranches, branchSearch],
|
||||
);
|
||||
|
||||
@@ -74,7 +74,7 @@ export default function LoanRemainingPage() {
|
||||
id: "userId",
|
||||
accessorKey: "userId",
|
||||
header: t("loanRemaining.columns.userId", "ULANYJY ID"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.userId}</span>,
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.user?.id ?? row.original.userId ?? "—"}</span>,
|
||||
size: 120,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -7,6 +7,8 @@ import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { InfoRow, Section } from "@/components/viewPageComponents";
|
||||
import { ConfirmDialog } from "@/components/confirmDialog";
|
||||
|
||||
import { formatFromApiDate } from "@/lib/utils";
|
||||
|
||||
// ─── Skeleton ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function LoanRemainingViewSkeleton() {
|
||||
@@ -78,16 +80,22 @@ export default function LoanRemainingViewPage() {
|
||||
{/* ── Basic Info ─────────────────────────────────────────────────────── */}
|
||||
<Section title={t("loanRemaining.sections.info", "Esasy maglumatlar")}>
|
||||
<InfoRow label={t("common.id", "ID")} value={String(record.id)} />
|
||||
<InfoRow label={t("loanRemaining.columns.userId", "Ulanyjy ID")} value={String(record.userId)} />
|
||||
<InfoRow
|
||||
label={t("loanRemaining.columns.userId", "Ulanyjy ID")}
|
||||
value={record.user?.id != null ? String(record.user.id) : record.userId != null ? String(record.userId) : "—"}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanRemaining.columns.userName", "Ulanyjy ady")}
|
||||
isLink
|
||||
href={`/all-users/${record.userId}`}
|
||||
value={String(record.userName)}
|
||||
isLink={Boolean(record.user?.id || record.userId)}
|
||||
href={`/all-users/${record.user?.id ?? record.userId}`}
|
||||
value={record.user?.name || record.user?.username || record.userName || "—"}
|
||||
/>
|
||||
<InfoRow label={t("loanRemaining.columns.passportSerie", "Pasport seriýasy")} value={record.passportSerie} />
|
||||
<InfoRow label={t("loanRemaining.columns.passportId", "Pasport belgisi")} value={record.passportId} />
|
||||
<InfoRow label={t("loanRemaining.columns.accountNumber", "Karz hasaby")} value={record.accountNumber} />
|
||||
{record.createdAt && (
|
||||
<InfoRow label={t("loanRemaining.columns.createdAt", "Döredilen wagty")} value={formatFromApiDate(record.createdAt)} />
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<ConfirmDialog
|
||||
|
||||
@@ -26,7 +26,7 @@ import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUser
|
||||
import { useInfiniteStaff } from "@/features/operators/hooks/useOperators";
|
||||
import { useAssignRoleToUser, useAssignPermissionToRole, useAssignBranchToUser } from "@/features/shared/hooks/useSharedUserAssignments";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
|
||||
import { formatFromApiDate } from "@/lib/utils/dateUtils";
|
||||
type AssignDialogKind = "role" | "permission" | "branch";
|
||||
|
||||
export default function ProfilePage() {
|
||||
@@ -44,6 +44,7 @@ export default function ProfilePage() {
|
||||
|
||||
const branches = user?.branches ?? [];
|
||||
const permissions = user?.permissions ?? [];
|
||||
const isAdmin = authUser?.role?.code === "admin";
|
||||
|
||||
// ── Form State for Editing ──
|
||||
const [formData, setFormData] = useState({
|
||||
@@ -182,10 +183,7 @@ export default function ProfilePage() {
|
||||
<BentoCard title={t("profile.sections.account", "Hasap maglumatlary")}>
|
||||
<InfoRow label={t("common.id", "ID")} value={user.id} />
|
||||
<InfoRow label={t("users.fields.username", "Ulanyjy ady")} value={user.name} />
|
||||
<InfoRow
|
||||
label={t("users.fields.createdAt", "Döredilen wagty")}
|
||||
value={user.createdAt ? new Date(user.createdAt).toLocaleString() : "—"}
|
||||
/>
|
||||
<InfoRow label={t("users.fields.createdAt", "Döredilen wagty")} value={formatFromApiDate(user.createdAt) || "—"} />
|
||||
{user.email && <InfoRow label={t("users.fields.email", "E-poçta")} value={user.email} />}
|
||||
</BentoCard>
|
||||
|
||||
@@ -253,22 +251,24 @@ export default function ProfilePage() {
|
||||
</InfoRow>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("profile.sections.actions", "Amallar")}>
|
||||
<div className="flex flex-wrap gap-2 px-4 py-3">
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("role")}>
|
||||
<Shield size={14} />
|
||||
{t("profile.actions.assignRole", "Rol birikdiriň")}
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("permission")}>
|
||||
<KeyRound size={14} />
|
||||
{t("profile.actions.assignPermission", "Rugsat birikdiriň")}
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("branch")}>
|
||||
<Building2 size={14} />
|
||||
{t("profile.actions.assignBranch", "Şahamça birikdiriň")}
|
||||
</Button>
|
||||
</div>
|
||||
</BentoCard>
|
||||
{isAdmin && (
|
||||
<BentoCard title={t("profile.sections.actions", "Amallar")}>
|
||||
<div className="flex flex-wrap gap-2 px-4 py-3">
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("role")}>
|
||||
<Shield size={14} />
|
||||
{t("profile.actions.assignRole", "Rol birikdiriň")}
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("permission")}>
|
||||
<KeyRound size={14} />
|
||||
{t("profile.actions.assignPermission", "Rugsat birikdiriň")}
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("branch")}>
|
||||
<Building2 size={14} />
|
||||
{t("profile.actions.assignBranch", "Şahamça birikdiriň")}
|
||||
</Button>
|
||||
</div>
|
||||
</BentoCard>
|
||||
)}
|
||||
</BentoGrid>
|
||||
</>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user