fixed some ux components, added constants
This commit is contained in:
1 parent
6da59f42d9
commit
5073166931
30 files changed
+409
-425
No files matched your search
@@ -7,7 +7,7 @@ import { toast } from "sonner";
|
||||
import { CreditCard, User, FileText } from "lucide-react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
|
||||
import { FormInput } from "@/components/formInput";
|
||||
import { FormInput, type SelectOption } from "@/components/formInput";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
@@ -15,6 +15,10 @@ import type { CardPinOrder, CreateCardPinPayload } from "@/features/cardPins/api
|
||||
import { useCreateCardPin, useUpdateCardPin } from "@/features/cardPins/hooks/useCardPins";
|
||||
import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "@/features/cardPins/schemas/cardPin.schema";
|
||||
import type { CardPinFormData } from "@/features/cardPins/schemas/cardPin.schema";
|
||||
import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -85,19 +89,15 @@ interface StepContentProps {
|
||||
errors: FlatErrors;
|
||||
set: <K extends keyof CardPinFormData>(k: K, v: CardPinFormData[K]) => void;
|
||||
t: TFunction;
|
||||
cardTypeOptions: SelectOption[];
|
||||
branchOptions: SelectOption[];
|
||||
districtOptions: SelectOption[];
|
||||
}
|
||||
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
|
||||
function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
const STATUS_OPTIONS = useMemo(
|
||||
() => [
|
||||
{ value: "pending", label: t("cardPin.status.pending", "Garaşylýar") },
|
||||
{ value: "approved", label: t("cardPin.status.approved", "Tassyklandy") },
|
||||
{ value: "rejected", label: t("cardPin.status.rejected", "Ýatyryldy") },
|
||||
],
|
||||
[t],
|
||||
);
|
||||
function StepCard({ form, errors, set, t, cardTypeOptions, branchOptions, districtOptions }: StepContentProps) {
|
||||
const statusOptions = useMemo(() => getStatusOptions(t, "cardPin.status"), [t]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
@@ -109,7 +109,7 @@ function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
required
|
||||
value={form.status}
|
||||
onChange={(v) => set("status", v)}
|
||||
options={STATUS_OPTIONS}
|
||||
options={statusOptions}
|
||||
error={errors.status}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
/>
|
||||
@@ -139,33 +139,36 @@ function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
error={errors.cardNumber}
|
||||
/>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("cardPin.field.cardTypeId", "Kart görnüşi ID")}
|
||||
type="searchable-select"
|
||||
label={t("cardPin.field.cardTypeId", "Kart görnüşi")}
|
||||
required
|
||||
value={form.cardTypeId}
|
||||
onChange={(v) => set("cardTypeId", v)}
|
||||
placeholder={t("cardPin.field.cardTypeId", "Kart görnüşi ID")}
|
||||
options={cardTypeOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.cardTypeId}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardPinForm.titles.location") || "Lokasiýa"}>
|
||||
<FormInput
|
||||
type="text"
|
||||
type="searchable-select"
|
||||
label={t("cardPin.field.region", "Sebit")}
|
||||
required
|
||||
value={form.region}
|
||||
onChange={(v) => set("region", v)}
|
||||
placeholder={t("cardPin.field.region", "Sebit")}
|
||||
options={districtOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.region}
|
||||
/>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("cardPin.field.branchId", "Şahamça ID")}
|
||||
type="searchable-select"
|
||||
label={t("cardPin.field.branchId", "Şahamça")}
|
||||
required
|
||||
value={form.branchId}
|
||||
onChange={(v) => set("branchId", v)}
|
||||
placeholder={t("cardPin.field.branchId", "Şahamça ID")}
|
||||
options={branchOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.branchId}
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -267,12 +270,13 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
type="select"
|
||||
label={t("cardPin.field.passportSerie", "Pasport seriýasy")}
|
||||
required
|
||||
value={form.passportSerie}
|
||||
onChange={(v) => set("passportSerie", v)}
|
||||
placeholder={t("cardPin.field.passportSerie", "Pasport seriýasy")}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.passportSerie}
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -336,10 +340,44 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
export function CardPinForm({ mode, initialData }: CardPinFormProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as "tm" | "ru" | "en";
|
||||
|
||||
const createMutation = useCreateCardPin();
|
||||
const updateMutation = useUpdateCardPin(initialData?.id ?? 0);
|
||||
const isPending = createMutation.isPending || updateMutation.isPending;
|
||||
|
||||
const { data: cardTypesData } = useCardTypes({ page: 1, limit: 100 });
|
||||
const { data: branchesData } = useBranches({ page: 1, limit: 100 });
|
||||
const { data: districtsData } = useDistricts({ page: 1, limit: 100 });
|
||||
|
||||
const cardTypeOptions = useMemo(
|
||||
() =>
|
||||
(cardTypesData?.paymentCards ?? []).map((ct) => ({
|
||||
value: String(ct.id),
|
||||
label: ct.title[lang] || ct.title.tm,
|
||||
})),
|
||||
[cardTypesData, lang],
|
||||
);
|
||||
|
||||
const branchOptions = useMemo(
|
||||
() =>
|
||||
(branchesData?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
[branchesData, lang],
|
||||
);
|
||||
|
||||
const districtOptions = useMemo(
|
||||
() =>
|
||||
(districtsData?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
[districtsData, lang],
|
||||
);
|
||||
|
||||
const {
|
||||
watch,
|
||||
setValue,
|
||||
@@ -388,7 +426,10 @@ export function CardPinForm({ mode, initialData }: CardPinFormProps) {
|
||||
return { ...fromRHF, ...allSubmittedErrors };
|
||||
}, [rhfErrors, allSubmittedErrors]);
|
||||
|
||||
const stepProps = useMemo(() => ({ form, errors, set, t }), [form, errors, set, t]);
|
||||
const stepProps = useMemo(
|
||||
() => ({ form, errors, set, t, cardTypeOptions, branchOptions, districtOptions }),
|
||||
[form, errors, set, t, cardTypeOptions, branchOptions, districtOptions],
|
||||
);
|
||||
|
||||
// ── Navigation ─────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import apiClient from "@/lib/api/client";
|
||||
import type { StatusValue } from "@/constants";
|
||||
|
||||
// ─── Types ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export type LoanOrderMobileStatus = "GARAŞYLÝAR" | "KANAGATLANDYRYLAN" | "RED_EDILDI" | "IŞLENÝÄR";
|
||||
export type LoanOrderMobileStatus = StatusValue;
|
||||
|
||||
export interface LoanOrderMobile {
|
||||
id: string;
|
||||
@@ -159,7 +160,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
firstName: "Oraz",
|
||||
lastName: "Annaýew",
|
||||
phone: "+99361123456",
|
||||
status: "GARAŞYLÝAR",
|
||||
status: "pending",
|
||||
note: "Müşderi dokumentleri tassyklamady",
|
||||
loanAmount: 15000,
|
||||
loanHistory: "positive",
|
||||
@@ -169,7 +170,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
dateOfBirth: "1992-04-18",
|
||||
residence: "Aşgabat, Bitarap Türkmenistan şaýoly, 15",
|
||||
currentResidence: "Aşgabat, Garaşsyzlyk köçesi, 5",
|
||||
passportSerie: "I",
|
||||
passportSerie: "I-AŞ",
|
||||
passportNumber: "123456",
|
||||
passportDateOfIssue: "2015-03-10",
|
||||
passportGivenBy: "Aşgabat şäheriniň Içeri işler müdirligi",
|
||||
@@ -190,7 +191,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
guarantor1Name: "Berdi",
|
||||
guarantor1Surname: "Berdiýew",
|
||||
guarantor1Patronic: "Annagulyýewiç",
|
||||
guarantor1PassportSerie: "II",
|
||||
guarantor1PassportSerie: "II-MR",
|
||||
guarantor1PassportNumber: "654321",
|
||||
guarantor1CardNumber: "4222222222222222",
|
||||
guarantor1CardName: "BERDI BERDIÝEW",
|
||||
@@ -211,7 +212,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
firstName: "Merjen",
|
||||
lastName: "Hudaýewa",
|
||||
phone: "+99362234567",
|
||||
status: "KANAGATLANDYRYLAN",
|
||||
status: "approved",
|
||||
loanAmount: 30000,
|
||||
loanHistory: "new",
|
||||
patronicName: "Myratowna",
|
||||
@@ -219,7 +220,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
marriageStatus: "SINGLE",
|
||||
dateOfBirth: "1995-11-20",
|
||||
residence: "Änew şäher, Garaşsyzlyk köçesi, 10",
|
||||
passportSerie: "I",
|
||||
passportSerie: "I-MR",
|
||||
passportNumber: "789012",
|
||||
passportDateOfIssue: "2018-07-22",
|
||||
passportGivenBy: "Ahal welaýatynyň Içeri işler müdirligi",
|
||||
@@ -235,7 +236,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
cardExpYear: "2028",
|
||||
guarantor1Name: "Merdan",
|
||||
guarantor1Surname: "Merdanow",
|
||||
guarantor1PassportSerie: "I",
|
||||
guarantor1PassportSerie: "I-AH",
|
||||
guarantor1PassportNumber: "345678",
|
||||
guarantor1CardNumber: "4444444444444444",
|
||||
guarantor1CardName: "MERDAN MERDANOW",
|
||||
@@ -256,7 +257,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
firstName: "Serdar",
|
||||
lastName: "Durdyýew",
|
||||
phone: "+99363345678",
|
||||
status: "IŞLENÝÄR",
|
||||
status: "pending",
|
||||
loanAmount: 50000,
|
||||
loanHistory: "positive",
|
||||
patronicName: "Annagylyjowiç",
|
||||
@@ -264,7 +265,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
marriageStatus: "MARRIED",
|
||||
dateOfBirth: "1988-07-12",
|
||||
residence: "Balkanabat, Magtymguly köçesi, 25",
|
||||
passportSerie: "II",
|
||||
passportSerie: "II-AH",
|
||||
passportNumber: "456123",
|
||||
passportDateOfIssue: "2016-05-18",
|
||||
passportGivenBy: "Balkan welaýatynyň Içeri işler müdirligi",
|
||||
@@ -279,7 +280,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
cardExpYear: "2029",
|
||||
guarantor1Name: "Döwran",
|
||||
guarantor1Surname: "Döwranow",
|
||||
guarantor1PassportSerie: "I",
|
||||
guarantor1PassportSerie: "I-LB",
|
||||
guarantor1PassportNumber: "789456",
|
||||
guarantor1CardNumber: "4666666666666666",
|
||||
guarantor1CardName: "DÖWRAN DÖWRANOW",
|
||||
@@ -296,14 +297,14 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
firstName: "Aýna",
|
||||
lastName: "Meredowa",
|
||||
phone: "+99365456789",
|
||||
status: "RED_EDILDI",
|
||||
status: "rejected",
|
||||
loanAmount: 25000,
|
||||
patronicName: "Begenjowna",
|
||||
education: "high",
|
||||
marriageStatus: "DIVORCED",
|
||||
dateOfBirth: "1991-02-28",
|
||||
residence: "Türkmenabat, Lebap köçesi, 8",
|
||||
passportSerie: "I",
|
||||
passportSerie: "II-LB",
|
||||
passportNumber: "321654",
|
||||
passportDateOfIssue: "2017-11-05",
|
||||
passportGivenBy: "Lebap welaýatynyň Içeri işler müdirligi",
|
||||
@@ -325,7 +326,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
firstName: "Begmyrat",
|
||||
lastName: "Oraz",
|
||||
phone: "+99366567890",
|
||||
status: "GARAŞYLÝAR",
|
||||
status: "pending",
|
||||
loanAmount: 8000,
|
||||
loanHistory: "new",
|
||||
patronicName: "Annageldiwiç",
|
||||
@@ -333,7 +334,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
marriageStatus: "SINGLE",
|
||||
dateOfBirth: "2000-08-15",
|
||||
residence: "Mary şäher, Saýat köçesi, 3",
|
||||
passportSerie: "I",
|
||||
passportSerie: "I-BN",
|
||||
passportNumber: "567890",
|
||||
passportDateOfIssue: "2020-01-20",
|
||||
passportGivenBy: "Mary welaýatynyň Içeri işler müdirligi",
|
||||
@@ -351,14 +352,14 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
firstName: "Gülälek",
|
||||
lastName: "Saparowa",
|
||||
phone: "+99361678901",
|
||||
status: "KANAGATLANDYRYLAN",
|
||||
status: "approved",
|
||||
loanAmount: 12000,
|
||||
patronicName: "Mämmedowna",
|
||||
education: "phd",
|
||||
marriageStatus: "MARRIED",
|
||||
dateOfBirth: "1985-12-03",
|
||||
residence: "Daşoguz, Gurbansoltan eje köçesi, 12",
|
||||
passportSerie: "II",
|
||||
passportSerie: "II-BN",
|
||||
passportNumber: "901234",
|
||||
passportDateOfIssue: "2014-08-30",
|
||||
passportGivenBy: "Daşoguz welaýatynyň Içeri işler müdirligi",
|
||||
@@ -373,7 +374,7 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
cardExpYear: "2028",
|
||||
guarantor1Name: "Maksat",
|
||||
guarantor1Surname: "Saparow",
|
||||
guarantor1PassportSerie: "I",
|
||||
guarantor1PassportSerie: "I-DZ",
|
||||
guarantor1PassportNumber: "112233",
|
||||
guarantor1CardNumber: "4999999999999999",
|
||||
guarantor1CardName: "MAKSAT SAPAROW",
|
||||
@@ -390,14 +391,14 @@ const MOCK_DATA: LoanOrderMobile[] = [
|
||||
firstName: "Myrat",
|
||||
lastName: "Ataýew",
|
||||
phone: "+99362789012",
|
||||
status: "IŞLENÝÄR",
|
||||
status: "pending",
|
||||
loanAmount: 35000,
|
||||
patronicName: "Batyrowiç",
|
||||
education: "high",
|
||||
marriageStatus: "MARRIED",
|
||||
dateOfBirth: "1989-09-22",
|
||||
residence: "Aşgabat, Çandybil köçesi, 45",
|
||||
passportSerie: "I",
|
||||
passportSerie: "II-DZ",
|
||||
passportNumber: "334455",
|
||||
passportDateOfIssue: "2015-12-12",
|
||||
passportGivenBy: "Aşgabat şäheriniň Içeri işler müdirligi",
|
||||
|
||||
@@ -15,6 +15,7 @@ import type { LoanOrderMobile } from "@/features/loanOrderMobiles/api/loanOrderM
|
||||
import { BRANCHES_BY_REGION_MOBILE } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi";
|
||||
import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "@/features/loanOrderMobiles/schemas/loanOrderMobile.schema";
|
||||
import type { LoanOrderMobileFormData } from "@/features/loanOrderMobiles/schemas/loanOrderMobile.schema";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
|
||||
// ─── Static options ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -46,13 +47,6 @@ const MARRIAGE_OPTIONS = [
|
||||
{ value: "LEGAL", label: "Raýat nika" },
|
||||
];
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: "GARAŞYLÝAR", label: "Garaşylýar" },
|
||||
{ value: "IŞLENÝÄR", label: "Işlenýär" },
|
||||
{ value: "KANAGATLANDYRYLAN", label: "Kanagatlandyrylan" },
|
||||
{ value: "RED_EDILDI", label: "Red edildi" },
|
||||
];
|
||||
|
||||
const LOAN_TYPE_OPTIONS = [
|
||||
{ value: "consumer", label: "Sarp ediş karzy" },
|
||||
{ value: "mortgage", label: "Ipoteka" },
|
||||
@@ -61,11 +55,6 @@ const LOAN_TYPE_OPTIONS = [
|
||||
{ value: "business", label: "Işewürlik karzy" },
|
||||
];
|
||||
|
||||
const PASSPORT_SERIES_OPTIONS = [
|
||||
{ value: "I", label: "I" },
|
||||
{ value: "II", label: "II" },
|
||||
];
|
||||
|
||||
const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({
|
||||
value: String(i + 1).padStart(2, "0"),
|
||||
label: String(i + 1).padStart(2, "0"),
|
||||
@@ -687,6 +676,7 @@ function StepFiles({
|
||||
mode,
|
||||
initialData,
|
||||
}: StepContentProps & { mode: "create" | "edit"; initialData?: LoanOrderMobile }) {
|
||||
const statusOptions = useMemo(() => getStatusOptions(t, "loanOrderStatus"), [t]);
|
||||
const existingFiles =
|
||||
mode === "edit" && initialData
|
||||
? [
|
||||
@@ -707,7 +697,7 @@ function StepFiles({
|
||||
required
|
||||
value={form.status}
|
||||
onChange={(v) => set("status", v)}
|
||||
options={STATUS_OPTIONS}
|
||||
options={statusOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.status}
|
||||
/>
|
||||
@@ -993,7 +983,7 @@ export function LoanOrderMobileForm({ mode, initialData }: LoanOrderMobileFormPr
|
||||
|
||||
function mapInitial(order: LoanOrderMobile): Partial<LoanOrderMobileFormData> {
|
||||
return {
|
||||
status: order.status ?? "GARAŞYLÝAR",
|
||||
status: order.status ?? "pending",
|
||||
loanType: order.loanType ?? "",
|
||||
region: order.region ?? "Aşgabat",
|
||||
branch: order.branch ?? "",
|
||||
|
||||
@@ -191,7 +191,7 @@ export function validateStep(
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: LoanOrderMobileFormData = {
|
||||
status: "GARAŞYLÝAR",
|
||||
status: "pending",
|
||||
loanType: "",
|
||||
region: "Aşgabat",
|
||||
branch: "",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { StatusValue } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export type LoanOrderStatus = "GARAŞYLÝAR" | "KANAGATLANDYRYLAN" | "RED_EDILDI" | "IŞLENÝÄR";
|
||||
export type LoanOrderStatus = StatusValue;
|
||||
|
||||
export interface LoanOrder {
|
||||
id: string;
|
||||
@@ -166,7 +168,7 @@ const MOCK_DATA: LoanOrder[] = [
|
||||
firstName: "Aman",
|
||||
lastName: "Amanow",
|
||||
phone: "+993 65 112233",
|
||||
status: "GARAŞYLÝAR",
|
||||
status: "pending",
|
||||
note: "Müşderi dokumentleri tassyklamady",
|
||||
loanAmount: 50000,
|
||||
loanHistory: "positive",
|
||||
@@ -176,7 +178,7 @@ const MOCK_DATA: LoanOrder[] = [
|
||||
dateOfBirth: "1990-05-15",
|
||||
residence: "Aşgabat, Bitarap Türkmenistan şaýoly, 15",
|
||||
currentResidence: "Aşgabat, Garaşsyzlyk köçesi, 5",
|
||||
passportSerie: "I",
|
||||
passportSerie: "I-AŞ",
|
||||
passportNumber: "123456",
|
||||
passportDateOfIssue: "2015-03-10",
|
||||
passportGivenBy: "Aşgabat şäheriniň Içeri işler müdirligi",
|
||||
@@ -198,7 +200,7 @@ const MOCK_DATA: LoanOrder[] = [
|
||||
guarantor1Name: "Berdi",
|
||||
guarantor1Surname: "Berdiýew",
|
||||
guarantor1Patronic: "Annagulyýewiç",
|
||||
guarantor1PassportSerie: "II",
|
||||
guarantor1PassportSerie: "II-MR",
|
||||
guarantor1PassportNumber: "654321",
|
||||
guarantor1CardNumber: "4222222222222222",
|
||||
guarantor1CardName: "BERDI BERDIÝEW",
|
||||
@@ -219,7 +221,7 @@ const MOCK_DATA: LoanOrder[] = [
|
||||
firstName: "Oguljan",
|
||||
lastName: "Berdiýewa",
|
||||
phone: "+993 61 445566",
|
||||
status: "IŞLENÝÄR",
|
||||
status: "pending",
|
||||
note: null,
|
||||
loanAmount: 10000,
|
||||
loanHistory: "new",
|
||||
@@ -229,7 +231,7 @@ const MOCK_DATA: LoanOrder[] = [
|
||||
dateOfBirth: "1995-11-20",
|
||||
residence: "Mary şäher, Gurbansoltan eje köçesi, 10",
|
||||
currentResidence: "Mary şäher, Gurbansoltan eje köçesi, 10",
|
||||
passportSerie: "I",
|
||||
passportSerie: "I-MR",
|
||||
passportNumber: "789012",
|
||||
passportDateOfIssue: "2018-07-22",
|
||||
passportGivenBy: "Mary şäheriniň Içeri işler müdirligi",
|
||||
@@ -251,7 +253,7 @@ const MOCK_DATA: LoanOrder[] = [
|
||||
guarantor1Name: "Merdan",
|
||||
guarantor1Surname: "Merdanow",
|
||||
guarantor1Patronic: "Amanowiç",
|
||||
guarantor1PassportSerie: "I",
|
||||
guarantor1PassportSerie: "I-AH",
|
||||
guarantor1PassportNumber: "345678",
|
||||
guarantor1CardNumber: "4444444444444444",
|
||||
guarantor1CardName: "MERDAN MERDANOW",
|
||||
|
||||
@@ -16,6 +16,7 @@ import type { LoanOrder } from "@/features/loanOrders/api/loanOrdersApi";
|
||||
import { BRANCHES_BY_REGION } from "@/features/loanOrders/api/loanOrdersApi";
|
||||
import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "@/features/loanOrders/schemas/loanOrder.schema";
|
||||
import type { LoanOrderFormData } from "@/features/loanOrders/schemas/loanOrder.schema";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
|
||||
// ─── Static options ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -47,13 +48,6 @@ const MARRIAGE_OPTIONS = [
|
||||
{ value: "LEGAL", label: "Raýat nika" },
|
||||
];
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: "GARAŞYLÝAR", label: "Garaşylýar" },
|
||||
{ value: "IŞLENÝÄR", label: "Işlenýär" },
|
||||
{ value: "KANAGATLANDYRYLAN", label: "Kanagatlandyrylan" },
|
||||
{ value: "RED_EDILDI", label: "Red edildi" },
|
||||
];
|
||||
|
||||
const LOAN_TYPE_OPTIONS = [
|
||||
{ value: "consumer", label: "Sarp ediş karzy" },
|
||||
{ value: "mortgage", label: "Ipoteka" },
|
||||
@@ -62,11 +56,6 @@ const LOAN_TYPE_OPTIONS = [
|
||||
{ value: "business", label: "Işewürlik karzy" },
|
||||
];
|
||||
|
||||
const PASSPORT_SERIES_OPTIONS = [
|
||||
{ value: "I", label: "I" },
|
||||
{ value: "II", label: "II" },
|
||||
];
|
||||
|
||||
const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({
|
||||
value: String(i + 1).padStart(2, "0"),
|
||||
label: String(i + 1).padStart(2, "0"),
|
||||
@@ -207,6 +196,8 @@ interface StepContentProps {
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
|
||||
function StepStatus({ form, errors, set, t }: StepContentProps) {
|
||||
const statusOptions = useMemo(() => getStatusOptions(t, "loanOrderStatus"), [t]);
|
||||
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
@@ -216,7 +207,7 @@ function StepStatus({ form, errors, set, t }: StepContentProps) {
|
||||
required
|
||||
value={form.status}
|
||||
onChange={(v) => set("status", v)}
|
||||
options={STATUS_OPTIONS}
|
||||
options={statusOptions}
|
||||
error={errors.status}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
/>
|
||||
@@ -1061,7 +1052,7 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
|
||||
|
||||
function mapInitial(order: LoanOrder): Partial<LoanOrderFormData> {
|
||||
return {
|
||||
status: order.status ?? "GARAŞYLÝAR",
|
||||
status: order.status ?? "pending",
|
||||
loanType: order.loanType ?? "",
|
||||
region: order.region ?? "Aşgabat",
|
||||
branch: order.branch ?? "",
|
||||
|
||||
@@ -195,7 +195,7 @@ export function validateStep(
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: LoanOrderFormData = {
|
||||
status: "GARAŞYLÝAR",
|
||||
status: "pending",
|
||||
loanType: "",
|
||||
region: "Aşgabat",
|
||||
branch: "",
|
||||
|
||||
@@ -11,6 +11,7 @@ import { FormInput, type SelectOption } from "@/components/formInput";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
|
||||
import { useCreateLoanPaidOffLetter, useUpdateLoanPaidOffLetter } from "../hooks/useLoanPaidOffLetters";
|
||||
import type { LoanPaidOffLetter } from "../api/loanPaidOffLettersApi";
|
||||
@@ -161,11 +162,12 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
<BentoCard span="full">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="text"
|
||||
type="select"
|
||||
label={t("loanPaidOffLetters.fields.passportSerie", "Pasport seriýasy")}
|
||||
value={form.passportSerie}
|
||||
onChange={set("passportSerie")}
|
||||
placeholder="I-AG"
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder="I-AŞ"
|
||||
error={errors.passportSerie}
|
||||
required
|
||||
/>
|
||||
@@ -338,14 +340,7 @@ export function LoanPaidOffLetterForm({ mode, initialData }: LoanPaidOffLetterFo
|
||||
[setValue, clearErrors],
|
||||
);
|
||||
|
||||
const statusOptions = useMemo<SelectOption[]>(
|
||||
() => [
|
||||
{ value: "pending", label: t("loanPaidOffLetters.status.pending", "Pending") },
|
||||
{ value: "approved", label: t("loanPaidOffLetters.status.approved", "Approved") },
|
||||
{ value: "rejected", label: t("loanPaidOffLetters.status.rejected", "Rejected") },
|
||||
],
|
||||
[t],
|
||||
);
|
||||
const statusOptions = useMemo<SelectOption[]>(() => getStatusOptions(t, "loanPaidOffLetters.status"), [t]);
|
||||
|
||||
const regionOptions = useMemo<SelectOption[]>(
|
||||
() =>
|
||||
|
||||
@@ -7,7 +7,7 @@ import { CreditCard, User, FileText, MapPin } from "lucide-react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { FormInput } from "@/components/formInput";
|
||||
import { FormInput, type SelectOption } from "@/components/formInput";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
@@ -15,6 +15,11 @@ import type { CardOrder } from "../api/orderNewCardApi";
|
||||
import { useCreateCard, useUpdateCard } from "../hooks/useOrderNewCard";
|
||||
import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/orderNewCard.schema";
|
||||
import type { OrderNewCardFormData } from "../schemas/orderNewCard.schema";
|
||||
import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { useCardReasons } from "@/features/cardReasons/hooks/useCardReasons";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -94,19 +99,16 @@ interface StepContentProps {
|
||||
errors: FlatErrors;
|
||||
set: <K extends keyof OrderNewCardFormData>(k: K, v: OrderNewCardFormData[K]) => void;
|
||||
t: TFunction;
|
||||
cardTypeOptions: SelectOption[];
|
||||
cardStateOptions: SelectOption[];
|
||||
branchOptions: SelectOption[];
|
||||
districtOptions: SelectOption[];
|
||||
}
|
||||
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
|
||||
function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
const STATUS_OPTIONS = useMemo(
|
||||
() => [
|
||||
{ value: "PENDING", label: t("cardOrder.status.pending", "Garaşylýar") },
|
||||
{ value: "APPROVED", label: t("cardOrder.status.approved", "Tassyklandy") },
|
||||
{ value: "REJECTED", label: t("cardOrder.status.rejected", "Ýatyryldy") },
|
||||
],
|
||||
[t],
|
||||
);
|
||||
function StepCard({ form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions }: StepContentProps) {
|
||||
const statusOptions = useMemo(() => getStatusOptions(t, "cardOrder.status"), [t]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
@@ -118,7 +120,7 @@ function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
required
|
||||
value={form.status}
|
||||
onChange={(v) => set("status", v)}
|
||||
options={STATUS_OPTIONS}
|
||||
options={statusOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.status}
|
||||
/>
|
||||
@@ -169,42 +171,46 @@ function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("loanOrderForm.titles.cardInfo") || "Kart maglumatlary"}>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("cardOrder.field.cardTypeId", "Kart görnüşi ID")}
|
||||
type="searchable-select"
|
||||
label={t("cardOrder.field.cardTypeId", "Kart görnüşi")}
|
||||
required
|
||||
value={form.cardTypeId}
|
||||
onChange={(v) => set("cardTypeId", v)}
|
||||
placeholder={t("cardOrder.field.cardTypeId", "Kart görnüşi ID")}
|
||||
options={cardTypeOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.cardTypeId}
|
||||
/>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("cardOrder.field.cardStateId", "Kart ýagdaýy ID")}
|
||||
type="searchable-select"
|
||||
label={t("cardOrder.field.cardStateId", "Kart ýagdaýy")}
|
||||
required
|
||||
value={form.cardStateId}
|
||||
onChange={(v) => set("cardStateId", v)}
|
||||
placeholder={t("cardOrder.field.cardStateId", "Kart ýagdaýy ID")}
|
||||
options={cardStateOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.cardStateId}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardPinForm.titles.location") || "Lokasiýa"}>
|
||||
<FormInput
|
||||
type="text"
|
||||
type="searchable-select"
|
||||
label={t("cardOrder.field.region", "Sebit")}
|
||||
required
|
||||
value={form.region}
|
||||
onChange={(v) => set("region", v)}
|
||||
placeholder={t("cardOrder.field.region", "Sebit")}
|
||||
options={districtOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.region}
|
||||
/>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("cardOrder.field.branchId", "Şahamça ID")}
|
||||
type="searchable-select"
|
||||
label={t("cardOrder.field.branchId", "Şahamça")}
|
||||
required
|
||||
value={form.branchId}
|
||||
onChange={(v) => set("branchId", v)}
|
||||
placeholder={t("cardOrder.field.branchId", "Şahamça ID")}
|
||||
options={branchOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.branchId}
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -323,12 +329,13 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
type="select"
|
||||
label={t("cardOrder.field.passportSerie", "Pasport seriýasy")}
|
||||
required
|
||||
value={form.passportSerie}
|
||||
onChange={(v) => set("passportSerie", v)}
|
||||
placeholder={t("cardOrder.field.passportSerie", "Pasport seriýasy")}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.passportSerie}
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -464,10 +471,53 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as "tm" | "ru" | "en";
|
||||
|
||||
const createMutation = useCreateCard();
|
||||
const updateMutation = useUpdateCard(initialData?.id ?? 0);
|
||||
const isPending = createMutation.isPending || updateMutation.isPending;
|
||||
|
||||
const { data: cardTypesData } = useCardTypes({ page: 1, limit: 100 });
|
||||
const { data: cardReasonsData } = useCardReasons({ page: 1, limit: 100 });
|
||||
const { data: branchesData } = useBranches({ page: 1, limit: 100 });
|
||||
const { data: districtsData } = useDistricts({ page: 1, limit: 100 });
|
||||
|
||||
const cardTypeOptions = useMemo(
|
||||
() =>
|
||||
(cardTypesData?.paymentCards ?? []).map((ct) => ({
|
||||
value: String(ct.id),
|
||||
label: ct.title[lang] || ct.title.tm,
|
||||
})),
|
||||
[cardTypesData, lang],
|
||||
);
|
||||
|
||||
const cardStateOptions = useMemo(
|
||||
() =>
|
||||
(cardReasonsData?.reasonCards ?? []).map((cr) => ({
|
||||
value: String(cr.id),
|
||||
label: cr.title[lang] || cr.title.tm,
|
||||
})),
|
||||
[cardReasonsData, lang],
|
||||
);
|
||||
|
||||
const branchOptions = useMemo(
|
||||
() =>
|
||||
(branchesData?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
[branchesData, lang],
|
||||
);
|
||||
|
||||
const districtOptions = useMemo(
|
||||
() =>
|
||||
(districtsData?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
[districtsData, lang],
|
||||
);
|
||||
|
||||
const {
|
||||
watch,
|
||||
setValue,
|
||||
@@ -519,7 +569,10 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) {
|
||||
return { ...fromRHF, ...allSubmittedErrors };
|
||||
}, [rhfErrors, allSubmittedErrors]);
|
||||
|
||||
const stepProps = useMemo(() => ({ form, errors, set, t }), [form, errors, set, t]);
|
||||
const stepProps = useMemo(
|
||||
() => ({ form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions }),
|
||||
[form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions],
|
||||
);
|
||||
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import type { IntlPaymentItem, IntlPaymentCreatePayload } from "../api/visaMaste
|
||||
import { useCreateIntlPayment, useUpdateIntlPayment } from "../hooks/useVisaMasterPayments";
|
||||
import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/visaMasterPayment.schema";
|
||||
import type { IntlPaymentFormData } from "../schemas/visaMasterPayment.schema";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -26,24 +27,11 @@ type FlatErrors = Partial<Record<keyof IntlPaymentFormData, string>>;
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: "pending", label: "Garaşylýar" },
|
||||
{ value: "approved", label: "Tassyklandy" },
|
||||
{ value: "rejected", label: "Ret edildi" },
|
||||
];
|
||||
|
||||
const CURRENCY_OPTIONS = [
|
||||
{ value: "visa", label: "Visa" },
|
||||
{ value: "mastercard", label: "MasterCard" },
|
||||
];
|
||||
|
||||
const PASSPORT_SERIES_OPTIONS = [
|
||||
{ value: "I", label: "I" },
|
||||
{ value: "II", label: "II" },
|
||||
{ value: "I-MR", label: "I-MR" },
|
||||
{ value: "II-MR", label: "II-MR" },
|
||||
];
|
||||
|
||||
const PROVINCE_OPTIONS = [
|
||||
{ value: "ashgabat", label: "Aşgabat" },
|
||||
{ value: "ahal", label: "Ahal" },
|
||||
@@ -157,6 +145,8 @@ interface StepContentProps {
|
||||
}
|
||||
|
||||
function StepGeneral({ form, errors, set, t }: StepContentProps) {
|
||||
const statusOptions = useMemo(() => getStatusOptions(t, "intlPayment.status"), [t]);
|
||||
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
@@ -178,7 +168,7 @@ function StepGeneral({ form, errors, set, t }: StepContentProps) {
|
||||
label={t("loanOrderForm.labels.status") || "Status"}
|
||||
value={form.status}
|
||||
onChange={(v) => set("status", v)}
|
||||
options={STATUS_OPTIONS}
|
||||
options={statusOptions}
|
||||
error={errors.status}
|
||||
required
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user