From a6981e2775ebe334950b144c52845b4a42459099 Mon Sep 17 00:00:00 2001 From: "@jcarymuhammedow" Date: Thu, 14 May 2026 18:38:14 +0500 Subject: [PATCH] fixed some ui --- .../api/loanOrderMobilesApi.ts | 262 ++- .../components/loanOrderMobileForm.tsx | 1858 +++++++---------- src/features/loanOrders/api/loanOrdersApi.ts | 201 +- .../loanOrders/components/loanOrderForm.tsx | 90 +- .../cardDepartment/cardBalance/index.tsx | 2 + src/pages/cardDepartment/cardPins/index.tsx | 165 +- .../cardDepartment/cardPinsView/index.tsx | 210 +- .../cardDepartment/cardRequisites/index.tsx | 284 ++- .../cardDepartment/cardTransactions/index.tsx | 4 + .../cardDepartment/orderNewCardView/index.tsx | 378 ++-- src/pages/currencies/currencyRates/index.tsx | 209 +- .../visaMasterSberSettings/index.tsx | 204 +- .../sberPayments/index.tsx | 4 +- .../visaMasterPayments/index.tsx | 2 + .../loanOrderMobileView/index.tsx | 706 +++---- .../loanDepartment/loanOrderView/index.tsx | 569 +++-- src/pages/onlinePaymentsHistory/index.tsx | 3 + src/pages/settings/card/cardTypes/index.tsx | 2 + src/pages/settings/card/reasons/index.tsx | 2 + src/pages/settings/loan/loanTypes/index.tsx | 2 + .../settings/loan/requiredDocuments/index.tsx | 2 + .../settings/location/branches/index.tsx | 2 + .../settings/location/districts/index.tsx | 2 + .../settings/users/permissions/index.tsx | 8 +- src/pages/settings/users/roles/index.tsx | 9 +- src/pages/users/allUsers/index.tsx | 10 +- src/pages/users/clients/index.tsx | 2 + src/pages/users/clientsView/index.tsx | 406 +++- src/pages/users/operators/index.tsx | 2 + src/pages/users/operatorsView/index.tsx | 499 ++--- 30 files changed, 3093 insertions(+), 3006 deletions(-) diff --git a/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts b/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts index e5273a8..6cee8e2 100644 --- a/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts +++ b/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts @@ -145,27 +145,158 @@ export interface PaginatedResponse { // ─── Mock Data ───────────────────────────────────────────────────────────────── -const USE_MOCK = true // gerçek API hazır olunca false yap - const MOCK_DATA: LoanOrderMobile[] = [ - { id: 'LOM-0001', loanType: 'Sarp etmek karzy', createdAt: '2025-01-15 09:42', region: 'Aşgabat', branch: 'Merkezi', firstName: 'Oraz', lastName: 'Annaýew', phone: '+99361123456', status: 'GARAŞYLÝAR' }, - { id: 'LOM-0002', loanType: 'Awtoulag karzy', createdAt: '2025-01-18 11:05', region: 'Ahal', branch: 'Änew', firstName: 'Merjen', lastName: 'Hudaýewa', phone: '+99362234567', status: 'KANAGATLANDYRYLAN' }, - { id: 'LOM-0003', loanType: 'Ipoteka karzy', createdAt: '2025-01-20 14:30', region: 'Balkan', branch: 'Türkmenbaşy', firstName: 'Serdar', lastName: 'Durdyýew', phone: '+99363345678', status: 'IŞLENÝÄR' }, - { id: 'LOM-0004', loanType: 'Telekeçilik karzy', createdAt: '2025-01-22 08:15', region: 'Lebap', branch: 'Türkmenabat', firstName: 'Aýna', lastName: 'Meredowa', phone: '+99365456789', status: 'RED_EDILDI' }, - { id: 'LOM-0005', loanType: 'Sarp etmek karzy', createdAt: '2025-01-25 16:00', region: 'Mary', branch: 'Mary', firstName: 'Begmyrat',lastName: 'Oraz', phone: '+99366567890', status: 'GARAŞYLÝAR' }, - { id: 'LOM-0006', loanType: 'Bilim karzy', createdAt: '2025-01-28 10:20', region: 'Daşoguz', branch: 'Daşoguz', firstName: 'Gülälek', lastName: 'Saparowa', phone: '+99361678901', status: 'KANAGATLANDYRYLAN' }, - { id: 'LOM-0007', loanType: 'Awtoulag karzy', createdAt: '2025-02-01 13:45', region: 'Aşgabat', branch: 'Çoganly', firstName: 'Myrat', lastName: 'Ataýew', phone: '+99362789012', status: 'IŞLENÝÄR' }, - { id: 'LOM-0008', loanType: 'Ipoteka karzy', createdAt: '2025-02-03 09:00', region: 'Ahal', branch: 'Tejen', firstName: 'Ogulnur', lastName: 'Berdiýewa', phone: '+99363890123', status: 'GARAŞYLÝAR' }, - { id: 'LOM-0009', loanType: 'Telekeçilik karzy', createdAt: '2025-02-05 15:30', region: 'Balkan', branch: 'Balkanabat', firstName: 'Döwlet', lastName: 'Çaryýew', phone: '+99364901234', status: 'RED_EDILDI' }, - { id: 'LOM-0010', loanType: 'Sarp etmek karzy', createdAt: '2025-02-08 11:15', region: 'Lebap', branch: 'Farap', firstName: 'Maral', lastName: 'Ýollyýewa', phone: '+99365012345', status: 'KANAGATLANDYRYLAN' }, - { id: 'LOM-0011', loanType: 'Bilim karzy', createdAt: '2025-02-10 08:45', region: 'Mary', branch: 'Baýramaly', firstName: 'Nurmuhammet', lastName: 'Garaýew', phone: '+99366123456', status: 'GARAŞYLÝAR' }, - { id: 'LOM-0012', loanType: 'Awtoulag karzy', createdAt: '2025-02-12 14:00', region: 'Daşoguz', branch: 'Köneürgenç', firstName: 'Şemşat', lastName: 'Jumaýewa', phone: '+99361234567', status: 'IŞLENÝÄR' }, + { + 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-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', + 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', + }, + { + 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', + 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, + }, + { + 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', + }, ] +let mockStore = [...MOCK_DATA] +let nextId = 8 + +const delay = (ms = 300) => new Promise((r) => setTimeout(r, ms)) + function applyMockFilters( params: LoanOrderMobileListParams, ): PaginatedResponse { - let result = [...MOCK_DATA] + const page = params.page ?? 1 + const perPage = params.perPage ?? 25 + + let result = [...mockStore] if (params.search) { const q = params.search.toLowerCase() @@ -182,8 +313,6 @@ function applyMockFilters( if (params.branch) result = result.filter((r) => r.branch === params.branch) const total = result.length - const page = params.page ?? 1 - const perPage = params.perPage ?? 25 const start = (page - 1) * perPage return { data: result.slice(start, start + perPage), total } @@ -194,8 +323,10 @@ function applyMockFilters( export async function fetchLoanOrderMobiles( params: LoanOrderMobileListParams, ): Promise> { - if (USE_MOCK) return applyMockFilters(params) - + if (true) { + await delay(500) + return applyMockFilters(params) + } const { data } = await apiClient.get>( '/loan-order-mobiles', { params }, @@ -204,51 +335,78 @@ export async function fetchLoanOrderMobiles( } export async function deleteLoanOrderMobile(id: string): Promise { - if (USE_MOCK) { - const idx = MOCK_DATA.findIndex((r) => r.id === id) - if (idx !== -1) MOCK_DATA.splice(idx, 1) - return - } - await apiClient.delete(`/loan-order-mobiles/${id}`) + await delay(300) + mockStore = mockStore.filter((r) => r.id !== id) } export async function getLoanOrderMobileById(id: string): Promise { - if (USE_MOCK) { - const order = MOCK_DATA.find((r) => r.id === id) - if (!order) throw new Error('Not found') - return order - } - const { data } = await apiClient.get(`/loan-order-mobiles/${id}`) - return data + 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 { - if (USE_MOCK) { - const newOrder: LoanOrderMobile = { - ...payload, - id: `LOM-${String(MOCK_DATA.length + 1).padStart(4, '0')}`, - createdAt: new Date().toISOString().slice(0, 16).replace('T', ' '), - status: payload.status as LoanOrderMobileStatus, - } - MOCK_DATA.unshift(newOrder) - return newOrder + await delay(500) + const newOrder: LoanOrderMobile = { + ...payload, + id: `LOM-${String(nextId++).padStart(4, '0')}`, + createdAt: new Date().toISOString().slice(0, 16).replace('T', ' '), + status: payload.status as LoanOrderMobileStatus, } - const { data } = await apiClient.post('/loan-order-mobiles', payload) - return data + mockStore = [newOrder, ...mockStore] + return newOrder } export async function updateLoanOrderMobile( id: string, payload: Partial ): Promise { - if (USE_MOCK) { - const idx = MOCK_DATA.findIndex((r) => r.id === id) - if (idx === -1) throw new Error('Not found') - MOCK_DATA[idx] = { ...MOCK_DATA[idx], ...payload } as LoanOrderMobile - return MOCK_DATA[idx] - } - const { data } = await apiClient.put(`/loan-order-mobiles/${id}`, payload) - return data -} \ No newline at end of file + 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 = { + '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' }, + ], + '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' }, + ], + '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' }, + ], + 'Arkadag': [ + { value: 'Arkadag şahamçasy', label: 'Arkadag şahamçasy' }, + ], +} diff --git a/src/features/loanOrderMobiles/components/loanOrderMobileForm.tsx b/src/features/loanOrderMobiles/components/loanOrderMobileForm.tsx index f597a82..a3166f4 100644 --- a/src/features/loanOrderMobiles/components/loanOrderMobileForm.tsx +++ b/src/features/loanOrderMobiles/components/loanOrderMobileForm.tsx @@ -1,4 +1,4 @@ -import { useState, useCallback } from "react"; +import { useState, useCallback, useMemo } from "react"; import { useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; @@ -9,10 +9,10 @@ import { CreditCard, Upload, } from "lucide-react"; +import type { LucideIcon } from "lucide-react"; import { FormInput } from "@/components/formInput"; import { FormActions } from "@/components/formActions"; import { StepBarCards, type StepCardItem } from "@/components/stepBarV2"; -import { cn } from "@/lib/utils"; import { useCreateLoanOrderMobile, useUpdateLoanOrderMobile, @@ -21,90 +21,113 @@ import type { LoanOrderMobile, LoanOrderMobilePayload, } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi"; - -// ─── Section Wrapper ────────────────────────────────────────────────────────── - -function Section({ - title, - children, - className, -}: { - title: string; - children: React.ReactNode; - className?: string; -}) { - return ( -
-
-

{title}

-
-
{children}
-
- ); -} - -// ─── Grid helpers ───────────────────────────────────────────────────────────── - -const grid2 = "grid grid-cols-1 sm:grid-cols-2 gap-6"; -const grid3 = "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6"; -const grid4 = "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6"; +import { BRANCHES_BY_REGION_MOBILE } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi"; // ─── Static options ─────────────────────────────────────────────────────────── const REGION_OPTIONS = [ { value: "Aşgabat", label: "Aşgabat" }, - { value: "Ahal", label: "Ahal" }, - { value: "Balkan", label: "Balkan" }, + { value: "Ahal", label: "Ahal" }, + { value: "Balkan", label: "Balkan" }, { value: "Daşoguz", label: "Daşoguz" }, - { value: "Lebap", label: "Lebap" }, - { value: "Mary", label: "Mary" }, + { value: "Lebap", label: "Lebap" }, + { value: "Mary", label: "Mary" }, { value: "Arkadag", label: "Arkadag" }, ]; const EDUCATION_OPTIONS = [ - { value: "high", label: "Ýokary bilim" }, + { value: "high", label: "Ýokary bilim" }, { value: "unfinished_high", label: "Gutarylmadyk ýokary bilim" }, - { value: "masters", label: "Magistr" }, - { value: "phd", label: "Ylymlaryň doktory" }, - { value: "middle", label: "Orta mekdep" }, - { value: "school", label: "Orta bilim" }, - { value: "school_dropout", label: "Gutarylmadyk orta bilim" }, + { value: "masters", label: "Magistr" }, + { value: "phd", label: "Ylymlaryň doktory" }, + { value: "middle", label: "Orta mekdep" }, + { value: "school", label: "Orta bilim" }, + { value: "school_dropout", label: "Gutarylmadyk orta bilim" }, ]; const MARRIAGE_OPTIONS = [ - { value: "MARRIED", label: "Öýlenen / Durmuşa çykan" }, - { value: "SINGLE", label: "Öýlenmedik / Durmuşa çykmadyk" }, - { value: "DIVORCED", label: "Aýrylşan" }, - { value: "WIDOW", label: "Adamsy ýa-da aýaly aradan çykan" }, - { value: "LEGAL", label: "Raýat nika" }, + { value: "MARRIED", label: "Öýlenen / Durmuşa çykan" }, + { value: "SINGLE", label: "Öýlenmedik / Durmuşa çykmadyk" }, + { value: "DIVORCED", label: "Aýrylşan" }, + { value: "WIDOW", label: "Adamsy ýa-da aýaly aradan çykan" }, + { value: "LEGAL", label: "Raýat nika" }, ]; const STATUS_OPTIONS = [ - { value: "GARAŞYLÝAR", label: "Garaşylýar" }, - { value: "IŞLENÝÄR", label: "Işlenýär" }, + { 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" }, + { value: "RED_EDILDI", label: "Red edildi" }, ]; const LOAN_TYPE_OPTIONS = [ { value: "consumer", label: "Sarp ediş karzy" }, - { value: "mortgage", label: "Ipoteka" }, - { value: "car", label: "Awtoulag karzy" }, - { value: "student", label: "Talyplar üçin" }, - { value: "business", label: "Işewürlik karzy" }, + { value: "mortgage", label: "Ipoteka" }, + { value: "car", label: "Awtoulag karzy" }, + { value: "student", label: "Talyplar üçin" }, + { value: "business", label: "Işewürlik karzy" }, ]; const PASSPORT_SERIES_OPTIONS = [ - { value: "I", label: "I" }, + { value: "I", label: "I" }, { value: "II", label: "II" }, ]; -// ─── Form State ─────────────────────────────────────────────────────────────── +const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({ + value: String(i + 1).padStart(2, "0"), + label: String(i + 1).padStart(2, "0"), +})); + +const YEAR_OPTIONS = Array.from({ length: 15 }, (_, i) => ({ + value: String(new Date().getFullYear() + i), + label: String(new Date().getFullYear() + i), +})); + +// ─── BentoGrid / BentoCard ──────────────────────────────────────────────────── + +function BentoGrid({ + cols = 2, + children, +}: { + cols?: 1 | 2 | 3 | 4; + children: React.ReactNode; +}) { + const colClass = { + 1: "grid-cols-1", + 2: "grid-cols-1 sm:grid-cols-2", + 3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3", + 4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4", + }[cols]; + return
{children}
; +} + +function BentoCard({ + title, + span, + children, +}: { + title?: string; + span?: "full" | 2 | 3; + children: React.ReactNode; +}) { + const spanClass = + span === "full" ? "sm:col-span-full" : + span === 2 ? "sm:col-span-2" : + span === 3 ? "sm:col-span-3" : ""; + + return ( +
+ {title && ( +

+ {title} +

+ )} + {children} +
+ ); +} + +// ─── FormState ──────────────────────────────────────────────────────────────── interface FormState { status: string; @@ -161,229 +184,514 @@ interface FormState { type FormErrors = Partial>; 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: "", + 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 ?? "", + 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 ?? "", + 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 ?? "", + 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) : "", + guarantor1CardNumber: order.guarantor1CardNumber ?? "", + guarantor1CardName: order.guarantor1CardName ?? "", + guarantor1CardExpMonth: order.guarantor1CardExpMonth ?? "", + guarantor1CardExpYear: order.guarantor1CardExpYear ?? "", + guarantor1Salary: order.guarantor1Salary != null ? String(order.guarantor1Salary) : "", }; } // ─── Step definitions ───────────────────────────────────────────────────────── -// Keys that belong to each step — used for per-step validation -const STEP_FIELDS: Array> = [ - // Step 0 — Karz & Lokasiýa - ["loanType", "loanAmount", "region", "branch"], - // Step 1 — Şahsy maglumatlar & Pasport - [ - "firstName", - "lastName", - "education", - "marriageStatus", - "dateOfBirth", - "residence", - "passportSerie", - "passportNumber", - "passportDateOfIssue", - "passportGivenBy", - ], - // Step 2 — Habarlaşmak & Iş - [ - "phone", - "workCompany", - "position", - "salary", - "workStartedAt", - ], - // Step 3 — Kart & Zamun - [ - "cardNumber", - "cardName", - "cardExpMonth", - "cardExpYear", - "guarantor1Name", - "guarantor1Surname", - "guarantor1PassportSerie", - "guarantor1PassportNumber", - "guarantor1CardNumber", - "guarantor1CardName", - "guarantor1CardExpMonth", - "guarantor1CardExpYear", - "guarantor1Salary", - ], - // Step 4 — Faýllar & Status - ["passportPage1", "passportPage23"], +interface StepDef { + id: string; + title: string; + subtitle: string; + icon: LucideIcon; + fields: Array; + validate: (form: FormState, mode: "create" | "edit") => FormErrors; +} + +const STEPS: StepDef[] = [ + { + id: "loan", + 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; + }, + }, + { + 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; + }, + }, + { + 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; + }, + }, + { + 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; + }, + }, + { + 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; + }, + }, ]; -// ─── Validation ─────────────────────────────────────────────────────────────── +// ─── Shared step content props ──────────────────────────────────────────────── -function validate( - form: FormState, - t: (k: string) => string, - mode: "create" | "edit", - stepIndex?: number, -): FormErrors { - const allErrors: FormErrors = {}; +interface StepContentProps { + form: FormState; + errors: FormErrors; + set: (k: K, v: FormState[K]) => void; +} - const req = (key: keyof FormState, label: string) => { - const val = form[key]; - if (!val || (typeof val === "string" && !val.trim())) { - allErrors[key] = `${label} — ${t("required") || "hökmany"}`; - } - }; +// ─── Step panels ────────────────────────────────────────────────────────────── - req("loanType", t("Loan type") || "Karz görnüşi"); - req("region", t("Region") || "Welaýat"); - req("branch", t("Branch") || "Şahamça"); - req("firstName", t("Name") || "Ady"); - req("lastName", t("Surname") || "Familiýasy"); - req("education", t("Education") || "Bilimi"); - req("marriageStatus", t("Marriage status") || "Maşgala ýagdaýy"); - req("dateOfBirth", t("Date of birth") || "Doglan güni"); - req("residence", t("Residence (passport)") || "Ýazgy edilen salgy"); - req("passportSerie", t("Passport serie") || "Pasport seriýasy"); - req("passportNumber", t("Passport number") || "Pasport belgisi"); - req("passportDateOfIssue", t("Passport date of issue") || "Pasport berlen senesi"); - req("passportGivenBy", t("Passport given by") || "Kim tarapyndan berildi"); - req("phone", t("Phone") || "Telefon"); - req("workCompany", t("Work company name") || "Kärhananyň ady"); - req("position", t("Position") || "Wezipe"); - req("salary", t("Salary") || "Zähmet haky"); - req("workStartedAt", t("Work started at") || "Işe başlan wagty"); - req("loanAmount", t("Loan amount") || "Karz möçberi"); - req("cardNumber", t("Card number") || "Kart belgisi"); - req("cardName", t("Card name") || "Kartdaky ady"); - req("cardExpMonth", t("Card exp month") || "Kart Möhleti (aý)"); - req("cardExpYear", t("Card exp year") || "Kart Möhleti (ýyl)"); - req("guarantor1Name", t("Guarantor name") || "Zamunyň ady"); - req("guarantor1Surname", t("Guarantor surname") || "Zamunyň familiýasy"); - req("guarantor1PassportSerie", t("Guarantor passport serie") || "Pasport seriýasy (Zamun)"); - req("guarantor1PassportNumber", t("Guarantor passport number") || "Pasport belgisi (Zamun)"); - req("guarantor1CardNumber", t("Guarantor card number") || "Kart belgisi (Zamun)"); - req("guarantor1CardName", t("Guarantor card name") || "Kartdaky ady (Zamun)"); - req("guarantor1CardExpMonth", t("Guarantor card exp month") || "Möhleti (aý) (Zamun)"); - req("guarantor1CardExpYear", t("Guarantor card exp year") || "Möhleti (ýyl) (Zamun)"); - req("guarantor1Salary", t("Guarantor salary") || "Ortaca zähmet haky (Zamun)"); +function StepLoan({ form, errors, set }: StepContentProps) { + return ( +
+ + {/* Loan type — single input, no title */} + + set("loanType", v)} + options={LOAN_TYPE_OPTIONS} + placeholder="Saýlamak üçin basyň" + error={errors.loanType} + /> + - if (form.phone && form.phone.replace(/\D/g, "").length < 8) { - allErrors.phone = "Telefon belgisi nädogry"; - } + {/* Loan amount — single input, no title */} + + set("loanAmount", v)} + placeholder="0.00" + error={errors.loanAmount} + /> + + - if (mode === "create") { - if (!form.passportPage1) allErrors.passportPage1 = "Pasport (sahypa 1) hökmany"; - if (!form.passportPage23) allErrors.passportPage23 = "Pasport (sahypa 2-3) hökmany"; - } + + {/* Region — single input, no title */} + + { set("region", v); set("branch", ""); }} + options={REGION_OPTIONS} + placeholder="Saýlamak üçin basyň" + error={errors.region} + /> + - // If stepIndex provided, filter to only that step's fields - if (stepIndex !== undefined) { - const stepKeys = STEP_FIELDS[stepIndex]; - const stepErrors: FormErrors = {}; - for (const key of stepKeys) { - if (allErrors[key]) stepErrors[key] = allErrors[key]; - } - return stepErrors; - } + {/* Branch — single input, no title */} + + set("branch", v)} + options={BRANCHES_BY_REGION_MOBILE[form.region] ?? []} + placeholder="Saýlamak üçin basyň" + disabled={!form.region} + error={errors.branch} + /> + + +
+ ); +} - return allErrors; +function StepPersonal({ form, errors, set }: StepContentProps) { + return ( +
+ {/* Name row */} + + + set("firstName", v)} placeholder="Ady" error={errors.firstName} /> + + + set("lastName", v)} placeholder="Familiýasy" error={errors.lastName} /> + + + set("patronicName", v)} placeholder="Atasynyň ady" /> + + + + {/* Education / Marriage / DOB */} + + + set("education", v)} options={EDUCATION_OPTIONS} placeholder="Saýlaň" error={errors.education} /> + + + set("marriageStatus", v)} options={MARRIAGE_OPTIONS} placeholder="Saýlaň" error={errors.marriageStatus} /> + + + set("dateOfBirth", v)} error={errors.dateOfBirth} /> + + + + {/* Residence */} + + + set("residence", v)} placeholder="Ýazgy edilen salgy" error={errors.residence} /> + + + set("currentResidence", v)} placeholder="Häzirki ýaşaýyş ýeri" /> + + + set("loanHistory", v)} options={[]} placeholder="Saýlamak üçin basyň" /> + + + + {/* Passport */} + + + set("passportSerie", v)} options={PASSPORT_SERIES_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.passportSerie} /> + + + set("passportNumber", v)} placeholder="Pasport belgisi" error={errors.passportNumber} /> + + + set("passportDateOfIssue", v)} error={errors.passportDateOfIssue} /> + + + + + + set("passportGivenBy", v)} placeholder="Kim tarapyndan berildi" error={errors.passportGivenBy} /> + + + set("bornPlace", v)} placeholder="Doglan ýeri (pasport)" /> + + +
+ ); +} + +function StepContact({ form, errors, set }: StepContentProps) { + return ( +
+ {/* Contact */} + + + set("phone", v)} placeholder="61 097 651" error={errors.phone} /> + set("email", v)} placeholder="E-poçta" /> + + + set("phoneAdditional", v)} placeholder="61 097 651" /> + set("homePhone", v)} placeholder="61 097 651" /> + + + + {/* Job */} + + + set("workCompany", v)} placeholder="Kärhananyň ady" error={errors.workCompany} /> + set("workHrPhone", v)} placeholder="61 097 651" /> + + + set("workRegion", v)} options={REGION_OPTIONS} placeholder="Saýlamak üçin basyň" /> + set("workProvince", v)} options={[]} placeholder="Saýlamak üçin basyň" /> + + + + + + set("position", v)} placeholder="Wezipe" error={errors.position} /> + + + set("salary", v)} placeholder="Zähmet haky" error={errors.salary} /> + + + set("workStartedAt", v)} error={errors.workStartedAt} /> + + +
+ ); +} + +function StepCard({ form, errors, set }: StepContentProps) { + return ( +
+ {/* Salary card */} + + + set("cardNumber", v)} placeholder="Kart belgisi" error={errors.cardNumber} /> + set("cardName", v)} placeholder="Kartdaky ady" error={errors.cardName} /> + + + set("cardExpMonth", v)} options={MONTH_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.cardExpMonth} /> + set("cardExpYear", v)} options={YEAR_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.cardExpYear} /> + + + + {/* Guarantor identity */} + + + set("guarantor1Name", v)} placeholder="Zamunyň ady" error={errors.guarantor1Name} /> + + + set("guarantor1Surname", v)} placeholder="Zamunyň familiýasy" error={errors.guarantor1Surname} /> + + + set("guarantor1Patronic", v)} placeholder="Zamunyň atasynyň ady" /> + + + + {/* Guarantor passport */} + + + set("guarantor1PassportSerie", v)} options={PASSPORT_SERIES_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.guarantor1PassportSerie} /> + + + set("guarantor1PassportNumber", v)} placeholder="Pasport belgisi" error={errors.guarantor1PassportNumber} /> + + + + {/* Guarantor card */} + + + set("guarantor1CardNumber", v)} placeholder="Kart belgisi" error={errors.guarantor1CardNumber} /> + set("guarantor1CardName", v)} placeholder="Kartdaky ady" error={errors.guarantor1CardName} /> + + + set("guarantor1CardExpMonth", v)} options={MONTH_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.guarantor1CardExpMonth} /> + set("guarantor1CardExpYear", v)} options={YEAR_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.guarantor1CardExpYear} /> + set("guarantor1Salary", v)} placeholder="Ortaca zähmet haky" error={errors.guarantor1Salary} /> + + +
+ ); +} + +function StepFiles({ + form, errors, set, mode, initialData, +}: StepContentProps & { mode: "create" | "edit"; initialData?: LoanOrderMobile }) { + const existingFiles = + mode === "edit" && initialData + ? [ + { url: initialData.passportPage1Url, label: "Pasport (sahypa 1)" }, + { url: initialData.passportPage23Url, label: "Pasport (2-3-nji sahypa)" }, + { url: initialData.passportPage89Url, label: "Pasport (8-9 sahypa)" }, + { url: initialData.passportPage32Url, label: "Pasport (32-nji sahypa)" }, + ].filter((f): f is { url: string; label: string } => !!f.url) + : []; + + return ( +
+ {/* Status & note */} + + + set("status", v)} options={STATUS_OPTIONS} placeholder="Saýlaň" error={errors.status} /> + + + set("note", v)} placeholder="Bellik..." rows={3} /> + + + + {/* Existing files (edit mode) */} + {existingFiles.length > 0 && ( + + {existingFiles.map(({ url, label }) => ( + + + Faýly gör + + + ))} + + )} + + {/* File uploads */} + + + set("passportPage1", f)} + error={errors.passportPage1} + /> + + + set("passportPage23", f)} + error={errors.passportPage23} + /> + + + set("passportPage89", f)} + /> + + + set("passportPage32", f)} + /> + + +
+ ); } // ─── Props ──────────────────────────────────────────────────────────────────── @@ -394,187 +702,144 @@ interface LoanOrderMobileFormProps { loanOrderId?: string; } -// ─── Component ──────────────────────────────────────────────────────────────── +// ─── Main Component ─────────────────────────────────────────────────────────── -export function LoanOrderMobileForm({ - mode, - initialData, - loanOrderId, -}: LoanOrderMobileFormProps) { - const { t } = useTranslation(); +export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrderMobileFormProps) { + const { t } = useTranslation(); const navigate = useNavigate(); const createMutation = useCreateLoanOrderMobile(); const updateMutation = useUpdateLoanOrderMobile(); const isPending = createMutation.isPending || updateMutation.isPending; - const [form, setForm] = useState(() => - initialData ? mapToFormState(initialData) : INITIAL_STATE, - ); + const [form, setForm] = useState(() => initialData ? mapToFormState(initialData) : INITIAL_STATE); const [errors, setErrors] = useState({}); - // Track which steps have been validated (done or error) - const [stepStatuses, setStepStatuses] = useState< - Array<"idle" | "active" | "done" | "error"> - >(["active", "idle", "idle", "idle", "idle"]); const [currentStep, setCurrentStep] = useState(0); + const [visited, setVisited] = useState>( + () => mode === "edit" ? new Set(STEPS.map((_, i) => i)) : new Set(), + ); + + const stepsWithErrors = useMemo(() => { + const out = new Set(); + visited.forEach((i) => { + if (Object.keys(STEPS[i].validate(form, mode)).length > 0) out.add(i); + }); + return out; + }, [form, mode, visited]); const set = useCallback((key: K, value: FormState[K]) => { setForm((prev) => ({ ...prev, [key]: value })); setErrors((prev) => ({ ...prev, [key]: undefined })); }, []); - // Build step items for StepBarCards - const STEP_DEFS = [ - { - id: "loan", - title: t("Loan") || "Karz", - subtitle: t("Type & amount") || "Görnüş & möçber", - icon: FileText, - }, - { - id: "personal", - title: t("Personal") || "Şahsy", - subtitle: t("Identity & passport") || "Şahsyýet & pasport", - icon: User, - }, - { - id: "contact", - title: t("Contact & Job") || "Habarlaşmak & Iş", - subtitle: t("Phone & employment") || "Telefon & iş", - icon: Phone, - }, - { - id: "card", - title: t("Card & Guarantor") || "Kart & Zamun", - subtitle: t("Payment & guarantor") || "Töleg & zamun", - icon: CreditCard, - }, - { - id: "files", - title: t("Files & Status") || "Faýllar & Status", - subtitle: t("Documents & review") || "Resminamalar", - icon: Upload, - }, - ]; + const stepProps = useMemo(() => ({ form, errors, set }), [form, errors, set]); - const stepItems: StepCardItem[] = STEP_DEFS.map((def, i) => ({ - ...def, - status: stepStatuses[i], - })); + // ── Navigation ────────────────────────────────────────────────────────────── - const updateStepStatus = ( - index: number, - status: "idle" | "active" | "done" | "error", - ) => { - setStepStatuses((prev) => { - const next = [...prev]; - next[index] = status; - return next; - }); - }; - - const goToStep = (index: number) => { - updateStepStatus(currentStep, stepStatuses[currentStep] === "error" ? "error" : "done"); - updateStepStatus(index, "active"); - setCurrentStep(index); - window.scrollTo({ top: 0, behavior: "smooth" }); - }; + const markVisited = (i: number) => + setVisited((prev) => new Set([...prev, i])); const handleNext = () => { - const stepErrors = validate(form, t, mode, currentStep); - if (Object.keys(stepErrors).length > 0) { - setErrors((prev) => ({ ...prev, ...stepErrors })); - updateStepStatus(currentStep, "error"); - toast.error(t("Write a correct data please") || "Dogry maglumat girizmegiňizi haýyş edýäris."); - const firstKey = Object.keys(stepErrors)[0]; - document.getElementById(`field-${firstKey}`)?.scrollIntoView({ behavior: "smooth", block: "center" }); + 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; } - updateStepStatus(currentStep, "done"); - const next = currentStep + 1; - updateStepStatus(next, "active"); - setCurrentStep(next); + setErrors({}); + if (currentStep < STEPS.length - 1) { + setCurrentStep(currentStep + 1); + window.scrollTo({ top: 0, behavior: "smooth" }); + } + }; + + const handleBack = () => { + if (currentStep > 0) { + markVisited(currentStep); + setErrors({}); + setCurrentStep(currentStep - 1); + window.scrollTo({ top: 0, behavior: "smooth" }); + } + }; + + const handleGoTo = (i: number) => { + markVisited(currentStep); + setErrors({}); + setCurrentStep(i); window.scrollTo({ top: 0, behavior: "smooth" }); }; - const handlePrev = () => { - const prev = currentStep - 1; - updateStepStatus(currentStep, stepStatuses[currentStep] === "error" ? "error" : "idle"); - updateStepStatus(prev, "active"); - setCurrentStep(prev); - window.scrollTo({ top: 0, behavior: "smooth" }); - }; + // ── Submit ────────────────────────────────────────────────────────────────── const handleSubmit = () => { - // Full validation across all steps - const allErrors = validate(form, t, mode); + setVisited(new Set(STEPS.map((_, i) => i))); + + const allErrors: FormErrors = {}; + for (const step of STEPS) Object.assign(allErrors, step.validate(form, mode)); + if (Object.keys(allErrors).length > 0) { setErrors(allErrors); - // Mark steps with errors - const newStatuses = stepStatuses.map((s, i) => { - const stepKeys = STEP_FIELDS[i]; - const hasError = stepKeys.some((k) => allErrors[k]); - if (i === currentStep) return hasError ? "error" : "active"; - if (hasError) return "error"; - return s === "idle" ? "idle" : "done"; - }) as typeof stepStatuses; - setStepStatuses(newStatuses); - toast.error(t("Write a correct data please") || "Dogry maglumat girizmegiňizi haýyş edýäris."); + 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) { + setCurrentStep(i); + break; + } + } 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, + 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, + 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, + guarantor1CardNumber: form.guarantor1CardNumber || undefined, + guarantor1CardName: form.guarantor1CardName || undefined, + guarantor1CardExpMonth: form.guarantor1CardExpMonth || undefined, + guarantor1CardExpYear: form.guarantor1CardExpYear || undefined, + guarantor1Salary: Number(form.guarantor1Salary) || undefined, }; if (mode === "create") { - createMutation.mutate(payload, { - onSuccess: () => navigate("/loan-order-mobiles"), - }); + createMutation.mutate(payload, { onSuccess: () => navigate("/loan-order-mobiles") }); } else { updateMutation.mutate( { id: loanOrderId!, payload }, @@ -583,771 +848,68 @@ export function LoanOrderMobileForm({ } }; - const isLastStep = currentStep === STEP_DEFS.length - 1; - const isFirstStep = currentStep === 0; + // ── StepBar items ─────────────────────────────────────────────────────────── + + const stepBarItems: StepCardItem[] = STEPS.map((s, i) => { + const isActive = i === currentStep; + const hasErrors = stepsWithErrors.has(i); + const isDone = visited.has(i) && !hasErrors; + return { + id: s.id, + title: t(s.title) || s.title, + subtitle: s.subtitle, + icon: s.icon, + status: isActive ? "active" : hasErrors ? "error" : isDone ? "done" : "idle", + }; + }); + + const isLastStep = currentStep === STEPS.length - 1; // ── Render ────────────────────────────────────────────────────────────────── + return (
- {/* Page title */} + {/* Page header */}

