added zod validation
This commit is contained in:
@@ -1,412 +1,509 @@
|
||||
import { apiClient } from '@/lib/api/client'
|
||||
import apiClient from "@/lib/api/client";
|
||||
|
||||
// ─── Types ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export type LoanOrderMobileStatus =
|
||||
| 'GARAŞYLÝAR'
|
||||
| 'KANAGATLANDYRYLAN'
|
||||
| 'RED_EDILDI'
|
||||
| 'IŞLENÝÄR'
|
||||
export type LoanOrderMobileStatus = "GARAŞYLÝAR" | "KANAGATLANDYRYLAN" | "RED_EDILDI" | "IŞLENÝÄR";
|
||||
|
||||
export interface LoanOrderMobile {
|
||||
id: string
|
||||
loanType: string
|
||||
createdAt: string
|
||||
region: string
|
||||
branch: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
phone: string
|
||||
status: LoanOrderMobileStatus
|
||||
createdBy?: string
|
||||
id: string;
|
||||
loanType: string;
|
||||
createdAt: string;
|
||||
region: string;
|
||||
branch: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
phone: string;
|
||||
status: LoanOrderMobileStatus;
|
||||
createdBy?: string;
|
||||
|
||||
// ── Detail fields ─────────────────────────────────────────────────────────
|
||||
patronicName?: string | null
|
||||
education?: string | null
|
||||
marriageStatus?: string | null
|
||||
dateOfBirth?: string | null
|
||||
residence?: string | null
|
||||
currentResidence?: string | null
|
||||
patronicName?: string | null;
|
||||
education?: string | null;
|
||||
marriageStatus?: string | null;
|
||||
dateOfBirth?: string | null;
|
||||
residence?: string | null;
|
||||
currentResidence?: string | null;
|
||||
|
||||
// Passport
|
||||
passportSerie?: string | null
|
||||
passportNumber?: string | null
|
||||
passportDateOfIssue?: string | null
|
||||
passportGivenBy?: string | null
|
||||
bornPlace?: string | null
|
||||
passportPage1Url?: string | null
|
||||
passportPage23Url?: string | null
|
||||
passportPage89Url?: string | null
|
||||
passportPage32Url?: string | null
|
||||
passportSerie?: string | null;
|
||||
passportNumber?: string | null;
|
||||
passportDateOfIssue?: string | null;
|
||||
passportGivenBy?: string | null;
|
||||
bornPlace?: string | null;
|
||||
passportPage1Url?: string | null;
|
||||
passportPage23Url?: string | null;
|
||||
passportPage89Url?: string | null;
|
||||
passportPage32Url?: string | null;
|
||||
|
||||
// Contact
|
||||
email?: string | null
|
||||
phoneAdditional?: string | null
|
||||
homePhone?: string | null
|
||||
email?: string | null;
|
||||
phoneAdditional?: string | null;
|
||||
homePhone?: string | null;
|
||||
|
||||
// Employment
|
||||
workCompany?: string | null
|
||||
workHrPhone?: string | null
|
||||
workRegion?: string | null
|
||||
workProvince?: string | null
|
||||
position?: string | null
|
||||
salary?: number | null
|
||||
workStartedAt?: string | null
|
||||
workCompany?: string | null;
|
||||
workHrPhone?: string | null;
|
||||
workRegion?: string | null;
|
||||
workProvince?: string | null;
|
||||
position?: string | null;
|
||||
salary?: number | null;
|
||||
workStartedAt?: string | null;
|
||||
|
||||
// New fields
|
||||
note?: string | null
|
||||
loanAmount?: number | null
|
||||
loanHistory?: string | null
|
||||
note?: string | null;
|
||||
loanAmount?: number | null;
|
||||
loanHistory?: string | null;
|
||||
|
||||
// Card (Zähmet haky)
|
||||
cardNumber?: string | null
|
||||
cardName?: string | null
|
||||
cardExpMonth?: string | null
|
||||
cardExpYear?: string | null
|
||||
cardNumber?: string | null;
|
||||
cardName?: string | null;
|
||||
cardExpMonth?: string | null;
|
||||
cardExpYear?: string | null;
|
||||
|
||||
// Guarantor (Zamun)
|
||||
guarantor1Name?: string | null
|
||||
guarantor1Surname?: string | null
|
||||
guarantor1Patronic?: string | null
|
||||
guarantor1PassportSerie?: string | null
|
||||
guarantor1PassportNumber?: string | null
|
||||
guarantor1CardNumber?: string | null
|
||||
guarantor1CardName?: string | null
|
||||
guarantor1CardExpMonth?: string | null
|
||||
guarantor1CardExpYear?: string | null
|
||||
guarantor1Salary?: number | null
|
||||
guarantor1Name?: string | null;
|
||||
guarantor1Surname?: string | null;
|
||||
guarantor1Patronic?: string | null;
|
||||
guarantor1PassportSerie?: string | null;
|
||||
guarantor1PassportNumber?: string | null;
|
||||
guarantor1CardNumber?: string | null;
|
||||
guarantor1CardName?: string | null;
|
||||
guarantor1CardExpMonth?: string | null;
|
||||
guarantor1CardExpYear?: string | null;
|
||||
guarantor1Salary?: number | null;
|
||||
}
|
||||
|
||||
export interface LoanOrderMobilePayload {
|
||||
status: string
|
||||
loanType: string
|
||||
region: string
|
||||
branch: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
patronicName?: string
|
||||
education: string
|
||||
marriageStatus: string
|
||||
dateOfBirth: string
|
||||
residence: string
|
||||
currentResidence?: string
|
||||
passportSerie: string
|
||||
passportNumber: string
|
||||
passportDateOfIssue: string
|
||||
passportGivenBy: string
|
||||
bornPlace?: string
|
||||
email?: string
|
||||
phone: string
|
||||
phoneAdditional?: string
|
||||
homePhone?: string
|
||||
workCompany: string
|
||||
workHrPhone?: string
|
||||
workRegion?: string
|
||||
workProvince?: string
|
||||
position: string
|
||||
salary: number
|
||||
workStartedAt: string
|
||||
status: string;
|
||||
loanType: string;
|
||||
region: string;
|
||||
branch: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
patronicName?: string;
|
||||
education: string;
|
||||
marriageStatus: string;
|
||||
dateOfBirth: string;
|
||||
residence: string;
|
||||
currentResidence?: string;
|
||||
passportSerie: string;
|
||||
passportNumber: string;
|
||||
passportDateOfIssue: string;
|
||||
passportGivenBy: string;
|
||||
bornPlace?: string;
|
||||
email?: string;
|
||||
phone: string;
|
||||
phoneAdditional?: string;
|
||||
homePhone?: string;
|
||||
workCompany: string;
|
||||
workHrPhone?: string;
|
||||
workRegion?: string;
|
||||
workProvince?: string;
|
||||
position: string;
|
||||
salary: number;
|
||||
workStartedAt: string;
|
||||
|
||||
note?: string
|
||||
loanAmount?: number
|
||||
loanHistory?: string
|
||||
note?: string;
|
||||
loanAmount?: number;
|
||||
loanHistory?: string;
|
||||
|
||||
cardNumber?: string
|
||||
cardName?: string
|
||||
cardExpMonth?: string
|
||||
cardExpYear?: string
|
||||
cardNumber?: string;
|
||||
cardName?: string;
|
||||
cardExpMonth?: string;
|
||||
cardExpYear?: string;
|
||||
|
||||
guarantor1Name?: string
|
||||
guarantor1Surname?: string
|
||||
guarantor1Patronic?: string
|
||||
guarantor1PassportSerie?: string
|
||||
guarantor1PassportNumber?: string
|
||||
guarantor1CardNumber?: string
|
||||
guarantor1CardName?: string
|
||||
guarantor1CardExpMonth?: string
|
||||
guarantor1CardExpYear?: string
|
||||
guarantor1Salary?: number
|
||||
guarantor1Name?: string;
|
||||
guarantor1Surname?: string;
|
||||
guarantor1Patronic?: string;
|
||||
guarantor1PassportSerie?: string;
|
||||
guarantor1PassportNumber?: string;
|
||||
guarantor1CardNumber?: string;
|
||||
guarantor1CardName?: string;
|
||||
guarantor1CardExpMonth?: string;
|
||||
guarantor1CardExpYear?: string;
|
||||
guarantor1Salary?: number;
|
||||
}
|
||||
|
||||
export interface LoanOrderMobileListParams {
|
||||
search?: string
|
||||
region?: string
|
||||
status?: LoanOrderMobileStatus
|
||||
branch?: string
|
||||
archived?: string
|
||||
page?: number
|
||||
perPage?: number
|
||||
search?: string;
|
||||
region?: string;
|
||||
status?: LoanOrderMobileStatus;
|
||||
branch?: string;
|
||||
archived?: string;
|
||||
page?: number;
|
||||
perPage?: number;
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
data: T[]
|
||||
total: number
|
||||
data: T[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
// ─── Mock Data ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const MOCK_DATA: LoanOrderMobile[] = [
|
||||
{
|
||||
id: 'LOM-0001', loanType: 'Sarp ediş karzy', createdAt: '2025-01-15 09:42',
|
||||
region: 'Aşgabat', branch: 'Merkezi şahamça',
|
||||
firstName: 'Oraz', lastName: 'Annaýew', phone: '+99361123456', status: 'GARAŞYLÝAR',
|
||||
note: 'Müşderi dokumentleri tassyklamady',
|
||||
loanAmount: 15000, loanHistory: 'positive',
|
||||
patronicName: 'Myradowiç', education: 'high', marriageStatus: 'MARRIED',
|
||||
dateOfBirth: '1992-04-18',
|
||||
residence: 'Aşgabat, Bitarap Türkmenistan şaýoly, 15',
|
||||
currentResidence: 'Aşgabat, Garaşsyzlyk köçesi, 5',
|
||||
passportSerie: 'I', passportNumber: '123456',
|
||||
passportDateOfIssue: '2015-03-10',
|
||||
passportGivenBy: 'Aşgabat şäheriniň Içeri işler müdirligi',
|
||||
bornPlace: 'Aşgabat şäheri',
|
||||
email: 'oraz.annayew@email.com',
|
||||
phoneAdditional: '+99365443322',
|
||||
workCompany: 'Türkmennebit', workHrPhone: '+99312456789',
|
||||
workRegion: 'Aşgabat', workProvince: 'Büzmeýin etraby',
|
||||
position: 'Inžener', salary: 2500, workStartedAt: '2018-06-01',
|
||||
cardNumber: '4111111111111111', cardName: 'ORAZ ANNAÝEW',
|
||||
cardExpMonth: '12', cardExpYear: '2027',
|
||||
guarantor1Name: 'Berdi', guarantor1Surname: 'Berdiýew',
|
||||
guarantor1Patronic: 'Annagulyýewiç',
|
||||
guarantor1PassportSerie: 'II', guarantor1PassportNumber: '654321',
|
||||
guarantor1CardNumber: '4222222222222222', guarantor1CardName: 'BERDI BERDIÝEW',
|
||||
guarantor1CardExpMonth: '06', guarantor1CardExpYear: '2026', guarantor1Salary: 3000,
|
||||
id: "LOM-0001",
|
||||
loanType: "Sarp ediş karzy",
|
||||
createdAt: "2025-01-15 09:42",
|
||||
region: "Aşgabat",
|
||||
branch: "Merkezi şahamça",
|
||||
firstName: "Oraz",
|
||||
lastName: "Annaýew",
|
||||
phone: "+99361123456",
|
||||
status: "GARAŞYLÝAR",
|
||||
note: "Müşderi dokumentleri tassyklamady",
|
||||
loanAmount: 15000,
|
||||
loanHistory: "positive",
|
||||
patronicName: "Myradowiç",
|
||||
education: "high",
|
||||
marriageStatus: "MARRIED",
|
||||
dateOfBirth: "1992-04-18",
|
||||
residence: "Aşgabat, Bitarap Türkmenistan şaýoly, 15",
|
||||
currentResidence: "Aşgabat, Garaşsyzlyk köçesi, 5",
|
||||
passportSerie: "I",
|
||||
passportNumber: "123456",
|
||||
passportDateOfIssue: "2015-03-10",
|
||||
passportGivenBy: "Aşgabat şäheriniň Içeri işler müdirligi",
|
||||
bornPlace: "Aşgabat şäheri",
|
||||
email: "oraz.annayew@email.com",
|
||||
phoneAdditional: "+99365443322",
|
||||
workCompany: "Türkmennebit",
|
||||
workHrPhone: "+99312456789",
|
||||
workRegion: "Aşgabat",
|
||||
workProvince: "Büzmeýin etraby",
|
||||
position: "Inžener",
|
||||
salary: 2500,
|
||||
workStartedAt: "2018-06-01",
|
||||
cardNumber: "4111111111111111",
|
||||
cardName: "ORAZ ANNAÝEW",
|
||||
cardExpMonth: "12",
|
||||
cardExpYear: "2027",
|
||||
guarantor1Name: "Berdi",
|
||||
guarantor1Surname: "Berdiýew",
|
||||
guarantor1Patronic: "Annagulyýewiç",
|
||||
guarantor1PassportSerie: "II",
|
||||
guarantor1PassportNumber: "654321",
|
||||
guarantor1CardNumber: "4222222222222222",
|
||||
guarantor1CardName: "BERDI BERDIÝEW",
|
||||
guarantor1CardExpMonth: "06",
|
||||
guarantor1CardExpYear: "2026",
|
||||
guarantor1Salary: 3000,
|
||||
},
|
||||
{
|
||||
id: 'LOM-0002', loanType: 'Awtoulag karzy', createdAt: '2025-01-18 11:05',
|
||||
region: 'Ahal', branch: 'Änew şahamçasy',
|
||||
firstName: 'Merjen', lastName: 'Hudaýewa', phone: '+99362234567', status: 'KANAGATLANDYRYLAN',
|
||||
loanAmount: 30000, loanHistory: 'new',
|
||||
patronicName: 'Myratowna', education: 'masters', marriageStatus: 'SINGLE',
|
||||
dateOfBirth: '1995-11-20',
|
||||
residence: 'Änew şäher, Garaşsyzlyk köçesi, 10',
|
||||
passportSerie: 'I', passportNumber: '789012',
|
||||
passportDateOfIssue: '2018-07-22',
|
||||
passportGivenBy: 'Ahal welaýatynyň Içeri işler müdirligi',
|
||||
bornPlace: 'Änew şäheri',
|
||||
email: 'merjen.hudayewa@email.com',
|
||||
workCompany: 'Änew etrap hasap bölümi', position: 'Hasapçy',
|
||||
salary: 1800, workStartedAt: '2019-03-15',
|
||||
cardNumber: '4333333333333333', cardName: 'MERJEN HUDAÝEWA',
|
||||
cardExpMonth: '09', cardExpYear: '2028',
|
||||
guarantor1Name: 'Merdan', guarantor1Surname: 'Merdanow',
|
||||
guarantor1PassportSerie: 'I', guarantor1PassportNumber: '345678',
|
||||
guarantor1CardNumber: '4444444444444444', guarantor1CardName: 'MERDAN MERDANOW',
|
||||
guarantor1CardExpMonth: '03', guarantor1CardExpYear: '2025', guarantor1Salary: 2200,
|
||||
id: "LOM-0002",
|
||||
loanType: "Awtoulag karzy",
|
||||
createdAt: "2025-01-18 11:05",
|
||||
region: "Ahal",
|
||||
branch: "Änew şahamçasy",
|
||||
firstName: "Merjen",
|
||||
lastName: "Hudaýewa",
|
||||
phone: "+99362234567",
|
||||
status: "KANAGATLANDYRYLAN",
|
||||
loanAmount: 30000,
|
||||
loanHistory: "new",
|
||||
patronicName: "Myratowna",
|
||||
education: "masters",
|
||||
marriageStatus: "SINGLE",
|
||||
dateOfBirth: "1995-11-20",
|
||||
residence: "Änew şäher, Garaşsyzlyk köçesi, 10",
|
||||
passportSerie: "I",
|
||||
passportNumber: "789012",
|
||||
passportDateOfIssue: "2018-07-22",
|
||||
passportGivenBy: "Ahal welaýatynyň Içeri işler müdirligi",
|
||||
bornPlace: "Änew şäheri",
|
||||
email: "merjen.hudayewa@email.com",
|
||||
workCompany: "Änew etrap hasap bölümi",
|
||||
position: "Hasapçy",
|
||||
salary: 1800,
|
||||
workStartedAt: "2019-03-15",
|
||||
cardNumber: "4333333333333333",
|
||||
cardName: "MERJEN HUDAÝEWA",
|
||||
cardExpMonth: "09",
|
||||
cardExpYear: "2028",
|
||||
guarantor1Name: "Merdan",
|
||||
guarantor1Surname: "Merdanow",
|
||||
guarantor1PassportSerie: "I",
|
||||
guarantor1PassportNumber: "345678",
|
||||
guarantor1CardNumber: "4444444444444444",
|
||||
guarantor1CardName: "MERDAN MERDANOW",
|
||||
guarantor1CardExpMonth: "03",
|
||||
guarantor1CardExpYear: "2025",
|
||||
guarantor1Salary: 2200,
|
||||
},
|
||||
{
|
||||
id: 'LOM-0003', loanType: 'Ipoteka karzy', createdAt: '2025-01-20 14:30',
|
||||
region: 'Balkan', branch: 'Balkanabat şahamçasy',
|
||||
firstName: 'Serdar', lastName: 'Durdyýew', phone: '+99363345678', status: 'IŞLENÝÄR',
|
||||
loanAmount: 50000, loanHistory: 'positive',
|
||||
patronicName: 'Annagylyjowiç', education: 'high', marriageStatus: 'MARRIED',
|
||||
dateOfBirth: '1988-07-12',
|
||||
residence: 'Balkanabat, Magtymguly köçesi, 25',
|
||||
passportSerie: 'II', passportNumber: '456123',
|
||||
passportDateOfIssue: '2016-05-18',
|
||||
passportGivenBy: 'Balkan welaýatynyň Içeri işler müdirligi',
|
||||
email: 'serdar.durdyyew@email.com',
|
||||
workCompany: 'Balkan nebit', position: 'Operator',
|
||||
salary: 3200, workStartedAt: '2015-09-01',
|
||||
cardNumber: '4555555555555555', cardName: 'SERDAR DURDYÝEW',
|
||||
cardExpMonth: '04', cardExpYear: '2029',
|
||||
guarantor1Name: 'Döwran', guarantor1Surname: 'Döwranow',
|
||||
guarantor1PassportSerie: 'I', guarantor1PassportNumber: '789456',
|
||||
guarantor1CardNumber: '4666666666666666', guarantor1CardName: 'DÖWRAN DÖWRANOW',
|
||||
guarantor1CardExpMonth: '11', guarantor1CardExpYear: '2027', guarantor1Salary: 3500,
|
||||
id: "LOM-0003",
|
||||
loanType: "Ipoteka karzy",
|
||||
createdAt: "2025-01-20 14:30",
|
||||
region: "Balkan",
|
||||
branch: "Balkanabat şahamçasy",
|
||||
firstName: "Serdar",
|
||||
lastName: "Durdyýew",
|
||||
phone: "+99363345678",
|
||||
status: "IŞLENÝÄR",
|
||||
loanAmount: 50000,
|
||||
loanHistory: "positive",
|
||||
patronicName: "Annagylyjowiç",
|
||||
education: "high",
|
||||
marriageStatus: "MARRIED",
|
||||
dateOfBirth: "1988-07-12",
|
||||
residence: "Balkanabat, Magtymguly köçesi, 25",
|
||||
passportSerie: "II",
|
||||
passportNumber: "456123",
|
||||
passportDateOfIssue: "2016-05-18",
|
||||
passportGivenBy: "Balkan welaýatynyň Içeri işler müdirligi",
|
||||
email: "serdar.durdyyew@email.com",
|
||||
workCompany: "Balkan nebit",
|
||||
position: "Operator",
|
||||
salary: 3200,
|
||||
workStartedAt: "2015-09-01",
|
||||
cardNumber: "4555555555555555",
|
||||
cardName: "SERDAR DURDYÝEW",
|
||||
cardExpMonth: "04",
|
||||
cardExpYear: "2029",
|
||||
guarantor1Name: "Döwran",
|
||||
guarantor1Surname: "Döwranow",
|
||||
guarantor1PassportSerie: "I",
|
||||
guarantor1PassportNumber: "789456",
|
||||
guarantor1CardNumber: "4666666666666666",
|
||||
guarantor1CardName: "DÖWRAN DÖWRANOW",
|
||||
guarantor1CardExpMonth: "11",
|
||||
guarantor1CardExpYear: "2027",
|
||||
guarantor1Salary: 3500,
|
||||
},
|
||||
{
|
||||
id: 'LOM-0004', loanType: 'Telekeçilik karzy', createdAt: '2025-01-22 08:15',
|
||||
region: 'Lebap', branch: 'Türkmenabat şahamçasy',
|
||||
firstName: 'Aýna', lastName: 'Meredowa', phone: '+99365456789', status: 'RED_EDILDI',
|
||||
id: "LOM-0004",
|
||||
loanType: "Telekeçilik karzy",
|
||||
createdAt: "2025-01-22 08:15",
|
||||
region: "Lebap",
|
||||
branch: "Türkmenabat şahamçasy",
|
||||
firstName: "Aýna",
|
||||
lastName: "Meredowa",
|
||||
phone: "+99365456789",
|
||||
status: "RED_EDILDI",
|
||||
loanAmount: 25000,
|
||||
patronicName: 'Begenjowna', education: 'high', marriageStatus: 'DIVORCED',
|
||||
dateOfBirth: '1991-02-28',
|
||||
residence: 'Türkmenabat, Lebap köçesi, 8',
|
||||
passportSerie: 'I', passportNumber: '321654',
|
||||
passportDateOfIssue: '2017-11-05',
|
||||
passportGivenBy: 'Lebap welaýatynyň Içeri işler müdirligi',
|
||||
workCompany: 'Hususy telekeçi', position: 'Telekeçi',
|
||||
salary: 4000, workStartedAt: '2020-01-10',
|
||||
cardNumber: '4777777777777777', cardName: 'AÝNA MEREDOWA',
|
||||
cardExpMonth: '07', cardExpYear: '2026',
|
||||
patronicName: "Begenjowna",
|
||||
education: "high",
|
||||
marriageStatus: "DIVORCED",
|
||||
dateOfBirth: "1991-02-28",
|
||||
residence: "Türkmenabat, Lebap köçesi, 8",
|
||||
passportSerie: "I",
|
||||
passportNumber: "321654",
|
||||
passportDateOfIssue: "2017-11-05",
|
||||
passportGivenBy: "Lebap welaýatynyň Içeri işler müdirligi",
|
||||
workCompany: "Hususy telekeçi",
|
||||
position: "Telekeçi",
|
||||
salary: 4000,
|
||||
workStartedAt: "2020-01-10",
|
||||
cardNumber: "4777777777777777",
|
||||
cardName: "AÝNA MEREDOWA",
|
||||
cardExpMonth: "07",
|
||||
cardExpYear: "2026",
|
||||
},
|
||||
{
|
||||
id: 'LOM-0005', loanType: 'Sarp ediş karzy', createdAt: '2025-01-25 16:00',
|
||||
region: 'Mary', branch: 'Mary-1 şahamçasy',
|
||||
firstName: 'Begmyrat', lastName: 'Oraz', phone: '+99366567890', status: 'GARAŞYLÝAR',
|
||||
loanAmount: 8000, loanHistory: 'new',
|
||||
patronicName: 'Annageldiwiç', education: 'middle', marriageStatus: 'SINGLE',
|
||||
dateOfBirth: '2000-08-15',
|
||||
residence: 'Mary şäher, Saýat köçesi, 3',
|
||||
passportSerie: 'I', passportNumber: '567890',
|
||||
passportDateOfIssue: '2020-01-20',
|
||||
passportGivenBy: 'Mary welaýatynyň Içeri işler müdirligi',
|
||||
workCompany: 'Mary gurluşyk', position: 'Işçi',
|
||||
salary: 1200, workStartedAt: '2022-06-01',
|
||||
id: "LOM-0005",
|
||||
loanType: "Sarp ediş karzy",
|
||||
createdAt: "2025-01-25 16:00",
|
||||
region: "Mary",
|
||||
branch: "Mary-1 şahamçasy",
|
||||
firstName: "Begmyrat",
|
||||
lastName: "Oraz",
|
||||
phone: "+99366567890",
|
||||
status: "GARAŞYLÝAR",
|
||||
loanAmount: 8000,
|
||||
loanHistory: "new",
|
||||
patronicName: "Annageldiwiç",
|
||||
education: "middle",
|
||||
marriageStatus: "SINGLE",
|
||||
dateOfBirth: "2000-08-15",
|
||||
residence: "Mary şäher, Saýat köçesi, 3",
|
||||
passportSerie: "I",
|
||||
passportNumber: "567890",
|
||||
passportDateOfIssue: "2020-01-20",
|
||||
passportGivenBy: "Mary welaýatynyň Içeri işler müdirligi",
|
||||
workCompany: "Mary gurluşyk",
|
||||
position: "Işçi",
|
||||
salary: 1200,
|
||||
workStartedAt: "2022-06-01",
|
||||
},
|
||||
{
|
||||
id: 'LOM-0006', loanType: 'Bilim karzy', createdAt: '2025-01-28 10:20',
|
||||
region: 'Daşoguz', branch: 'Daşoguz şahamçasy',
|
||||
firstName: 'Gülälek', lastName: 'Saparowa', phone: '+99361678901', status: 'KANAGATLANDYRYLAN',
|
||||
id: "LOM-0006",
|
||||
loanType: "Bilim karzy",
|
||||
createdAt: "2025-01-28 10:20",
|
||||
region: "Daşoguz",
|
||||
branch: "Daşoguz şahamçasy",
|
||||
firstName: "Gülälek",
|
||||
lastName: "Saparowa",
|
||||
phone: "+99361678901",
|
||||
status: "KANAGATLANDYRYLAN",
|
||||
loanAmount: 12000,
|
||||
patronicName: 'Mämmedowna', education: 'phd', marriageStatus: 'MARRIED',
|
||||
dateOfBirth: '1985-12-03',
|
||||
residence: 'Daşoguz, Gurbansoltan eje köçesi, 12',
|
||||
passportSerie: 'II', passportNumber: '901234',
|
||||
passportDateOfIssue: '2014-08-30',
|
||||
passportGivenBy: 'Daşoguz welaýatynyň Içeri işler müdirligi',
|
||||
email: 'gulalek.saparowa@email.com',
|
||||
workCompany: 'Daşoguz uniwersiteti', position: 'Mugallym',
|
||||
salary: 2000, workStartedAt: '2016-09-01',
|
||||
cardNumber: '4888888888888888', cardName: 'GÜLÄLEK SAPAROWA',
|
||||
cardExpMonth: '02', cardExpYear: '2028',
|
||||
guarantor1Name: 'Maksat', guarantor1Surname: 'Saparow',
|
||||
guarantor1PassportSerie: 'I', guarantor1PassportNumber: '112233',
|
||||
guarantor1CardNumber: '4999999999999999', guarantor1CardName: 'MAKSAT SAPAROW',
|
||||
guarantor1CardExpMonth: '10', guarantor1CardExpYear: '2027', guarantor1Salary: 2500,
|
||||
patronicName: "Mämmedowna",
|
||||
education: "phd",
|
||||
marriageStatus: "MARRIED",
|
||||
dateOfBirth: "1985-12-03",
|
||||
residence: "Daşoguz, Gurbansoltan eje köçesi, 12",
|
||||
passportSerie: "II",
|
||||
passportNumber: "901234",
|
||||
passportDateOfIssue: "2014-08-30",
|
||||
passportGivenBy: "Daşoguz welaýatynyň Içeri işler müdirligi",
|
||||
email: "gulalek.saparowa@email.com",
|
||||
workCompany: "Daşoguz uniwersiteti",
|
||||
position: "Mugallym",
|
||||
salary: 2000,
|
||||
workStartedAt: "2016-09-01",
|
||||
cardNumber: "4888888888888888",
|
||||
cardName: "GÜLÄLEK SAPAROWA",
|
||||
cardExpMonth: "02",
|
||||
cardExpYear: "2028",
|
||||
guarantor1Name: "Maksat",
|
||||
guarantor1Surname: "Saparow",
|
||||
guarantor1PassportSerie: "I",
|
||||
guarantor1PassportNumber: "112233",
|
||||
guarantor1CardNumber: "4999999999999999",
|
||||
guarantor1CardName: "MAKSAT SAPAROW",
|
||||
guarantor1CardExpMonth: "10",
|
||||
guarantor1CardExpYear: "2027",
|
||||
guarantor1Salary: 2500,
|
||||
},
|
||||
{
|
||||
id: 'LOM-0007', loanType: 'Awtoulag karzy', createdAt: '2025-02-01 13:45',
|
||||
region: 'Aşgabat', branch: 'Garaşsyzlyk şahamçasy',
|
||||
firstName: 'Myrat', lastName: 'Ataýew', phone: '+99362789012', status: 'IŞLENÝÄR',
|
||||
id: "LOM-0007",
|
||||
loanType: "Awtoulag karzy",
|
||||
createdAt: "2025-02-01 13:45",
|
||||
region: "Aşgabat",
|
||||
branch: "Garaşsyzlyk şahamçasy",
|
||||
firstName: "Myrat",
|
||||
lastName: "Ataýew",
|
||||
phone: "+99362789012",
|
||||
status: "IŞLENÝÄR",
|
||||
loanAmount: 35000,
|
||||
patronicName: 'Batyrowiç', education: 'high', marriageStatus: 'MARRIED',
|
||||
dateOfBirth: '1989-09-22',
|
||||
residence: 'Aşgabat, Çandybil köçesi, 45',
|
||||
passportSerie: 'I', passportNumber: '334455',
|
||||
passportDateOfIssue: '2015-12-12',
|
||||
passportGivenBy: 'Aşgabat şäheriniň Içeri işler müdirligi',
|
||||
workCompany: 'Türkmenhowaýollar', position: 'Sürüji',
|
||||
salary: 2800, workStartedAt: '2017-04-01',
|
||||
cardNumber: '4111111111112222', cardName: 'MYRAT ATAÝEW',
|
||||
cardExpMonth: '08', cardExpYear: '2027',
|
||||
patronicName: "Batyrowiç",
|
||||
education: "high",
|
||||
marriageStatus: "MARRIED",
|
||||
dateOfBirth: "1989-09-22",
|
||||
residence: "Aşgabat, Çandybil köçesi, 45",
|
||||
passportSerie: "I",
|
||||
passportNumber: "334455",
|
||||
passportDateOfIssue: "2015-12-12",
|
||||
passportGivenBy: "Aşgabat şäheriniň Içeri işler müdirligi",
|
||||
workCompany: "Türkmenhowaýollar",
|
||||
position: "Sürüji",
|
||||
salary: 2800,
|
||||
workStartedAt: "2017-04-01",
|
||||
cardNumber: "4111111111112222",
|
||||
cardName: "MYRAT ATAÝEW",
|
||||
cardExpMonth: "08",
|
||||
cardExpYear: "2027",
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
let mockStore = [...MOCK_DATA]
|
||||
let nextId = 8
|
||||
let mockStore = [...MOCK_DATA];
|
||||
let nextId = 8;
|
||||
|
||||
const delay = (ms = 300) => new Promise((r) => setTimeout(r, ms))
|
||||
const delay = (ms = 300) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
function applyMockFilters(
|
||||
params: LoanOrderMobileListParams,
|
||||
): PaginatedResponse<LoanOrderMobile> {
|
||||
const page = params.page ?? 1
|
||||
const perPage = params.perPage ?? 25
|
||||
function applyMockFilters(params: LoanOrderMobileListParams): PaginatedResponse<LoanOrderMobile> {
|
||||
const page = params.page ?? 1;
|
||||
const perPage = params.perPage ?? 25;
|
||||
|
||||
let result = [...mockStore]
|
||||
let result = [...mockStore];
|
||||
|
||||
if (params.search) {
|
||||
const q = params.search.toLowerCase()
|
||||
const q = params.search.toLowerCase();
|
||||
result = result.filter(
|
||||
(r) =>
|
||||
r.firstName.toLowerCase().includes(q) ||
|
||||
r.lastName.toLowerCase().includes(q) ||
|
||||
r.phone.includes(q) ||
|
||||
r.id.toLowerCase().includes(q),
|
||||
)
|
||||
);
|
||||
}
|
||||
if (params.region) result = result.filter((r) => r.region === params.region)
|
||||
if (params.status) result = result.filter((r) => r.status === params.status)
|
||||
if (params.branch) result = result.filter((r) => r.branch === params.branch)
|
||||
if (params.region) result = result.filter((r) => r.region === params.region);
|
||||
if (params.status) result = result.filter((r) => r.status === params.status);
|
||||
if (params.branch) result = result.filter((r) => r.branch === params.branch);
|
||||
|
||||
const total = result.length
|
||||
const start = (page - 1) * perPage
|
||||
const total = result.length;
|
||||
const start = (page - 1) * perPage;
|
||||
|
||||
return { data: result.slice(start, start + perPage), total }
|
||||
return { data: result.slice(start, start + perPage), total };
|
||||
}
|
||||
|
||||
// ─── API Functions ─────────────────────────────────────────────────────────────
|
||||
|
||||
export async function fetchLoanOrderMobiles(
|
||||
params: LoanOrderMobileListParams,
|
||||
): Promise<PaginatedResponse<LoanOrderMobile>> {
|
||||
export async function fetchLoanOrderMobiles(params: LoanOrderMobileListParams): Promise<PaginatedResponse<LoanOrderMobile>> {
|
||||
if (true) {
|
||||
await delay(500)
|
||||
return applyMockFilters(params)
|
||||
await delay(500);
|
||||
return applyMockFilters(params);
|
||||
}
|
||||
const { data } = await apiClient.get<PaginatedResponse<LoanOrderMobile>>(
|
||||
'/loan-order-mobiles',
|
||||
{ params },
|
||||
)
|
||||
return data
|
||||
const { data } = await apiClient.get<PaginatedResponse<LoanOrderMobile>>("/loan-order-mobiles", { params });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function deleteLoanOrderMobile(id: string): Promise<void> {
|
||||
await delay(300)
|
||||
mockStore = mockStore.filter((r) => r.id !== id)
|
||||
await delay(300);
|
||||
mockStore = mockStore.filter((r) => r.id !== id);
|
||||
}
|
||||
|
||||
export async function getLoanOrderMobileById(id: string): Promise<LoanOrderMobile> {
|
||||
await delay(300)
|
||||
const order = mockStore.find((r) => r.id === id)
|
||||
if (!order) throw new Error('Not found')
|
||||
return { ...order }
|
||||
await delay(300);
|
||||
const order = mockStore.find((r) => r.id === id);
|
||||
if (!order) throw new Error("Not found");
|
||||
return { ...order };
|
||||
}
|
||||
|
||||
export async function createLoanOrderMobile(
|
||||
payload: LoanOrderMobilePayload
|
||||
): Promise<LoanOrderMobile> {
|
||||
await delay(500)
|
||||
export async function createLoanOrderMobile(payload: LoanOrderMobilePayload): Promise<LoanOrderMobile> {
|
||||
await delay(500);
|
||||
const newOrder: LoanOrderMobile = {
|
||||
...payload,
|
||||
id: `LOM-${String(nextId++).padStart(4, '0')}`,
|
||||
createdAt: new Date().toISOString().slice(0, 16).replace('T', ' '),
|
||||
id: `LOM-${String(nextId++).padStart(4, "0")}`,
|
||||
createdAt: new Date().toISOString().slice(0, 16).replace("T", " "),
|
||||
status: payload.status as LoanOrderMobileStatus,
|
||||
}
|
||||
mockStore = [newOrder, ...mockStore]
|
||||
return newOrder
|
||||
};
|
||||
mockStore = [newOrder, ...mockStore];
|
||||
return newOrder;
|
||||
}
|
||||
|
||||
export async function updateLoanOrderMobile(
|
||||
id: string,
|
||||
payload: Partial<LoanOrderMobilePayload>
|
||||
): Promise<LoanOrderMobile> {
|
||||
await delay(500)
|
||||
const idx = mockStore.findIndex((r) => r.id === id)
|
||||
if (idx === -1) throw new Error('Not found')
|
||||
const updated = { ...mockStore[idx], ...payload } as LoanOrderMobile
|
||||
mockStore = mockStore.map((r) => (r.id === id ? updated : r))
|
||||
return updated
|
||||
export async function updateLoanOrderMobile(id: string, payload: Partial<LoanOrderMobilePayload>): Promise<LoanOrderMobile> {
|
||||
await delay(500);
|
||||
const idx = mockStore.findIndex((r) => r.id === id);
|
||||
if (idx === -1) throw new Error("Not found");
|
||||
const updated = { ...mockStore[idx], ...payload } as LoanOrderMobile;
|
||||
mockStore = mockStore.map((r) => (r.id === id ? updated : r));
|
||||
return updated;
|
||||
}
|
||||
|
||||
// ─── Branch options by region ─────────────────────────────────────────────────
|
||||
|
||||
export const BRANCHES_BY_REGION_MOBILE: Record<string, { value: string; label: string }[]> = {
|
||||
'Aşgabat': [
|
||||
{ value: 'Merkezi şahamça', label: 'Merkezi şahamça' },
|
||||
{ value: 'Garaşsyzlyk şahamçasy', label: 'Garaşsyzlyk şahamçasy' },
|
||||
{ value: 'Bitarap şahamça', label: 'Bitarap şahamça' },
|
||||
{ value: 'Aşgabat-1 şahamçasy', label: 'Aşgabat-1 şahamçasy' },
|
||||
Aşgabat: [
|
||||
{ value: "Merkezi şahamça", label: "Merkezi şahamça" },
|
||||
{ value: "Garaşsyzlyk şahamçasy", label: "Garaşsyzlyk şahamçasy" },
|
||||
{ value: "Bitarap şahamça", label: "Bitarap şahamça" },
|
||||
{ value: "Aşgabat-1 şahamçasy", label: "Aşgabat-1 şahamçasy" },
|
||||
],
|
||||
'Ahal': [
|
||||
{ value: 'Änew şahamçasy', label: 'Änew şahamçasy' },
|
||||
{ value: 'Gökdepe şahamçasy', label: 'Gökdepe şahamçasy' },
|
||||
{ value: 'Tejen şahamçasy', label: 'Tejen şahamçasy' },
|
||||
Ahal: [
|
||||
{ value: "Änew şahamçasy", label: "Änew şahamçasy" },
|
||||
{ value: "Gökdepe şahamçasy", label: "Gökdepe şahamçasy" },
|
||||
{ value: "Tejen şahamçasy", label: "Tejen şahamçasy" },
|
||||
],
|
||||
'Balkan': [
|
||||
{ value: 'Balkanabat şahamçasy', label: 'Balkanabat şahamçasy' },
|
||||
{ value: 'Türkmenbaşy şahamçasy', label: 'Türkmenbaşy şahamçasy' },
|
||||
{ value: 'Bereket şahamçasy', label: 'Bereket şahamçasy' },
|
||||
Balkan: [
|
||||
{ value: "Balkanabat şahamçasy", label: "Balkanabat şahamçasy" },
|
||||
{ value: "Türkmenbaşy şahamçasy", label: "Türkmenbaşy şahamçasy" },
|
||||
{ value: "Bereket şahamçasy", label: "Bereket şahamçasy" },
|
||||
],
|
||||
'Daşoguz': [
|
||||
{ value: 'Daşoguz şahamçasy', label: 'Daşoguz şahamçasy' },
|
||||
{ value: 'Akdepe şahamçasy', label: 'Akdepe şahamçasy' },
|
||||
{ value: 'Boldumsaz şahamçasy', label: 'Boldumsaz şahamçasy' },
|
||||
Daşoguz: [
|
||||
{ value: "Daşoguz şahamçasy", label: "Daşoguz şahamçasy" },
|
||||
{ value: "Akdepe şahamçasy", label: "Akdepe şahamçasy" },
|
||||
{ value: "Boldumsaz şahamçasy", label: "Boldumsaz şahamçasy" },
|
||||
],
|
||||
'Lebap': [
|
||||
{ value: 'Türkmenabat şahamçasy', label: 'Türkmenabat şahamçasy' },
|
||||
{ value: 'Seýdi şahamçasy', label: 'Seýdi şahamçasy' },
|
||||
{ value: 'Kerki şahamçasy', label: 'Kerki şahamçasy' },
|
||||
Lebap: [
|
||||
{ value: "Türkmenabat şahamçasy", label: "Türkmenabat şahamçasy" },
|
||||
{ value: "Seýdi şahamçasy", label: "Seýdi şahamçasy" },
|
||||
{ value: "Kerki şahamçasy", label: "Kerki şahamçasy" },
|
||||
],
|
||||
'Mary': [
|
||||
{ value: 'Mary-1 şahamçasy', label: 'Mary-1 şahamçasy' },
|
||||
{ value: 'Mary-2 şahamçasy', label: 'Mary-2 şahamçasy' },
|
||||
{ value: 'Baýramaly şahamçasy', label: 'Baýramaly şahamçasy' },
|
||||
Mary: [
|
||||
{ value: "Mary-1 şahamçasy", label: "Mary-1 şahamçasy" },
|
||||
{ value: "Mary-2 şahamçasy", label: "Mary-2 şahamçasy" },
|
||||
{ value: "Baýramaly şahamçasy", label: "Baýramaly şahamçasy" },
|
||||
],
|
||||
'Arkadag': [
|
||||
{ value: 'Arkadag şahamçasy', label: 'Arkadag şahamçasy' },
|
||||
],
|
||||
}
|
||||
Arkadag: [{ value: "Arkadag şahamçasy", label: "Arkadag şahamçasy" }],
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, useCallback, useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
FileText,
|
||||
@@ -19,9 +20,10 @@ import {
|
||||
} from "@/features/loanOrderMobiles/hooks/useLoanOrderMobiles";
|
||||
import type {
|
||||
LoanOrderMobile,
|
||||
LoanOrderMobilePayload,
|
||||
} from "@/features/loanOrderMobiles/api/loanOrderMobilesApi";
|
||||
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";
|
||||
|
||||
// ─── Static options ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -127,129 +129,17 @@ function BentoCard({
|
||||
);
|
||||
}
|
||||
|
||||
// ─── FormState ────────────────────────────────────────────────────────────────
|
||||
// ─── Form errors helper ──────────────────────────────────────────────────────
|
||||
|
||||
interface FormState {
|
||||
status: string;
|
||||
loanType: string;
|
||||
region: string;
|
||||
branch: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
patronicName: string;
|
||||
education: string;
|
||||
marriageStatus: string;
|
||||
dateOfBirth: string;
|
||||
residence: string;
|
||||
currentResidence: string;
|
||||
passportSerie: string;
|
||||
passportNumber: string;
|
||||
passportDateOfIssue: string;
|
||||
passportGivenBy: string;
|
||||
bornPlace: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
phoneAdditional: string;
|
||||
homePhone: string;
|
||||
workCompany: string;
|
||||
workHrPhone: string;
|
||||
workRegion: string;
|
||||
workProvince: string;
|
||||
position: string;
|
||||
salary: string;
|
||||
workStartedAt: string;
|
||||
passportPage1: File | null;
|
||||
passportPage23: File | null;
|
||||
passportPage89: File | null;
|
||||
passportPage32: File | null;
|
||||
note: string;
|
||||
loanAmount: string;
|
||||
loanHistory: string;
|
||||
cardNumber: string;
|
||||
cardName: string;
|
||||
cardExpMonth: string;
|
||||
cardExpYear: string;
|
||||
guarantor1Name: string;
|
||||
guarantor1Surname: string;
|
||||
guarantor1Patronic: string;
|
||||
guarantor1PassportSerie: string;
|
||||
guarantor1PassportNumber: string;
|
||||
guarantor1CardNumber: string;
|
||||
guarantor1CardName: string;
|
||||
guarantor1CardExpMonth: string;
|
||||
guarantor1CardExpYear: string;
|
||||
guarantor1Salary: string;
|
||||
}
|
||||
type FlatErrors = Partial<Record<keyof LoanOrderMobileFormData, string>>
|
||||
|
||||
type FormErrors = Partial<Record<keyof FormState, string>>;
|
||||
|
||||
const INITIAL_STATE: FormState = {
|
||||
status: "GARAŞYLÝAR", loanType: "", region: "Aşgabat", branch: "",
|
||||
firstName: "", lastName: "", patronicName: "", education: "",
|
||||
marriageStatus: "", dateOfBirth: "", residence: "", currentResidence: "",
|
||||
passportSerie: "", passportNumber: "", passportDateOfIssue: "",
|
||||
passportGivenBy: "", bornPlace: "", email: "", phone: "",
|
||||
phoneAdditional: "", homePhone: "", workCompany: "", workHrPhone: "",
|
||||
workRegion: "Aşgabat", workProvince: "", position: "", salary: "",
|
||||
workStartedAt: "", passportPage1: null, passportPage23: null,
|
||||
passportPage89: null, passportPage32: null, note: "", loanAmount: "",
|
||||
loanHistory: "", cardNumber: "", cardName: "", cardExpMonth: "", cardExpYear: "",
|
||||
guarantor1Name: "", guarantor1Surname: "", guarantor1Patronic: "",
|
||||
guarantor1PassportSerie: "", guarantor1PassportNumber: "",
|
||||
guarantor1CardNumber: "", guarantor1CardName: "",
|
||||
guarantor1CardExpMonth: "", guarantor1CardExpYear: "", guarantor1Salary: "",
|
||||
};
|
||||
|
||||
function mapToFormState(order: LoanOrderMobile): FormState {
|
||||
return {
|
||||
status: order.status ?? "GARAŞYLÝAR",
|
||||
loanType: order.loanType ?? "",
|
||||
region: order.region ?? "Aşgabat",
|
||||
branch: order.branch ?? "",
|
||||
firstName: order.firstName ?? "",
|
||||
lastName: order.lastName ?? "",
|
||||
patronicName: order.patronicName ?? "",
|
||||
education: order.education ?? "",
|
||||
marriageStatus: order.marriageStatus ?? "",
|
||||
dateOfBirth: order.dateOfBirth ?? "",
|
||||
residence: order.residence ?? "",
|
||||
currentResidence: order.currentResidence ?? "",
|
||||
passportSerie: order.passportSerie ?? "",
|
||||
passportNumber: order.passportNumber ?? "",
|
||||
passportDateOfIssue: order.passportDateOfIssue ?? "",
|
||||
passportGivenBy: order.passportGivenBy ?? "",
|
||||
bornPlace: order.bornPlace ?? "",
|
||||
email: order.email ?? "",
|
||||
phone: order.phone ?? "",
|
||||
phoneAdditional: order.phoneAdditional ?? "",
|
||||
homePhone: order.homePhone ?? "",
|
||||
workCompany: order.workCompany ?? "",
|
||||
workHrPhone: order.workHrPhone ?? "",
|
||||
workRegion: order.workRegion ?? "Aşgabat",
|
||||
workProvince: order.workProvince ?? "",
|
||||
position: order.position ?? "",
|
||||
salary: order.salary != null ? String(order.salary) : "",
|
||||
workStartedAt: order.workStartedAt ?? "",
|
||||
passportPage1: null, passportPage23: null,
|
||||
passportPage89: null, passportPage32: null,
|
||||
note: order.note ?? "",
|
||||
loanAmount: order.loanAmount != null ? String(order.loanAmount) : "",
|
||||
loanHistory: order.loanHistory ?? "",
|
||||
cardNumber: order.cardNumber ?? "",
|
||||
cardName: order.cardName ?? "",
|
||||
cardExpMonth: order.cardExpMonth ?? "",
|
||||
cardExpYear: order.cardExpYear ?? "",
|
||||
guarantor1Name: order.guarantor1Name ?? "",
|
||||
guarantor1Surname: order.guarantor1Surname ?? "",
|
||||
guarantor1Patronic: order.guarantor1Patronic ?? "",
|
||||
guarantor1PassportSerie: order.guarantor1PassportSerie ?? "",
|
||||
guarantor1PassportNumber: order.guarantor1PassportNumber ?? "",
|
||||
guarantor1CardNumber: order.guarantor1CardNumber ?? "",
|
||||
guarantor1CardName: order.guarantor1CardName ?? "",
|
||||
guarantor1CardExpMonth: order.guarantor1CardExpMonth ?? "",
|
||||
guarantor1CardExpYear: order.guarantor1CardExpYear ?? "",
|
||||
guarantor1Salary: order.guarantor1Salary != null ? String(order.guarantor1Salary) : "",
|
||||
};
|
||||
function flattenErrors(errors: Record<string, { message?: string } | undefined>): FlatErrors {
|
||||
const result: FlatErrors = {}
|
||||
for (const key of Object.keys(errors)) {
|
||||
const msg = errors[key]?.message
|
||||
if (msg) result[key as keyof LoanOrderMobileFormData] = msg
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// ─── Step definitions ─────────────────────────────────────────────────────────
|
||||
@@ -259,8 +149,7 @@ interface StepDef {
|
||||
title: string;
|
||||
subtitle: string;
|
||||
icon: LucideIcon;
|
||||
fields: Array<keyof FormState>;
|
||||
validate: (form: FormState, mode: "create" | "edit") => FormErrors;
|
||||
validate: (form: LoanOrderMobileFormData, mode: "create" | "edit") => FlatErrors;
|
||||
}
|
||||
|
||||
const STEPS: StepDef[] = [
|
||||
@@ -269,113 +158,44 @@ const STEPS: StepDef[] = [
|
||||
title: "Karz",
|
||||
subtitle: "Görnüş, möçber & lokasiýa",
|
||||
icon: FileText,
|
||||
fields: ["loanType", "loanAmount", "region", "branch"],
|
||||
validate: (form) => {
|
||||
const e: FormErrors = {};
|
||||
if (!form.loanType) e.loanType = "Karz görnüşi — hökmany";
|
||||
if (!form.loanAmount) e.loanAmount = "Karz möçberi — hökmany";
|
||||
if (!form.region) e.region = "Welaýat — hökmany";
|
||||
if (!form.branch) e.branch = "Şahamça — hökmany";
|
||||
return e;
|
||||
},
|
||||
validate: (form, mode) => validateStep(0, form, mode),
|
||||
},
|
||||
{
|
||||
id: "personal",
|
||||
title: "Şahsy & Pasport",
|
||||
subtitle: "Şahsyýet & pasport",
|
||||
icon: User,
|
||||
fields: [
|
||||
"firstName", "lastName", "education", "marriageStatus",
|
||||
"dateOfBirth", "residence", "passportSerie", "passportNumber",
|
||||
"passportDateOfIssue", "passportGivenBy",
|
||||
],
|
||||
validate: (form) => {
|
||||
const e: FormErrors = {};
|
||||
if (!form.firstName) e.firstName = "Ady — hökmany";
|
||||
if (!form.lastName) e.lastName = "Familiýasy — hökmany";
|
||||
if (!form.education) e.education = "Bilimi — hökmany";
|
||||
if (!form.marriageStatus) e.marriageStatus = "Maşgala ýagdaýy — hökmany";
|
||||
if (!form.dateOfBirth) e.dateOfBirth = "Doglan güni — hökmany";
|
||||
if (!form.residence) e.residence = "Ýazgy edilen salgy — hökmany";
|
||||
if (!form.passportSerie) e.passportSerie = "Pasport seriýasy — hökmany";
|
||||
if (!form.passportNumber) e.passportNumber = "Pasport belgisi — hökmany";
|
||||
if (!form.passportDateOfIssue) e.passportDateOfIssue = "Pasport berlen senesi — hökmany";
|
||||
if (!form.passportGivenBy) e.passportGivenBy = "Kim tarapyndan berildi — hökmany";
|
||||
return e;
|
||||
},
|
||||
validate: (form, mode) => validateStep(1, form, mode),
|
||||
},
|
||||
{
|
||||
id: "contact",
|
||||
title: "Habarlaşmak & Iş",
|
||||
subtitle: "Telefon & iş",
|
||||
icon: Phone,
|
||||
fields: ["phone", "workCompany", "position", "salary", "workStartedAt"],
|
||||
validate: (form) => {
|
||||
const e: FormErrors = {};
|
||||
if (!form.phone) {
|
||||
e.phone = "Telefon — hökmany";
|
||||
} else if (form.phone.replace(/\D/g, "").length < 8) {
|
||||
e.phone = "Telefon belgisi nädogry";
|
||||
}
|
||||
if (!form.workCompany) e.workCompany = "Kärhananyň ady — hökmany";
|
||||
if (!form.position) e.position = "Wezipe — hökmany";
|
||||
if (!form.salary) e.salary = "Zähmet haky — hökmany";
|
||||
if (!form.workStartedAt) e.workStartedAt = "Işe başlan wagty — hökmany";
|
||||
return e;
|
||||
},
|
||||
validate: (form, mode) => validateStep(2, form, mode),
|
||||
},
|
||||
{
|
||||
id: "card",
|
||||
title: "Kart & Zamun",
|
||||
subtitle: "Töleg & zamun",
|
||||
icon: CreditCard,
|
||||
fields: [
|
||||
"cardNumber", "cardName", "cardExpMonth", "cardExpYear",
|
||||
"guarantor1Name", "guarantor1Surname", "guarantor1PassportSerie",
|
||||
"guarantor1PassportNumber", "guarantor1CardNumber", "guarantor1CardName",
|
||||
"guarantor1CardExpMonth", "guarantor1CardExpYear", "guarantor1Salary",
|
||||
],
|
||||
validate: (form) => {
|
||||
const e: FormErrors = {};
|
||||
if (!form.cardNumber) e.cardNumber = "Kart belgisi — hökmany";
|
||||
if (!form.cardName) e.cardName = "Kartdaky ady — hökmany";
|
||||
if (!form.cardExpMonth) e.cardExpMonth = "Kart möhleti (aý) — hökmany";
|
||||
if (!form.cardExpYear) e.cardExpYear = "Kart möhleti (ýyl) — hökmany";
|
||||
if (!form.guarantor1Name) e.guarantor1Name = "Zamunyň ady — hökmany";
|
||||
if (!form.guarantor1Surname) e.guarantor1Surname = "Zamunyň familiýasy — hökmany";
|
||||
if (!form.guarantor1PassportSerie) e.guarantor1PassportSerie = "Pasport seriýasy — hökmany";
|
||||
if (!form.guarantor1PassportNumber) e.guarantor1PassportNumber = "Pasport belgisi — hökmany";
|
||||
if (!form.guarantor1CardNumber) e.guarantor1CardNumber = "Kart belgisi — hökmany";
|
||||
if (!form.guarantor1CardName) e.guarantor1CardName = "Kartdaky ady — hökmany";
|
||||
if (!form.guarantor1CardExpMonth) e.guarantor1CardExpMonth = "Möhleti (aý) — hökmany";
|
||||
if (!form.guarantor1CardExpYear) e.guarantor1CardExpYear = "Möhleti (ýyl) — hökmany";
|
||||
if (!form.guarantor1Salary) e.guarantor1Salary = "Ortaca zähmet haky — hökmany";
|
||||
return e;
|
||||
},
|
||||
validate: (form, mode) => validateStep(3, form, mode),
|
||||
},
|
||||
{
|
||||
id: "files",
|
||||
title: "Faýllar & Status",
|
||||
subtitle: "Resminamalar",
|
||||
icon: Upload,
|
||||
fields: ["passportPage1", "passportPage23"],
|
||||
validate: (form, mode) => {
|
||||
const e: FormErrors = {};
|
||||
if (mode === "create") {
|
||||
if (!form.passportPage1) e.passportPage1 = "Pasport (sahypa 1) hökmany";
|
||||
if (!form.passportPage23) e.passportPage23 = "Pasport (sahypa 2-3) hökmany";
|
||||
}
|
||||
return e;
|
||||
},
|
||||
validate: (form, mode) => validateStep(4, form, mode),
|
||||
},
|
||||
];
|
||||
|
||||
// ─── Shared step content props ────────────────────────────────────────────────
|
||||
|
||||
interface StepContentProps {
|
||||
form: FormState;
|
||||
errors: FormErrors;
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void;
|
||||
form: LoanOrderMobileFormData;
|
||||
errors: FlatErrors;
|
||||
set: <K extends keyof LoanOrderMobileFormData>(k: K, v: LoanOrderMobileFormData[K]) => void;
|
||||
}
|
||||
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
@@ -712,8 +532,13 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
const updateMutation = useUpdateLoanOrderMobile();
|
||||
const isPending = createMutation.isPending || updateMutation.isPending;
|
||||
|
||||
const [form, setForm] = useState<FormState>(() => initialData ? mapToFormState(initialData) : INITIAL_STATE);
|
||||
const [errors, setErrors] = useState<FormErrors>({});
|
||||
const {
|
||||
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors,
|
||||
} = useForm<LoanOrderMobileFormData>({ defaultValues: initialData ? { ...DEFAULT_FORM_VALUES, ...mapInitial(initialData) } : DEFAULT_FORM_VALUES });
|
||||
|
||||
const form = watch();
|
||||
const errors = useMemo(() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>), [rhfErrors]);
|
||||
|
||||
const [currentStep, setCurrentStep] = useState(0);
|
||||
const [visited, setVisited] = useState<Set<number>>(
|
||||
() => mode === "edit" ? new Set(STEPS.map((_, i) => i)) : new Set<number>(),
|
||||
@@ -727,10 +552,10 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
return out;
|
||||
}, [form, mode, visited]);
|
||||
|
||||
const set = useCallback(<K extends keyof FormState>(key: K, value: FormState[K]) => {
|
||||
setForm((prev) => ({ ...prev, [key]: value }));
|
||||
setErrors((prev) => ({ ...prev, [key]: undefined }));
|
||||
}, []);
|
||||
const set = useCallback(<K extends keyof LoanOrderMobileFormData>(key: K, value: LoanOrderMobileFormData[K]) => {
|
||||
(setValue as (name: K, val: LoanOrderMobileFormData[K]) => void)(key, value);
|
||||
clearErrors(key);
|
||||
}, [setValue, clearErrors]);
|
||||
|
||||
const stepProps = useMemo(() => ({ form, errors, set }), [form, errors, set]);
|
||||
|
||||
@@ -743,11 +568,9 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
markVisited(currentStep);
|
||||
const errs = STEPS[currentStep].validate(form, mode);
|
||||
if (Object.keys(errs).length > 0) {
|
||||
setErrors(errs);
|
||||
toast.error("Dogry maglumat girizmegiňizi haýyş edýäris.");
|
||||
return;
|
||||
}
|
||||
setErrors({});
|
||||
if (currentStep < STEPS.length - 1) {
|
||||
setCurrentStep(currentStep + 1);
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
@@ -757,7 +580,6 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
const handleBack = () => {
|
||||
if (currentStep > 0) {
|
||||
markVisited(currentStep);
|
||||
setErrors({});
|
||||
setCurrentStep(currentStep - 1);
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
}
|
||||
@@ -765,21 +587,19 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
|
||||
const handleGoTo = (i: number) => {
|
||||
markVisited(currentStep);
|
||||
setErrors({});
|
||||
setCurrentStep(i);
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
};
|
||||
|
||||
// ── Submit ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const handleSubmit = () => {
|
||||
const doSubmit = () => {
|
||||
setVisited(new Set(STEPS.map((_, i) => i)));
|
||||
|
||||
const allErrors: FormErrors = {};
|
||||
const allErrors: FlatErrors = {};
|
||||
for (const step of STEPS) Object.assign(allErrors, step.validate(form, mode));
|
||||
|
||||
if (Object.keys(allErrors).length > 0) {
|
||||
setErrors(allErrors);
|
||||
toast.error("Käbir hökmany meýdanlar doldurylan däldir.");
|
||||
for (let i = 0; i < STEPS.length; i++) {
|
||||
if (Object.keys(STEPS[i].validate(form, mode)).length > 0) {
|
||||
@@ -790,53 +610,7 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
return;
|
||||
}
|
||||
|
||||
const payload: LoanOrderMobilePayload = {
|
||||
status: form.status,
|
||||
loanType: form.loanType,
|
||||
region: form.region,
|
||||
branch: form.branch,
|
||||
firstName: form.firstName,
|
||||
lastName: form.lastName,
|
||||
patronicName: form.patronicName || undefined,
|
||||
education: form.education,
|
||||
marriageStatus: form.marriageStatus,
|
||||
dateOfBirth: form.dateOfBirth,
|
||||
residence: form.residence,
|
||||
currentResidence: form.currentResidence || undefined,
|
||||
passportSerie: form.passportSerie,
|
||||
passportNumber: form.passportNumber,
|
||||
passportDateOfIssue: form.passportDateOfIssue,
|
||||
passportGivenBy: form.passportGivenBy,
|
||||
bornPlace: form.bornPlace || undefined,
|
||||
email: form.email || undefined,
|
||||
phone: form.phone,
|
||||
phoneAdditional: form.phoneAdditional || undefined,
|
||||
homePhone: form.homePhone || undefined,
|
||||
workCompany: form.workCompany,
|
||||
workHrPhone: form.workHrPhone || undefined,
|
||||
workRegion: form.workRegion || undefined,
|
||||
workProvince: form.workProvince || undefined,
|
||||
position: form.position,
|
||||
salary: Number(form.salary),
|
||||
workStartedAt: form.workStartedAt,
|
||||
note: form.note || undefined,
|
||||
loanAmount: Number(form.loanAmount) || undefined,
|
||||
loanHistory: form.loanHistory || undefined,
|
||||
cardNumber: form.cardNumber || undefined,
|
||||
cardName: form.cardName || undefined,
|
||||
cardExpMonth: form.cardExpMonth || undefined,
|
||||
cardExpYear: form.cardExpYear || undefined,
|
||||
guarantor1Name: form.guarantor1Name || undefined,
|
||||
guarantor1Surname: form.guarantor1Surname || undefined,
|
||||
guarantor1Patronic: form.guarantor1Patronic || undefined,
|
||||
guarantor1PassportSerie: form.guarantor1PassportSerie || undefined,
|
||||
guarantor1PassportNumber: form.guarantor1PassportNumber || undefined,
|
||||
guarantor1CardNumber: form.guarantor1CardNumber || undefined,
|
||||
guarantor1CardName: form.guarantor1CardName || undefined,
|
||||
guarantor1CardExpMonth: form.guarantor1CardExpMonth || undefined,
|
||||
guarantor1CardExpYear: form.guarantor1CardExpYear || undefined,
|
||||
guarantor1Salary: Number(form.guarantor1Salary) || undefined,
|
||||
};
|
||||
const payload = buildPayload(getValues());
|
||||
|
||||
if (mode === "create") {
|
||||
createMutation.mutate(payload, { onSuccess: () => navigate("/loan-order-mobiles") });
|
||||
@@ -900,7 +674,7 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
onPrev={currentStep > 0 ? handleBack : undefined}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={isLastStep ? handleSubmit : undefined}
|
||||
onSubmit={isLastStep ? doSubmit : undefined}
|
||||
submitLabel={
|
||||
mode === "create"
|
||||
? (t("loanOrderMobiles.createButton") || "Karz sargyt döredüň")
|
||||
@@ -913,4 +687,54 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function mapInitial(order: LoanOrderMobile): Partial<LoanOrderMobileFormData> {
|
||||
return {
|
||||
status: order.status ?? "GARAŞYLÝAR",
|
||||
loanType: order.loanType ?? "",
|
||||
region: order.region ?? "Aşgabat",
|
||||
branch: order.branch ?? "",
|
||||
firstName: order.firstName ?? "",
|
||||
lastName: order.lastName ?? "",
|
||||
patronicName: order.patronicName ?? "",
|
||||
education: order.education ?? "",
|
||||
marriageStatus: order.marriageStatus ?? "",
|
||||
dateOfBirth: order.dateOfBirth ?? "",
|
||||
residence: order.residence ?? "",
|
||||
currentResidence: order.currentResidence ?? "",
|
||||
passportSerie: order.passportSerie ?? "",
|
||||
passportNumber: order.passportNumber ?? "",
|
||||
passportDateOfIssue: order.passportDateOfIssue ?? "",
|
||||
passportGivenBy: order.passportGivenBy ?? "",
|
||||
bornPlace: order.bornPlace ?? "",
|
||||
email: order.email ?? "",
|
||||
phone: order.phone ?? "",
|
||||
phoneAdditional: order.phoneAdditional ?? "",
|
||||
homePhone: order.homePhone ?? "",
|
||||
workCompany: order.workCompany ?? "",
|
||||
workHrPhone: order.workHrPhone ?? "",
|
||||
workRegion: order.workRegion ?? "Aşgabat",
|
||||
workProvince: order.workProvince ?? "",
|
||||
position: order.position ?? "",
|
||||
salary: order.salary != null ? String(order.salary) : "",
|
||||
workStartedAt: order.workStartedAt ?? "",
|
||||
note: order.note ?? "",
|
||||
loanAmount: order.loanAmount != null ? String(order.loanAmount) : "",
|
||||
loanHistory: order.loanHistory ?? "",
|
||||
cardNumber: order.cardNumber ?? "",
|
||||
cardName: order.cardName ?? "",
|
||||
cardExpMonth: order.cardExpMonth ?? "",
|
||||
cardExpYear: order.cardExpYear ?? "",
|
||||
guarantor1Name: order.guarantor1Name ?? "",
|
||||
guarantor1Surname: order.guarantor1Surname ?? "",
|
||||
guarantor1Patronic: order.guarantor1Patronic ?? "",
|
||||
guarantor1PassportSerie: order.guarantor1PassportSerie ?? "",
|
||||
guarantor1PassportNumber: order.guarantor1PassportNumber ?? "",
|
||||
guarantor1CardNumber: order.guarantor1CardNumber ?? "",
|
||||
guarantor1CardName: order.guarantor1CardName ?? "",
|
||||
guarantor1CardExpMonth: order.guarantor1CardExpMonth ?? "",
|
||||
guarantor1CardExpYear: order.guarantor1CardExpYear ?? "",
|
||||
guarantor1Salary: order.guarantor1Salary != null ? String(order.guarantor1Salary) : "",
|
||||
};
|
||||
}
|
||||
164
src/features/loanOrderMobiles/schemas/loanOrderMobile.schema.ts
Normal file
164
src/features/loanOrderMobiles/schemas/loanOrderMobile.schema.ts
Normal file
@@ -0,0 +1,164 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
const fileRequired = z.custom<File>((val) => val instanceof File, 'Faýl hökmany')
|
||||
|
||||
export const loanOrderMobileFormSchema = z.object({
|
||||
status: z.string().min(1, 'Status — hökmany'),
|
||||
loanType: z.string().min(1, 'Karz görnüşi — hökmany'),
|
||||
region: z.string().min(1, 'Welaýat — hökmany'),
|
||||
branch: z.string().min(1, 'Şahamça — hökmany'),
|
||||
firstName: z.string().min(1, 'Ady — hökmany'),
|
||||
lastName: z.string().min(1, 'Familiýasy — hökmany'),
|
||||
patronicName: z.string().optional(),
|
||||
education: z.string().min(1, 'Bilimi — hökmany'),
|
||||
marriageStatus: z.string().min(1, 'Maşgala ýagdaýy — hökmany'),
|
||||
dateOfBirth: z.string().min(1, 'Doglan güni — hökmany'),
|
||||
residence: z.string().min(1, 'Ýazgy edilen salgy — hökmany'),
|
||||
currentResidence: z.string().optional(),
|
||||
passportSerie: z.string().min(1, 'Pasport seriýasy — hökmany'),
|
||||
passportNumber: z.string().min(1, 'Pasport belgisi — hökmany'),
|
||||
passportDateOfIssue: z.string().min(1, 'Pasport berlen senesi — hökmany'),
|
||||
passportGivenBy: z.string().min(1, 'Kim tarapyndan berildi — hökmany'),
|
||||
bornPlace: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
phone: z.string()
|
||||
.min(1, 'Telefon — hökmany')
|
||||
.refine((val) => val.replace(/\D/g, '').length >= 8, { message: 'Telefon belgisi nädogry' }),
|
||||
phoneAdditional: z.string().optional(),
|
||||
homePhone: z.string().optional(),
|
||||
workCompany: z.string().min(1, 'Kärhananyň ady — hökmany'),
|
||||
workHrPhone: z.string().optional(),
|
||||
workRegion: z.string().optional(),
|
||||
workProvince: z.string().optional(),
|
||||
position: z.string().min(1, 'Wezipe — hökmany'),
|
||||
salary: z.string().min(1, 'Zähmet haky — hökmany'),
|
||||
workStartedAt: z.string().min(1, 'Işe başlan wagty — hökmany'),
|
||||
passportPage1: z.custom<File | null>().nullable(),
|
||||
passportPage23: z.custom<File | null>().nullable(),
|
||||
passportPage89: z.custom<File | null>().nullable(),
|
||||
passportPage32: z.custom<File | null>().nullable(),
|
||||
note: z.string().optional(),
|
||||
loanAmount: z.string().min(1, 'Karz möçberi — hökmany'),
|
||||
loanHistory: z.string().optional(),
|
||||
cardNumber: z.string().min(1, 'Kart belgisi — hökmany'),
|
||||
cardName: z.string().min(1, 'Kartdaky ady — hökmany'),
|
||||
cardExpMonth: z.string().min(1, 'Kart möhleti (aý) — hökmany'),
|
||||
cardExpYear: z.string().min(1, 'Kart möhleti (ýyl) — hökmany'),
|
||||
guarantor1Name: z.string().min(1, 'Zamunyň ady — hökmany'),
|
||||
guarantor1Surname: z.string().min(1, 'Zamunyň familiýasy — hökmany'),
|
||||
guarantor1Patronic: z.string().optional(),
|
||||
guarantor1PassportSerie: z.string().min(1, 'Pasport seriýasy — hökmany'),
|
||||
guarantor1PassportNumber: z.string().min(1, 'Pasport belgisi — hökmany'),
|
||||
guarantor1CardNumber: z.string().min(1, 'Kart belgisi — hökmany'),
|
||||
guarantor1CardName: z.string().min(1, 'Kartdaky ady — hökmany'),
|
||||
guarantor1CardExpMonth: z.string().min(1, 'Möhleti (aý) — hökmany'),
|
||||
guarantor1CardExpYear: z.string().min(1, 'Möhleti (ýyl) — hökmany'),
|
||||
guarantor1Salary: z.string().min(1, 'Ortaca zähmet haky — hökmany'),
|
||||
})
|
||||
|
||||
export type LoanOrderMobileFormData = z.infer<typeof loanOrderMobileFormSchema>
|
||||
|
||||
export const stepSchemas: Record<number, z.ZodType<Partial<LoanOrderMobileFormData>>> = {
|
||||
0: loanOrderMobileFormSchema.pick({ loanType: true, loanAmount: true, region: true, branch: true }),
|
||||
1: loanOrderMobileFormSchema.pick({
|
||||
firstName: true, lastName: true, education: true,
|
||||
marriageStatus: true, dateOfBirth: true, residence: true,
|
||||
passportSerie: true, passportNumber: true,
|
||||
passportDateOfIssue: true, passportGivenBy: true,
|
||||
}),
|
||||
2: loanOrderMobileFormSchema.pick({
|
||||
phone: true, workCompany: true, position: true, salary: true, workStartedAt: true,
|
||||
}),
|
||||
3: loanOrderMobileFormSchema.pick({
|
||||
cardNumber: true, cardName: true, cardExpMonth: true, cardExpYear: true,
|
||||
guarantor1Name: true, guarantor1Surname: true,
|
||||
guarantor1PassportSerie: true, guarantor1PassportNumber: true,
|
||||
guarantor1CardNumber: true, guarantor1CardName: true,
|
||||
guarantor1CardExpMonth: true, guarantor1CardExpYear: true,
|
||||
guarantor1Salary: true,
|
||||
}),
|
||||
4: z.object({
|
||||
passportPage1: fileRequired,
|
||||
passportPage23: fileRequired,
|
||||
}),
|
||||
}
|
||||
|
||||
export function validateStep(stepIndex: number, form: LoanOrderMobileFormData, mode: 'create' | 'edit'): Partial<Record<keyof LoanOrderMobileFormData, string>> {
|
||||
if (stepIndex === 4 && mode === 'edit') return {}
|
||||
const schema = stepSchemas[stepIndex]
|
||||
const result = schema.safeParse(form)
|
||||
if (result.success) return {}
|
||||
const errors: Partial<Record<keyof LoanOrderMobileFormData, string>> = {}
|
||||
for (const issue of result.error.issues) {
|
||||
const key = issue.path[0] as keyof LoanOrderMobileFormData
|
||||
if (!errors[key]) errors[key] = issue.message
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: LoanOrderMobileFormData = {
|
||||
status: 'GARAŞYLÝAR', loanType: '', region: 'Aşgabat', branch: '',
|
||||
firstName: '', lastName: '', patronicName: '', education: '',
|
||||
marriageStatus: '', dateOfBirth: '', residence: '', currentResidence: '',
|
||||
passportSerie: '', passportNumber: '', passportDateOfIssue: '',
|
||||
passportGivenBy: '', bornPlace: '', email: '', phone: '',
|
||||
phoneAdditional: '', homePhone: '', workCompany: '', workHrPhone: '',
|
||||
workRegion: 'Aşgabat', workProvince: '', position: '', salary: '',
|
||||
workStartedAt: '', passportPage1: null, passportPage23: null,
|
||||
passportPage89: null, passportPage32: null, note: '', loanAmount: '',
|
||||
loanHistory: '', cardNumber: '', cardName: '', cardExpMonth: '', cardExpYear: '',
|
||||
guarantor1Name: '', guarantor1Surname: '', guarantor1Patronic: '',
|
||||
guarantor1PassportSerie: '', guarantor1PassportNumber: '',
|
||||
guarantor1CardNumber: '', guarantor1CardName: '',
|
||||
guarantor1CardExpMonth: '', guarantor1CardExpYear: '', guarantor1Salary: '',
|
||||
}
|
||||
|
||||
export function buildPayload(data: LoanOrderMobileFormData) {
|
||||
return {
|
||||
status: data.status,
|
||||
loanType: data.loanType,
|
||||
region: data.region,
|
||||
branch: data.branch,
|
||||
firstName: data.firstName,
|
||||
lastName: data.lastName,
|
||||
patronicName: data.patronicName || 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,
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user