fixed some page ui
This commit is contained in:
@@ -95,3 +95,15 @@ src/
|
||||
[Feature]CreatePage.tsx ← <[Feature]Form mode="create" />
|
||||
[Feature]EditPage.tsx ← id fetch → <[Feature]Form mode="edit" initialData={data} loanOrderId={id} />
|
||||
```
|
||||
8. **Hata Yönetimi Kuralları:**
|
||||
- Custom hook'lar veya API istekleri yazarken, hatalar zaten merkezi QueryCache ve MutationCache tarafından yakalandığı için hook içinde tekrar toast.error() yazma (kod tekrarını önle).
|
||||
- İstisnai olarak, bir hatanın ekrana toast basmasını istemiyorsan, query veya mutation tanımına meta: { silent: true } parametresini geç.
|
||||
- Kod bloklarında asla ham try-catch kullanarak hataları yutma (catch (e) { } boş bırakılamaz). Hata yutulacaksa bile konsola console.error ile basılmalı veya log servisine yönlendirilmelidir.
|
||||
9. **Senior Authentication (Refresh Token & Session) Kuralları:**
|
||||
- **Giriş (Login):** API'den dönen `token` ve `user` verilerini `authStore.setAuth()` ile zustand state'ine kaydet.
|
||||
- **İstekler (Requests):** `axios` client'ı otomatik olarak zustand'dan token çeker ve `Authorization: Bearer <token>` header'ını ekler.
|
||||
- **401 Unauthorized:** Kullanıcı başka bir yerde oturum açar veya token süresi solar ve istek 401 dönerse:
|
||||
1. **Otomatik Yenileme (Auto-Refresh):** Interceptor, durumu yakalar ve gizlice yeni token almaya çalışır.
|
||||
2. **Çakışma Önleme:** Aynı anda birden fazla 401 gelirse, `isRefreshing` bayrağı ile diğer istekler beklemede tutulur.
|
||||
- **Başarısız Refresh:** Yeni token alınamazsa (`refreshToken` hata dönerse), sistem kullanıcıyı otomatik olarak çıkışa zorlar (`logout()`) ve kullanıcıyı Login sayfasına yönlendirir.
|
||||
- **403 Forbidden:** Kullanıcının o sayfaya erişim izni yoksa (Rol yetkisi eksik), toast ile uyarı verilir ancak kullanıcı aynı sayfada kalır (Kritik sayfadan atılmaz).
|
||||
|
||||
@@ -1,12 +1,39 @@
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { QueryClient, QueryClientProvider, QueryCache, MutationCache } from '@tanstack/react-query'
|
||||
import type { ReactNode } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import i18next from 'i18next'
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
queryCache: new QueryCache({
|
||||
onError: (error: any, query) => {
|
||||
// Eğer sorguya özel gizlilik istenmediyse tekilleştirilmiş toast göster
|
||||
if (query.meta?.silent !== true) {
|
||||
const serverMessage = error?.response?.data?.message
|
||||
toast.error(serverMessage || i18next.t('errors.fetchFailed'), {
|
||||
id: 'global-query-error', // Aynı ID'li toast'lar üst üste binmez
|
||||
})
|
||||
}
|
||||
},
|
||||
}),
|
||||
mutationCache: new MutationCache({
|
||||
onError: (error: any, _variables, _context, mutation) => {
|
||||
if (mutation.meta?.silent !== true) {
|
||||
const serverMessage = error?.response?.data?.message
|
||||
toast.error(serverMessage || i18next.t('errors.actionFailed'), {
|
||||
id: 'global-mutation-error',
|
||||
})
|
||||
}
|
||||
},
|
||||
}),
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 1000 * 60 * 5, // 5 min
|
||||
gcTime: 1000 * 60 * 10, // 10 min
|
||||
retry: 1,
|
||||
retry: (failureCount, error: any) => {
|
||||
// Kritik auth veya bulunamadı hatalarında boşa retry atıp ağı yorma
|
||||
if ([401, 403, 404].includes(error.response?.status)) return false
|
||||
return failureCount < 1
|
||||
},
|
||||
refetchOnWindowFocus: false,
|
||||
},
|
||||
mutations: {
|
||||
@@ -25,4 +52,4 @@ export function QueryProvider({ children }: QueryProviderProps) {
|
||||
{children}
|
||||
</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -3,87 +3,44 @@ import { createBrowserRouter, Navigate, Outlet } from "react-router-dom";
|
||||
import { useAuthStore } from "../store/authStore";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { DashboardLayout } from "@/layouts/DashboardLayout";
|
||||
import NotFoundPage from "@/pages/notFoundPage";
|
||||
|
||||
const LoginPage = lazy(() => import("@/pages/login"));
|
||||
const DashboardPage = lazy(() => import("@/pages/dashboard"));
|
||||
const LoanOrdersPage = lazy(() => import("@/pages/loanDepartment/loanOrders"));
|
||||
const LoanOrderMobilesPage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanOrderMobile"),
|
||||
);
|
||||
const LoanRemainingPage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanRemaining"),
|
||||
);
|
||||
const LoanRemainingCreatePage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanRemainingCreate"),
|
||||
);
|
||||
const LoanRemainingViewPage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanRemainingView"),
|
||||
);
|
||||
const LoanRemainingEditPage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanRemainingEdit"),
|
||||
);
|
||||
const LoanPaidOffLettersPage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanPaidOffLetters"),
|
||||
);
|
||||
const LoanOrderCreatePage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanOrderCreate"),
|
||||
);
|
||||
const LoanOrderViewPage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanOrderView"),
|
||||
);
|
||||
const LoanOrderMobileViewPage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanOrderMobileView"),
|
||||
);
|
||||
const LoanOrderMobileEditPage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanOrderMobileEdit"),
|
||||
);
|
||||
const LoanOrderMobileCreatePage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanOrderMobileCreate"),
|
||||
);
|
||||
const LoanOrderEditPage = lazy(
|
||||
() => import("@/pages/loanDepartment/loanOrderEdit"),
|
||||
);
|
||||
const OrderNewCardPage = lazy(
|
||||
() => import("@/pages/cardDepartment/orderNewCard"),
|
||||
);
|
||||
const OrderNewCardCreatePage = lazy(
|
||||
() => import("@/pages/cardDepartment/orderNewCardCreate"),
|
||||
);
|
||||
const OrderNewCardViewPage = lazy(
|
||||
() => import("@/pages/cardDepartment/orderNewCardView"),
|
||||
);
|
||||
const OrderNewCardEditPage = lazy(
|
||||
() => import("@/pages/cardDepartment/orderNewCardEdit"),
|
||||
);
|
||||
const CardTransactionsPage = lazy(
|
||||
() => import("@/pages/cardDepartment/cardTransactions"),
|
||||
);
|
||||
const CardTransactionViewPage = lazy(
|
||||
() => import("@/pages/cardDepartment/cardTransactionsView"),
|
||||
);
|
||||
const CardTransactionCreatePage = lazy(
|
||||
() => import("@/pages/cardDepartment/cardTransactionsCreate"),
|
||||
);
|
||||
const CardTransactionEditPage = lazy(
|
||||
() => import("@/pages/cardDepartment/cardTransactionsEdit"),
|
||||
);
|
||||
const LoanOrderMobilesPage = lazy(() => import("@/pages/loanDepartment/loanOrderMobile"));
|
||||
const LoanRemainingPage = lazy(() => import("@/pages/loanDepartment/loanRemaining"));
|
||||
const LoanRemainingCreatePage = lazy(() => import("@/pages/loanDepartment/loanRemainingCreate"));
|
||||
const LoanRemainingViewPage = lazy(() => import("@/pages/loanDepartment/loanRemainingView"));
|
||||
const LoanRemainingEditPage = lazy(() => import("@/pages/loanDepartment/loanRemainingEdit"));
|
||||
const LoanPaidOffLettersPage = lazy(() => import("@/pages/loanDepartment/loanPaidOffLetters"));
|
||||
const LoanOrderCreatePage = lazy(() => import("@/pages/loanDepartment/loanOrderCreate"));
|
||||
const LoanOrderViewPage = lazy(() => import("@/pages/loanDepartment/loanOrderView"));
|
||||
const LoanOrderMobileViewPage = lazy(() => import("@/pages/loanDepartment/loanOrderMobileView"));
|
||||
const LoanOrderMobileEditPage = lazy(() => import("@/pages/loanDepartment/loanOrderMobileEdit"));
|
||||
const LoanOrderMobileCreatePage = lazy(() => import("@/pages/loanDepartment/loanOrderMobileCreate"));
|
||||
const LoanOrderEditPage = lazy(() => import("@/pages/loanDepartment/loanOrderEdit"));
|
||||
|
||||
const OrderNewCardPage = lazy(() => import("@/pages/cardDepartment/orderNewCard"));
|
||||
const OrderNewCardCreatePage = lazy(() => import("@/pages/cardDepartment/orderNewCardCreate"));
|
||||
const OrderNewCardViewPage = lazy(() => import("@/pages/cardDepartment/orderNewCardView"));
|
||||
const OrderNewCardEditPage = lazy(() => import("@/pages/cardDepartment/orderNewCardEdit"));
|
||||
|
||||
const CardTransactionsPage = lazy(() => import("@/pages/cardDepartment/cardTransactions"));
|
||||
const CardTransactionViewPage = lazy(() => import("@/pages/cardDepartment/cardTransactionsView"));
|
||||
const CardTransactionCreatePage = lazy(() => import("@/pages/cardDepartment/cardTransactionsCreate"));
|
||||
const CardTransactionEditPage = lazy(() => import("@/pages/cardDepartment/cardTransactionsEdit"));
|
||||
|
||||
const CardRequisitesPage = lazy(() => import("@/pages/cardDepartment/cardRequisites"));
|
||||
const CardRequisiteViewPage = lazy(() => import("@/pages/cardDepartment/cardRequisitesView"));
|
||||
const CardRequisiteCreatePage = lazy(() => import("@/pages/cardDepartment/cardRequisitesCreate"));
|
||||
const CardRequisiteEditPage = lazy(() => import("@/pages/cardDepartment/cardRequisitesEdit"));
|
||||
|
||||
const CardRequisitesPage = lazy(
|
||||
() => import("@/pages/cardDepartment/cardRequisites"),
|
||||
);
|
||||
const CardRequisiteViewPage = lazy(
|
||||
() => import("@/pages/cardDepartment/cardRequisitesView"),
|
||||
);
|
||||
const CardRequisiteCreatePage = lazy(
|
||||
() => import("@/pages/cardDepartment/cardRequisitesCreate"),
|
||||
);
|
||||
const CardRequisiteEditPage = lazy(
|
||||
() => import("@/pages/cardDepartment/cardRequisitesEdit"),
|
||||
);
|
||||
const CardBalancePage = lazy(() => import("@/pages/cardDepartment/cardBalance"));
|
||||
const CardBalanceCreatePage = lazy(() => import("@/pages/cardDepartment/cardBalanceCreate"));
|
||||
const CardBalanceViewPage = lazy(() => import("@/pages/cardDepartment/cardBalanceView"));
|
||||
const CardBalanceEditPage = lazy(() => import("@/pages/cardDepartment/cardBalanceEdit"));
|
||||
|
||||
const CardPinsPage = lazy(() => import("@/pages/cardDepartment/cardPins"));
|
||||
const CardPinsCreatePage = lazy(() => import("@/pages/cardDepartment/cardPinsCreate"));
|
||||
const CardPinsViewPage = lazy(() => import("@/pages/cardDepartment/cardPinsView"));
|
||||
@@ -93,13 +50,12 @@ const VisaMasterPaymentsPage = lazy(() => import("@/pages/internationalPayments/
|
||||
const VisaMasterPaymentCreatePage = lazy(() => import("@/pages/internationalPayments/visaMasterPaymentsCreate"));
|
||||
const VisaMasterPaymentViewPage = lazy(() => import("@/pages/internationalPayments/visaMasterPaymentsView"));
|
||||
const VisaMasterPaymentEditPage = lazy(() => import("@/pages/internationalPayments/visaMasterPaymentsEdit"));
|
||||
|
||||
const SberPaymentPage = lazy(() => import("@/pages/internationalPayments/sberPayments"));
|
||||
const SberPaymentCreatePage = lazy(() => import("@/pages/internationalPayments/sberPaymentsCreate"));
|
||||
const SberPaymentViewPage = lazy(() => import("@/pages/internationalPayments/sberPaymentsView"));
|
||||
const SberPaymentEditPage = lazy(() => import("@/pages/internationalPayments/sberPaymentsEdit"));
|
||||
|
||||
|
||||
|
||||
const OperatorsPage = lazy(() => import("@/pages/users/operators"));
|
||||
const OperatorCreatePage = lazy(() => import("@/pages/users/operatorsCreate"));
|
||||
const OperatorsViewPage = lazy(() => import("@/pages/users/operatorsView"));
|
||||
@@ -487,7 +443,8 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{ // Sidebar: /visa-master-payments
|
||||
{
|
||||
// Sidebar: /visa-master-payments
|
||||
path: "/visa-master",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
@@ -519,7 +476,8 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{ // Sidebar: /sber-payments
|
||||
{
|
||||
// Sidebar: /sber-payments
|
||||
path: "/sber-payments",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
@@ -551,7 +509,8 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{ // Sidebar: /operators
|
||||
{
|
||||
// Sidebar: /operators
|
||||
path: "/operators",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
@@ -583,7 +542,8 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{ // Sidebar: /all-users
|
||||
{
|
||||
// Sidebar: /all-users
|
||||
path: "/all-users",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
@@ -615,7 +575,8 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{ // Sidebar: /clients
|
||||
{
|
||||
// Sidebar: /clients
|
||||
path: "/clients",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
@@ -647,7 +608,8 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{ // Sidebar: /currencies-rates
|
||||
{
|
||||
// Sidebar: /currencies-rates
|
||||
path: "/currency-rates",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
@@ -679,7 +641,8 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{ // Sidebar: /visa-master-sber-settings
|
||||
{
|
||||
// Sidebar: /visa-master-sber-settings
|
||||
path: "/visa-master-sber-settings",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
@@ -911,7 +874,8 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{ // Sidebar: /settings/location/districts
|
||||
{
|
||||
// Sidebar: /settings/location/districts
|
||||
path: "/settings/location/districts",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
@@ -943,7 +907,8 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{ // Sidebar: /settings/location/branches
|
||||
{
|
||||
// Sidebar: /settings/location/branches
|
||||
path: "/settings/location/branches",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
@@ -981,6 +946,6 @@ export const router = createBrowserRouter([
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: <Navigate to="/" replace />,
|
||||
element: <NotFoundPage />,
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
import axios from 'axios'
|
||||
|
||||
export interface AuthUser {
|
||||
id: string
|
||||
@@ -15,21 +16,54 @@ interface AuthState {
|
||||
isAuthenticated: boolean
|
||||
setAuth: (token: string, user: AuthUser) => void
|
||||
clearAuth: () => void
|
||||
logout: () => void // Eklendi
|
||||
refreshToken: () => Promise<string> // Eklendi
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
(set, get) => ({
|
||||
token: null,
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
|
||||
setAuth: (token, user) =>
|
||||
set({ token, user, isAuthenticated: true }),
|
||||
|
||||
clearAuth: () =>
|
||||
set({ token: null, user: null, isAuthenticated: false }),
|
||||
|
||||
logout: () => {
|
||||
// Çıkış yapıldığında hem local state'i temizle hem de gerekirse API'ye logout isteği at
|
||||
get().clearAuth()
|
||||
},
|
||||
|
||||
refreshToken: async () => {
|
||||
try {
|
||||
// Interceptor dairesel bağımlılığı bozmasın diye doğrudan bağımsız axios çağrısı yapıyoruz
|
||||
const response = await axios.post<{ token: string }>(
|
||||
`${import.meta.env.VITE_API_BASE_URL}/auth/refresh`,
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${get().token}`, // Mevcut süresi dolmuş token'ı gönderiyoruz
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const newToken = response.data.token
|
||||
// Yeni token'ı store'a kaydet
|
||||
set((state) => ({ ...state, token: newToken }))
|
||||
return newToken
|
||||
} catch (error) {
|
||||
// Eğer refresh token da patlarsa her şeyi sıfırla
|
||||
get().clearAuth()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}),
|
||||
{
|
||||
name: 'tbbank-auth',
|
||||
},
|
||||
),
|
||||
)
|
||||
)
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useState, useCallback, useMemo, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { toast } from 'sonner'
|
||||
import { CreditCard, User, FileText } 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'
|
||||
@@ -38,223 +40,502 @@ interface FormState {
|
||||
}
|
||||
|
||||
type FormErrors = Partial<Record<keyof FormState, string>>
|
||||
type StepStatus = 'idle' | 'active' | 'done' | 'error'
|
||||
|
||||
// ─── Step field mapping ───────────────────────────────────────────────────────
|
||||
|
||||
const STEP_FIELDS: Array<Array<keyof FormState>> = [
|
||||
// Step 0 — Kart & Lokasiýa
|
||||
['status', 'card_type', 'card_number', 'province', 'branch'],
|
||||
// Step 1 — Şahsy maglumatlar
|
||||
['first_name', 'last_name', 'birth_date', 'phone'],
|
||||
// Step 2 — Pasport & Faýllar
|
||||
['passport_series', 'passport_number', 'passport_file_1', 'passport_file_2', 'passport_file_3', 'passport_file_4'],
|
||||
]
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: 'pending', label: 'Garaşylýar' },
|
||||
{ value: 'pending', label: 'Garaşylýar' },
|
||||
{ value: 'approved', label: 'Tassyklandy' },
|
||||
{ value: 'rejected', label: 'Ret edildi' },
|
||||
{ value: 'rejected', label: 'Ret edildi' },
|
||||
]
|
||||
|
||||
const CARD_TYPE_OPTIONS = [
|
||||
{ value: 'altyn_asyr', label: 'Altyn Asyr' },
|
||||
{ value: 'visa', label: 'Visa' },
|
||||
{ value: 'mastercard', label: 'MasterCard' },
|
||||
{ value: 'visa', label: 'Visa' },
|
||||
{ value: 'mastercard', label: 'MasterCard' },
|
||||
]
|
||||
|
||||
const PASSPORT_SERIES_OPTIONS = [
|
||||
{ value: 'I', label: 'I' },
|
||||
{ value: 'II', label: 'II' },
|
||||
{ value: 'I-MR', label: 'I-MR' },
|
||||
{ value: 'I', label: 'I' },
|
||||
{ value: 'II', label: 'II' },
|
||||
{ value: 'I-MR', label: 'I-MR' },
|
||||
{ value: 'II-MR', label: 'II-MR' },
|
||||
]
|
||||
|
||||
const PROVINCE_OPTIONS = [
|
||||
{ value: 'ashgabat', label: 'Aşgabat' },
|
||||
{ value: 'mary', label: 'Mary' },
|
||||
{ value: 'mary', label: 'Mary' },
|
||||
{ value: 'dasoguz', label: 'Daşoguz' },
|
||||
{ value: 'lebap', label: 'Lebap' },
|
||||
{ value: 'balkan', label: 'Balkan' },
|
||||
{ value: 'ahal', label: 'Ahal' },
|
||||
{ value: 'lebap', label: 'Lebap' },
|
||||
{ value: 'balkan', label: 'Balkan' },
|
||||
{ value: 'ahal', label: 'Ahal' },
|
||||
]
|
||||
|
||||
// ─── Default state ────────────────────────────────────────────────────────────
|
||||
|
||||
const defaultState: FormState = {
|
||||
status: 'pending',
|
||||
note: '',
|
||||
card_type: '',
|
||||
card_number: '',
|
||||
province: '',
|
||||
branch: '',
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
father_name: '',
|
||||
birth_date: '',
|
||||
phone: '',
|
||||
passport_series: '',
|
||||
passport_number: '',
|
||||
passport_file_1: null,
|
||||
passport_file_2: null,
|
||||
passport_file_3: null,
|
||||
passport_file_4: null,
|
||||
const INITIAL_STATE: FormState = {
|
||||
status: 'pending', note: '', card_type: '', card_number: '',
|
||||
province: '', branch: '', first_name: '', last_name: '', father_name: '',
|
||||
birth_date: '', phone: '', passport_series: '', passport_number: '',
|
||||
passport_file_1: null, passport_file_2: null,
|
||||
passport_file_3: null, passport_file_4: null,
|
||||
}
|
||||
|
||||
// ─── Validation ───────────────────────────────────────────────────────────────
|
||||
|
||||
function validate(
|
||||
form: FormState,
|
||||
mode: 'create' | 'edit',
|
||||
stepIndex?: number,
|
||||
): FormErrors {
|
||||
const allErrors: FormErrors = {}
|
||||
|
||||
if (!form.status) allErrors.status = 'Status hökmany'
|
||||
if (!form.card_type) allErrors.card_type = 'Kart görnüşi hökmany'
|
||||
if (!form.card_number) allErrors.card_number = 'Kart belgisi hökmany'
|
||||
if (!form.province) allErrors.province = 'Welaýat hökmany'
|
||||
if (!form.branch) allErrors.branch = 'Şahamça hökmany'
|
||||
if (!form.first_name) allErrors.first_name = 'Ady hökmany'
|
||||
if (!form.last_name) allErrors.last_name = 'Familiýasy hökmany'
|
||||
if (!form.birth_date) allErrors.birth_date = 'Doglan güni hökmany'
|
||||
if (!form.phone) allErrors.phone = 'Telefon hökmany'
|
||||
if (!form.passport_series) allErrors.passport_series = 'Pasport seriýasy hökmany'
|
||||
if (!form.passport_number) allErrors.passport_number = 'Pasport belgisi hökmany'
|
||||
|
||||
if (mode === 'create') {
|
||||
if (!form.passport_file_1) allErrors.passport_file_1 = 'Pasport (sahypa 1) hökmany'
|
||||
if (!form.passport_file_2) allErrors.passport_file_2 = 'Pasport (2-3-nji sahypa) hökmany'
|
||||
if (!form.passport_file_3) allErrors.passport_file_3 = 'Pasport (8-9 sahypa) hökmany'
|
||||
if (!form.passport_file_4) allErrors.passport_file_4 = 'Pasport (32-nji sahypa) hökmany'
|
||||
function mapToFormState(data: CardPinItem): FormState {
|
||||
return {
|
||||
status: data.status ?? 'pending',
|
||||
note: data.note ?? '',
|
||||
card_type: data.card_type ?? '',
|
||||
card_number: data.card_number ?? '',
|
||||
province: data.province ?? '',
|
||||
branch: data.branch ?? '',
|
||||
first_name: data.first_name ?? '',
|
||||
last_name: data.last_name ?? '',
|
||||
father_name: data.father_name ?? '',
|
||||
birth_date: data.birth_date ?? '',
|
||||
phone: data.phone ?? '',
|
||||
passport_series: data.passport_series ?? '',
|
||||
passport_number: data.passport_number ?? '',
|
||||
passport_file_1: null, passport_file_2: null,
|
||||
passport_file_3: null, passport_file_4: null,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
return allErrors
|
||||
}
|
||||
|
||||
// ─── Section wrapper ──────────────────────────────────────────────────────────
|
||||
// ─── Step definitions ─────────────────────────────────────────────────────────
|
||||
|
||||
interface StepDef {
|
||||
id: string
|
||||
titleKey: string
|
||||
titleFallback: string
|
||||
subtitle: string
|
||||
icon: LucideIcon
|
||||
validate: (form: FormState, mode: 'create' | 'edit') => FormErrors
|
||||
}
|
||||
|
||||
const STEPS: StepDef[] = [
|
||||
{
|
||||
id: 'card',
|
||||
titleKey: 'cardPin.step.card',
|
||||
titleFallback: 'Kart',
|
||||
subtitle: 'Görnüş & lokasiýa',
|
||||
icon: CreditCard,
|
||||
validate: (form) => {
|
||||
const e: FormErrors = {}
|
||||
if (!form.status) e.status = 'Status hökmany'
|
||||
if (!form.card_type) e.card_type = 'Kart görnüşi hökmany'
|
||||
if (!form.card_number) e.card_number = 'Kart belgisi hökmany'
|
||||
if (!form.province) e.province = 'Welaýat hökmany'
|
||||
if (!form.branch) e.branch = 'Şahamça hökmany'
|
||||
return e
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'personal',
|
||||
titleKey: 'cardPin.step.personal',
|
||||
titleFallback: 'Şahsy',
|
||||
subtitle: 'Maglumatlar',
|
||||
icon: User,
|
||||
validate: (form) => {
|
||||
const e: FormErrors = {}
|
||||
if (!form.first_name) e.first_name = 'Ady hökmany'
|
||||
if (!form.last_name) e.last_name = 'Familiýasy hökmany'
|
||||
if (!form.birth_date) e.birth_date = 'Doglan güni hökmany'
|
||||
if (!form.phone) e.phone = 'Telefon hökmany'
|
||||
return e
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'passport',
|
||||
titleKey: 'cardPin.step.passport',
|
||||
titleFallback: 'Pasport',
|
||||
subtitle: 'Resminamalar',
|
||||
icon: FileText,
|
||||
validate: (form, mode) => {
|
||||
const e: FormErrors = {}
|
||||
if (!form.passport_series) e.passport_series = 'Pasport seriýasy hökmany'
|
||||
if (!form.passport_number) e.passport_number = 'Pasport belgisi hökmany'
|
||||
if (mode === 'create') {
|
||||
if (!form.passport_file_1) e.passport_file_1 = 'Pasport (sahypa 1) hökmany'
|
||||
if (!form.passport_file_2) e.passport_file_2 = 'Pasport (2-3-nji sahypa) hökmany'
|
||||
if (!form.passport_file_3) e.passport_file_3 = 'Pasport (8-9 sahypa) hökmany'
|
||||
if (!form.passport_file_4) e.passport_file_4 = 'Pasport (32-nji sahypa) hökmany'
|
||||
}
|
||||
return e
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
// ─── 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 <div className={`grid ${colClass} gap-4`}>{children}</div>
|
||||
}
|
||||
|
||||
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' : ''
|
||||
|
||||
function Section({ title, children }: { title?: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<div className={`bg-card border border-border rounded-xl p-5 space-y-4 ${spanClass}`}>
|
||||
{title && (
|
||||
<div className="px-5 py-3.5 border-b border-border">
|
||||
<h2 className="text-sm font-semibold text-foreground">{title}</h2>
|
||||
</div>
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
<div className="p-5">{children}</div>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Component ────────────────────────────────────────────────────────────────
|
||||
// ─── Shared step content props ────────────────────────────────────────────────
|
||||
|
||||
interface StepContentProps {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}
|
||||
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
|
||||
function StepCard({ form, errors, set }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="select"
|
||||
label="Status"
|
||||
required
|
||||
value={form.status}
|
||||
onChange={(v) => set('status', v)}
|
||||
options={STATUS_OPTIONS}
|
||||
error={errors.status}
|
||||
placeholder="Saýlaň"
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Bellik"
|
||||
value={form.note}
|
||||
onChange={(v) => set('note', v)}
|
||||
placeholder="Bellik..."
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Kart maglumatlary">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Kart görnüşi"
|
||||
required
|
||||
value={form.card_type}
|
||||
onChange={(v) => set('card_type', v)}
|
||||
options={CARD_TYPE_OPTIONS}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.card_type}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Kart belgisi"
|
||||
required
|
||||
value={form.card_number}
|
||||
onChange={(v) => set('card_number', v)}
|
||||
placeholder="Kart belgisi"
|
||||
error={errors.card_number}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Lokasiýa">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Welaýat"
|
||||
required
|
||||
value={form.province}
|
||||
onChange={(v) => { set('province', v); set('branch', '') }}
|
||||
options={PROVINCE_OPTIONS}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.province}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Şahamça"
|
||||
required
|
||||
value={form.branch}
|
||||
onChange={(v) => set('branch', v)}
|
||||
options={[]}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
disabled={!form.province}
|
||||
error={errors.branch}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StepPersonal({ form, errors, set }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text" label="Ady" required
|
||||
value={form.first_name} onChange={(v) => set('first_name', v)}
|
||||
placeholder="Ady" error={errors.first_name}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text" label="Familiýasy" required
|
||||
value={form.last_name} onChange={(v) => set('last_name', v)}
|
||||
placeholder="Familiýasy" error={errors.last_name}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text" label="Atasynyň ady"
|
||||
value={form.father_name} onChange={(v) => set('father_name', v)}
|
||||
placeholder="Atasynyň ady"
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="date" label="Doglan güni" required
|
||||
value={form.birth_date} onChange={(v) => set('birth_date', v)}
|
||||
error={errors.birth_date}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="phone" label="Telefon" required
|
||||
value={form.phone} onChange={(v) => set('phone', v)}
|
||||
error={errors.phone}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StepPassport({ form, errors, set, mode, initialData }: StepContentProps & {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: CardPinItem
|
||||
}) {
|
||||
const existingFiles =
|
||||
mode === 'edit' && initialData
|
||||
? [
|
||||
{ url: initialData.passport_file_1, label: 'Pasport (sahypa 1)' },
|
||||
{ url: initialData.passport_file_2, label: 'Pasport (2-3-nji sahypa)' },
|
||||
{ url: initialData.passport_file_3, label: 'Pasport (8-9 sahypa)' },
|
||||
{ url: initialData.passport_file_4, label: 'Pasport (32-nji sahypa)' },
|
||||
].filter((f): f is { url: string; label: string } => !!f.url)
|
||||
: []
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Pasport seriýasy"
|
||||
required
|
||||
value={form.passport_series}
|
||||
onChange={(v) => set('passport_series', v)}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.passport_series}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasport belgisi"
|
||||
required
|
||||
value={form.passport_number}
|
||||
onChange={(v) => set('passport_number', v)}
|
||||
placeholder="Pasport belgisi"
|
||||
error={errors.passport_number}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{existingFiles.length > 0 && (
|
||||
<BentoGrid cols={4}>
|
||||
{existingFiles.map(({ url, label }) => (
|
||||
<BentoCard key={label} title={label}>
|
||||
<a
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-xs text-primary underline truncate block"
|
||||
>
|
||||
Faýly gör
|
||||
</a>
|
||||
</BentoCard>
|
||||
))}
|
||||
</BentoGrid>
|
||||
)}
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={mode === 'edit' ? 'Pasport (sahypa 1) (çalyşmak)' : 'Pasport (sahypa 1)'}
|
||||
required={mode === 'create'}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={form.passport_file_1}
|
||||
onFileChange={(f) => set('passport_file_1', f)}
|
||||
error={errors.passport_file_1}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={mode === 'edit' ? 'Pasport (2-3-nji sahypa) (çalyşmak)' : 'Pasport (2-3-nji sahypa)'}
|
||||
required={mode === 'create'}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={form.passport_file_2}
|
||||
onFileChange={(f) => set('passport_file_2', f)}
|
||||
error={errors.passport_file_2}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={mode === 'edit' ? 'Pasport (8-9 sahypa) (çalyşmak)' : 'Pasport (8-9 sahypa)'}
|
||||
required={mode === 'create'}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={form.passport_file_3}
|
||||
onFileChange={(f) => set('passport_file_3', f)}
|
||||
error={errors.passport_file_3}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={mode === 'edit' ? 'Pasport (32-nji sahypa) (çalyşmak)' : 'Pasport (32-nji sahypa)'}
|
||||
required={mode === 'create'}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={form.passport_file_4}
|
||||
onFileChange={(f) => set('passport_file_4', f)}
|
||||
error={errors.passport_file_4}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardPinFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [form, setForm] = useState<FormState>(defaultState)
|
||||
const [form, setForm] = useState<FormState>(() => initialData ? mapToFormState(initialData) : INITIAL_STATE)
|
||||
const [errors, setErrors] = useState<FormErrors>({})
|
||||
const [currentStep, setCurrentStep] = useState(0)
|
||||
const [stepStatuses, setStepStatuses] = useState<StepStatus[]>(['active', 'idle', 'idle'])
|
||||
const [currentStep, setCurrentStep] = useState(0)
|
||||
const [visited, setVisited] = useState<Set<number>>(
|
||||
() => mode === 'edit' ? new Set(STEPS.map((_, i) => i)) : new Set<number>(),
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === 'edit' && initialData) {
|
||||
setForm({
|
||||
status: initialData.status,
|
||||
note: initialData.note ?? '',
|
||||
card_type: initialData.card_type,
|
||||
card_number: initialData.card_number,
|
||||
province: initialData.province,
|
||||
branch: initialData.branch,
|
||||
first_name: initialData.first_name,
|
||||
last_name: initialData.last_name,
|
||||
father_name: initialData.father_name,
|
||||
birth_date: initialData.birth_date,
|
||||
phone: initialData.phone,
|
||||
passport_series: initialData.passport_series,
|
||||
passport_number: initialData.passport_number,
|
||||
passport_file_1: null,
|
||||
passport_file_2: null,
|
||||
passport_file_3: null,
|
||||
passport_file_4: null,
|
||||
})
|
||||
}
|
||||
}, [mode, initialData])
|
||||
if (initialData) setForm(mapToFormState(initialData))
|
||||
}, [initialData])
|
||||
|
||||
const set = <K extends keyof FormState>(key: K, value: FormState[K]) => {
|
||||
// ── Computed step errors ───────────────────────────────────────────────────
|
||||
|
||||
const stepsWithErrors = useMemo(() => {
|
||||
const out = new Set<number>()
|
||||
visited.forEach((i) => {
|
||||
if (Object.keys(STEPS[i].validate(form, mode)).length > 0) out.add(i)
|
||||
})
|
||||
return out
|
||||
}, [form, mode, visited])
|
||||
|
||||
// ── set helper ─────────────────────────────────────────────────────────────
|
||||
|
||||
const set = useCallback(<K extends keyof FormState>(key: K, value: FormState[K]) => {
|
||||
setForm((prev) => ({ ...prev, [key]: value }))
|
||||
setErrors((prev) => ({ ...prev, [key]: undefined }))
|
||||
}
|
||||
}, [])
|
||||
|
||||
// ── Step navigation ────────────────────────────────────────────────────────
|
||||
const stepProps = useMemo(() => ({ form, errors, set }), [form, errors, set])
|
||||
|
||||
const updateStatus = (index: number, status: StepStatus) => {
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]
|
||||
next[index] = status
|
||||
return next
|
||||
})
|
||||
}
|
||||
// ── Navigation ─────────────────────────────────────────────────────────────
|
||||
|
||||
const goToStep = (index: number) => {
|
||||
updateStatus(currentStep, stepStatuses[currentStep] === 'error' ? 'error' : 'done')
|
||||
updateStatus(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, mode, currentStep)
|
||||
if (Object.keys(stepErrors).length > 0) {
|
||||
setErrors((prev) => ({ ...prev, ...stepErrors }))
|
||||
updateStatus(currentStep, 'error')
|
||||
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.')
|
||||
const firstKey = Object.keys(stepErrors)[0]
|
||||
document.getElementById(`field-${firstKey}`)?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
return
|
||||
}
|
||||
updateStatus(currentStep, 'done')
|
||||
const next = currentStep + 1
|
||||
updateStatus(next, 'active')
|
||||
setCurrentStep(next)
|
||||
setErrors({})
|
||||
setCurrentStep(currentStep + 1)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const handlePrev = () => {
|
||||
const prev = currentStep - 1
|
||||
updateStatus(currentStep, stepStatuses[currentStep] === 'error' ? 'error' : 'idle')
|
||||
updateStatus(prev, 'active')
|
||||
setCurrentStep(prev)
|
||||
const handleBack = () => {
|
||||
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' })
|
||||
}
|
||||
|
||||
// ── Submit ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const handleSubmit = () => {
|
||||
const allErrors = validate(form, 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)
|
||||
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 StepStatus[]
|
||||
setStepStatuses(newStatuses)
|
||||
toast.error('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
|
||||
}
|
||||
|
||||
@@ -279,287 +560,56 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
|
||||
})
|
||||
}
|
||||
|
||||
// ── Step bar items ─────────────────────────────────────────────────────────
|
||||
// ── StepBar items ──────────────────────────────────────────────────────────
|
||||
|
||||
const stepDefs = [
|
||||
{
|
||||
id: 'card',
|
||||
title: t('cardPin.step.card', 'Kart'),
|
||||
subtitle: t('cardPin.step.cardSub', 'Görnüş & lokasiýa'),
|
||||
icon: CreditCard,
|
||||
},
|
||||
{
|
||||
id: 'personal',
|
||||
title: t('cardPin.step.personal', 'Şahsy'),
|
||||
subtitle: t('cardPin.step.personalSub', 'Maglumatlar'),
|
||||
icon: User,
|
||||
},
|
||||
{
|
||||
id: 'passport',
|
||||
title: t('cardPin.step.passport', 'Pasport'),
|
||||
subtitle: t('cardPin.step.passportSub', 'Resminamalar'),
|
||||
icon: FileText,
|
||||
},
|
||||
]
|
||||
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.titleKey) || s.titleFallback,
|
||||
subtitle: s.subtitle,
|
||||
icon: s.icon,
|
||||
status: isActive ? 'active' : hasErrors ? 'error' : isDone ? 'done' : 'idle',
|
||||
}
|
||||
})
|
||||
|
||||
const stepItems: StepCardItem[] = stepDefs.map((def, i) => ({
|
||||
...def,
|
||||
status: stepStatuses[i],
|
||||
}))
|
||||
|
||||
const isFirstStep = currentStep === 0
|
||||
const isLastStep = currentStep === stepDefs.length - 1
|
||||
|
||||
const title = mode === 'create'
|
||||
? t('cardPin.create', 'Kart pin bukja dörediň')
|
||||
: t('cardPin.edit', 'Kart pin bukja redaktirläň')
|
||||
|
||||
const submitLabel = mode === 'create'
|
||||
? t('cardPin.createBtn', 'Kart pin bukja dörediň')
|
||||
: t('cardPin.editBtn', 'Kart pin bukja redaktirläň')
|
||||
const isLastStep = currentStep === STEPS.length - 1
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">{title}</h1>
|
||||
|
||||
|
||||
{/* ── Step Bar ─────────────────────────────────────────────────────── */}
|
||||
{/* Step bar */}
|
||||
<div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
|
||||
<StepBarCards steps={stepItems} onGoTo={goToStep} />
|
||||
<StepBarCards steps={stepBarItems} onGoTo={handleGoTo} />
|
||||
</div>
|
||||
|
||||
{/* ── Step 0: Kart & Lokasiýa ──────────────────────────────────────── */}
|
||||
{currentStep === 0 && (
|
||||
<>
|
||||
<Section>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div id="field-status">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('cardPin.status', 'Status')}
|
||||
value={form.status}
|
||||
onChange={(v) => set('status', v)}
|
||||
options={STATUS_OPTIONS}
|
||||
error={errors.status}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('cardPin.note', 'Bellik')}
|
||||
value={form.note}
|
||||
onChange={(v) => set('note', v)}
|
||||
placeholder={t('cardPin.notePlaceholder', 'Bellik')}
|
||||
/>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<Section title={t('cardPin.cardSection', 'Kart')}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div id="field-card_type">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('cardPin.cardType', 'Kart görnüşi')}
|
||||
value={form.card_type}
|
||||
onChange={(v) => set('card_type', v)}
|
||||
options={CARD_TYPE_OPTIONS}
|
||||
error={errors.card_type}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-card_number">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('cardPin.cardNumber', 'Kart belgisi')}
|
||||
value={form.card_number}
|
||||
onChange={(v) => set('card_number', v)}
|
||||
placeholder={t('cardPin.cardNumberPlaceholder', 'Kart belgisi')}
|
||||
error={errors.card_number}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<Section title={t('cardPin.locationSection', 'Lokasiýa')}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div id="field-province">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('cardPin.province', 'Welaýat')}
|
||||
value={form.province}
|
||||
onChange={(v) => { set('province', v); set('branch', '') }}
|
||||
options={PROVINCE_OPTIONS}
|
||||
error={errors.province}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-branch">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('cardPin.branch', 'Şahamça')}
|
||||
value={form.branch}
|
||||
onChange={(v) => set('branch', v)}
|
||||
options={[]}
|
||||
placeholder={t('cardPin.branchPlaceholder', 'Saýlamak üçin basyň')}
|
||||
error={errors.branch}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ── Step 1: Şahsy maglumatlar ─────────────────────────────────────── */}
|
||||
{currentStep === 1 && (
|
||||
<Section title={t('cardPin.personalSection', 'Şahsy maglumatlar')}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<div id="field-first_name">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('cardPin.firstName', 'Ady')}
|
||||
value={form.first_name}
|
||||
onChange={(v) => set('first_name', v)}
|
||||
placeholder={t('cardPin.firstName', 'Ady')}
|
||||
error={errors.first_name}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-last_name">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('cardPin.lastName', 'Familiýasy')}
|
||||
value={form.last_name}
|
||||
onChange={(v) => set('last_name', v)}
|
||||
placeholder={t('cardPin.lastName', 'Familiýasy')}
|
||||
error={errors.last_name}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('cardPin.fatherName', 'Atasynyň ady')}
|
||||
value={form.father_name}
|
||||
onChange={(v) => set('father_name', v)}
|
||||
placeholder={t('cardPin.fatherName', 'Atasynyň ady')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-4">
|
||||
<div id="field-birth_date">
|
||||
<FormInput
|
||||
type="date"
|
||||
label={t('cardPin.birthDate', 'Doglan güni')}
|
||||
value={form.birth_date}
|
||||
onChange={(v) => set('birth_date', v)}
|
||||
error={errors.birth_date}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-phone">
|
||||
<FormInput
|
||||
type="phone"
|
||||
label={t('cardPin.phone', 'Telefon')}
|
||||
value={form.phone}
|
||||
onChange={(v) => set('phone', v)}
|
||||
error={errors.phone}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{/* ── Step 2: Pasport & Faýllar ─────────────────────────────────────── */}
|
||||
{/* Step content */}
|
||||
{currentStep === 0 && <StepCard {...stepProps} />}
|
||||
{currentStep === 1 && <StepPersonal {...stepProps} />}
|
||||
{currentStep === 2 && (
|
||||
<Section title={t('cardPin.passportSection', 'Pasport')}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div id="field-passport_series">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('cardPin.passportSeries', 'Pasport seriýasy')}
|
||||
value={form.passport_series}
|
||||
onChange={(v) => set('passport_series', v)}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
error={errors.passport_series}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-passport_number">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('cardPin.passportNumber', 'Pasport belgisi')}
|
||||
value={form.passport_number}
|
||||
onChange={(v) => set('passport_number', v)}
|
||||
placeholder={t('cardPin.passportNumber', 'Pasport belgisi')}
|
||||
error={errors.passport_number}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-4">
|
||||
<div id="field-passport_file_1">
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('cardPin.passportFile1', 'Pasport (sahypa 1)')}
|
||||
onFileChange={(f) => set('passport_file_1', f)}
|
||||
fileValue={form.passport_file_1}
|
||||
accept="image/*,.pdf"
|
||||
error={errors.passport_file_1}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-passport_file_2">
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('cardPin.passportFile2', 'Pasport (2-3-nji sahypa)')}
|
||||
onFileChange={(f) => set('passport_file_2', f)}
|
||||
fileValue={form.passport_file_2}
|
||||
accept="image/*,.pdf"
|
||||
error={errors.passport_file_2}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-passport_file_3">
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('cardPin.passportFile3', 'Pasport (8-9 sahypa)')}
|
||||
onFileChange={(f) => set('passport_file_3', f)}
|
||||
fileValue={form.passport_file_3}
|
||||
accept="image/*,.pdf"
|
||||
error={errors.passport_file_3}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-passport_file_4">
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('cardPin.passportFile4', 'Pasport (32-nji sahypa)')}
|
||||
onFileChange={(f) => set('passport_file_4', f)}
|
||||
fileValue={form.passport_file_4}
|
||||
accept="image/*,.pdf"
|
||||
error={errors.passport_file_4}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
<StepPassport {...stepProps} mode={mode} initialData={initialData} />
|
||||
)}
|
||||
|
||||
{/* ── Form Actions ──────────────────────────────────────────────────── */}
|
||||
{/* Actions */}
|
||||
<FormActions
|
||||
isPending={isSubmitting}
|
||||
onCancel={() => navigate('/card-pins')}
|
||||
onPrev={!isFirstStep ? handlePrev : undefined}
|
||||
onCancel={currentStep === 0 ? () => navigate('/card-pins') : undefined}
|
||||
onPrev={currentStep > 0 ? handleBack : undefined}
|
||||
prevLabel={t('common.prev', 'Yza')}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
nextLabel={t('common.next', 'Indiki')}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={handleSubmit}
|
||||
submitLabel={submitLabel}
|
||||
onSubmit={isLastStep ? handleSubmit : undefined}
|
||||
submitLabel={
|
||||
mode === 'create'
|
||||
? t('cardPin.createBtn', 'Kart pin bukja dörediň')
|
||||
: t('cardPin.editBtn', 'Kart pin bukja redaktirläň')
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ export interface CardRequisite {
|
||||
// Personal
|
||||
first_name: string
|
||||
last_name: string
|
||||
middle_name: string
|
||||
middle_name?: string
|
||||
birth_date: string
|
||||
phone: string
|
||||
|
||||
@@ -47,7 +47,7 @@ export interface CardRequisiteListResponse {
|
||||
|
||||
export interface CreateCardRequisitePayload {
|
||||
status: CardRequisiteStatus
|
||||
note: string
|
||||
note?: string
|
||||
card_type: string
|
||||
card_number: string
|
||||
card_expiry_month: string
|
||||
@@ -56,7 +56,7 @@ export interface CreateCardRequisitePayload {
|
||||
branch_id: string
|
||||
first_name: string
|
||||
last_name: string
|
||||
middle_name: string
|
||||
middle_name?: string
|
||||
birth_date: string
|
||||
phone: string
|
||||
passport_series: string
|
||||
@@ -102,15 +102,132 @@ function buildFormData(payload: CreateCardRequisitePayload): FormData {
|
||||
return fd
|
||||
}
|
||||
|
||||
// ─── Mock data ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const MOCK_CARD_REQUISITES: CardRequisite[] = [
|
||||
{
|
||||
id: '1',
|
||||
status: 'pending',
|
||||
note: '',
|
||||
card_type: 'UZCARD',
|
||||
card_number: '8600123456789012',
|
||||
card_expiry_month: '12',
|
||||
card_expiry_year: '28',
|
||||
province_id: '1',
|
||||
branch_id: '1',
|
||||
province_name: 'Toshkent',
|
||||
branch_name: 'Filial 1',
|
||||
first_name: 'Ali',
|
||||
last_name: 'Valiyev',
|
||||
middle_name: 'Akbarovich',
|
||||
birth_date: '1990-05-15',
|
||||
phone: '+998901234567',
|
||||
passport_series: 'AA',
|
||||
passport_number: '1234567',
|
||||
created_at: '2025-01-15T10:30:00Z',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
status: 'approved',
|
||||
note: 'Approved',
|
||||
card_type: 'HUMO',
|
||||
card_number: '9860123456789012',
|
||||
card_expiry_month: '05',
|
||||
card_expiry_year: '27',
|
||||
province_id: '2',
|
||||
branch_id: '3',
|
||||
province_name: 'Samarqand',
|
||||
branch_name: 'Filial 3',
|
||||
first_name: 'Bobur',
|
||||
last_name: 'Karimov',
|
||||
middle_name: 'Rustamovich',
|
||||
birth_date: '1985-08-22',
|
||||
phone: '+998907654321',
|
||||
passport_series: 'AB',
|
||||
passport_number: '7654321',
|
||||
created_at: '2025-02-20T14:00:00Z',
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
status: 'rejected',
|
||||
note: 'Hujjatlar not\'g\'ri',
|
||||
card_type: 'VISA',
|
||||
card_number: '4400123456789012',
|
||||
card_expiry_month: '08',
|
||||
card_expiry_year: '26',
|
||||
province_id: '3',
|
||||
branch_id: '5',
|
||||
province_name: 'Buxoro',
|
||||
branch_name: 'Filial 5',
|
||||
first_name: 'Dilorom',
|
||||
last_name: 'Rahimova',
|
||||
middle_name: 'Shavkatovna',
|
||||
birth_date: '1995-11-02',
|
||||
phone: '+998903334455',
|
||||
passport_series: 'AC',
|
||||
passport_number: '1122334',
|
||||
created_at: '2025-03-10T09:15:00Z',
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
status: 'pending',
|
||||
note: '',
|
||||
card_type: 'UZCARD',
|
||||
card_number: '5300123456789012',
|
||||
card_expiry_month: '01',
|
||||
card_expiry_year: '30',
|
||||
province_id: '4',
|
||||
branch_id: '7',
|
||||
province_name: 'Farg\'ona',
|
||||
branch_name: 'Filial 7',
|
||||
first_name: 'Elyor',
|
||||
last_name: 'Toshmatov',
|
||||
middle_name: 'Olimovich',
|
||||
birth_date: '2000-03-18',
|
||||
phone: '+998905556677',
|
||||
passport_series: 'KA',
|
||||
passport_number: '9988776',
|
||||
created_at: '2025-04-05T16:45:00Z',
|
||||
},
|
||||
{
|
||||
id: '5',
|
||||
status: 'approved',
|
||||
note: 'Tasdiqlangan',
|
||||
card_type: 'HUMO',
|
||||
card_number: '6200123456789012',
|
||||
card_expiry_month: '03',
|
||||
card_expiry_year: '29',
|
||||
province_id: '5',
|
||||
branch_id: '9',
|
||||
province_name: 'Namangan',
|
||||
branch_name: 'Filial 9',
|
||||
first_name: 'Gulnora',
|
||||
last_name: 'Abdullayeva',
|
||||
middle_name: 'Anvarovna',
|
||||
birth_date: '1992-07-30',
|
||||
phone: '+998908889900',
|
||||
passport_series: 'KB',
|
||||
passport_number: '5566778',
|
||||
created_at: '2025-05-12T11:30:00Z',
|
||||
},
|
||||
]
|
||||
|
||||
// ─── API functions ────────────────────────────────────────────────────────────
|
||||
|
||||
export const cardRequisitesApi = {
|
||||
getAll: async (params?: CardRequisiteListParams): Promise<CardRequisiteListResponse> => {
|
||||
// Mock data kullanmak için aşağıdaki satırı yorumdan çıkarabilirsiniz:
|
||||
return { data: MOCK_CARD_REQUISITES, total: MOCK_CARD_REQUISITES.length, page: params?.page || 1, per_page: params?.per_page || 10 }
|
||||
|
||||
const { data } = await apiClient.get('/card-requisites', { params })
|
||||
return data
|
||||
},
|
||||
|
||||
getById: async (id: string): Promise<CardRequisite> => {
|
||||
// Mock data kullanmak için aşağıdaki satırı yorumdan çıkarabilirsiniz:
|
||||
const mock = MOCK_CARD_REQUISITES.find(r => r.id === id)
|
||||
if (mock) return mock
|
||||
|
||||
const { data } = await apiClient.get(`/card-requisites/${id}`)
|
||||
return data
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,40 +1,79 @@
|
||||
import axios from 'axios'
|
||||
import axios from "axios";
|
||||
import { useAuthStore } from "@/app/store/authStore";
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL ?? '/api'
|
||||
const apiClient = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
export const apiClient = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: 15_000,
|
||||
})
|
||||
let isRefreshing = false;
|
||||
let failedQueue: any[] = [];
|
||||
|
||||
// Request interceptor — attach token
|
||||
const processQueue = (error: any, token: string | null = null) => {
|
||||
failedQueue.forEach((prom) => {
|
||||
if (error) prom.reject(error);
|
||||
else prom.resolve(token);
|
||||
});
|
||||
failedQueue = [];
|
||||
};
|
||||
|
||||
// Request Interceptor (Token ekleme)
|
||||
apiClient.interceptors.request.use((config) => {
|
||||
const raw = localStorage.getItem('tbbank-auth')
|
||||
if (raw) {
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as { state?: { token?: string } }
|
||||
const token = parsed?.state?.token
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
} catch {
|
||||
// ignore parse errors
|
||||
}
|
||||
const token = useAuthStore.getState().token;
|
||||
if (token && config.headers) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config
|
||||
})
|
||||
return config;
|
||||
}, (error) => Promise.reject(error));
|
||||
|
||||
// Response interceptor — handle 401
|
||||
// Response Interceptor (Senior Hata Yönetimi)
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error: unknown) => {
|
||||
if (axios.isAxiosError(error) && error.response?.status === 401) {
|
||||
localStorage.removeItem('tbbank-auth')
|
||||
window.location.replace('/login')
|
||||
async (error) => {
|
||||
const originalRequest = error.config;
|
||||
const status = error.response?.status;
|
||||
|
||||
// 1. 401 Unauthorized & Refresh Token Yönetimi
|
||||
if (status === 401 && !originalRequest._retry) {
|
||||
if (isRefreshing) {
|
||||
return new Promise((resolve, reject) => {
|
||||
failedQueue.push({ resolve, reject });
|
||||
})
|
||||
.then((token) => {
|
||||
originalRequest.headers.Authorization = `Bearer ${token}`;
|
||||
return apiClient(originalRequest);
|
||||
})
|
||||
.catch((err) => Promise.reject(err));
|
||||
}
|
||||
|
||||
originalRequest._retry = true;
|
||||
isRefreshing = true;
|
||||
|
||||
try {
|
||||
// Sessizce yeni token almayı dene (Zustand içindeki refresh action'ı)
|
||||
const newToken = await useAuthStore.getState().refreshToken();
|
||||
processQueue(null, newToken);
|
||||
originalRequest.headers.Authorization = `Bearer ${newToken}`;
|
||||
return apiClient(originalRequest);
|
||||
} catch (refreshError) {
|
||||
processQueue(refreshError, null);
|
||||
// Refresh de patladıysa kullanıcıyı temizce çıkışa zorla
|
||||
useAuthStore.getState().logout();
|
||||
// SPA dostu yönlendirme: Sayfa yenilemeden custom bir event veya global history ile
|
||||
window.dispatchEvent(new Event("auth:unauthorized"));
|
||||
return Promise.reject(refreshError);
|
||||
} finally {
|
||||
isRefreshing = false;
|
||||
}
|
||||
}
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
// 2. 403 Forbidden Yönetimi (Kullanıcıyı haberdar et, akışı durdur)
|
||||
if (status === 403) {
|
||||
window.dispatchEvent(new Event("auth:forbidden"));
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default apiClient;
|
||||
@@ -1,415 +1,306 @@
|
||||
import { format } from "date-fns";
|
||||
import {
|
||||
Trash2,
|
||||
Edit,
|
||||
Search,
|
||||
Download,
|
||||
Clock,
|
||||
XCircle,
|
||||
CheckCircle2,
|
||||
AlertCircle,
|
||||
} from "lucide-react";
|
||||
import { format } from 'date-fns'
|
||||
import { Trash2, Edit, Search, Download, XCircle, CheckCircle2, AlertCircle } from 'lucide-react'
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge'
|
||||
import { InfoRow, AuditLog, type AuditRowProps } from '@/components/viewPageComponents'
|
||||
import { useSberPaymentOrder, useDeleteSberPayment } from '@/features/sberPayments/hooks/useSberPayments'
|
||||
import type { PaymentPaidStatus, PaymentStatus } from '@/features/sberPayments/api/sberPaymentsApi'
|
||||
import { useState } from 'react'
|
||||
|
||||
import {
|
||||
useSberPaymentOrder,
|
||||
useDeleteSberPayment,
|
||||
} from "@/features/sberPayments/hooks/useSberPayments";
|
||||
import type {
|
||||
PaymentPaidStatus,
|
||||
PaymentStatus,
|
||||
} from "@/features/sberPayments/api/sberPaymentsApi";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import {
|
||||
StatusBadge,
|
||||
type StatusBadgeVariant,
|
||||
} from "@/components/ui/statusBadge";
|
||||
import { InfoRow, Section } from "@/components/viewPageComponents";
|
||||
// ─── Status config ────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CONFIG = {
|
||||
GARASYLYYAR: {
|
||||
label: "Garaşylýar",
|
||||
variant: "warning" as StatusBadgeVariant,
|
||||
icon: AlertCircle,
|
||||
},
|
||||
KANAGATLANDYRYLAN: {
|
||||
label: "Tassyklandy",
|
||||
variant: "success" as StatusBadgeVariant,
|
||||
icon: CheckCircle2,
|
||||
},
|
||||
RET_EDILEN: {
|
||||
label: "Ýatyryldy",
|
||||
variant: "error" as StatusBadgeVariant,
|
||||
icon: XCircle,
|
||||
},
|
||||
} satisfies Record<
|
||||
PaymentStatus,
|
||||
{ label: string; variant: StatusBadgeVariant; icon: React.ElementType }
|
||||
>;
|
||||
GARASYLYYAR: { label: 'Garaşylýar', variant: 'warning' as StatusBadgeVariant, icon: AlertCircle },
|
||||
KANAGATLANDYRYLAN: { label: 'Tassyklandy', variant: 'success' as StatusBadgeVariant, icon: CheckCircle2 },
|
||||
RET_EDILEN: { label: 'Ýatyryldy', variant: 'error' as StatusBadgeVariant, icon: XCircle },
|
||||
} satisfies Record<PaymentStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>
|
||||
|
||||
const PAID_STATUS_CONFIG = {
|
||||
Tolenmedik: {
|
||||
label: "Tölmedi",
|
||||
variant: "error" as StatusBadgeVariant,
|
||||
icon: XCircle,
|
||||
},
|
||||
Tolendi: {
|
||||
label: "Tölendi",
|
||||
variant: "success" as StatusBadgeVariant,
|
||||
icon: CheckCircle2,
|
||||
},
|
||||
} satisfies Record<
|
||||
PaymentPaidStatus,
|
||||
{ label: string; variant: StatusBadgeVariant; icon: React.ElementType }
|
||||
>;
|
||||
|
||||
function PaymentPaidStatusBadge({ status }: { status: PaymentPaidStatus }) {
|
||||
const cfg = PAID_STATUS_CONFIG[status];
|
||||
if (!cfg)
|
||||
return (
|
||||
<span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
);
|
||||
return (
|
||||
<StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
);
|
||||
}
|
||||
Tolenmedik: { label: 'Tölmedi', variant: 'error' as StatusBadgeVariant, icon: XCircle },
|
||||
Tolendi: { label: 'Tölendi', variant: 'success' as StatusBadgeVariant, icon: CheckCircle2 },
|
||||
} satisfies Record<PaymentPaidStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>
|
||||
|
||||
function PaymentStatusBadge({ status }: { status: PaymentStatus }) {
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg)
|
||||
return (
|
||||
<span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
);
|
||||
return (
|
||||
<StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
);
|
||||
const cfg = STATUS_CONFIG[status]
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
}
|
||||
// ─── Info Row Component ───────────────────────────────────────────────────────
|
||||
|
||||
function PaymentPaidStatusBadge({ status }: { status: PaymentPaidStatus }) {
|
||||
const cfg = PAID_STATUS_CONFIG[status]
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
}
|
||||
|
||||
// ─── Bento primitives ─────────────────────────────────────────────────────────
|
||||
|
||||
// ─── Document Item Component ──────────────────────────────────────────────────
|
||||
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 <div className={`grid ${colClass} gap-4`}>{children}</div>
|
||||
}
|
||||
|
||||
function DocumentItem({
|
||||
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 (
|
||||
<div className={`bg-card border border-border rounded-xl overflow-hidden ${spanClass}`}>
|
||||
{title && (
|
||||
<div className="px-4 py-2.5 border-b border-border">
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Document row ─────────────────────────────────────────────────────────────
|
||||
|
||||
function DocumentRow({
|
||||
label,
|
||||
fileName,
|
||||
fileUrl,
|
||||
}: {
|
||||
label: string;
|
||||
fileName: string | null;
|
||||
fileUrl: string | null;
|
||||
label: string
|
||||
fileName: string | null
|
||||
fileUrl: string | null
|
||||
}) {
|
||||
if (!fileUrl) return (
|
||||
<InfoRow label={label}>
|
||||
<span className="text-muted-foreground/50">—</span>
|
||||
</InfoRow>
|
||||
)
|
||||
|
||||
const name = fileName ?? fileUrl.split('/').pop() ?? 'faýl'
|
||||
|
||||
return (
|
||||
<div className="flex items-start gap-4 py-3 border-b border-border last:border-b-0 px-4">
|
||||
<span className="w-80 shrink-0 text-sm text-muted-foreground leading-relaxed">
|
||||
{label}
|
||||
</span>
|
||||
<div className="flex-1">
|
||||
{fileUrl ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<button className="p-1.5 rounded bg-muted hover:bg-accent transition-colors">
|
||||
<Search size={14} className="text-muted-foreground" />
|
||||
</button>
|
||||
<button className="p-1.5 rounded bg-muted hover:bg-accent transition-colors">
|
||||
<Download size={14} className="text-muted-foreground" />
|
||||
</button>
|
||||
<span className="px-3 py-1.5 bg-primary/20 text-primary text-xs font-medium rounded">
|
||||
{fileName}
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-sm text-muted-foreground">—</span>
|
||||
)}
|
||||
<InfoRow label={label}>
|
||||
<div className="flex items-center gap-2">
|
||||
<button className="p-1.5 rounded bg-muted hover:bg-accent transition-colors">
|
||||
<Search size={12} className="text-muted-foreground" />
|
||||
</button>
|
||||
<a
|
||||
href={fileUrl}
|
||||
download
|
||||
className="flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-primary/10 hover:bg-primary/20 text-xs text-primary transition-colors"
|
||||
>
|
||||
<Download size={12} />
|
||||
<span className="max-w-[140px] truncate">{name}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
</InfoRow>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── View Page Component ──────────────────────────────────────────────────────
|
||||
// ─── Skeleton ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function SberPaymentViewSkeleton() {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Skeleton className="h-7 w-64" />
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
{[...Array(4)].map((_, i) => (
|
||||
<div key={i} className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3">
|
||||
<Skeleton className="h-3 w-24 mb-1" />
|
||||
{[...Array(3)].map((_, j) => (
|
||||
<Skeleton key={j} className="h-4 w-full" />
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function SberPaymentViewPage() {
|
||||
const params = useParams();
|
||||
const navigate = useNavigate();
|
||||
const id = params.id as string;
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const [historySearch, setHistorySearch] = useState('')
|
||||
|
||||
const { data: order, isLoading } = useSberPaymentOrder(id);
|
||||
const deleteMutation = useDeleteSberPayment();
|
||||
const { data: order, isLoading } = useSberPaymentOrder(id!)
|
||||
const deleteMutation = useDeleteSberPayment()
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (confirm("Bu tolegi pozmak isleyanizmi?")) {
|
||||
await deleteMutation.mutateAsync(id);
|
||||
navigate("/sber-payments");
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Spinner className="w-8 h-8" />
|
||||
</div>
|
||||
);
|
||||
if (!window.confirm('Bu tolegi pozmak isleyanizmi?')) return
|
||||
await deleteMutation.mutateAsync(id!)
|
||||
navigate('/sber-payments')
|
||||
}
|
||||
|
||||
if (isLoading) return <SberPaymentViewSkeleton />
|
||||
|
||||
if (!order) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-[400px] text-muted-foreground">
|
||||
<p>Toleg tapylmady</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => navigate("/sber-payments")}
|
||||
className="mt-4"
|
||||
>
|
||||
Yza
|
||||
</Button>
|
||||
<div className="flex items-center justify-center h-64 text-muted-foreground text-sm">
|
||||
Toleg tapylmady
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
const kabulDocs = order.documents?.slice(0, 6) ?? []
|
||||
const ugradDocs = order.documents?.slice(6) ?? []
|
||||
|
||||
const auditLogs: AuditRowProps[] = order.activityLog?.map((log) => ({
|
||||
id: log.id.split('-')[1] ?? log.id,
|
||||
action: log.analysisName,
|
||||
by: log.createdBy,
|
||||
target: log.target,
|
||||
status: log.status,
|
||||
date: format(new Date(log.createdAt), 'dd/MM/yyyy, HH:mm:ss') + ' GMT+5',
|
||||
})) ?? []
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header Actions */}
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={handleDelete}
|
||||
className="text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
>
|
||||
<Trash2 size={18} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => navigate(`/sber-payments/${id}/edit`)}
|
||||
>
|
||||
<Edit size={18} />
|
||||
</Button>
|
||||
<div className="flex flex-col gap-6">
|
||||
|
||||
{/* ── Page header ──────────────────────────────────────────────────── */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
Sberbank töleg: {order.id}
|
||||
</h1>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<button
|
||||
onClick={handleDelete}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="p-2 rounded-md cursor-pointer hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
|
||||
title="Poz"
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate(`/sber-payments/${id}/edit`)}
|
||||
className="p-2 rounded-md cursor-pointer hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title="Redaktirle"
|
||||
>
|
||||
<Edit size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Status Section */}
|
||||
<Section title="Status">
|
||||
<div className="px-4">
|
||||
{/* ── Row 1: Meta + Lokasiýa ────────────────────────────────────────── */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Esasy maglumatlar">
|
||||
<InfoRow label="ID" value={order.id} />
|
||||
<InfoRow label="Status">
|
||||
<PaymentStatusBadge status={order.status} />
|
||||
</InfoRow>
|
||||
<InfoRow label="Tolenen (Sul ay)">
|
||||
<InfoRow label="Tölenen (Sul aý)">
|
||||
<PaymentPaidStatusBadge status={order.paidStatus} />
|
||||
</InfoRow>
|
||||
<InfoRow label="Bellik" value={order.bellik} />
|
||||
</div>
|
||||
</Section>
|
||||
</BentoCard>
|
||||
|
||||
{/* Location Section */}
|
||||
<Section title="Lokasiya">
|
||||
<div className="px-4">
|
||||
<InfoRow label="Welayat" value={order.welayat} />
|
||||
<InfoRow label="Sahamca" value={order.sahamca} isLink />
|
||||
</div>
|
||||
</Section>
|
||||
<BentoCard title="Lokasiýa">
|
||||
<InfoRow label="Welaýat" value={order.welayat} />
|
||||
<InfoRow label="Şahamça" value={order.sahamca} isLink />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Personal Info Section */}
|
||||
<Section title="Sahsy maglumatlar">
|
||||
<div className="px-4">
|
||||
<InfoRow label="Pasportdaky ady" value={order.firstName} />
|
||||
<InfoRow label="Pasportdaky familiya" value={order.lastName} />
|
||||
<InfoRow label="Telefon" value={order.phone} />
|
||||
<InfoRow label="E-pocta" value={order.email} />
|
||||
<InfoRow label="Hazirki yasayys yeri" value={order.address} />
|
||||
</div>
|
||||
</Section>
|
||||
{/* ── Row 2: Şahsy maglumatlar + Töleg ─────────────────────────────── */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Şahsy maglumatlar">
|
||||
<InfoRow label="Pasportdaky ady" value={order.firstName} />
|
||||
<InfoRow label="Pasportdaky familiýa" value={order.lastName} />
|
||||
<InfoRow label="Telefon" value={order.phone} />
|
||||
<InfoRow label="E-poçta" value={order.email} />
|
||||
<InfoRow label="Häzirki ýaşaýyş ýeri" value={order.address} />
|
||||
</BentoCard>
|
||||
|
||||
{/* Payment Info Section */}
|
||||
<Section title="Toleg">
|
||||
<div className="px-4">
|
||||
<BentoCard title="Töleg">
|
||||
<InfoRow
|
||||
label="Tolegi ugradyjynyn maglumatlary"
|
||||
value={`I-M${order.passportNumber?.slice(0, 2) ?? "XX"}-${order.passportNumber ?? ""} ${order.fullName}`}
|
||||
label="Töleg ugradyjynyň maglumatlary"
|
||||
value={`I-M${order.passportNumber?.slice(0, 2) ?? 'XX'}-${order.passportNumber ?? ''} ${order.fullName}`}
|
||||
/>
|
||||
<InfoRow
|
||||
label="Toleg ugradyjynyn goyum hasaby"
|
||||
value={order.accountNumber}
|
||||
/>
|
||||
</div>
|
||||
<InfoRow label="Töleg ugradyjynyň goýum hasaby" value={order.accountNumber} />
|
||||
<InfoRow label="Pasport seriýasy" value={order.passportSeries} />
|
||||
<InfoRow label="Pasport nomeri" value={order.passportNumber} />
|
||||
<InfoRow label="Ady Familiýasy Atasynyň ady" value={order.fullName} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<div className="px-4 py-3 bg-muted/30 border-t border-border">
|
||||
<div className="text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-2">
|
||||
Tolegi kabul edijinin maglumatlary
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-4 text-sm">
|
||||
<div>
|
||||
<span className="text-muted-foreground">Pasport seriyasy</span>
|
||||
<p className="font-medium">{order.passportSeries}</p>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-muted-foreground">Pasport nomeri</span>
|
||||
<p className="font-medium">{order.passportNumber}</p>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-muted-foreground">
|
||||
Ady Familiyasy Atasynyn ady
|
||||
</span>
|
||||
<p className="font-medium">{order.fullName}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
{/* ── Row 3: Kabul ediji resminamalary ─────────────────────────────── */}
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title="Kabul ediji talyp boyunca resminamalary">
|
||||
{kabulDocs.length > 0
|
||||
? kabulDocs.map((doc) => (
|
||||
<DocumentRow key={doc.id} label={doc.label} fileName={doc.name} fileUrl={doc.fileUrl} />
|
||||
))
|
||||
: (
|
||||
<div className="px-4 py-8 text-center text-sm text-muted-foreground">
|
||||
Resminamalar ýok
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Documents - Accepted */}
|
||||
<div className="space-y-3">
|
||||
<h2 className="text-base font-semibold text-foreground">
|
||||
Kabul ediji talyp boyunca resminamalary
|
||||
</h2>
|
||||
<div className="bg-card rounded-lg border border-border">
|
||||
{order.documents?.slice(0, 6).map((doc) => (
|
||||
<DocumentItem
|
||||
key={doc.id}
|
||||
label={doc.label}
|
||||
fileName={doc.name}
|
||||
fileUrl={doc.fileUrl}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{/* ── Row 4: Ugradyjy resminamalary ────────────────────────────────── */}
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title="Ugradyjy boyunca resminamalary">
|
||||
{ugradDocs.length > 0
|
||||
? ugradDocs.map((doc) => (
|
||||
<DocumentRow key={doc.id} label={doc.label} fileName={doc.name} fileUrl={doc.fileUrl} />
|
||||
))
|
||||
: (
|
||||
<div className="px-4 py-8 text-center text-sm text-muted-foreground">
|
||||
Resminamalar ýok
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Documents - Sent */}
|
||||
<div className="space-y-3">
|
||||
<h2 className="text-base font-semibold text-foreground">
|
||||
Ugradyjy boyunca resminamalary
|
||||
</h2>
|
||||
<div className="bg-card rounded-lg border border-border">
|
||||
{order.documents
|
||||
?.slice(6)
|
||||
.map((doc) => (
|
||||
<DocumentItem
|
||||
key={doc.id}
|
||||
label={doc.label}
|
||||
fileName={doc.name}
|
||||
fileUrl={doc.fileUrl}
|
||||
{/* ── Row 5: Töleg taryhy ───────────────────────────────────────────── */}
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title="Töleg taryhy">
|
||||
<div className="p-4">
|
||||
<div className="relative max-w-xs mb-4">
|
||||
<Search size={13} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
|
||||
<input
|
||||
type="text"
|
||||
value={historySearch}
|
||||
onChange={(e) => setHistorySearch(e.target.value)}
|
||||
placeholder="Gözlemek"
|
||||
className="h-9 w-full pl-9 pr-3 rounded-md border border-border bg-background text-sm focus:outline-none focus:ring-2 focus:ring-ring"
|
||||
/>
|
||||
)) || (
|
||||
<div className="px-4 py-8 text-center text-muted-foreground text-sm">
|
||||
Resminamalar yok
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Payment History */}
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<h2 className="text-base font-semibold text-foreground">
|
||||
Toleg taryhy
|
||||
</h2>
|
||||
<button className="text-muted-foreground hover:text-foreground transition-colors">
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor">
|
||||
<path d="M6 0L7.5 4.5L12 6L7.5 7.5L6 12L4.5 7.5L0 6L4.5 4.5L6 0Z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="bg-card rounded-lg border border-border">
|
||||
<div className="flex items-center gap-2 px-4 py-3 border-b border-border">
|
||||
<Search size={14} className="text-muted-foreground" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Gozlemek"
|
||||
className="flex-1 bg-transparent text-sm placeholder:text-muted-foreground/50 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-center py-12 text-muted-foreground">
|
||||
<div className="text-center">
|
||||
<div className="w-12 h-12 mx-auto mb-3 rounded-lg bg-muted/50 flex items-center justify-center">
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
>
|
||||
<div className="flex flex-col items-center justify-center py-10 text-muted-foreground/50">
|
||||
<div className="w-12 h-12 mb-3 rounded-lg border-2 border-dashed border-muted-foreground/20 flex items-center justify-center">
|
||||
<svg viewBox="0 0 24 24" className="w-6 h-6" fill="none" stroke="currentColor" strokeWidth={1.5}>
|
||||
<rect x="3" y="3" width="18" height="18" rx="2" />
|
||||
<line x1="3" y1="9" x2="21" y2="9" />
|
||||
<line x1="9" y1="21" x2="9" y2="9" />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-sm">
|
||||
Berlen kriteriyalara Toleg gabat gelmedi.
|
||||
</p>
|
||||
<p className="text-sm">Berlen kriteriýalara Töleg gabat gelmedi.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<div className="flex items-center justify-end">
|
||||
<button className="p-1.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors">
|
||||
<Clock size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/* ── Audit log ────────────────────────────────────────────────────── */}
|
||||
<AuditLog logs={auditLogs} />
|
||||
|
||||
{/* Activity Log */}
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<h2 className="text-base font-semibold text-foreground">Ammallar</h2>
|
||||
<button className="text-muted-foreground hover:text-foreground transition-colors">
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor">
|
||||
<path d="M6 0L7.5 4.5L12 6L7.5 7.5L6 12L4.5 7.5L0 6L4.5 4.5L6 0Z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="bg-card rounded-lg border border-border overflow-hidden">
|
||||
{/* Table Header */}
|
||||
<div className="grid grid-cols-6 gap-4 px-4 py-2 bg-muted/40 text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
<span>ID</span>
|
||||
<span>Analys ady</span>
|
||||
<span>Kim tarapyndan</span>
|
||||
<span>Analys nysany (Targets)</span>
|
||||
<span>Analys statusy</span>
|
||||
<span>Sene</span>
|
||||
</div>
|
||||
|
||||
{/* Table Body */}
|
||||
{order.activityLog?.length ? (
|
||||
order.activityLog.map((log) => (
|
||||
<div
|
||||
key={log.id}
|
||||
className="grid grid-cols-6 gap-4 px-4 py-3 border-t border-border text-sm"
|
||||
>
|
||||
<span className="text-primary font-medium">
|
||||
{log.id.split("-")[1] ?? "45384"}
|
||||
</span>
|
||||
<span>{log.analysisName}</span>
|
||||
<span className="text-muted-foreground">{log.createdBy}</span>
|
||||
<span className="text-muted-foreground">{log.target}</span>
|
||||
<span>
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold",
|
||||
log.status === "FINISHED"
|
||||
? "bg-primary/20 text-primary"
|
||||
: "bg-muted text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{log.status}
|
||||
</span>
|
||||
</span>
|
||||
<span className="text-muted-foreground">
|
||||
{format(new Date(log.createdAt), "dd/MM/yyyy, HH:mm:ss")}{" "}
|
||||
GMT+5
|
||||
</span>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<div className="px-4 py-8 text-center text-muted-foreground text-sm border-t border-border">
|
||||
Ammallar yok
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
import { useState } from 'react'
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useIntlPayment, useDeleteIntlPayment } from '@/features/visaMasterPayments/hooks/useVisaMasterPayments'
|
||||
import type { IntlPaymentStatus } from '@/features/visaMasterPayments/api/visaMasterPaymentsApi'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Pencil, Trash2, Download, Search } from 'lucide-react'
|
||||
import { Pencil, Trash2, Download, Search, AlertCircle, CheckCircle2, XCircle } from 'lucide-react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
@@ -16,59 +13,120 @@ import {
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { useState } from 'react'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge'
|
||||
import { InfoRow, Section } from '@/components/viewPageComponents'
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
import { InfoRow } from '@/components/viewPageComponents'
|
||||
import { useIntlPayment, useDeleteIntlPayment } from '@/features/visaMasterPayments/hooks/useVisaMasterPayments'
|
||||
import type { IntlPaymentStatus } from '@/features/visaMasterPayments/api/visaMasterPaymentsApi'
|
||||
|
||||
const STATUS_MAP: Record<IntlPaymentStatus, { label: string; variant: StatusBadgeVariant }> = {
|
||||
pending: { label: 'Garaşylýar', variant: 'warning' },
|
||||
approved: { label: 'Tassyklandy', variant: 'success' },
|
||||
rejected: { label: 'Ret edildi', variant: 'error' },
|
||||
// ─── Status config ────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_MAP: Record<IntlPaymentStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }> = {
|
||||
pending: { label: 'Garaşylýar', variant: 'warning', icon: AlertCircle },
|
||||
approved: { label: 'Tassyklandy', variant: 'success', icon: CheckCircle2 },
|
||||
rejected: { label: 'Ret edildi', variant: 'error', icon: XCircle },
|
||||
}
|
||||
|
||||
function PaymentStatusBadge({ status }: { status: IntlPaymentStatus }) {
|
||||
const cfg = STATUS_MAP[status] ?? STATUS_MAP.pending
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||
}
|
||||
|
||||
// ─── 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 <div className={`grid ${colClass} gap-4`}>{children}</div>
|
||||
}
|
||||
|
||||
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 (
|
||||
<StatusBadge label={cfg.label} variant={cfg.variant} />
|
||||
<div className={`bg-card border border-border rounded-xl overflow-hidden ${spanClass}`}>
|
||||
{title && (
|
||||
<div className="px-4 py-2.5 border-b border-border">
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ─── DocFile row ─────────────────────────────────────────────────────────────
|
||||
// ─── DocFile row ──────────────────────────────────────────────────────────────
|
||||
|
||||
function DocFileRow({ label, url }: { label: string; url: string | null }) {
|
||||
if (!url) return (
|
||||
<div className="flex items-start gap-4 py-3 border-b border-border last:border-0">
|
||||
<span className="text-sm text-muted-foreground flex-1 leading-snug">{label}</span>
|
||||
<span className="text-sm text-muted-foreground/50">—</span>
|
||||
</div>
|
||||
<InfoRow label={label}>
|
||||
<span className="text-muted-foreground/50">—</span>
|
||||
</InfoRow>
|
||||
)
|
||||
|
||||
const filename = url.split('/').pop() ?? 'faýl'
|
||||
const isImage = /\.(jpg|jpeg|png|gif|webp)$/i.test(url)
|
||||
const isImage = /\.(jpg|jpeg|png|gif|webp)$/i.test(url)
|
||||
|
||||
return (
|
||||
<div className="flex items-start gap-4 py-3 border-b border-border last:border-0">
|
||||
<span className="text-sm text-muted-foreground flex-1 leading-snug">{label}</span>
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
<InfoRow label={label}>
|
||||
<div className="flex items-center gap-2">
|
||||
{isImage && (
|
||||
<a href={url} target="_blank" rel="noreferrer"
|
||||
<a
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-muted/50 hover:bg-muted text-xs text-foreground transition-colors"
|
||||
>
|
||||
<Search size={12} />
|
||||
<span className="max-w-[140px] truncate">{filename}</span>
|
||||
</a>
|
||||
)}
|
||||
<a href={url} download
|
||||
<a
|
||||
href={url}
|
||||
download
|
||||
className="flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-primary/10 hover:bg-primary/20 text-xs text-primary transition-colors"
|
||||
>
|
||||
<Download size={12} />
|
||||
<span className="max-w-[140px] truncate">{filename}</span>
|
||||
</a>
|
||||
</div>
|
||||
</InfoRow>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Skeleton ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function IntlPaymentViewSkeleton() {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Skeleton className="h-7 w-64" />
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
{[...Array(4)].map((_, i) => (
|
||||
<div key={i} className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3">
|
||||
<Skeleton className="h-3 w-24 mb-1" />
|
||||
{[...Array(3)].map((_, j) => (
|
||||
<Skeleton key={j} className="h-4 w-full" />
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -76,62 +134,62 @@ function DocFileRow({ label, url }: { label: string; url: string | null }) {
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function IntlPaymentViewPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data, isLoading, isError } = useIntlPayment(id!)
|
||||
const { mutate: deletePayment, isPending: isDeleting } = useDeleteIntlPayment()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
const [historySearch, setHistorySearch] = useState('')
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-8 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const { data, isLoading, isError } = useIntlPayment(id!)
|
||||
const { mutate: deletePayment, isPending: isDeleting } = useDeleteIntlPayment()
|
||||
|
||||
if (isLoading) return <IntlPaymentViewSkeleton />
|
||||
|
||||
if (isError || !data) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24 text-muted-foreground">
|
||||
<div className="flex items-center justify-center h-64 text-muted-foreground text-sm">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const KABUL_DOCS = [
|
||||
{ label: 'Talypyň degişli welaýata "SBERBANK" kartyň rekwizitleri', url: data.doc_sberbank_account },
|
||||
{ label: 'Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasy', url: data.doc_school_enrollment },
|
||||
{ label: 'Talypyň bilendiriň göçürmesi', url: data.doc_summons },
|
||||
{ label: 'Talypyň degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi', url: data.doc_passport_tm },
|
||||
{ label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi', url: data.doc_foreign_passport },
|
||||
{ label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň daşary ýurtda galan döwründe bakýan döwleti baradaky bellenen sahypasynyň göçürmesi', url: data.doc_foreign_passport_copy },
|
||||
{ label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň dowletiniň girmesiz baradaky bellenen sahypasynyň göçürmesi', url: data.doc_exit_permission },
|
||||
{ label: 'Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy barada maglumatlary daşary ýurt döwletiniň ýokary okuw mekdebinden haty', url: data.doc_school_foreign_info },
|
||||
{ label: 'Talypyň daşary ýurt döwletinde okaýandygy baradaky güwänamany daşary ýurt döwletiniň ýokary okuw mekdebinden haty', url: data.doc_school_departure_info },
|
||||
{ label: 'Talypyň degişli welaýata "SBERBANK" kartyň rekwizitleri', url: data.doc_sberbank_account },
|
||||
{ label: 'Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasy', url: data.doc_school_enrollment },
|
||||
{ label: 'Talypyň bilendiriň göçürmesi', url: data.doc_summons },
|
||||
{ label: 'Talypyň degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi', url: data.doc_passport_tm },
|
||||
{ label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi', url: data.doc_foreign_passport },
|
||||
{ label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň daşary ýurtda galan döwründe bakýan döwleti baradaky bellenen sahypasynyň göçürmesi', url: data.doc_foreign_passport_copy },
|
||||
{ label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň dowletiniň girmesiz baradaky bellenen sahypasynyň göçürmesi', url: data.doc_exit_permission },
|
||||
{ label: 'Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy barada maglumatlary daşary ýurt döwletiniň ýokary okuw mekdebinden haty', url: data.doc_school_foreign_info },
|
||||
{ label: 'Talypyň daşary ýurt döwletinde okaýandygy baradaky güwänamany daşary ýurt döwletiniň ýokary okuw mekdebinden haty', url: data.doc_school_departure_info },
|
||||
]
|
||||
|
||||
const UPGRAD_DOCS = [
|
||||
{ label: 'Upgradyý degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi', url: data.upd_doc_passport_tm },
|
||||
{ label: 'Upgradyý degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi', url: data.upd_doc_foreign_passport },
|
||||
{ label: 'Upgradyý Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň daşary ýurt döwletinde galýandygy baradaky şaýmynyň bellenen sahypasynyň göçürmesi', url: data.upd_doc_visa },
|
||||
{ label: 'Upgradyýyň we kabul edijiniň resminamalarynyň göçürmesi', url: data.upd_doc_acceptance_letter },
|
||||
{ label: 'Upgradyý we kabul ediji täze 2015-nji ýyldan soňra pasportynyň seriýasy baradaky maglumatlary', url: data.upd_doc_passport_biometric },
|
||||
{ label: 'Upgradyý we kabul ediji täze 2015-nji ýyldan soňra pasportynyň seriýasy baradaky göwnamasy', url: data.upd_doc_passport_old },
|
||||
{ label: 'Upgradyý degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi', url: data.upd_doc_passport_tm },
|
||||
{ label: 'Upgradyý degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi', url: data.upd_doc_foreign_passport },
|
||||
{ label: 'Upgradyý Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň daşary ýurt döwletinde galýandygy baradaky şaýmynyň bellenen sahypasynyň göçürmesi', url: data.upd_doc_visa },
|
||||
{ label: 'Upgradyýyň we kabul edijiniň resminamalarynyň göçürmesi', url: data.upd_doc_acceptance_letter },
|
||||
{ label: 'Upgradyý we kabul ediji täze 2015-nji ýyldan soňra pasportynyň seriýasy baradaky maglumatlary', url: data.upd_doc_passport_biometric },
|
||||
{ label: 'Upgradyý we kabul ediji täze 2015-nji ýyldan soňra pasportynyň seriýasy baradaky göwnamasy', url: data.upd_doc_passport_old },
|
||||
]
|
||||
|
||||
return (
|
||||
<div className=" mx-auto space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between">
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex flex-col gap-6">
|
||||
|
||||
{/* ── Page header ──────────────────────────────────────────────────── */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('intlPayment.viewTitle', 'Halkara töleg')}: {data.id}
|
||||
</h1>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button size="icon" variant="ghost" className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10">
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
<button
|
||||
className="p-2 rounded-md cursor-pointer hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
|
||||
title={t('common.delete', 'Poz')}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
@@ -153,17 +211,19 @@ export default function IntlPaymentViewPage() {
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
<Button size="icon" variant="ghost" className="h-8 w-8"
|
||||
<button
|
||||
onClick={() => navigate(`/intl-payments/visa-master/${id}/edit`)}
|
||||
className="p-2 rounded-md cursor-pointer hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t('common.edit', 'Redaktirle')}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
<Pencil size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Status */}
|
||||
<Section title={t('intlPayment.statusSection', 'Status')}>
|
||||
<div className="divide-y divide-border">
|
||||
{/* ── Row 1: Meta + Ýüztuman + Lokasiýa ───────────────────────────── */}
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard title={t('intlPayment.statusSection', 'Esasy maglumatlar')}>
|
||||
<InfoRow label={t('intlPayment.client', 'Ulanyjy')}>
|
||||
<span className="text-primary font-medium">{data.client_label}</span>
|
||||
</InfoRow>
|
||||
@@ -173,125 +233,89 @@ export default function IntlPaymentViewPage() {
|
||||
<InfoRow label={t('intlPayment.status', 'Status')}>
|
||||
<PaymentStatusBadge status={data.status} />
|
||||
</InfoRow>
|
||||
<InfoRow label={t('intlPayment.tilowanMonth', 'Tölewan (Aý/aý)')}>
|
||||
{data.created_at}
|
||||
</InfoRow>
|
||||
<InfoRow label={t('intlPayment.note', 'Bellik')}>
|
||||
{data.note}
|
||||
</InfoRow>
|
||||
</div>
|
||||
</Section>
|
||||
<InfoRow label={t('intlPayment.tilowanMonth', 'Tölewan (Aý/aý)')} value={data.created_at} />
|
||||
<InfoRow label={t('intlPayment.note', 'Bellik')} value={data.note} />
|
||||
</BentoCard>
|
||||
|
||||
{/* Ýüztumanyň görnüşi */}
|
||||
<Section title={t('intlPayment.currencySection', 'Ýüztumanyň görnüşi')}>
|
||||
<div className="divide-y divide-border">
|
||||
<InfoRow label={t('intlPayment.currencyType', 'Ýüztumanyň görnüşi')}>
|
||||
{data.currency_type_label}
|
||||
</InfoRow>
|
||||
</div>
|
||||
</Section>
|
||||
<BentoCard title={t('intlPayment.currencySection', 'Ýüztumanyň görnüşi')}>
|
||||
<InfoRow label={t('intlPayment.currencyType', 'Görnüşi')} value={data.currency_type_label} />
|
||||
</BentoCard>
|
||||
|
||||
{/* Lokasiýa */}
|
||||
<Section title={t('intlPayment.locationSection', 'Lokasiýa')}>
|
||||
<div className="divide-y divide-border">
|
||||
<InfoRow label={t('intlPayment.province', 'Welaýat')}>{data.province_label}</InfoRow>
|
||||
<BentoCard title={t('intlPayment.locationSection', 'Lokasiýa')}>
|
||||
<InfoRow label={t('intlPayment.province', 'Welaýat')} value={data.province_label} />
|
||||
<InfoRow label={t('intlPayment.branch', 'Şahamça')}>
|
||||
<span className="text-primary font-medium">{data.branch_label}</span>
|
||||
</InfoRow>
|
||||
</div>
|
||||
</Section>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Şahsy maglumatlar */}
|
||||
<Section title={t('intlPayment.personalSection', 'Şahsy maglumatlar')}>
|
||||
<div className="divide-y divide-border">
|
||||
<InfoRow label={t('intlPayment.passportFirstName', 'Pasportdaky ady')}>{data.passport_first_name}</InfoRow>
|
||||
<InfoRow label={t('intlPayment.passportLastName', 'Pasportdaky familiýa')}>{data.passport_last_name}</InfoRow>
|
||||
<InfoRow label={t('intlPayment.phone', 'Telefon')}>+{data.phone}</InfoRow>
|
||||
<InfoRow label={t('intlPayment.email', 'E-poçta')}>{data.email}</InfoRow>
|
||||
<InfoRow label={t('intlPayment.homeAddress', 'Häzirki ýaşyş ýeri')}>{data.home_address}</InfoRow>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* Töleg */}
|
||||
<Section title={t('intlPayment.paymentSection', 'Töleg')}>
|
||||
<div className="divide-y divide-border mb-4">
|
||||
<InfoRow label={t('intlPayment.payerFullName', 'Töleg upgradyjynyň maglumatlary')}>
|
||||
{data.payer_full_name}
|
||||
{/* ── Row 2: Şahsy maglumatlar + Töleg ─────────────────────────────── */}
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t('intlPayment.personalSection', 'Şahsy maglumatlar')}>
|
||||
<InfoRow label={t('intlPayment.passportFirstName', 'Pasportdaky ady')} value={data.passport_first_name} />
|
||||
<InfoRow label={t('intlPayment.passportLastName', 'Pasportdaky familiýa')} value={data.passport_last_name} />
|
||||
<InfoRow label={t('intlPayment.phone', 'Telefon')}>
|
||||
<span>+{data.phone}</span>
|
||||
</InfoRow>
|
||||
<InfoRow label={t('intlPayment.payerAccount', 'Töleg upgradyjynyň goşun hasaby')}>
|
||||
{data.payer_account_number}
|
||||
</InfoRow>
|
||||
</div>
|
||||
{/* Receiver table */}
|
||||
<div className="border border-border rounded-lg overflow-hidden">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-muted/40">
|
||||
<tr>
|
||||
<th className="text-left px-4 py-2.5 text-xs font-semibold text-muted-foreground uppercase">
|
||||
{t('intlPayment.passportSeries', 'Pasport seriýasy')}
|
||||
</th>
|
||||
<th className="text-left px-4 py-2.5 text-xs font-semibold text-muted-foreground uppercase">
|
||||
{t('intlPayment.passportNumber', 'Pasport nomeri')}
|
||||
</th>
|
||||
<th className="text-left px-4 py-2.5 text-xs font-semibold text-muted-foreground uppercase">
|
||||
{t('intlPayment.payerFullName', 'Ady Familiýasy Atasnyň ady')}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr className="border-t border-border">
|
||||
<td className="px-4 py-3">{data.passport_series} – {data.passport_number}</td>
|
||||
<td className="px-4 py-3">{data.passport_number}</td>
|
||||
<td className="px-4 py-3">{data.payer_full_name}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</Section>
|
||||
<InfoRow label={t('intlPayment.email', 'E-poçta')} value={data.email} />
|
||||
<InfoRow label={t('intlPayment.homeAddress', 'Häzirki ýaşyş ýeri')} value={data.home_address} />
|
||||
</BentoCard>
|
||||
|
||||
{/* Kabul ediji talyp boyunca resminamalar */}
|
||||
<Section title={t('intlPayment.kabulDocsSection', 'Kabul ediji talyp boyunca resminamalar')}>
|
||||
<div>
|
||||
<BentoCard title={t('intlPayment.paymentSection', 'Töleg')}>
|
||||
<InfoRow label={t('intlPayment.payerFullName', 'Töleg upgradyjynyň maglumatlary')} value={data.payer_full_name} />
|
||||
<InfoRow label={t('intlPayment.payerAccount', 'Töleg upgradyjynyň goşun hasaby')} value={data.payer_account_number} />
|
||||
<InfoRow label={t('intlPayment.passportSeries', 'Pasport seriýasy')} value={data.passport_series} />
|
||||
<InfoRow label={t('intlPayment.passportNumber', 'Pasport nomeri')} value={data.passport_number} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Row 3: Kabul ediji resminamalar ──────────────────────────────── */}
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title={t('intlPayment.kabulDocsSection', 'Kabul ediji talyp boyunca resminamalar')}>
|
||||
{KABUL_DOCS.map((doc, i) => (
|
||||
<DocFileRow key={i} label={doc.label} url={doc.url} />
|
||||
))}
|
||||
</div>
|
||||
</Section>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Upgradyý boyunca resminamalar */}
|
||||
<Section title={t('intlPayment.upgradDocsSection', 'Upgradyý boyunca resminamalar')}>
|
||||
<div>
|
||||
{/* ── Row 4: Upgradyý resminamalar ─────────────────────────────────── */}
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title={t('intlPayment.upgradDocsSection', 'Upgradyý boyunca resminamalar')}>
|
||||
{UPGRAD_DOCS.map((doc, i) => (
|
||||
<DocFileRow key={i} label={doc.label} url={doc.url} />
|
||||
))}
|
||||
</div>
|
||||
</Section>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* Töleg taryhy */}
|
||||
<Section title={t('intlPayment.paymentHistory', 'Töleg taryhy')}>
|
||||
<div className="flex items-center gap-2 mb-4">
|
||||
<div className="relative flex-1 max-w-xs">
|
||||
<Search size={13} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
|
||||
<input
|
||||
type="text"
|
||||
value={historySearch}
|
||||
onChange={(e) => setHistorySearch(e.target.value)}
|
||||
placeholder={t('intlPayment.search', 'Gözlemek')}
|
||||
className="h-9 w-full pl-9 pr-3 rounded-md border border-border bg-background text-sm focus:outline-none focus:ring-2 focus:ring-ring"
|
||||
/>
|
||||
{/* ── Row 5: Töleg taryhy ───────────────────────────────────────────── */}
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title={t('intlPayment.paymentHistory', 'Töleg taryhy')}>
|
||||
<div className="p-4">
|
||||
<div className="relative max-w-xs mb-4">
|
||||
<Search size={13} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
|
||||
<input
|
||||
type="text"
|
||||
value={historySearch}
|
||||
onChange={(e) => setHistorySearch(e.target.value)}
|
||||
placeholder={t('intlPayment.search', 'Gözlemek')}
|
||||
className="h-9 w-full pl-9 pr-3 rounded-md border border-border bg-background text-sm focus:outline-none focus:ring-2 focus:ring-ring"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col items-center justify-center py-10 text-muted-foreground/50">
|
||||
<div className="w-12 h-12 mb-3 rounded-lg border-2 border-dashed border-muted-foreground/20 flex items-center justify-center">
|
||||
<svg viewBox="0 0 24 24" className="w-6 h-6" fill="none" stroke="currentColor" strokeWidth={1.5}>
|
||||
<rect x="3" y="3" width="18" height="18" rx="2" />
|
||||
<line x1="3" y1="9" x2="21" y2="9" />
|
||||
<line x1="9" y1="9" x2="9" y2="21" />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-sm">{t('intlPayment.noHistory', 'Beriilen kriteriýalara Töleg gabat gelmedi')}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col items-center justify-center py-12 text-muted-foreground/50">
|
||||
<div className="w-12 h-12 mb-3 rounded-lg border-2 border-dashed border-muted-foreground/20 flex items-center justify-center">
|
||||
<svg viewBox="0 0 24 24" className="w-6 h-6" fill="none" stroke="currentColor" strokeWidth={1.5}>
|
||||
<rect x="3" y="3" width="18" height="18" rx="2" />
|
||||
<line x1="3" y1="9" x2="21" y2="9" />
|
||||
<line x1="9" y1="9" x2="9" y2="21" />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-sm">{t('intlPayment.noHistory', 'Beriilen kriteriýalara Töleg gabat gelmedi')}</p>
|
||||
</div>
|
||||
</Section>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
42
src/pages/notFoundPage/index.tsx
Normal file
42
src/pages/notFoundPage/index.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export default function NotFoundPage() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen bg-background text-foreground p-6 transition-colors duration-300">
|
||||
<div className="text-center space-y-6 max-w-md">
|
||||
<h1 className="text-9xl font-extrabold tracking-widest text-primary/80 select-none">
|
||||
404
|
||||
</h1>
|
||||
|
||||
<div className="space-y-2">
|
||||
<h2 className="text-2xl font-bold tracking-tight sm:text-3xl">
|
||||
{t("errors.pageNotFoundTitle")}
|
||||
</h2>
|
||||
<p className="text-muted-foreground">
|
||||
{t("errors.pageNotFoundDescription")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-center gap-4">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => navigate(-1)}
|
||||
>
|
||||
{t("common.goBack")}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
onClick={() => navigate("/")}
|
||||
>
|
||||
{t("common.backToHome")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user