{mode === "create" - ? t("Loan order create") || "Karz sargyt döredüň" - : t("Loan order edit") || "Karz sargydy üýtget"} + ? (t("Loan order create") || "Karz sargyt döredüň") + : (t("Loan order edit") || "Karz sargydy üýtget")}

+

+ {t("Fill in all sections step by step") || "Ähli meýdanlary dolduryp, ädim-ädim öň geçiň."} +

- {/* ── Step Bar ───────────────────────────────────────────────────────── */} + {/* Step bar */}
- +
- {/* ── Step 0: Karz & Lokasiýa ────────────────────────────────────────── */} - {currentStep === 0 && ( - <> -
-
-
- set("loanType", v)} - options={LOAN_TYPE_OPTIONS} - placeholder="Saýlamak üçin basyň" - error={errors.loanType} - /> -
-
- set("loanAmount", v)} - placeholder="Karz möçberi" - error={errors.loanAmount} - /> -
-
-
+ {/* Step content */} + {currentStep === 0 && } + {currentStep === 1 && } + {currentStep === 2 && } + {currentStep === 3 && } + {currentStep === 4 && } -
-
-
- set("region", v)} - options={REGION_OPTIONS} - placeholder="Saýlamak üçin basyň" - error={errors.region} - /> -
-
- set("branch", v)} - options={[]} - placeholder="Saýlamak üçin basyň" - error={errors.branch} - /> -
-
-
- - )} - - {/* ── Step 1: Şahsy maglumatlar & Pasport ───────────────────────────── */} - {currentStep === 1 && ( - <> -
-
-
-
- set("firstName", v)} - placeholder={t("Name") || "Ady"} - error={errors.firstName} - /> -
-
- set("lastName", v)} - placeholder={t("Surname") || "Familiýasy"} - error={errors.lastName} - /> -
-
- set("patronicName", v)} - placeholder={t("Patronic name") || "Atasynyň ady"} - /> -
-
- -
-
- set("education", v)} - options={EDUCATION_OPTIONS} - placeholder="Saýlaň" - error={errors.education} - /> -
-
- set("marriageStatus", v)} - options={MARRIAGE_OPTIONS} - placeholder="Saýlaň" - error={errors.marriageStatus} - /> -
-
- set("dateOfBirth", v)} - error={errors.dateOfBirth} - /> -
-
- -
-
- set("residence", v)} - placeholder={t("Residence (passport)") || "Ýazgy edilen salgyňyz"} - error={errors.residence} - /> -
-
- set("currentResidence", v)} - placeholder={t("Current Residence") || "Häzirki ýaşaýyş ýeri"} - /> -
-
- -
- set("loanHistory", v)} - options={[]} - placeholder="Saýlamak üçin basyň" - /> -
-
-
- -
-
-
-
- set("passportSerie", v)} - options={PASSPORT_SERIES_OPTIONS} - placeholder="Saýlamak üçin basyň" - error={errors.passportSerie} - /> -
-
- set("passportNumber", v)} - placeholder={t("Passport number") || "Pasport belgisi"} - error={errors.passportNumber} - /> -
-
- set("passportDateOfIssue", v)} - error={errors.passportDateOfIssue} - /> -
-
- -
-
- set("passportGivenBy", v)} - placeholder={t("Passport given by") || "Kim tarapyndan berildi"} - error={errors.passportGivenBy} - /> -
-
- set("bornPlace", v)} - placeholder={t("Born place (passport)") || "Doglan ýeri (pasport)"} - /> -
-
-
-
- - )} - - {/* ── Step 2: Habarlaşmak & Iş ──────────────────────────────────────── */} - {currentStep === 2 && ( - <> -
-
-
- set("email", v)} - placeholder="E-poçta" - /> -
-
- set("phone", v)} - placeholder="61 097 651" - error={errors.phone} - /> -
-
- set("phoneAdditional", v)} - placeholder="61 097 651" - /> -
-
- set("homePhone", v)} - placeholder="61 097 651" - /> -
-
-
- -
-
-
-
- set("workCompany", v)} - placeholder={t("Work company name") || "Işleýän edaranyň/kärhananyň ady"} - error={errors.workCompany} - /> -
-
- set("workHrPhone", v)} - placeholder="61 097 651" - /> -
-
- -
-
- set("workRegion", v)} - options={REGION_OPTIONS} - placeholder="Saýlamak üçin basyň" - /> -
-
- set("workProvince", v)} - options={[]} - placeholder="Saýlamak üçin basyň" - /> -
-
- -
-
- set("position", v)} - placeholder={t("Position") || "Wezipe"} - error={errors.position} - /> -
-
- set("salary", v)} - placeholder={t("Salary") || "Zähmet haky"} - error={errors.salary} - /> -
-
- set("workStartedAt", v)} - error={errors.workStartedAt} - /> -
-
-
-
- - )} - - {/* ── Step 3: Kart & Zamun ──────────────────────────────────────────── */} - {currentStep === 3 && ( - <> -
-
-
- set("cardNumber", v)} - placeholder="Kart belgisi" - error={errors.cardNumber} - /> -
-
- set("cardName", v)} - placeholder="Kartdaky ady" - error={errors.cardName} - /> -
-
- set("cardExpMonth", v)} - options={Array.from({ length: 12 }, (_, i) => ({ - value: String(i + 1).padStart(2, "0"), - label: String(i + 1).padStart(2, "0"), - }))} - placeholder="Saýlamak üçin basyň" - error={errors.cardExpMonth} - /> -
-
- set("cardExpYear", v)} - options={Array.from({ length: 15 }, (_, i) => ({ - value: String(new Date().getFullYear() + i), - label: String(new Date().getFullYear() + i), - }))} - placeholder="Saýlamak üçin basyň" - error={errors.cardExpYear} - /> -
-
-
- -
-
-
-
- set("guarantor1Name", v)} - placeholder="Zamunyň ady" - error={errors.guarantor1Name} - /> -
-
- set("guarantor1Surname", v)} - placeholder="Zamunyň familiýasy" - error={errors.guarantor1Surname} - /> -
-
- set("guarantor1Patronic", v)} - placeholder="Zamunyň atasynyň ady" - /> -
-
- -
-
- set("guarantor1PassportSerie", v)} - options={PASSPORT_SERIES_OPTIONS} - placeholder="Saýlamak üçin basyň" - error={errors.guarantor1PassportSerie} - /> -
-
- set("guarantor1PassportNumber", v)} - placeholder="Pasport belgisi" - error={errors.guarantor1PassportNumber} - /> -
-
- -
-
- set("guarantor1CardNumber", v)} - placeholder="Kart belgisi" - error={errors.guarantor1CardNumber} - /> -
-
- set("guarantor1CardName", v)} - placeholder="Kartdaky ady" - error={errors.guarantor1CardName} - /> -
-
- set("guarantor1CardExpMonth", v)} - options={Array.from({ length: 12 }, (_, i) => ({ - value: String(i + 1).padStart(2, "0"), - label: String(i + 1).padStart(2, "0"), - }))} - placeholder="Saýlamak üçin basyň" - error={errors.guarantor1CardExpMonth} - /> -
-
- set("guarantor1CardExpYear", v)} - options={Array.from({ length: 15 }, (_, i) => ({ - value: String(new Date().getFullYear() + i), - label: String(new Date().getFullYear() + i), - }))} - placeholder="Saýlamak üçin basyň" - error={errors.guarantor1CardExpYear} - /> -
-
- -
-
- set("guarantor1Salary", v)} - placeholder="Ortaca zähmet haky" - error={errors.guarantor1Salary} - /> -
-
-
-
- - )} - - {/* ── Step 4: Faýllar & Status ──────────────────────────────────────── */} - {currentStep === 4 && ( - <> -
-
-
- set("status", v)} - options={STATUS_OPTIONS} - error={errors.status} - placeholder="Saýlaň" - /> -
-
- set("note", v)} - placeholder={t("Note") || "Bellik"} - /> -
-
-
- -
- {/* Edit modunda mevcut dosyaları göster */} - {mode === "edit" && initialData && ( -
- {initialData.passportPage1Url && ( -
- - {t("Passport (page 1)") || "Pasport (sahypa 1)"} —{" "} - {t("current") || "häzirki"} - - - {t("View file") || "Faýly gör"} - -
- )} - {initialData.passportPage23Url && ( -
- - {t("Passport (page 2-3)") || "Pasport (2-3-nji sahypa)"} —{" "} - {t("current") || "häzirki"} - - - {t("View file") || "Faýly gör"} - -
- )} - {initialData.passportPage89Url && ( -
- - {t("Passport (page 8-9)") || "Pasport (8-9 sahypa)"} —{" "} - {t("current") || "häzirki"} - - - {t("View file") || "Faýly gör"} - -
- )} - {initialData.passportPage32Url && ( -
- - {t("Passport (page 32)") || "Pasport (32-nji sahypa)"} —{" "} - {t("current") || "häzirki"} - - - {t("View file") || "Faýly gör"} - -
- )} -
- )} - -
-
- set("passportPage1", f)} - placeholder="Faýl saýlaň ýa-da salmak üçin basyň" - error={errors.passportPage1} - /> -
-
- set("passportPage23", f)} - placeholder="Faýl saýlaň ýa-da salmak üçin basyň" - error={errors.passportPage23} - /> -
-
- set("passportPage89", f)} - placeholder="Faýl saýlaň ýa-da salmak üçin basyň" - /> -
-
- set("passportPage32", f)} - placeholder="Faýl saýlaň ýa-da salmak üçin basyň" - /> -
-
-
- - )} - - {/* ── Form Actions ───────────────────────────────────────────────────── */} + {/* Actions */} navigate(-1)} - cancelLabel={t("Cancel") || "Ýatyr"} - loadingLabel={t("Loading") || "Ýüklenilýär..."} - // Prev button: visible from step 1 onward - onPrev={!isFirstStep ? handlePrev : undefined} - prevLabel={t("common.prev") || "Yza"} - // Next button: visible on all steps except the last + onCancel={currentStep === 0 ? () => navigate(-1) : undefined} + onPrev={currentStep > 0 ? handleBack : undefined} onNext={!isLastStep ? handleNext : undefined} - nextLabel={t("common.next") || "Indiki"} - // Submit button: only on the last step showSubmit={isLastStep} - onSubmit={handleSubmit} + onSubmit={isLastStep ? handleSubmit : undefined} submitLabel={ mode === "create" - ? t("loanOrderMobiles.createButton") || "Karz sargyt döredüň" - : t("loanOrders.saveButton") || "Ýatda sakla" + ? (t("loanOrderMobiles.createButton") || "Karz sargyt döredüň") + : (t("loanOrders.saveButton") || "Ýatda sakla") } + loadingLabel={t("Loading") || "Ýüklenilýär..."} + cancelLabel={t("Cancel") || "Ýatyr"} + prevLabel={t("common.prev") || "Yza"} + nextLabel={t("common.next") || "Indiki"} />
); diff --git a/src/features/loanOrders/api/loanOrdersApi.ts b/src/features/loanOrders/api/loanOrdersApi.ts index dfd16d1..ac059b7 100644 --- a/src/features/loanOrders/api/loanOrdersApi.ts +++ b/src/features/loanOrders/api/loanOrdersApi.ts @@ -1,5 +1,3 @@ -import { apiClient } from '@/lib/api/client' - // ─── Types ──────────────────────────────────────────────────────────────────── export type LoanOrderStatus = @@ -9,7 +7,6 @@ export type LoanOrderStatus = | 'IŞLENÝÄR' export interface LoanOrder { - // ── List fields ────────────────────────────────────────────────────────── id: string loanType: string createdAt: string @@ -21,7 +18,6 @@ export interface LoanOrder { status: LoanOrderStatus note?: string | null - // ── Detail fields ───────────────────────────────────────────────────────── loanAmount?: number | null loanHistory?: string | null patronicName?: string | null @@ -31,7 +27,6 @@ export interface LoanOrder { residence?: string | null currentResidence?: string | null - // Passport passportSerie?: string | null passportNumber?: string | null passportDateOfIssue?: string | null @@ -42,12 +37,10 @@ export interface LoanOrder { passportPage89Url?: string | null passportPage32Url?: string | null - // Contact email?: string | null phoneAdditional?: string | null homePhone?: string | null - // Employment workCompany?: string | null workHrPhone?: string | null workRegion?: string | null @@ -56,13 +49,11 @@ export interface LoanOrder { salary?: number | null workStartedAt?: string | null - // Card (Zähmet haky) cardNumber?: string | null cardName?: string | null cardExpMonth?: string | null cardExpYear?: string | null - // Guarantor (Zamun) guarantor1Name?: string | null guarantor1Surname?: string | null guarantor1Patronic?: string | null @@ -74,7 +65,6 @@ export interface LoanOrder { guarantor1CardExpYear?: string | null guarantor1Salary?: number | null - // ── Restored fields from previous version ─────────────────────────────── amount?: number | null createdBy?: string | null fullName?: string | null @@ -172,6 +162,44 @@ const MOCK_DATA: LoanOrder[] = [ lastName: 'Amanow', phone: '+993 65 112233', status: 'GARAŞYLÝAR', + note: 'Müşderi dokumentleri tassyklamady', + loanAmount: 50000, + loanHistory: 'positive', + patronicName: 'Myradowiç', + education: 'high', + marriageStatus: 'MARRIED', + dateOfBirth: '1990-05-15', + 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: 'aman.amanow@email.com', + phoneAdditional: '+993 65 334455', + homePhone: '+993 12 456789', + workCompany: 'Türkmennebit', + workHrPhone: '+993 12 987654', + workRegion: 'Aşgabat', + workProvince: 'Büzmeýin etraby', + position: 'Inžener', + salary: 2500, + workStartedAt: '2018-06-01', + cardNumber: '4111111111111111', + cardName: 'AMAN AMANOW', + 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: 'L-1002', @@ -183,56 +211,159 @@ const MOCK_DATA: LoanOrder[] = [ lastName: 'Berdiýewa', phone: '+993 61 445566', status: 'IŞLENÝÄR', + note: null, + loanAmount: 10000, + loanHistory: 'new', + patronicName: 'Myratowna', + education: 'masters', + marriageStatus: 'SINGLE', + dateOfBirth: '1995-11-20', + residence: 'Mary şäher, Gurbansoltan eje köçesi, 10', + currentResidence: 'Mary şäher, Gurbansoltan eje köçesi, 10', + passportSerie: 'I', + passportNumber: '789012', + passportDateOfIssue: '2018-07-22', + passportGivenBy: 'Mary şäheriniň Içeri işler müdirligi', + bornPlace: 'Mary şäheri', + email: 'oguljan.berdiýewa@email.com', + phoneAdditional: null, + homePhone: null, + workCompany: 'Mary ýangyn söndüriş bölümi', + workHrPhone: '+993 55 112233', + workRegion: 'Mary', + workProvince: 'Mary şäher', + position: 'Hasapçy', + salary: 1800, + workStartedAt: '2019-03-15', + cardNumber: '4333333333333333', + cardName: 'OGULJAN BERDIÝEWA', + cardExpMonth: '09', + cardExpYear: '2028', + guarantor1Name: 'Merdan', + guarantor1Surname: 'Merdanow', + guarantor1Patronic: 'Amanowiç', + guarantor1PassportSerie: 'I', + guarantor1PassportNumber: '345678', + guarantor1CardNumber: '4444444444444444', + guarantor1CardName: 'MERDAN MERDANOW', + guarantor1CardExpMonth: '03', + guarantor1CardExpYear: '2025', + guarantor1Salary: 2200, }, ] +let mockStore = [...MOCK_DATA] +let nextId = 1003 + +const delay = (ms = 300) => new Promise((r) => setTimeout(r, ms)) + // ─── API Functions ──────────────────────────────────────────────────────────── export async function fetchLoanOrders( params: LoanOrdersParams ): Promise { - // Mock — real API hazır bolanda aşakdaky commentden çykar - await new Promise((resolve) => setTimeout(resolve, 800)) + await delay(600) const page = params.page || 1 const perPage = params.perPage || 25 - const filtered = MOCK_DATA.filter( - (item) => - !params.search || - item.firstName.toLowerCase().includes(params.search.toLowerCase()) || - item.id.toLowerCase().includes(params.search.toLowerCase()) - ) - const start = (page - 1) * perPage - return { - data: filtered.slice(start, start + perPage), - total: filtered.length, - page, - perPage, - } - // const { data } = await apiClient.get('/loan-orders', { params }) - // return data + let filtered = mockStore.filter((item) => { + const matchSearch = + !params.search || + `${item.firstName} ${item.lastName}`.toLowerCase().includes(params.search.toLowerCase()) || + item.id.toLowerCase().includes(params.search.toLowerCase()) || + item.phone.includes(params.search) + const matchStatus = + !params.status + ? true + : item.status === params.status + const matchRegion = + !params.region ? true : item.region === params.region + const matchBranch = + !params.branch ? true : item.branch === params.branch + return matchSearch && matchStatus && matchRegion && matchBranch + }) + + filtered = [...filtered].sort((a, b) => b.createdAt.localeCompare(a.createdAt)) + const total = filtered.length + const start = (page - 1) * perPage + const data = filtered.slice(start, start + perPage) + + return { data, total, page, perPage } } export async function getLoanOrderById(id: string): Promise { - const { data } = await apiClient.get(`/loan-orders/${id}`) - return data + await delay(300) + const item = mockStore.find((o) => o.id === id) + if (!item) throw new Error('Not found') + return { ...item } } export async function createLoanOrder( payload: LoanOrderPayload ): Promise { - const { data } = await apiClient.post('/loan-orders', payload) - return data + await delay(500) + const newItem = { + id: `L-${nextId++}`, + createdAt: new Date().toISOString().slice(0, 16).replace('T', ' '), + ...payload, + } as LoanOrder + mockStore = [newItem, ...mockStore] + return newItem } export async function updateLoanOrder( id: string, payload: Partial ): Promise { - const { data } = await apiClient.put(`/loan-orders/${id}`, payload) - return data + await delay(500) + const idx = mockStore.findIndex((o) => o.id === id) + if (idx === -1) throw new Error('Not found') + const updated = { ...mockStore[idx], ...payload } as LoanOrder + mockStore = mockStore.map((o) => (o.id === id ? updated : o)) + return updated } export async function deleteLoanOrder(id: string): Promise { - await apiClient.delete(`/loan-orders/${id}`) -} \ No newline at end of file + await delay(300) + mockStore = mockStore.filter((o) => o.id !== id) +} + +// ─── Branch options by region ───────────────────────────────────────────────── + +export const BRANCHES_BY_REGION: Record = { + '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' }, + { value: 'Aşgabat-2 şahamçasy', label: 'Aşgabat-2 ş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' }, + ], + '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' }, + ], + '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' }, + ], +} diff --git a/src/features/loanOrders/components/loanOrderForm.tsx b/src/features/loanOrders/components/loanOrderForm.tsx index 0676b37..16191de 100644 --- a/src/features/loanOrders/components/loanOrderForm.tsx +++ b/src/features/loanOrders/components/loanOrderForm.tsx @@ -13,6 +13,7 @@ import { FormActions } from '@/components/formActions' import { StepBarCards, type StepCardItem } from '@/components/stepBarV2' import { useCreateLoanOrder, useUpdateLoanOrder } from '@/features/loanOrders/hooks/useLoanOrders' import type { LoanOrder, LoanOrderPayload } from '@/features/loanOrders/api/loanOrdersApi' +import { BRANCHES_BY_REGION } from '@/features/loanOrders/api/loanOrdersApi' // ─── Static options ─────────────────────────────────────────────────────────── @@ -387,7 +388,7 @@ interface StepContentProps { function StepStatus({ form, errors, set }: StepContentProps) { return ( - + - + - + - + - + -

- Welaýaty saýlasaňyz şahamçalar güncellenar. -

- + set('branch', v)} - options={[]} + options={branchOptions} placeholder="Saýlamak üçin basyň" disabled={!form.region} error={errors.branch} @@ -485,37 +485,37 @@ function StepPersonal({ form, errors, set }: StepContentProps) { return (
- + set('firstName', v)} placeholder="Ady" error={errors.firstName} /> - + set('lastName', v)} placeholder="Familiýasy" error={errors.lastName} /> - + set('patronicName', v)} placeholder="Atasynyň ady" /> - + set('education', v)} options={EDUCATION_OPTIONS} placeholder="Saýlaň" error={errors.education} /> - + set('marriageStatus', v)} options={MARRIAGE_OPTIONS} placeholder="Saýlaň" error={errors.marriageStatus} /> - + set('dateOfBirth', v)} error={errors.dateOfBirth} /> - + set('residence', v)} placeholder="Ýazgy edilen salgy" error={errors.residence} /> - + set('currentResidence', v)} placeholder="Häzirki ýaşaýyş ýeri" /> - + set('loanHistory', v)} options={[]} placeholder="Saýlamak üçin basyň" /> @@ -543,22 +543,22 @@ function StepPassport({ form, errors, set }: StepContentProps) { return (
- + set('passportSerie', v)} options={PASSPORT_SERIES_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.passportSerie} /> - + set('passportNumber', v)} placeholder="Pasport belgisi" error={errors.passportNumber} /> - + set('passportDateOfIssue', v)} error={errors.passportDateOfIssue} /> - + set('passportGivenBy', v)} placeholder="Kim tarapyndan berildi" error={errors.passportGivenBy} /> - + set('bornPlace', v)} placeholder="Doglan ýeri (pasport)" /> @@ -586,25 +586,25 @@ function StepJob({ form, errors, set }: StepContentProps) { return (
- + set('workCompany', v)} placeholder="Kärhananyň ady" error={errors.workCompany} /> set('workHrPhone', v)} placeholder="61 097 651" /> - + set('workRegion', v)} options={REGION_OPTIONS} placeholder="Saýlamak üçin basyň" /> set('workProvince', v)} options={[]} placeholder="Saýlamak üçin basyň" /> - + set('position', v)} placeholder="Wezipe" error={errors.position} /> - + set('salary', v)} placeholder="Zähmet haky" error={errors.salary} /> - + set('workStartedAt', v)} error={errors.workStartedAt} /> @@ -644,7 +644,7 @@ function StepFiles({ )} - + - + - + - + - + set('guarantor1Name', v)} placeholder="Zamunyň ady" error={errors.guarantor1Name} /> - + set('guarantor1Surname', v)} placeholder="Zamunyň familiýasy" error={errors.guarantor1Surname} /> - + set('guarantor1Patronic', v)} placeholder="Zamunyň atasynyň ady" /> - + set('guarantor1PassportSerie', v)} options={PASSPORT_SERIES_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.guarantor1PassportSerie} /> - + set('guarantor1PassportNumber', v)} placeholder="Pasport belgisi" error={errors.guarantor1PassportNumber} /> - + set('guarantor1CardNumber', v)} placeholder="Kart belgisi" error={errors.guarantor1CardNumber} /> set('guarantor1CardName', v)} placeholder="Kartdaky ady" error={errors.guarantor1CardName} /> - + set('guarantor1CardExpMonth', v)} options={MONTH_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.guarantor1CardExpMonth} /> set('guarantor1CardExpYear', v)} options={YEAR_OPTIONS} placeholder="Saýlamak üçin basyň" error={errors.guarantor1CardExpYear} /> set('guarantor1Salary', v)} placeholder="Ortaca zähmet haky" error={errors.guarantor1Salary} /> @@ -923,16 +923,6 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
- {/* Step label */} -
- - {currentStep + 1} / {STEPS.length} - -

- {t(STEPS[currentStep].titleKey) || STEPS[currentStep].titleFallback} -

-
- {/* Step content */} {currentStep === 0 && } {currentStep === 1 && } diff --git a/src/pages/cardDepartment/cardBalance/index.tsx b/src/pages/cardDepartment/cardBalance/index.tsx index eb72f10..101b794 100644 --- a/src/pages/cardDepartment/cardBalance/index.tsx +++ b/src/pages/cardDepartment/cardBalance/index.tsx @@ -149,6 +149,7 @@ export default function CardBalancesPage() { {t('Card balances', 'Kart galyndylary')}
+
+
!open && setDeleteId(null)}> diff --git a/src/pages/cardDepartment/cardPins/index.tsx b/src/pages/cardDepartment/cardPins/index.tsx index 1448357..06e9105 100644 --- a/src/pages/cardDepartment/cardPins/index.tsx +++ b/src/pages/cardDepartment/cardPins/index.tsx @@ -11,7 +11,14 @@ import type { CardPinStatus, } from "@/features/cardPins/api/cardPinApi"; import { Button } from "@/components/ui/button"; -import { Eye, Pencil, Trash2, AlertCircle, CheckCircle2, XCircle } from "lucide-react"; +import { + Eye, + Pencil, + Trash2, + AlertCircle, + CheckCircle2, + XCircle, +} from "lucide-react"; import { AlertDialog, AlertDialogAction, @@ -25,33 +32,43 @@ import { // ─── Status Badge ───────────────────────────────────────────────────────────── -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' - +import { + StatusBadge, + type StatusBadgeVariant, +} from "@/components/ui/statusBadge"; // ─── Status badge ───────────────────────────────────────────────────────────── const STATUS_CONFIG = { pending: { - label: 'Garaşylýar', - variant: 'warning' as StatusBadgeVariant, - icon: AlertCircle, + label: "Garaşylýar", + variant: "warning" as StatusBadgeVariant, + icon: AlertCircle, }, approved: { - label: 'Tassyklandy', - variant: 'success' as StatusBadgeVariant, - icon: CheckCircle2, + label: "Tassyklandy", + variant: "success" as StatusBadgeVariant, + icon: CheckCircle2, }, rejected: { - label: 'Ýatyryldy', - variant: 'error' as StatusBadgeVariant, - icon: XCircle, + label: "Ýatyryldy", + variant: "error" as StatusBadgeVariant, + icon: XCircle, }, -} satisfies Record +} satisfies Record< + CardPinStatus, + { label: string; variant: StatusBadgeVariant; icon: React.ElementType } +>; function CardPinStatusStatusBadge({ status }: { status: CardPinStatus }) { - const cfg = STATUS_CONFIG[status] - if (!cfg) return {String(status)} - return + const cfg = STATUS_CONFIG[status]; + if (!cfg) + return ( + {String(status)} + ); + return ( + + ); } // ─── Page ───────────────────────────────────────────────────────────────────── @@ -137,7 +154,9 @@ export default function CardPinsPage() { { accessorKey: "status", header: t("cardPin.status", "Status"), - cell: ({ row }) => , + cell: ({ row }) => ( + + ), }, { id: "actions", @@ -193,62 +212,64 @@ export default function CardPinsPage() { {t("Card pins", "Kart pin bukjalary")}
- { - setSearch(v); - setPage(1); - }} - searchPlaceholder={t("cardPin.search", "Gözlemek")} - columns={columnMeta} - columnVisibility={columnVisibility} - onColumnVisibilityChange={setColumnVisibility} - columnOrder={columnOrder} - onColumnOrderChange={setColumnOrder} - filterFields={[ - { - id: "status", - label: t("cardPin.status", "Status"), - options: [ - { value: "pending", label: "Garaşylýar" }, - { value: "approved", label: "Tassyklandy" }, - { value: "rejected", label: "Ret edildi" }, - ], - }, - ]} - activeFilters={[{ fieldId: "status", value: statusFilter }]} - onFilterChange={(fieldId, value) => { - if (fieldId === "status") - setStatusFilter(value as CardPinStatus | ""); - setPage(1); - }} - onFilterReset={() => { - setStatusFilter(""); - setPage(1); - }} - perPage={perPage} - onPerPageChange={(v) => { - setPerPage(v); - setPage(1); - }} - actionLabel={t("cardPin.createBtn", "Kart pin bukja dörediň")} - onAction={() => navigate("/card-pins/create")} - /> +
+ { + setSearch(v); + setPage(1); + }} + searchPlaceholder={t("cardPin.search", "Gözlemek")} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + filterFields={[ + { + id: "status", + label: t("cardPin.status", "Status"), + options: [ + { value: "pending", label: "Garaşylýar" }, + { value: "approved", label: "Tassyklandy" }, + { value: "rejected", label: "Ret edildi" }, + ], + }, + ]} + activeFilters={[{ fieldId: "status", value: statusFilter }]} + onFilterChange={(fieldId, value) => { + if (fieldId === "status") + setStatusFilter(value as CardPinStatus | ""); + setPage(1); + }} + onFilterReset={() => { + setStatusFilter(""); + setPage(1); + }} + perPage={perPage} + onPerPageChange={(v) => { + setPerPage(v); + setPage(1); + }} + actionLabel={t("cardPin.createBtn", "Kart pin bukja dörediň")} + onAction={() => navigate("/card-pins/create")} + /> - + +
{/* Delete confirmation */} ; + pending: { label: "Garaşylýar", variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, + approved: { label: "Tassyklandy", variant: "success" as StatusBadgeVariant, icon: CheckCircle2 }, + rejected: { label: "Ýatyryldy", variant: "error" as StatusBadgeVariant, icon: XCircle }, +} satisfies Record function CardPinStatusBadge({ status }: { status: CardPinStatus }) { - const cfg = STATUS_CONFIG[status]; - if (!cfg) - return ( - {String(status)} - ); + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return +} + +// ─── Bento primitives ───────────────────────────────────────────────────────── + +function BentoGrid({ cols = 2, children }: { cols?: 1 | 2 | 3 | 4; children: React.ReactNode }) { + const colClass = { + 1: "grid-cols-1", + 2: "grid-cols-1 sm:grid-cols-2", + 3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3", + 4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4", + }[cols] + return
{children}
+} + +function BentoCard({ + title, + span, + children, +}: { + title?: string + span?: "full" | 2 | 3 + children: React.ReactNode +}) { + const spanClass = + span === "full" ? "sm:col-span-full" : + span === 2 ? "sm:col-span-2" : + span === 3 ? "sm:col-span-3" : "" + return ( - - ); +
+ {title && ( +
+

+ {title} +

+
+ )} + {children} +
+ ) } // ─── Page ───────────────────────────────────────────────────────────────────── export default function CardPinViewPage() { - const { id } = useParams<{ id: string }>(); - const navigate = useNavigate(); - const { t } = useTranslation(); + const { id } = useParams<{ id: string }>() + const navigate = useNavigate() + const { t } = useTranslation() - const { data, isLoading, isError } = useCardPin(id!); - const { mutate: deletePin, isPending: isDeleting } = useDeleteCardPin(); + const { data, isLoading, isError } = useCardPin(id!) + const { mutate: deletePin, isPending: isDeleting } = useDeleteCardPin() if (isLoading) { return (
- ); + ) } if (isError || !data) { @@ -82,12 +103,13 @@ export default function CardPinViewPage() {
{t("common.notFound", "Maglumat tapylmady")}
- ); + ) } return ( -
- {/* Header */} +
+ + {/* ── Page header ──────────────────────────────────────────────────── */}

{t("cardPin.viewTitle", "Kart pin bukja giňişleýin")}: {data.id} @@ -120,11 +142,7 @@ export default function CardPinViewPage() { - deletePin(data.id, { - onSuccess: () => navigate("/card-pins"), - }) - } + onClick={() => deletePin(data.id, { onSuccess: () => navigate("/card-pins") })} > {t("common.delete", "Poz")} @@ -143,33 +161,27 @@ export default function CardPinViewPage() {

- {/* Main Info */} -
- - {data.id} - - - {data.created_at} - - - - - - {data.note || "—"} - - - - {data.created_by_label} - - -
+ {/* ── Row 1: Meta + Kart + Lokasiýa ───────────────────────────────── */} + + + + {data.id} + + + {data.created_at} + + + + + + {data.note || "—"} + + + {data.created_by_label} + + - {/* Kart */} -
-

- {t("cardPin.cardSection", "Kart")} -

-
+ {data.card_number} @@ -179,74 +191,70 @@ export default function CardPinViewPage() { — -
-
+ - {/* Lokasiýa */} -
-

- {t("cardPin.locationSection", "Lokasiýa")} -

-
+ {data.province_label} - - {data.branch_label} - + {data.branch_label} -
-
+ +
- {/* Şahsy maglumatlar */} -
-

- {t("cardPin.personalSection", "Şahsy maglumatlar")} -

-
+ {/* ── Row 2: Şahsy + Pasport maglumatlary ─────────────────────────── */} + + {`${data.last_name} ${data.first_name} ${data.father_name}`} {data.birth_date} - +{data.phone} -
-
+ + +{data.phone} + + - {/* Pasport */} -
-

- {t("cardPin.passportSection", "Pasport")} -

-
+ {data.passport_series} {data.passport_number} -
-
+ + + + {/* ── Row 3: Passport images ───────────────────────────────────────── */} + + + + + + + + -
-
+ + +
- ); -} + ) +} \ No newline at end of file diff --git a/src/pages/cardDepartment/cardRequisites/index.tsx b/src/pages/cardDepartment/cardRequisites/index.tsx index a755a17..b95f25c 100644 --- a/src/pages/cardDepartment/cardRequisites/index.tsx +++ b/src/pages/cardDepartment/cardRequisites/index.tsx @@ -1,8 +1,8 @@ -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Download, Eye, Pencil, Trash2 } from 'lucide-react' -import { Button } from '@/components/ui/button' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Download, Eye, Pencil, Trash2 } from "lucide-react"; +import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogAction, @@ -12,60 +12,84 @@ import { AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { DataTable, type ColumnDef } from '@/components/dataTable' -import { DataTableToolbar, type ColumnMeta } from '@/components/dataTableToolbar' -import type { VisibilityState } from '@tanstack/react-table' +} from "@/components/ui/alert-dialog"; +import { DataTable, type ColumnDef } from "@/components/dataTable"; +import { + DataTableToolbar, + type ColumnMeta, +} from "@/components/dataTableToolbar"; +import type { VisibilityState } from "@tanstack/react-table"; import { useCardRequisites, useDeleteCardRequisite, useDownloadCardRequisite, -} from '@/features/cardRequisites/hooks/useCardRequisites' -import type { CardRequisite, CardRequisiteStatus } from '@/features/cardRequisites/api/cardRequisitesApi' +} from "@/features/cardRequisites/hooks/useCardRequisites"; +import type { + CardRequisite, + CardRequisiteStatus, +} from "@/features/cardRequisites/api/cardRequisitesApi"; // ─── Status badge ───────────────────────────────────────────────────────────── -const STATUS_BADGE: Record = { - pending: { label: 'Garaşylýar', className: 'bg-yellow-500/15 text-yellow-500 border-yellow-500/20' }, - approved: { label: 'Tassyklanan', className: 'bg-emerald-500/15 text-emerald-500 border-emerald-500/20' }, - rejected: { label: 'Ret edilen', className: 'bg-red-500/15 text-red-500 border-red-500/20' }, -} +const STATUS_BADGE: Record< + CardRequisiteStatus, + { label: string; className: string } +> = { + pending: { + label: "Garaşylýar", + className: "bg-yellow-500/15 text-yellow-500 border-yellow-500/20", + }, + approved: { + label: "Tassyklanan", + className: "bg-emerald-500/15 text-emerald-500 border-emerald-500/20", + }, + rejected: { + label: "Ret edilen", + className: "bg-red-500/15 text-red-500 border-red-500/20", + }, +}; function StatusBadge({ status }: { status: CardRequisiteStatus }) { - const cfg = STATUS_BADGE[status] ?? STATUS_BADGE.pending + const cfg = STATUS_BADGE[status] ?? STATUS_BADGE.pending; return ( - + {cfg.label} - ) + ); } // ─── Page ───────────────────────────────────────────────────────────────────── -const PER_PAGE = 25 +const PER_PAGE = 25; export default function CardRequisitesPage() { - const { t } = useTranslation() - const navigate = useNavigate() + const { t } = useTranslation(); + const navigate = useNavigate(); - const [page, setPage] = useState(1) - const [perPage, setPerPage] = useState(PER_PAGE) - const [search, setSearch] = useState('') - const [deleteId, setDeleteId] = useState(null) - const [columnVisibility, setColumnVisibility] = useState({}) - const [columnOrder, setColumnOrder] = useState([]) + const [page, setPage] = useState(1); + const [perPage, setPerPage] = useState(PER_PAGE); + const [search, setSearch] = useState(""); + const [deleteId, setDeleteId] = useState(null); + const [columnVisibility, setColumnVisibility] = useState({}); + const [columnOrder, setColumnOrder] = useState([]); - const { data, isLoading } = useCardRequisites({ page, per_page: perPage, search }) - const deleteMutation = useDeleteCardRequisite() - const downloadMutation = useDownloadCardRequisite() + const { data, isLoading } = useCardRequisites({ + page, + per_page: perPage, + search, + }); + const deleteMutation = useDeleteCardRequisite(); + const downloadMutation = useDownloadCardRequisite(); // ── Columns ────────────────────────────────────────────────────────────────── const columns: ColumnDef[] = [ { - id: 'id', - accessorKey: 'id', - header: t('ID', 'ID'), + id: "id", + accessorKey: "id", + header: t("ID", "ID"), cell: ({ row }) => ( - @@ -69,29 +80,35 @@ export default function CurrencyRatesPage() { size: 80, }, { - accessorKey: 'currencyFrom', - header: t('currencyRates.columns.currencyFrom', 'CURRENCY FROM'), + accessorKey: "currencyFrom", + header: t("currencyRates.columns.currencyFrom", "CURRENCY FROM"), cell: ({ row }) => ( - {row.original.currencyFrom} + + {row.original.currencyFrom} + ), }, { - accessorKey: 'currencyTo', - header: t('currencyRates.columns.currencyTo', 'CURRENCY TO'), + accessorKey: "currencyTo", + header: t("currencyRates.columns.currencyTo", "CURRENCY TO"), cell: ({ row }) => ( - {row.original.currencyTo} + + {row.original.currencyTo} + ), }, { - accessorKey: 'value', - header: t('currencyRates.columns.value', 'VALUE'), + accessorKey: "value", + header: t("currencyRates.columns.value", "VALUE"), cell: ({ row }) => ( - {row.original.value} + + {row.original.value} + ), }, { - id: 'actions', - header: '', + id: "actions", + header: "", enableSorting: false, enableHiding: false, cell: ({ row }) => ( @@ -101,7 +118,7 @@ export default function CurrencyRatesPage() { size="icon" className="h-8 w-8 text-muted-foreground hover:text-foreground" onClick={() => navigate(`/currency-rates/${row.original.id}`)} - title={t('common.view', 'Görmek')} + title={t("common.view", "Görmek")} > @@ -110,7 +127,7 @@ export default function CurrencyRatesPage() { size="icon" className="h-8 w-8 text-muted-foreground hover:text-foreground" onClick={() => navigate(`/currency-rates/${row.original.id}/edit`)} - title={t('common.edit', 'Üýtgetmek')} + title={t("common.edit", "Üýtgetmek")} > @@ -119,7 +136,7 @@ export default function CurrencyRatesPage() { size="icon" className="h-8 w-8 text-muted-foreground hover:text-destructive" onClick={() => setDeleteId(row.original.id)} - title={t('common.delete', 'Pozmak')} + title={t("common.delete", "Pozmak")} > @@ -127,82 +144,92 @@ export default function CurrencyRatesPage() { ), size: 120, }, - ] + ]; const columnMeta = columns - .filter((c) => 'accessorKey' in c && c.accessorKey) + .filter((c) => "accessorKey" in c && c.accessorKey) .map((c) => ({ - id: String(('accessorKey' in c ? c.accessorKey : c.id) ?? ''), - label: typeof c.header === 'string' ? c.header : String(('accessorKey' in c ? c.accessorKey : '') ?? ''), - })) + id: String(("accessorKey" in c ? c.accessorKey : c.id) ?? ""), + label: + typeof c.header === "string" + ? c.header + : String(("accessorKey" in c ? c.accessorKey : "") ?? ""), + })); // ─── Render ─────────────────────────────────────────────────────────────── return (
- -

- {t('currencyRates.title', 'Walýuta kursy')} + {t("currencyRates.title", "Walýuta kursy")}

+
+ navigate("/currency-rates/create")} + /> - navigate('/currency-rates/create')} - /> - - String(row.id)} - currentPage={page} - totalPages={data?.totalPages ?? 1} - totalCount={data?.total ?? 0} - onPageChange={setPage} - /> + String(row.id)} + currentPage={page} + totalPages={data?.totalPages ?? 1} + totalCount={data?.total ?? 0} + onPageChange={setPage} + /> +
{/* Delete Confirmation Dialog */} - { if (!open) setDeleteId(null) }}> + { + if (!open) setDeleteId(null); + }} + > - {t('currencyRates.deleteDialog.title', 'Pozmak isleýärsiňizmi?')} + {t("currencyRates.deleteDialog.title", "Pozmak isleýärsiňizmi?")} {t( - 'currencyRates.deleteDialog.description', - 'Bu amal yzyna gaýtarylyp bilinmez. Walýuta kursy hemişelik pozular.' + "currencyRates.deleteDialog.description", + "Bu amal yzyna gaýtarylyp bilinmez. Walýuta kursy hemişelik pozular.", )} - {t('common.cancel', 'Ýatyr')} + {t("common.cancel", "Ýatyr")} {deleteMutation.isPending - ? t('common.deleting', 'Pozulýar...') - : t('common.delete', 'Pozmak')} + ? t("common.deleting", "Pozulýar...") + : t("common.delete", "Pozmak")}
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/currencies/visaMasterSberSettings/index.tsx b/src/pages/currencies/visaMasterSberSettings/index.tsx index e574986..6ae1f6f 100644 --- a/src/pages/currencies/visaMasterSberSettings/index.tsx +++ b/src/pages/currencies/visaMasterSberSettings/index.tsx @@ -1,9 +1,9 @@ // pages/VisaMasterSettingsPage.tsx -import { useState } from 'react' -import { useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Pencil, Trash2 } from 'lucide-react' +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Pencil, Trash2 } from "lucide-react"; import { AlertDialog, AlertDialogAction, @@ -13,97 +13,82 @@ import { AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { Button } from '@/components/ui/button' -import { DataTable, type ColumnDef } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import { - useGetVisaMasterSettings, - useDeleteVisaMasterSetting, -} from '@/features/visaMasterSberSettings/hooks/useVisaMasterSettings' -import type { VisaMasterSetting } from '@/features/visaMasterSberSettings/api/visaMasterSberSettingsApi' +} from "@/components/ui/alert-dialog"; +import { Button } from "@/components/ui/button"; +import { DataTable, type ColumnDef } from "@/components/dataTable"; +import { DataTableToolbar } from "@/components/dataTableToolbar"; +import { useGetVisaMasterSettings, useDeleteVisaMasterSetting } from "@/features/visaMasterSberSettings/hooks/useVisaMasterSettings"; +import type { VisaMasterSetting } from "@/features/visaMasterSberSettings/api/visaMasterSberSettingsApi"; // ─── Column defaults ────────────────────────────────────────────────────────── -const DEFAULT_VISIBILITY = { id: true, kod: true, ady: true, yazgy: true } -const DEFAULT_ORDER = ['id', 'kod', 'ady', 'yazgy', 'actions'] +const DEFAULT_VISIBILITY = { id: true, kod: true, ady: true, yazgy: true }; +const DEFAULT_ORDER = ["id", "kod", "ady", "yazgy", "actions"]; // ─── VisaMasterSettingsPage ─────────────────────────────────────────────────── export default function VisaMasterSettingsPage() { - const { t } = useTranslation() - const navigate = useNavigate() + const { t } = useTranslation(); + const navigate = useNavigate(); - const [page, setPage] = useState(1) - const [perPage] = useState(25) - const [search, setSearch] = useState('') - const [columnVisibility, setColumnVisibility] = useState>(DEFAULT_VISIBILITY) - const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER) - const [deleteId, setDeleteId] = useState(null) + const [page, setPage] = useState(1); + const [perPage] = useState(25); + const [search, setSearch] = useState(""); + const [columnVisibility, setColumnVisibility] = useState>(DEFAULT_VISIBILITY); + const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER); + const [deleteId, setDeleteId] = useState(null); - const { data, isLoading } = useGetVisaMasterSettings({ page, perPage, search }) - const deleteMutation = useDeleteVisaMasterSetting() + const { data, isLoading } = useGetVisaMasterSettings({ page, perPage, search }); + const deleteMutation = useDeleteVisaMasterSetting(); const handleDeleteConfirm = async () => { - if (deleteId === null) return - await deleteMutation.mutateAsync(deleteId) - setDeleteId(null) - } + if (deleteId === null) return; + await deleteMutation.mutateAsync(deleteId); + setDeleteId(null); + }; const handleSearchChange = (val: string) => { - setSearch(val) - setPage(1) - } + setSearch(val); + setPage(1); + }; // ─── Columns ────────────────────────────────────────────────────────────── const columns: ColumnDef[] = [ { - accessorKey: 'id', - header: 'ID', - cell: ({ row }) => ( - {row.original.id} - ), + accessorKey: "id", + header: "ID", + cell: ({ row }) => {row.original.id}, size: 80, }, { - accessorKey: 'kod', - header: t('visaMasterSettings.columns.kod', 'KOD'), - cell: ({ row }) => ( - - {row.original.kod} - - ), + accessorKey: "kod", + header: t("visaMasterSettings.columns.kod", "KOD"), + cell: ({ row }) => {row.original.kod}, }, { - accessorKey: 'ady', - header: t('visaMasterSettings.columns.ady', 'ADY'), - cell: ({ row }) => ( - {row.original.ady} - ), + accessorKey: "ady", + header: t("visaMasterSettings.columns.ady", "ADY"), + cell: ({ row }) => {row.original.ady}, }, { - accessorKey: 'yazgy', - header: t('visaMasterSettings.columns.yazgy', 'YAZGY'), - cell: ({ row }) => ( - {row.original.yazgy} - ), + accessorKey: "yazgy", + header: t("visaMasterSettings.columns.yazgy", "YAZGY"), + cell: ({ row }) => {row.original.yazgy}, }, { - id: 'actions', - header: '', + id: "actions", + header: "", enableSorting: false, - enableHiding: false, + enableHiding: false, cell: ({ row }) => (
@@ -112,7 +97,7 @@ export default function VisaMasterSettingsPage() { size="icon" className="h-8 w-8 text-muted-foreground hover:text-destructive" onClick={() => setDeleteId(row.original.id)} - title={t('common.delete', 'Pozmak')} + title={t("common.delete", "Pozmak")} > @@ -120,85 +105,78 @@ export default function VisaMasterSettingsPage() { ), size: 100, }, - ] + ]; const columnMeta = columns - .filter((c) => 'accessorKey' in c && c.accessorKey) + .filter((c) => "accessorKey" in c && c.accessorKey) .map((c) => ({ - id: String(('accessorKey' in c ? c.accessorKey : c.id) ?? ''), - label: typeof c.header === 'string' ? c.header : String(('accessorKey' in c ? c.accessorKey : '') ?? ''), - })) + id: String(("accessorKey" in c ? c.accessorKey : c.id) ?? ""), + label: typeof c.header === "string" ? c.header : String(("accessorKey" in c ? c.accessorKey : "") ?? ""), + })); // ─── Render ─────────────────────────────────────────────────────────────── return (
- +

{t("visaMasterSettings.title", "Visa/Master, Sber sazlamalar")}

-

- {t('visaMasterSettings.title', 'Visa/Master, Sber sazlamalar')} -

+
+ navigate("/visa-master-sber-settings/create")} + /> - navigate('/visa-master-sber-settings/create')} - /> - - String(row.id)} - currentPage={page} - totalPages={data?.totalPages ?? 1} - totalCount={data?.total ?? 0} - onPageChange={setPage} - /> + String(row.id)} + currentPage={page} + totalPages={data?.totalPages ?? 1} + totalCount={data?.total ?? 0} + onPageChange={setPage} + /> +
{/* Delete Confirmation */} { if (!open) setDeleteId(null) }} + onOpenChange={(open) => { + if (!open) setDeleteId(null); + }} > - - {t('visaMasterSettings.deleteDialog.title', 'Pozmak isleýärsiňizmi?')} - + {t("visaMasterSettings.deleteDialog.title", "Pozmak isleýärsiňizmi?")} - {t( - 'visaMasterSettings.deleteDialog.description', - 'Bu amal yzyna gaýtarylyp bilinmez. Sazlama hemişelik pozular.' - )} + {t("visaMasterSettings.deleteDialog.description", "Bu amal yzyna gaýtarylyp bilinmez. Sazlama hemişelik pozular.")} - {t('common.cancel', 'Ýatyr')} + {t("common.cancel", "Ýatyr")} - {deleteMutation.isPending - ? t('common.deleting', 'Pozulýar...') - : t('common.delete', 'Pozmak')} + {deleteMutation.isPending ? t("common.deleting", "Pozulýar...") : t("common.delete", "Pozmak")}
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/internationalPayments/sberPayments/index.tsx b/src/pages/internationalPayments/sberPayments/index.tsx index ccc5e4c..a0a870d 100644 --- a/src/pages/internationalPayments/sberPayments/index.tsx +++ b/src/pages/internationalPayments/sberPayments/index.tsx @@ -303,7 +303,8 @@ export default function SberPaymentsListPage() {

Sber tolegier (talyplar ucin)

- +
+ {/* Toolbar */}
+
) } diff --git a/src/pages/internationalPayments/visaMasterPayments/index.tsx b/src/pages/internationalPayments/visaMasterPayments/index.tsx index 44d26be..4262a0e 100644 --- a/src/pages/internationalPayments/visaMasterPayments/index.tsx +++ b/src/pages/internationalPayments/visaMasterPayments/index.tsx @@ -215,6 +215,7 @@ export default function IntlPaymentsPage() { { setMonth(v); setPage(1) }} /> +
+
!o && setDeleteTarget(null)}> diff --git a/src/pages/loanDepartment/loanOrderMobileView/index.tsx b/src/pages/loanDepartment/loanOrderMobileView/index.tsx index 17cc61c..28bdd59 100644 --- a/src/pages/loanDepartment/loanOrderMobileView/index.tsx +++ b/src/pages/loanDepartment/loanOrderMobileView/index.tsx @@ -1,6 +1,6 @@ import { useNavigate, useParams } from "react-router-dom"; import { useTranslation } from "react-i18next"; -import { Trash2, Pencil, ChevronRight } from "lucide-react"; +import { Trash2, Pencil } from "lucide-react"; import { useLoanOrderMobileById, useDeleteLoanOrderMobile, @@ -14,57 +14,69 @@ import { type StatusBadgeVariant, } from "@/components/ui/statusBadge"; import { AlertCircle, CheckCircle2, XCircle } from "lucide-react"; - import { InfoRow, - Section, PassportImage, + AuditLog, + type AuditRowProps, } from "@/components/viewPageComponents"; -import { AuditRow, type AuditRowProps } from "@/components/viewPageComponents"; -// ─── Status badge ───────────────────────────────────────────────────────────── + +// ─── Status config ──────────────────────────────────────────────────────────── const STATUS_CONFIG = { - GARAŞYLÝAR: { - label: "Garaşylýar", - variant: "warning" as StatusBadgeVariant, - icon: AlertCircle, - }, - KANAGATLANDYRYLAN: { - label: "Tassyklandy", - variant: "success" as StatusBadgeVariant, - icon: CheckCircle2, - }, - RED_EDILDI: { - label: "Ýatyryldy", - variant: "error" as StatusBadgeVariant, - icon: XCircle, - }, - IŞLENÝÄR: { - label: "Işlenýär", - variant: "warning" as StatusBadgeVariant, - icon: AlertCircle, - }, -} satisfies Record< - LoanOrderMobileStatus, - { label: string; variant: StatusBadgeVariant; icon: React.ElementType } ->; + GARAŞYLÝAR: { label: "Garaşylýar", variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, + KANAGATLANDYRYLAN: { label: "Tassyklandy", variant: "success" as StatusBadgeVariant, icon: CheckCircle2 }, + RED_EDILDI: { label: "Ýatyryldy", variant: "error" as StatusBadgeVariant, icon: XCircle }, + IŞLENÝÄR: { label: "Işlenýär", variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, +} satisfies Record -function LoanOrderMobileStatusBadge({ - status, -}: { - status: LoanOrderMobileStatus; -}) { - const cfg = STATUS_CONFIG[status]; - if (!cfg) - return ( - {String(status)} - ); - return ( - - ); +function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return } -// ─── InfoRow ───────────────────────────────────────────────────────────────── +// ─── Bento primitives ───────────────────────────────────────────────────────── + +function BentoGrid({ cols = 2, children }: { cols?: 1 | 2 | 3 | 4; children: React.ReactNode }) { + const colClass = { + 1: "grid-cols-1", + 2: "grid-cols-1 sm:grid-cols-2", + 3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3", + 4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4", + }[cols] + return
{children}
+} + +function BentoCard({ + title, + span, + children, + noPadding, +}: { + title?: string + span?: "full" | 2 | 3 + children: React.ReactNode + noPadding?: boolean +}) { + const spanClass = + span === "full" ? "sm:col-span-full" : + span === 2 ? "sm:col-span-2" : + span === 3 ? "sm:col-span-3" : "" + + return ( +
+ {title && ( +
+

+ {title} +

+
+ )} +
{children}
+
+ ) +} // ─── Skeleton ───────────────────────────────────────────────────────────────── @@ -72,77 +84,72 @@ function LoanOrderMobilesViewSkeleton() { return (
- {[...Array(5)].map((_, i) => ( -
- - {[...Array(3)].map((_, j) => ( - - ))} -
- ))} +
+ {[...Array(6)].map((_, i) => ( +
+ + {[...Array(3)].map((_, j) => ( + + ))} +
+ ))} +
- ); + ) } // ─── Page ───────────────────────────────────────────────────────────────────── export default function LoanOrderMobilesViewPage() { - const { t } = useTranslation(); - const navigate = useNavigate(); - const { id } = useParams<{ id: string }>(); - const deleteMutation = useDeleteLoanOrderMobile(); + const { t } = useTranslation() + const navigate = useNavigate() + const { id } = useParams<{ id: string }>() + const deleteMutation = useDeleteLoanOrderMobile() - const { data: order, isLoading } = useLoanOrderMobileById(id!); + const { data: order, isLoading } = useLoanOrderMobileById(id!) const handleDelete = () => { - if ( - !window.confirm( - t("loanOrderMobiles.deleteConfirm", "Bu sargyt pozulsynmy?"), - ) - ) - return; + if (!window.confirm(t("loanOrderMobiles.deleteConfirm", "Bu sargyt pozulsynmy?"))) return deleteMutation.mutate(id!, { onSuccess: () => { - toast.success(t("loanOrderMobiles.deleteSuccess", "Sargyt pozuldy")); - navigate("/loan-order-mobiles"); + toast.success(t("loanOrderMobiles.deleteSuccess", "Sargyt pozuldy")) + navigate("/loan-order-mobiles") }, onError: () => { - toast.error( - t("loanOrderMobiles.deleteError", "Pozma wagty ýalňyşlyk ýüze çykdy"), - ); + toast.error(t("loanOrderMobiles.deleteError", "Pozma wagty ýalňyşlyk ýüze çykdy")) }, - }); - }; + }) + } - if (isLoading) return ; + if (isLoading) return if (!order) { return (
{t("common.notFound", "Tapylmady")}
- ); + ) } - // Replace with real audit data from API when available const auditLogs: AuditRowProps[] = [ { - id: "44548", + id: "44548", action: t("audit.actions.view", "Görmek"), - by: order.createdBy ?? "", + by: order.createdBy ?? "", target: `${t("loanOrderMobiles.title", "Karz sargyt")}: ${order.id}`, status: "FINISHED", - date: order.createdAt ?? "", + date: order.createdAt ?? "", }, - ]; + ] + + const hasCard = !!(order.cardNumber || order.cardName) + const hasGuarantor = !!(order.guarantor1Name || order.guarantor1CardNumber) return ( -
- {/* Page Header */} -
+
+ + {/* ── Page header ──────────────────────────────────────────────────── */} +

{t("loanOrderMobiles.view.title", "Karz sargyt giriş")}: {order.id}

@@ -165,299 +172,270 @@ export default function LoanOrderMobilesViewPage() {
- {/* ── Basic Info ─────────────────────────────────────────────────────── */} -
- - {/* Status row — special render */} -
- - {t("loanOrders.columns.status", "Status")} - - -
- - - -
- - {/* ── Card ───────────────────────────────────────────────────────────── */} - {(order.cardNumber || order.cardName) && ( -
-
- -
+ {/* ── Row 1: Meta + Loan + Location ───────────────────────────────── */} + + + + + + -
- )} - - {/* ── Loan ───────────────────────────────────────────────────────────── */} -
- - -
- - {/* ── Location ───────────────────────────────────────────────────────── */} -
- -
- - {/* ── Personal Info ──────────────────────────────────────────────────── */} -
- - - - - - - -
- - {/* ── Contacts ───────────────────────────────────────────────────────── */} -
- - - - -
- - {/* ── Employment ─────────────────────────────────────────────────────── */} -
- - - - - - - -
- - {/* ── Passport ───────────────────────────────────────────────────────── */} -
- - - - - - - -
- - {/* ── Guarantor ──────────────────────────────────────────────────────── */} - {(order.guarantor1Name || order.guarantor1CardNumber) && ( -
- + + + + - {order.guarantor1CardNumber && ( -
+ + + + + + + + {/* ── Row 2: Card visual (conditional) ────────────────────────────── */} + {hasCard && ( + + +
+ + +
+ + {/* Guarantor card — shown side-by-side with main card when both exist */} + {hasGuarantor && ( + + + + + {order.guarantor1CardNumber && ( +
+ +
+ )} +
)} -
+ )} - {/* ── Audit Log ──────────────────────────────────────────────────────── */} -
-
- - {t("loanOrders.sections.audit", "Ammallar")} - - -
-
- - - - {[ - "ID", - t("audit.columns.action", "AMALYŇ ADY"), - t("audit.columns.by", "KIM TARAPYNDAN"), - t("audit.columns.target", "AMALYŇ NYŞANY (TARIBESI)"), - t("audit.columns.status", "AMALYŇ STATUSY"), - t("audit.columns.date", "SENE"), - "", - ].map((col, i) => ( - - ))} - - - - {auditLogs.map((log) => ( - - ))} - -
- {col} -
-
-
- {t("common.prev", "Öňki")} - - 1–{auditLogs.length} / {auditLogs.length} - - {t("common.next", "Soňky")} -
-
-
-
+ {/* ── Row 3: Personal + Contacts ──────────────────────────────────── */} + + + + + + + + + + + + + + + + + + + + {/* ── Row 4: Employment + Passport info ───────────────────────────── */} + + + + + + + + + + + + + + + + + + + {/* ── Row 5: Passport images ───────────────────────────────────────── */} + + + + + + + + + + + + + + + + {/* ── Guarantor (standalone — only when no card to pair with) ─────── */} + {hasGuarantor && !hasCard && ( + + + + + + {order.guarantor1CardNumber && ( +
+ +
+ )} +
+
+ )} + + {/* ── Audit log ────────────────────────────────────────────────────── */} + +
- ); -} + ) +} \ No newline at end of file diff --git a/src/pages/loanDepartment/loanOrderView/index.tsx b/src/pages/loanDepartment/loanOrderView/index.tsx index 81f14ef..2d28134 100644 --- a/src/pages/loanDepartment/loanOrderView/index.tsx +++ b/src/pages/loanDepartment/loanOrderView/index.tsx @@ -1,6 +1,6 @@ import { useNavigate, useParams } from "react-router-dom"; import { useTranslation } from "react-i18next"; -import { Trash2, Pencil, ChevronRight } from "lucide-react"; +import { Trash2, Pencil } from "lucide-react"; import { useLoanOrderById, useDeleteLoanOrder, @@ -15,50 +15,64 @@ import { AlertCircle, CheckCircle2, XCircle } from "lucide-react"; import type { LoanOrderMobileStatus } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi"; import { InfoRow, - Section, PassportImage, + AuditLog, + type AuditRowProps, } from "@/components/viewPageComponents"; -import { AuditRow, type AuditRowProps } from "@/components/viewPageComponents"; + +// ─── Status config ──────────────────────────────────────────────────────────── const STATUS_CONFIG = { - GARAŞYLÝAR: { - label: "Garaşylýar", - variant: "warning" as StatusBadgeVariant, - icon: AlertCircle, - }, - KANAGATLANDYRYLAN: { - label: "Tassyklandy", - variant: "success" as StatusBadgeVariant, - icon: CheckCircle2, - }, - RED_EDILDI: { - label: "Ýatyryldy", - variant: "error" as StatusBadgeVariant, - icon: XCircle, - }, - IŞLENÝÄR: { - label: "Işlenýär", - variant: "warning" as StatusBadgeVariant, - icon: AlertCircle, - }, -} satisfies Record< - LoanOrderMobileStatus, - { label: string; variant: StatusBadgeVariant; icon: React.ElementType } ->; + GARAŞYLÝAR: { label: "Garaşylýar", variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, + KANAGATLANDYRYLAN: { label: "Tassyklandy", variant: "success" as StatusBadgeVariant, icon: CheckCircle2 }, + RED_EDILDI: { label: "Ýatyryldy", variant: "error" as StatusBadgeVariant, icon: XCircle }, + IŞLENÝÄR: { label: "Işlenýär", variant: "warning" as StatusBadgeVariant, icon: AlertCircle }, +} satisfies Record -function LoanOrderMobileStatusBadge({ - status, +function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return +} + +// ─── Bento primitives ───────────────────────────────────────────────────────── + +function BentoGrid({ cols = 2, children }: { cols?: 1 | 2 | 3 | 4; children: React.ReactNode }) { + const colClass = { + 1: "grid-cols-1", + 2: "grid-cols-1 sm:grid-cols-2", + 3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3", + 4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4", + }[cols] + return
{children}
+} + +function BentoCard({ + title, + span, + children, }: { - status: LoanOrderMobileStatus; + title?: string + span?: "full" | 2 | 3 + children: React.ReactNode }) { - const cfg = STATUS_CONFIG[status]; - if (!cfg) - return ( - {String(status)} - ); + const spanClass = + span === "full" ? "sm:col-span-full" : + span === 2 ? "sm:col-span-2" : + span === 3 ? "sm:col-span-3" : "" + return ( - - ); +
+ {title && ( +
+

+ {title} +

+
+ )} + {children} +
+ ) } // ─── Skeleton ───────────────────────────────────────────────────────────────── @@ -67,73 +81,69 @@ function LoanOrderViewSkeleton() { return (
- {[...Array(5)].map((_, i) => ( -
- - {[...Array(3)].map((_, j) => ( - - ))} -
- ))} +
+ {[...Array(6)].map((_, i) => ( +
+ + {[...Array(3)].map((_, j) => ( + + ))} +
+ ))} +
- ); + ) } // ─── Page ───────────────────────────────────────────────────────────────────── export default function LoanOrderViewPage() { - const { t } = useTranslation(); - const navigate = useNavigate(); - const { id } = useParams<{ id: string }>(); - const deleteMutation = useDeleteLoanOrder(); + const { t } = useTranslation() + const navigate = useNavigate() + const { id } = useParams<{ id: string }>() + const deleteMutation = useDeleteLoanOrder() - const { data: order, isLoading } = useLoanOrderById(id!); + const { data: order, isLoading } = useLoanOrderById(id!) const handleDelete = () => { - if (!window.confirm(t("loanOrders.deleteConfirm", "Bu sargyt pozulsynmy?"))) - return; + if (!window.confirm(t("loanOrders.deleteConfirm", "Bu sargyt pozulsynmy?"))) return deleteMutation.mutate(id!, { onSuccess: () => { - toast.success(t("loanOrders.deleteSuccess", "Sargyt pozuldy")); - navigate("/loan-orders"); + toast.success(t("loanOrders.deleteSuccess", "Sargyt pozuldy")) + navigate("/loan-orders") }, onError: () => { - toast.error( - t("loanOrders.deleteError", "Pozma wagty ýalňyşlyk ýüze çykdy"), - ); + toast.error(t("loanOrders.deleteError", "Pozma wagty ýalňyşlyk ýüze çykdy")) }, - }); - }; + }) + } - if (isLoading) return ; + if (isLoading) return if (!order) { return (
{t("common.notFound", "Tapylmady")}
- ); + ) } - // Replace with real audit data from API when available const auditLogs: AuditRowProps[] = [ { - id: "44548", + id: "44548", action: t("audit.actions.view", "Görmek"), - by: order.createdBy ?? "", + by: order.createdBy ?? "", target: `${t("loanOrders.title", "Karz sargyt")}: ${order.id}`, status: "FINISHED", - date: order.createdAt ?? "", + date: order.createdAt ?? "", }, - ]; + ] return ( -
- {/* Page Header */} -
+
+ + {/* ── Page header ──────────────────────────────────────────────────── */} +

{t("loanOrders.view.title", "Karz sargyt giriş")}: {order.id}

@@ -156,243 +166,192 @@ export default function LoanOrderViewPage() {
- {/* ── Basic Info ─────────────────────────────────────────────────────── */} -
- - - {/* Status row — special render */} -
- - {t("loanOrders.columns.status", "Status")} - - -
- - -
+ {/* ── Row 1: Meta + Loan + Location ───────────────────────────────── */} + + {/* Meta */} + + + + + + + + + - {/* ── Loan ───────────────────────────────────────────────────────────── */} -
- - -
+ {/* Loan */} + + + + - {/* ── Location ───────────────────────────────────────────────────────── */} -
- - -
+ {/* Location */} + + + + +
- {/* ── Personal Info ──────────────────────────────────────────────────── */} -
- - - - - - -
+ {/* ── Row 2: Personal + Contacts ──────────────────────────────────── */} + + {/* Personal */} + + + + + + + + - {/* ── Contacts ───────────────────────────────────────────────────────── */} -
- - - - -
+ {/* Contacts */} + + + + + + +
- {/* ── Employment ─────────────────────────────────────────────────────── */} -
- - - - - - - -
+ {/* ── Row 3: Employment + Passport info ───────────────────────────── */} + + {/* Employment */} + + + + + + + + + - {/* ── Passport ───────────────────────────────────────────────────────── */} -
- - - - - - - -
+ {/* Passport info */} + + + + + +
+ + {/* ── Row 4: Passport images ───────────────────────────────────────── */} + + + + + + + + + + + + + + + + {/* ── Audit log ────────────────────────────────────────────────────── */} + - {/* ── Audit Log ──────────────────────────────────────────────────────── */} -
-
- - {t("loanOrders.sections.audit", "Ammallar")} - - -
-
- - - - {[ - "ID", - t("audit.columns.action", "AMALYŇ ADY"), - t("audit.columns.by", "KIM TARAPYNDAN"), - t("audit.columns.target", "AMALYŇ NYŞANY (TARIBESI)"), - t("audit.columns.status", "AMALYŇ STATUSY"), - t("audit.columns.date", "SENE"), - "", - ].map((col, i) => ( - - ))} - - - - {auditLogs.map((log) => ( - - ))} - -
- {col} -
-
-
- {t("common.prev", "Öňki")} - - 1–{auditLogs.length} / {auditLogs.length} - - {t("common.next", "Soňky")} -
-
-
-
- ); -} + ) +} \ No newline at end of file diff --git a/src/pages/onlinePaymentsHistory/index.tsx b/src/pages/onlinePaymentsHistory/index.tsx index 5d5e282..081cf4a 100644 --- a/src/pages/onlinePaymentsHistory/index.tsx +++ b/src/pages/onlinePaymentsHistory/index.tsx @@ -163,6 +163,8 @@ export default function OnlinePaymentHistoryPage() {

{t("onlinePayments.title", "Onlaýn töleg taryhy")}

+
+ +
); } diff --git a/src/pages/settings/card/cardTypes/index.tsx b/src/pages/settings/card/cardTypes/index.tsx index 7dc816f..3279276 100644 --- a/src/pages/settings/card/cardTypes/index.tsx +++ b/src/pages/settings/card/cardTypes/index.tsx @@ -172,6 +172,7 @@ export function CardTypesListPage() {
+
{/* Toolbar */} +
{/* Delete dialog */} setDeleteId(null)}> diff --git a/src/pages/settings/card/reasons/index.tsx b/src/pages/settings/card/reasons/index.tsx index 4a0e5bc..861a0b5 100644 --- a/src/pages/settings/card/reasons/index.tsx +++ b/src/pages/settings/card/reasons/index.tsx @@ -180,6 +180,7 @@ export function CardReasonsListPage() { +
{/* Toolbar */} +
{/* Delete dialog */} setDeleteId(null)}> diff --git a/src/pages/settings/loan/loanTypes/index.tsx b/src/pages/settings/loan/loanTypes/index.tsx index 3f2ca97..b21f5d9 100644 --- a/src/pages/settings/loan/loanTypes/index.tsx +++ b/src/pages/settings/loan/loanTypes/index.tsx @@ -161,6 +161,7 @@ export default function LoanTypesListPage() {

{t('loanTypes.title', 'Karz görnüşleri')}

+
+
{/* Delete confirmation dialog */} !open && setDeleteId(null)}> diff --git a/src/pages/settings/loan/requiredDocuments/index.tsx b/src/pages/settings/loan/requiredDocuments/index.tsx index 3190649..9b3cc1b 100644 --- a/src/pages/settings/loan/requiredDocuments/index.tsx +++ b/src/pages/settings/loan/requiredDocuments/index.tsx @@ -102,6 +102,7 @@ export default function RequiredDocumentsListPage() {

{t('loanDocuments.title', 'Karz gerekli resminamalary')}

+
{/* Toolbar */}
+ ) } \ No newline at end of file diff --git a/src/pages/settings/location/branches/index.tsx b/src/pages/settings/location/branches/index.tsx index 9e209d8..931759e 100644 --- a/src/pages/settings/location/branches/index.tsx +++ b/src/pages/settings/location/branches/index.tsx @@ -195,6 +195,7 @@ export function BranchesListPage() { +
+
setDeleteId(null)}> diff --git a/src/pages/settings/location/districts/index.tsx b/src/pages/settings/location/districts/index.tsx index a8c8ed1..0fe47aa 100644 --- a/src/pages/settings/location/districts/index.tsx +++ b/src/pages/settings/location/districts/index.tsx @@ -163,6 +163,7 @@ export function DistrictsListPage() { +
+
setDeleteId(null)}> diff --git a/src/pages/settings/users/permissions/index.tsx b/src/pages/settings/users/permissions/index.tsx index 7a1263f..4df3660 100644 --- a/src/pages/settings/users/permissions/index.tsx +++ b/src/pages/settings/users/permissions/index.tsx @@ -123,10 +123,9 @@ export default function PermissionsPage() {

{t('permissions.title', 'Rugsatlar')}

- + +
{/* Toolbar */} { setPerPage(v); setPage(1) }} + actionLabel={t('permissions.actions.create', 'Rugsat dörediň')} + onAction={() => navigate('/settings/users/permissions/create')} /> {/* Table */} @@ -158,6 +159,7 @@ export default function PermissionsPage() { totalCount={data?.meta?.total ?? 0} onPageChange={setPage} /> +
{/* Delete confirmation dialog */} {t('roles.title', 'Rollar')} - + +
{/* Toolbar */} { setPerPage(v); setPage(1) }} + actionLabel={t('roles.actions.create', 'Rol dörediň')} + onAction={() => navigate('/settings/users/roles/create')} /> {/* Table */} @@ -158,7 +159,7 @@ export default function RolesPage() { totalCount={data?.meta?.total ?? 0} onPageChange={setPage} /> - +
{/* Delete confirmation dialog */} - - +
+

+ {t('clients.title', 'Ahli Müşderiler')} +

+
+
+ {/* Toolbar */} +
{/* Delete confirm dialog */} !o && setDeleteTarget(null)}> diff --git a/src/pages/users/clients/index.tsx b/src/pages/users/clients/index.tsx index 004feb6..11eb0c5 100644 --- a/src/pages/users/clients/index.tsx +++ b/src/pages/users/clients/index.tsx @@ -146,6 +146,7 @@ export default function ClientsPage() { {t('clients.title', 'Müşderiler')} +
+
!open && setDeleteTarget(null)}> diff --git a/src/pages/users/clientsView/index.tsx b/src/pages/users/clientsView/index.tsx index f86b145..288e7c9 100644 --- a/src/pages/users/clientsView/index.tsx +++ b/src/pages/users/clientsView/index.tsx @@ -13,27 +13,158 @@ import { AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog' -import { Section, InfoRow, AuditLog } from '@/components/viewPageComponents' +import { InfoRow, AuditLog } from '@/components/viewPageComponents' import { DataTable, type ColumnDef } from '@/components/dataTable' import { DataTableToolbar } from '@/components/dataTableToolbar' import { useClient, useDeleteClient } from '@/features/clients/hooks/useClients' import type { ClientRole, ClientBranch, ClientAuditLog } from '@/features/clients/api/clientsApi' +// ─── Bento primitives ───────────────────────────────────────────────────────── + +function BentoGrid({ cols = 2, children }: { cols?: 1 | 2 | 3 | 4; children: React.ReactNode }) { + const colClass = { + 1: 'grid-cols-1', + 2: 'grid-cols-1 sm:grid-cols-2', + 3: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3', + 4: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-4', + }[cols] + return
{children}
+} + +function BentoCard({ + title, + span, + children, +}: { + title?: string + span?: 'full' | 2 | 3 + children: React.ReactNode +}) { + const spanClass = + span === 'full' ? 'sm:col-span-full' : + span === 2 ? 'sm:col-span-2' : + span === 3 ? 'sm:col-span-3' : '' + + return ( +
+ {title && ( +
+

+ {title} +

+
+ )} + {children} +
+ ) +} + +// ─── ActiveIndicator ────────────────────────────────────────────────────────── + +function ActiveIndicator({ active }: { active: boolean }) { + return active ? ( + + + + + + ) : ( + + + + + + ) +} + +// ─── CollapsibleSection ─────────────────────────────────────────────────────── + +interface CollapsibleSectionProps { + title: string + actionLabel: string + onAction: () => void + children: React.ReactNode +} + +function CollapsibleSection({ title, actionLabel, onAction, children }: CollapsibleSectionProps) { + const [open, setOpen] = useState(true) + return ( +
+
setOpen((v) => !v)} + > +

{title}

+ +
+ {open && ( +
+
+ +
+ {children} +
+ )} +
+ ) +} + +// ─── EmptyState ─────────────────────────────────────────────────────────────── + +interface EmptyStateProps { + label: string + actionLabel: string + onAction: () => void +} + +function EmptyState({ label, actionLabel, onAction }: EmptyStateProps) { + return ( +
+
+ + + + + + + +
+

{label}

+ +
+ ) +} + +// ─── Page ───────────────────────────────────────────────────────────────────── + export default function ClientDetailPage() { - const { id } = useParams<{ id: string }>() - const clientId = Number(id) - const { t } = useTranslation() - const navigate = useNavigate() + const { id } = useParams<{ id: string }>() + const clientId = Number(id) + const { t } = useTranslation() + const navigate = useNavigate() const deleteMutation = useDeleteClient() const { data: client, isLoading } = useClient(clientId) - const [deleteOpen, setDeleteOpen] = useState(false) - const [roleSearch, setRoleSearch] = useState('') - const [permSearch, setPermSearch] = useState('') + const [deleteOpen, setDeleteOpen] = useState(false) + const [roleSearch, setRoleSearch] = useState('') + const [permSearch, setPermSearch] = useState('') const [branchSearch, setBranchSearch] = useState('') - const [loanSearch, setLoanSearch] = useState('') - const [cardSearch, setCardSearch] = useState('') + const [loanSearch, setLoanSearch] = useState('') + const [cardSearch, setCardSearch] = useState('') + + // ── Role columns ────────────────────────────────────────────────────────── const roleColumns: ColumnDef[] = [ { @@ -71,6 +202,8 @@ export default function ClientDetailPage() { }, ] + // ── Branch columns ──────────────────────────────────────────────────────── + const branchColumns: ColumnDef[] = [ { accessorKey: 'id', @@ -112,6 +245,8 @@ export default function ClientDetailPage() { }, ] + // ── Loading ─────────────────────────────────────────────────────────────── + if (isLoading) { return (
@@ -125,104 +260,195 @@ export default function ClientDetailPage() { if (!client) return null const auditLogs = (client.auditLogs ?? []).map((log: ClientAuditLog) => ({ - id: String(log.id), + id: String(log.id), action: log.actionName, - by: log.performedBy, + by: log.performedBy, target: log.target, status: log.status, - date: log.createdAt, + date: log.createdAt, })) - const filteredRoles = (client.roles ?? []).filter((r) => - r.name.toLowerCase().includes(roleSearch.toLowerCase()) || r.code.toLowerCase().includes(roleSearch.toLowerCase()), + const filteredRoles = (client.roles ?? []).filter((r) => + r.name.toLowerCase().includes(roleSearch.toLowerCase()) || + r.code.toLowerCase().includes(roleSearch.toLowerCase()), ) - const filteredBranches = (client.branches ?? []).filter((b) => b.name.toLowerCase().includes(branchSearch.toLowerCase()), ) return ( -
- +
-
+ {/* ── Page header ──────────────────────────────────────────────────── */} +

{t('clients.detailTitle', 'Müşderi giňişleýin')}: {client.name}

- -
-
- - - - - - - {client.isActive ? ( - - - - - - ) : ( - - - - - - )} - -
+ {/* ── Row 1: Esasy maglumatlar + Kontakt ──────────────────────────── */} + + + + + + + + + - {}}> - {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction /> - {(filteredRoles.length > 0) ? ( + + + + + + + {/* ── Rollar ───────────────────────────────────────────────────────── */} + {}} + > + {}} + columnOrder={[]} onColumnOrderChange={() => {}} hideAction + /> + {filteredRoles.length > 0 ? ( String(r.id)} enableRowSelection /> ) : ( - {}} /> + {}} + /> )} - {}}> - {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction /> - {(client.permissions ?? []).length === 0 ? ( - {}} /> - ) : null} + {/* ── Rugsatlar ────────────────────────────────────────────────────── */} + {}} + > + {}} + columnOrder={[]} onColumnOrderChange={() => {}} hideAction + /> + {(client.permissions ?? []).length === 0 && ( + {}} + /> + )} - {}}> - {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction /> - {(filteredBranches.length > 0) ? ( + {/* ── Şahamçalar ───────────────────────────────────────────────────── */} + {}} + > + {}} + columnOrder={[]} onColumnOrderChange={() => {}} hideAction + /> + {filteredBranches.length > 0 ? ( String(r.id)} enableRowSelection /> ) : ( - {}} /> + {}} + /> )} - {}}> - {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction /> - {(client.loanOrders ?? []).length === 0 ? ( - {}} /> - ) : null} + {/* ── Karz sargyt ──────────────────────────────────────────────────── */} + {}} + > + {}} + columnOrder={[]} onColumnOrderChange={() => {}} hideAction + /> + {(client.loanOrders ?? []).length === 0 && ( + {}} + /> + )} - {}}> - {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction /> - {(client.cardOrders ?? []).length === 0 ? ( - {}} /> - ) : null} + {/* ── Kart sargyt ──────────────────────────────────────────────────── */} + {}} + > + {}} + columnOrder={[]} onColumnOrderChange={() => {}} hideAction + /> + {(client.cardOrders ?? []).length === 0 && ( + {}} + /> + )} + {/* ── Audit log ────────────────────────────────────────────────────── */} + {/* ── Delete dialog ────────────────────────────────────────────────── */} @@ -233,54 +459,16 @@ export default function ClientDetailPage() { {t('common.cancel', 'Ýatyr')} - deleteMutation.mutate(clientId, { onSuccess: () => navigate('/clients') })}> + deleteMutation.mutate(clientId, { onSuccess: () => navigate('/clients') })} + > {t('common.delete', 'Poz')} -
- ) -} -interface CollapsibleSectionProps { title: string; actionLabel: string; onAction: () => void; children: React.ReactNode } -function CollapsibleSection({ title, actionLabel, onAction, children }: CollapsibleSectionProps) { - const [open, setOpen] = useState(true) - return ( -
-
setOpen((v) => !v)}> -

{title}

- -
- {open && ( -
-
- -
- {children} -
- )}
) -} - -interface EmptyStateProps { label: string; actionLabel: string; onAction: () => void } -function EmptyState({ label, actionLabel, onAction }: EmptyStateProps) { - return ( -
-
- - - - - - - -
-

{label}

- -
- ) -} +} \ No newline at end of file diff --git a/src/pages/users/operators/index.tsx b/src/pages/users/operators/index.tsx index c02fd2d..aa7534c 100644 --- a/src/pages/users/operators/index.tsx +++ b/src/pages/users/operators/index.tsx @@ -180,6 +180,7 @@ export default function OperatorsPage() { {t('operators.title', 'Operatorlar')}
+
{/* Toolbar */} +
{/* Delete dialog */} {children}
; +} + +function BentoCard({ title, span, children }: { title?: string; span?: "full" | 2 | 3; children: React.ReactNode }) { + const spanClass = span === "full" ? "sm:col-span-full" : span === 2 ? "sm:col-span-2" : span === 3 ? "sm:col-span-3" : ""; + + return ( +
+ {title && ( +
+

{title}

+
+ )} + {children} +
+ ); +} + +// ─── IsActive indicator ─────────────────────────────────────────────────────── + +function ActiveIndicator({ active }: { active: boolean }) { + return active ? ( + + + + + + ) : ( + + + + + + ); +} + +// ─── CollapsibleSection ─────────────────────────────────────────────────────── + +interface CollapsibleSectionProps { + title: string; + actionLabel: string; + onAction: () => void; + children: React.ReactNode; +} + +function CollapsibleSection({ title, actionLabel, onAction, children }: CollapsibleSectionProps) { + const [open, setOpen] = useState(true); + + return ( +
+
setOpen((v) => !v)}> +

{title}

+ +
+ {open && ( +
+
+ +
+ {children} +
+ )} +
+ ); +} + +// ─── EmptyState ─────────────────────────────────────────────────────────────── + +interface EmptyStateProps { + label: string; + actionLabel: string; + onAction: () => void; +} + +function EmptyState({ label, actionLabel, onAction }: EmptyStateProps) { + return ( +
+
+ + + + + + + +
+

{label}

+ +
+ ); +} + +// ─── Page ───────────────────────────────────────────────────────────────────── export default function OperatorDetailPage() { - const { id } = useParams<{ id: string }>() - const operatorId = Number(id) - const { t } = useTranslation() - const navigate = useNavigate() - const deleteMutation = useDeleteOperator() + const { id } = useParams<{ id: string }>(); + const operatorId = Number(id); + const { t } = useTranslation(); + const navigate = useNavigate(); + const deleteMutation = useDeleteOperator(); - const { data: operator, isLoading } = useOperator(operatorId) + const { data: operator, isLoading } = useOperator(operatorId); - const [deleteOpen, setDeleteOpen] = useState(false) - const [roleSearch, setRoleSearch] = useState('') - const [permSearch, setPermSearch] = useState('') - const [branchSearch, setBranchSearch] = useState('') + const [deleteOpen, setDeleteOpen] = useState(false); + const [roleSearch, setRoleSearch] = useState(""); + const [permSearch, setPermSearch] = useState(""); + const [branchSearch, setBranchSearch] = useState(""); // ── Role columns ────────────────────────────────────────────────────────── + const roleColumns: ColumnDef[] = [ { - accessorKey: 'id', - header: 'ID', - cell: ({ row }) => ( - {row.original.id} - ), + accessorKey: "id", + header: "ID", + cell: ({ row }) => {row.original.id}, size: 80, }, { - accessorKey: 'code', - header: t('roles.fields.code', 'KOD'), + accessorKey: "code", + header: t("roles.fields.code", "KOD"), cell: ({ row }) => {row.original.code}, }, { - accessorKey: 'name', - header: t('roles.fields.name', 'ADY'), + accessorKey: "name", + header: t("roles.fields.name", "ADY"), cell: ({ row }) => {row.original.name}, }, { - accessorKey: 'guardName', - header: t('roles.fields.guardName', 'GUARD NAME'), + accessorKey: "guardName", + header: t("roles.fields.guardName", "GUARD NAME"), cell: ({ row }) => {row.original.guardName}, }, { - id: 'actions', - header: '', + id: "actions", + header: "", cell: ({ row }) => (
- -
), size: 120, }, - ] + ]; // ── Branch columns ──────────────────────────────────────────────────────── + const branchColumns: ColumnDef[] = [ { - accessorKey: 'id', - header: 'ID', - cell: ({ row }) => ( - {row.original.id} - ), + accessorKey: "id", + header: "ID", + cell: ({ row }) => {row.original.id}, size: 60, }, { - accessorKey: 'name', - header: t('branches.fields.name', 'ADY'), + accessorKey: "name", + header: t("branches.fields.name", "ADY"), cell: ({ row }) => {row.original.name}, }, { - accessorKey: 'region', - header: t('branches.fields.region', 'WELAÝAT'), + accessorKey: "region", + header: t("branches.fields.region", "WELAÝAT"), cell: ({ row }) => {row.original.region}, }, { - accessorKey: 'district', - header: t('branches.fields.district', 'ETRAP'), + accessorKey: "district", + header: t("branches.fields.district", "ETRAP"), cell: ({ row }) => {row.original.district}, }, { - accessorKey: 'uniqueCode', - header: t('branches.fields.uniqueCode', 'UNIKAL BELGI'), + accessorKey: "uniqueCode", + header: t("branches.fields.uniqueCode", "UNIKAL BELGI"), cell: ({ row }) => {row.original.uniqueCode}, }, { - accessorKey: 'isActive', - header: t('branches.fields.isActive', 'IŞJEŇ'), - cell: ({ row }) => - row.original.isActive ? ( - - - - - - ) : ( - - - - - - ), + accessorKey: "isActive", + header: t("branches.fields.isActive", "IŞJEŇ"), + cell: ({ row }) => , size: 80, }, { - accessorKey: 'billingUsernameIbr', - header: t('branches.fields.billingIbr', 'BILLING ULANYJY ADY'), + accessorKey: "billingUsernameIbr", + header: t("branches.fields.billingIbr", "BILLING ULANYJY ADY"), cell: ({ row }) => {row.original.billingUsernameIbr}, }, { - accessorKey: 'billingUsernameSber', - header: t('branches.fields.billingSber', 'BILLING USERNAME (SBER)'), + accessorKey: "billingUsernameSber", + header: t("branches.fields.billingSber", "BILLING USERNAME (SBER)"), cell: ({ row }) => {row.original.billingUsernameSber}, }, { - accessorKey: 'billingUsernameVisa', - header: t('branches.fields.billingVisa', 'BILLING USERNAME (VISA)'), + accessorKey: "billingUsernameVisa", + header: t("branches.fields.billingVisa", "BILLING USERNAME (VISA)"), cell: ({ row }) => {row.original.billingUsernameVisa}, }, { - id: 'actions', - header: '', + id: "actions", + header: "", cell: () => (
-
), size: 60, }, - ] + ]; + + // ── Loading ─────────────────────────────────────────────────────────────── if (isLoading) { return ( @@ -178,12 +265,11 @@ export default function OperatorDetailPage() {
))}
- ) + ); } - if (!operator) return null + if (!operator) return null; - // Map audit logs to AuditLog component format const auditLogs = (operator.auditLogs ?? []).map((log: OperatorAuditLog) => ({ id: String(log.id), action: log.actionName, @@ -191,24 +277,19 @@ export default function OperatorDetailPage() { target: log.target, status: log.status, date: log.createdAt, - })) + })); const filteredRoles = (operator.roles ?? []).filter( - (r) => - r.name.toLowerCase().includes(roleSearch.toLowerCase()) || - r.code.toLowerCase().includes(roleSearch.toLowerCase()), - ) - - const filteredBranches = (operator.branches ?? []).filter((b) => - b.name.toLowerCase().includes(branchSearch.toLowerCase()), - ) + (r) => r.name.toLowerCase().includes(roleSearch.toLowerCase()) || r.code.toLowerCase().includes(roleSearch.toLowerCase()), + ); + const filteredBranches = (operator.branches ?? []).filter((b) => b.name.toLowerCase().includes(branchSearch.toLowerCase())); return ( -
- {/* Page header */} -
+
+ {/* ── Page header ──────────────────────────────────────────────────── */} +

- {t('operators.detailTitle', 'Operator giňişleýin')}: {operator.name} + {t("operators.detailTitle", "Operator giňişleýin")}: {operator.name}

- {/* Basic info */} -
- - - - - - - {operator.isActive ? ( - - - - - - ) : ( - - - - - - )} - -
+ {/* ── Row 1: Esasy maglumatlar + Kontakt ──────────────────────────── */} + + + + + + + + + - {/* Roles */} + + + + + + + {/* ── Rollar ───────────────────────────────────────────────────────── */} {/* open role assign modal */}} + title={t("operators.sections.roles", "Rollar")} + actionLabel={t("operators.addRole", "Rol birikdiriň")} + onAction={() => {}} > {}} @@ -271,24 +345,19 @@ export default function OperatorDetailPage() { onColumnOrderChange={() => {}} hideAction /> - String(r.id)} - enableRowSelection - /> + String(r.id)} enableRowSelection /> - {/* Permissions */} + {/* ── Rugsatlar ────────────────────────────────────────────────────── */} {/* open permission modal */}} + title={t("operators.sections.permissions", "Rugsatlar")} + actionLabel={t("operators.addPermission", "Rugsat birikdiriň")} + onAction={() => {}} > {}} @@ -296,21 +365,25 @@ export default function OperatorDetailPage() { onColumnOrderChange={() => {}} hideAction /> - {(operator.permissions ?? []).length === 0 ? ( - {}} /> - ) : null} + {(operator.permissions ?? []).length === 0 && ( + {}} + /> + )} - {/* Branches */} + {/* ── Şahamçalar ───────────────────────────────────────────────────── */} {}} > {}} @@ -318,140 +391,68 @@ export default function OperatorDetailPage() { onColumnOrderChange={() => {}} hideAction /> - String(r.id)} - enableRowSelection - /> + String(r.id)} enableRowSelection /> - {/* Karz sargyt */} + {/* ── Karz sargyt ──────────────────────────────────────────────────── */} {}} > - {(operator.loanLimits ?? []).length === 0 ? ( - {}} /> - ) : null} + {(operator.loanLimits ?? []).length === 0 && ( + {}} + /> + )} - {/* Kart sargyt */} + {/* ── Kart sargyt ──────────────────────────────────────────────────── */} {}} > - {(operator.cardLimits ?? []).length === 0 ? ( - {}} /> - ) : null} + {(operator.cardLimits ?? []).length === 0 && ( + {}} + /> + )} - {/* Audit log */} + {/* ── Audit log ────────────────────────────────────────────────────── */} - {/* Delete dialog */} + {/* ── Delete dialog ────────────────────────────────────────────────── */} - {t('operators.deleteTitle', 'Operatory pozmak')} + {t("operators.deleteTitle", "Operatory pozmak")} - {t('operators.deleteConfirm', '{{name}} operatoryny pozmak isleýärsiňizmi?', { + {t("operators.deleteConfirm", "{{name}} operatoryny pozmak isleýärsiňizmi?", { name: operator.name, })} - {t('common.cancel', 'Ýatyr')} + {t("common.cancel", "Ýatyr")} deleteMutation.mutate(operatorId, { - onSuccess: () => navigate('/operators'), + onSuccess: () => navigate("/operators"), }) } > - {t('common.delete', 'Poz')} + {t("common.delete", "Poz")}
- ) + ); } - -// ─── CollapsibleSection ─────────────────────────────────────────────────────── - -interface CollapsibleSectionProps { - title: string - actionLabel: string - onAction: () => void - children: React.ReactNode -} - -function CollapsibleSection({ title, actionLabel, onAction, children }: CollapsibleSectionProps) { - const [open, setOpen] = useState(true) - - return ( -
-
setOpen((v) => !v)} - > -

{title}

- -
- {open && ( -
-
- -
- {children} -
- )} -
- ) -} - -// ─── EmptyState ─────────────────────────────────────────────────────────────── - -interface EmptyStateProps { - label: string - actionLabel: string - onAction: () => void -} - -function EmptyState({ label, actionLabel, onAction }: EmptyStateProps) { - return ( -
-
- - - - - - - -
-

{label}

- -
- ) -} \ No newline at end of file