started refactor and bento grid layout
This commit is contained in:
79
scratch/rewrite.cjs
Normal file
79
scratch/rewrite.cjs
Normal file
@@ -0,0 +1,79 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const content = fs.readFileSync('src/features/loanOrderMobiles/components/loanOrderMobileForm.tsx', 'utf8');
|
||||
|
||||
let newContent = content.replace(
|
||||
/{[\s\S]*?\/\* ── Status ──[\s\S]*?}/,
|
||||
` <div>
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? (t('Loan order create') || 'Karz sargyt döredüň')
|
||||
: (t('Loan order edit') || 'Karz sargydy üýtget')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className="py-2 mb-2">
|
||||
<StepBarCards steps={stepItems} onGoTo={setCurrentStep} />
|
||||
</div>
|
||||
|
||||
<div className={cn('flex flex-col gap-5', currentStep !== 0 && 'hidden')}>
|
||||
{/* ── Status ──`
|
||||
);
|
||||
|
||||
newContent = newContent.replace(
|
||||
/{\/\* ── Personal Data ──/,
|
||||
` </div>
|
||||
<div className={cn('flex flex-col gap-5', currentStep !== 1 && 'hidden')}>
|
||||
{/* ── Personal Data ──`
|
||||
);
|
||||
|
||||
newContent = newContent.replace(
|
||||
/{\/\* ── Job ──/,
|
||||
` </div>
|
||||
<div className={cn('flex flex-col gap-5', currentStep !== 2 && 'hidden')}>
|
||||
{/* ── Job ──`
|
||||
);
|
||||
|
||||
newContent = newContent.replace(
|
||||
/{\/\* ── Card ──/,
|
||||
` </div>
|
||||
<div className={cn('flex flex-col gap-5', currentStep !== 3 && 'hidden')}>
|
||||
{/* ── Card ──`
|
||||
);
|
||||
|
||||
newContent = newContent.replace(
|
||||
/{\/\* ── Passport ──/,
|
||||
` </div>
|
||||
<div className={cn('flex flex-col gap-5', currentStep !== 4 && 'hidden')}>
|
||||
{/* ── Passport ──`
|
||||
);
|
||||
|
||||
newContent = newContent.replace(
|
||||
/{\/\* ── Zamun ──/,
|
||||
` </div>
|
||||
<div className={cn('flex flex-col gap-5', currentStep !== 5 && 'hidden')}>
|
||||
{/* ── Zamun ──`
|
||||
);
|
||||
|
||||
newContent = newContent.replace(
|
||||
/ <FormActions[\s\S]*?\/>\n <\/div>/,
|
||||
` </div>
|
||||
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={currentStep === stepItems.length - 1 ? handleSubmit : undefined}
|
||||
onNext={currentStep < stepItems.length - 1 ? handleNext : undefined}
|
||||
onPrev={currentStep > 0 ? handlePrev : undefined}
|
||||
onCancel={() => navigate(-1)}
|
||||
cancelLabel={t('Cancel') || 'Ýatyr'}
|
||||
loadingLabel={t('Loading') || 'Ýüklenilýär...'}
|
||||
submitLabel={mode === 'create'
|
||||
? (t('loanOrderMobiles.createButton') || 'Karz sargyt döredüň')
|
||||
: (t('loanOrders.saveButton') || 'Ýatda sakla')}
|
||||
showSubmit={currentStep === stepItems.length - 1}
|
||||
/>
|
||||
</div>`
|
||||
);
|
||||
|
||||
fs.writeFileSync('src/features/loanOrderMobiles/components/loanOrderMobileForm.tsx', newContent);
|
||||
console.log('Done rewriting JSX!');
|
||||
76
src/components/formActions.tsx
Normal file
76
src/components/formActions.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
interface FormActionsProps {
|
||||
isPending?: boolean
|
||||
onSubmit?: () => void
|
||||
onCancel?: () => void
|
||||
submitLabel?: ReactNode
|
||||
cancelLabel?: ReactNode
|
||||
loadingLabel?: ReactNode
|
||||
cancelVariant?: 'outline' | 'ghost'
|
||||
className?: string
|
||||
onNext?: () => void
|
||||
onPrev?: () => void
|
||||
nextLabel?: ReactNode
|
||||
prevLabel?: ReactNode
|
||||
showSubmit?: boolean
|
||||
}
|
||||
|
||||
export function FormActions({
|
||||
isPending = false,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
submitLabel,
|
||||
cancelLabel,
|
||||
loadingLabel,
|
||||
cancelVariant = 'outline',
|
||||
className,
|
||||
onNext,
|
||||
onPrev,
|
||||
nextLabel,
|
||||
prevLabel,
|
||||
showSubmit = true,
|
||||
}: FormActionsProps) {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const cancelText = cancelLabel ?? t('common.cancel', 'Ýatyr')
|
||||
const loadingText = loadingLabel ?? t('common.saving', 'Saklanýar...')
|
||||
const prevText = prevLabel ?? t('common.prev', 'Yza')
|
||||
const nextText = nextLabel ?? t('common.next', 'Indiki')
|
||||
|
||||
return (
|
||||
<div className={cn('flex items-center justify-end gap-3', className)}>
|
||||
{onCancel && (
|
||||
<Button type="button" variant={cancelVariant} onClick={onCancel} disabled={isPending}>
|
||||
{cancelText}
|
||||
</Button>
|
||||
)}
|
||||
{onPrev && (
|
||||
<Button type="button" variant="outline" onClick={onPrev} disabled={isPending}>
|
||||
{prevText}
|
||||
</Button>
|
||||
)}
|
||||
{onNext && (
|
||||
<Button type="button" onClick={onNext} disabled={isPending}>
|
||||
{nextText}
|
||||
</Button>
|
||||
)}
|
||||
{showSubmit && onSubmit && (
|
||||
<Button type="button" onClick={onSubmit} disabled={isPending}>
|
||||
{isPending ? (
|
||||
<span className="flex items-center gap-2">
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
{loadingText}
|
||||
</span>
|
||||
) : (
|
||||
submitLabel
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useRef, type KeyboardEvent } from 'react'
|
||||
import { Check, AlertTriangle } from 'lucide-react'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Tooltip as TooltipPrimitive } from "radix-ui"
|
||||
|
||||
@@ -2,10 +2,9 @@ import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { useCreateUser, useUpdateUser } from '../hooks/useAllUsers'
|
||||
import type { User, CreateUserPayload, UpdateUserPayload } from '../api/allUsersApi'
|
||||
|
||||
@@ -300,27 +299,14 @@ export function UserForm({ mode, initialData, userId }: UserFormProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer actions */}
|
||||
<div className="flex items-center justify-end gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => navigate(-1)}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
>
|
||||
{isPending && <Loader2 size={14} className="mr-2 animate-spin" />}
|
||||
{mode === 'create'
|
||||
? t('users.actions.create', 'Ulanyjy dörediň')
|
||||
: t('users.actions.save', 'Ýatda sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate(-1)}
|
||||
submitLabel={mode === 'create'
|
||||
? t('users.actions.create', 'Ulanyjy dörediň')
|
||||
: t('users.actions.save', 'Ýatda sakla')}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { type CardBalance } from '@/features/cardBalance/api/cardBalanceApi'
|
||||
import { useCreateCardBalance, useUpdateCardBalance } from '@/features/cardBalance/hooks/useCardBalance'
|
||||
|
||||
@@ -186,19 +186,18 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex justify-end gap-3 mt-6">
|
||||
<Button variant="ghost" onClick={handleCancel} disabled={isPending}>
|
||||
{t('Cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} disabled={isPending}>
|
||||
{isPending
|
||||
? t('Saving...', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('Create card balance', 'Kart galyndysy dörediň')
|
||||
: t('Save changes', 'Üýtgetmeleri sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={handleCancel}
|
||||
cancelVariant="ghost"
|
||||
cancelLabel={t('Cancel', 'Ýatyr')}
|
||||
loadingLabel={t('Saving...', 'Saklanýar...')}
|
||||
submitLabel={mode === 'create'
|
||||
? t('Create card balance', 'Kart galyndysy dörediň')
|
||||
: t('Save changes', 'Üýtgetmeleri sakla')}
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import { useState, 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 { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
|
||||
import type { CardPinItem, CardPinCreatePayload } from '@/features/cardPins/api/cardPinApi'
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
@@ -36,6 +38,18 @@ 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 ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -45,7 +59,6 @@ const STATUS_OPTIONS = [
|
||||
{ value: 'rejected', label: 'Ret edildi' },
|
||||
]
|
||||
|
||||
// These would typically come from API — using static options as placeholder
|
||||
const CARD_TYPE_OPTIONS = [
|
||||
{ value: 'altyn_asyr', label: 'Altyn Asyr' },
|
||||
{ value: 'visa', label: 'Visa' },
|
||||
@@ -53,10 +66,10 @@ const CARD_TYPE_OPTIONS = [
|
||||
]
|
||||
|
||||
const PASSPORT_SERIES_OPTIONS = [
|
||||
{ value: 'I', label: 'I' },
|
||||
{ value: 'II', label: 'II' },
|
||||
{ value: 'I-MR', label: 'I-MR' },
|
||||
{ value: 'II-MR',label: 'II-MR' },
|
||||
{ value: 'I', label: 'I' },
|
||||
{ value: 'II', label: 'II' },
|
||||
{ value: 'I-MR', label: 'I-MR' },
|
||||
{ value: 'II-MR', label: 'II-MR' },
|
||||
]
|
||||
|
||||
const PROVINCE_OPTIONS = [
|
||||
@@ -92,29 +105,57 @@ const defaultState: FormState = {
|
||||
|
||||
// ─── Validation ───────────────────────────────────────────────────────────────
|
||||
|
||||
function validate(form: FormState, mode: 'create' | 'edit'): FormErrors {
|
||||
const errors: FormErrors = {}
|
||||
function validate(
|
||||
form: FormState,
|
||||
mode: 'create' | 'edit',
|
||||
stepIndex?: number,
|
||||
): FormErrors {
|
||||
const allErrors: FormErrors = {}
|
||||
|
||||
if (!form.status) errors.status = 'Status hökmany'
|
||||
if (!form.card_type) errors.card_type = 'Kart görnüşi hökmany'
|
||||
if (!form.card_number) errors.card_number = 'Kart belgisi hökmany'
|
||||
if (!form.province) errors.province = 'Welaýat hökmany'
|
||||
if (!form.branch) errors.branch = 'Şahamça hökmany'
|
||||
if (!form.first_name) errors.first_name = 'Ady hökmany'
|
||||
if (!form.last_name) errors.last_name = 'Familiýasy hökmany'
|
||||
if (!form.birth_date) errors.birth_date = 'Doglan güni hökmany'
|
||||
if (!form.phone) errors.phone = 'Telefon hökmany'
|
||||
if (!form.passport_series) errors.passport_series = 'Pasport seriýasy hökmany'
|
||||
if (!form.passport_number) errors.passport_number = 'Pasport belgisi hökmany'
|
||||
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) errors.passport_file_1 = 'Pasport (sahypa 1) hökmany'
|
||||
if (!form.passport_file_2) errors.passport_file_2 = 'Pasport (2-3-nji sahypa) hökmany'
|
||||
if (!form.passport_file_3) errors.passport_file_3 = 'Pasport (8-9 sahypa) hökmany'
|
||||
if (!form.passport_file_4) errors.passport_file_4 = 'Pasport (32-nji sahypa) hökmany'
|
||||
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'
|
||||
}
|
||||
|
||||
return errors
|
||||
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 ──────────────────────────────────────────────────────────
|
||||
|
||||
function Section({ title, children }: { title?: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{title && (
|
||||
<div className="px-5 py-3.5 border-b border-border">
|
||||
<h2 className="text-sm font-semibold text-foreground">{title}</h2>
|
||||
</div>
|
||||
)}
|
||||
<div className="p-5">{children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Component ────────────────────────────────────────────────────────────────
|
||||
@@ -123,10 +164,11 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [form, setForm] = useState<FormState>(defaultState)
|
||||
const [form, setForm] = useState<FormState>(defaultState)
|
||||
const [errors, setErrors] = useState<FormErrors>({})
|
||||
const [currentStep, setCurrentStep] = useState(0)
|
||||
const [stepStatuses, setStepStatuses] = useState<StepStatus[]>(['active', 'idle', 'idle'])
|
||||
|
||||
// Hydrate form when editing
|
||||
useEffect(() => {
|
||||
if (mode === 'edit' && initialData) {
|
||||
setForm({
|
||||
@@ -153,13 +195,66 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
|
||||
|
||||
const set = <K extends keyof FormState>(key: K, value: FormState[K]) => {
|
||||
setForm((prev) => ({ ...prev, [key]: value }))
|
||||
if (errors[key]) setErrors((prev) => ({ ...prev, [key]: undefined }))
|
||||
setErrors((prev) => ({ ...prev, [key]: undefined }))
|
||||
}
|
||||
|
||||
// ── Step navigation ────────────────────────────────────────────────────────
|
||||
|
||||
const updateStatus = (index: number, status: StepStatus) => {
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]
|
||||
next[index] = status
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
const goToStep = (index: number) => {
|
||||
updateStatus(currentStep, stepStatuses[currentStep] === 'error' ? 'error' : 'done')
|
||||
updateStatus(index, 'active')
|
||||
setCurrentStep(index)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const handleNext = () => {
|
||||
const stepErrors = validate(form, mode, currentStep)
|
||||
if (Object.keys(stepErrors).length > 0) {
|
||||
setErrors((prev) => ({ ...prev, ...stepErrors }))
|
||||
updateStatus(currentStep, 'error')
|
||||
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)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const handlePrev = () => {
|
||||
const prev = currentStep - 1
|
||||
updateStatus(currentStep, stepStatuses[currentStep] === 'error' ? 'error' : 'idle')
|
||||
updateStatus(prev, 'active')
|
||||
setCurrentStep(prev)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
// ── Submit ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const handleSubmit = () => {
|
||||
const errs = validate(form, mode)
|
||||
if (Object.keys(errs).length > 0) {
|
||||
setErrors(errs)
|
||||
const allErrors = 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.')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -184,6 +279,37 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
|
||||
})
|
||||
}
|
||||
|
||||
// ── Step bar 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 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äň')
|
||||
@@ -192,225 +318,249 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
|
||||
? t('cardPin.createBtn', 'Kart pin bukja dörediň')
|
||||
: t('cardPin.editBtn', 'Kart pin bukja redaktirläň')
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className=" mx-auto space-y-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">{title}</h1>
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">{title}</h1>
|
||||
|
||||
{/* ── Status & Note ────────────────────────────────────────────────── */}
|
||||
<section className="bg-card border border-border rounded-lg p-6 space-y-4">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('cardPin.status', 'Status')}
|
||||
value={form.status}
|
||||
onChange={(v) => set('status', v)}
|
||||
options={STATUS_OPTIONS}
|
||||
error={errors.status}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('cardPin.note', 'Bellik')}
|
||||
value={form.note}
|
||||
onChange={(v) => set('note', v)}
|
||||
placeholder={t('cardPin.notePlaceholder', 'Bellik')}
|
||||
/>
|
||||
</section>
|
||||
|
||||
{/* ── Kart ─────────────────────────────────────────────────────────── */}
|
||||
<section className="bg-card border border-border rounded-lg p-6">
|
||||
<h2 className="text-base font-semibold text-foreground mb-4">
|
||||
{t('cardPin.cardSection', 'Kart')}
|
||||
</h2>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<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
|
||||
/>
|
||||
<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>
|
||||
</section>
|
||||
|
||||
{/* ── Lokasiýa ─────────────────────────────────────────────────────── */}
|
||||
<section className="bg-card border border-border rounded-lg p-6">
|
||||
<h2 className="text-base font-semibold text-foreground mb-4">
|
||||
{t('cardPin.locationSection', 'Lokasiýa')}
|
||||
</h2>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<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
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('cardPin.branch', 'Şahamça')}
|
||||
value={form.branch}
|
||||
onChange={(v) => set('branch', v)}
|
||||
options={[]} // Populated dynamically based on province from API
|
||||
placeholder={t('cardPin.branchPlaceholder', 'Saýlamak üçin basyň')}
|
||||
error={errors.branch}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* ── Şahsy maglumatlar ─────────────────────────────────────────────── */}
|
||||
<section className="bg-card border border-border rounded-lg p-6">
|
||||
<h2 className="text-base font-semibold text-foreground mb-4">
|
||||
{t('cardPin.personalSection', 'Şahsy maglumatlar')}
|
||||
</h2>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<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
|
||||
/>
|
||||
<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
|
||||
/>
|
||||
<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">
|
||||
<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
|
||||
/>
|
||||
<FormInput
|
||||
type="phone"
|
||||
label={t('cardPin.phone', 'Telefon')}
|
||||
value={form.phone}
|
||||
onChange={(v) => set('phone', v)}
|
||||
error={errors.phone}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* ── Pasport ───────────────────────────────────────────────────────── */}
|
||||
<section className="bg-card border border-border rounded-lg p-6">
|
||||
<h2 className="text-base font-semibold text-foreground mb-4">
|
||||
{t('cardPin.passportSection', 'Pasport')}
|
||||
</h2>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mb-4">
|
||||
<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
|
||||
/>
|
||||
<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 className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<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'}
|
||||
/>
|
||||
<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'}
|
||||
/>
|
||||
<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'}
|
||||
/>
|
||||
<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>
|
||||
</section>
|
||||
|
||||
{/* ── Actions ───────────────────────────────────────────────────────── */}
|
||||
<div className="flex items-center justify-end gap-3 pb-6">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => navigate('/card-pins')}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isSubmitting}
|
||||
className="min-w-[180px]"
|
||||
>
|
||||
{isSubmitting ? (
|
||||
<Spinner className="size-4" />
|
||||
) : (
|
||||
submitLabel
|
||||
)}
|
||||
</Button>
|
||||
{/* ── Step Bar ─────────────────────────────────────────────────────── */}
|
||||
<div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
|
||||
<StepBarCards steps={stepItems} onGoTo={goToStep} />
|
||||
</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 ─────────────────────────────────────── */}
|
||||
{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>
|
||||
)}
|
||||
|
||||
{/* ── Form Actions ──────────────────────────────────────────────────── */}
|
||||
<FormActions
|
||||
isPending={isSubmitting}
|
||||
onCancel={() => navigate('/card-pins')}
|
||||
onPrev={!isFirstStep ? handlePrev : undefined}
|
||||
prevLabel={t('common.prev', 'Yza')}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
nextLabel={t('common.next', 'Indiki')}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={handleSubmit}
|
||||
submitLabel={submitLabel}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import type { CardReason, CreateCardReasonPayload } from '../api/cardReasonsApi'
|
||||
import { useCreateCardReason, useUpdateCardReason } from '../hooks/useCardReasons'
|
||||
@@ -203,29 +203,16 @@ export function CardReasonForm({ mode, initialData, CardReasonId }: CardReasonFo
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center justify-end gap-3 mt-6">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => navigate('/resources/card-states')}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('CardReasons.actions.create', 'Kartyň çykarylmagynyň sebäbini döretdiň')
|
||||
: t('CardReasons.actions.update', 'Täzelemek')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate('/resources/card-states')}
|
||||
cancelVariant="ghost"
|
||||
submitLabel={mode === 'create'
|
||||
? t('CardReasons.actions.create', 'Kartyň çykarylmagynyň sebäbini döretdiň')
|
||||
: t('CardReasons.actions.update', 'Täzelemek')}
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { toast } from 'sonner'
|
||||
import { CreditCard, User, FileText } from 'lucide-react'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { StepBarCards, type StepCardItem } from '@/components//stepBarV2'
|
||||
import type { CardRequisite, CardRequisiteStatus, CreateCardRequisitePayload } from '../api/cardRequisitesApi'
|
||||
import { useCreateCardRequisite, useUpdateCardRequisite } from '../hooks/useCardRequisites'
|
||||
|
||||
@@ -59,6 +62,19 @@ interface FormErrors {
|
||||
passport_page32?: string
|
||||
}
|
||||
|
||||
type StepStatus = 'idle' | 'active' | 'done' | 'error'
|
||||
|
||||
// ─── Step field mapping ───────────────────────────────────────────────────────
|
||||
|
||||
const STEP_FORM_FIELDS: Array<Array<keyof FormState | keyof FileState>> = [
|
||||
// Step 0 — Kart & Lokasiýa
|
||||
['status', 'card_type', 'card_number', 'card_expiry_month', 'card_expiry_year', 'province_id', 'branch_id'],
|
||||
// Step 1 — Şahsy maglumatlar
|
||||
['first_name', 'last_name', 'birth_date', 'phone'],
|
||||
// Step 2 — Pasport & Faýllar
|
||||
['passport_series', 'passport_number', 'passport_page1', 'passport_page2_3', 'passport_page8_9', 'passport_page32'],
|
||||
]
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
@@ -143,39 +159,56 @@ function validate(
|
||||
files: FileState,
|
||||
mode: 'create' | 'edit',
|
||||
t: (k: string, fallback: string) => string,
|
||||
stepIndex?: number,
|
||||
): FormErrors {
|
||||
const errors: FormErrors = {}
|
||||
const allErrors: FormErrors = {}
|
||||
|
||||
if (!form.status) errors.status = t('Status is required', 'Status hökmanydyr')
|
||||
if (!form.card_type) errors.card_type = t('Card type is required', 'Görnüşi hökmanydyr')
|
||||
if (!form.card_number) errors.card_number = t('Card number is required', 'Kart belgisi hökmanydyr')
|
||||
if (!form.card_expiry_month) errors.card_expiry_month = t('Expiry month is required', 'Möhleti (aý) hökmanydyr')
|
||||
if (!form.card_expiry_year) errors.card_expiry_year = t('Expiry year is required', 'Möhleti (ýyl) hökmanydyr')
|
||||
if (!form.province_id) errors.province_id = t('Province is required', 'Welaýat hökmanydyr')
|
||||
if (!form.branch_id) errors.branch_id = t('Branch is required', 'Şahamça hökmanydyr')
|
||||
if (!form.first_name) errors.first_name = t('First name is required', 'Ady hökmanydyr')
|
||||
if (!form.last_name) errors.last_name = t('Last name is required', 'Familiýasy hökmanydyr')
|
||||
if (!form.birth_date) errors.birth_date = t('Birth date is required', 'Doglan güni hökmanydyr')
|
||||
if (!form.phone) errors.phone = t('Phone is required', 'Telefon hökmanydyr')
|
||||
if (!form.passport_series) errors.passport_series = t('Passport series is required', 'Pasport seriýasy hökmanydyr')
|
||||
if (!form.passport_number) errors.passport_number = t('Passport number is required', 'Pasport belgisi hökmanydyr')
|
||||
if (!form.status) allErrors.status = t('Status is required', 'Status hökmanydyr')
|
||||
if (!form.card_type) allErrors.card_type = t('Card type is required', 'Görnüşi hökmanydyr')
|
||||
if (!form.card_number) allErrors.card_number = t('Card number is required', 'Kart belgisi hökmanydyr')
|
||||
if (!form.card_expiry_month) allErrors.card_expiry_month = t('Expiry month is required', 'Möhleti (aý) hökmanydyr')
|
||||
if (!form.card_expiry_year) allErrors.card_expiry_year = t('Expiry year is required', 'Möhleti (ýyl) hökmanydyr')
|
||||
if (!form.province_id) allErrors.province_id = t('Province is required', 'Welaýat hökmanydyr')
|
||||
if (!form.branch_id) allErrors.branch_id = t('Branch is required', 'Şahamça hökmanydyr')
|
||||
if (!form.first_name) allErrors.first_name = t('First name is required', 'Ady hökmanydyr')
|
||||
if (!form.last_name) allErrors.last_name = t('Last name is required', 'Familiýasy hökmanydyr')
|
||||
if (!form.birth_date) allErrors.birth_date = t('Birth date is required', 'Doglan güni hökmanydyr')
|
||||
if (!form.phone) allErrors.phone = t('Phone is required', 'Telefon hökmanydyr')
|
||||
if (!form.passport_series) allErrors.passport_series = t('Passport series is required', 'Pasport seriýasy hökmanydyr')
|
||||
if (!form.passport_number) allErrors.passport_number = t('Passport number is required', 'Pasport belgisi hökmanydyr')
|
||||
|
||||
// Files only required on create
|
||||
if (mode === 'create') {
|
||||
if (!files.passport_page1) errors.passport_page1 = t('Required', 'Hökmanydyr')
|
||||
if (!files.passport_page2_3) errors.passport_page2_3 = t('Required', 'Hökmanydyr')
|
||||
if (!files.passport_page8_9) errors.passport_page8_9 = t('Required', 'Hökmanydyr')
|
||||
if (!files.passport_page32) errors.passport_page32 = t('Required', 'Hökmanydyr')
|
||||
if (!files.passport_page1) allErrors.passport_page1 = t('Required', 'Hökmanydyr')
|
||||
if (!files.passport_page2_3) allErrors.passport_page2_3 = t('Required', 'Hökmanydyr')
|
||||
if (!files.passport_page8_9) allErrors.passport_page8_9 = t('Required', 'Hökmanydyr')
|
||||
if (!files.passport_page32) allErrors.passport_page32 = t('Required', 'Hökmanydyr')
|
||||
}
|
||||
|
||||
return errors
|
||||
if (stepIndex !== undefined) {
|
||||
const stepKeys = STEP_FORM_FIELDS[stepIndex]
|
||||
const stepErrors: FormErrors = {}
|
||||
for (const key of stepKeys) {
|
||||
const k = key as keyof FormErrors
|
||||
if (allErrors[k]) stepErrors[k] = allErrors[k]
|
||||
}
|
||||
return stepErrors
|
||||
}
|
||||
|
||||
return allErrors
|
||||
}
|
||||
|
||||
// ─── Section header ───────────────────────────────────────────────────────────
|
||||
// ─── Section wrapper ──────────────────────────────────────────────────────────
|
||||
|
||||
function SectionTitle({ children }: { children: React.ReactNode }) {
|
||||
function Section({ title, children }: { title?: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<h2 className="text-base font-semibold text-foreground mt-6 mb-3">{children}</h2>
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{title && (
|
||||
<div className="px-5 py-3.5 border-b border-border">
|
||||
<h2 className="text-sm font-semibold text-foreground">{title}</h2>
|
||||
</div>
|
||||
)}
|
||||
<div className="p-5">{children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -189,13 +222,14 @@ export function CardRequisiteForm({
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [form, setForm] = useState<FormState>(EMPTY_FORM)
|
||||
const [files, setFiles] = useState<FileState>(EMPTY_FILES)
|
||||
const [form, setForm] = useState<FormState>(EMPTY_FORM)
|
||||
const [files, setFiles] = useState<FileState>(EMPTY_FILES)
|
||||
const [errors, setErrors] = useState<FormErrors>({})
|
||||
const [currentStep, setCurrentStep] = useState(0)
|
||||
const [stepStatuses, setStepStatuses] = useState<StepStatus[]>(['active', 'idle', 'idle'])
|
||||
|
||||
const createMutation = useCreateCardRequisite()
|
||||
const updateMutation = useUpdateCardRequisite(cardRequisiteId ?? '')
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
useEffect(() => {
|
||||
@@ -220,27 +254,79 @@ export function CardRequisiteForm({
|
||||
}
|
||||
}, [mode, initialData])
|
||||
|
||||
// ── Field setters ──────────────────────────────────────────────────────────
|
||||
|
||||
const setField = (field: keyof FormState) => (value: string) => {
|
||||
setForm((prev) => {
|
||||
const next = { ...prev, [field]: value }
|
||||
// Reset branch when province changes
|
||||
if (field === 'province_id') next.branch_id = ''
|
||||
return next
|
||||
})
|
||||
if (errors[field as keyof FormErrors])
|
||||
setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||
setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||
}
|
||||
|
||||
const setFile = (field: keyof FileState) => (file: File | null) => {
|
||||
setFiles((prev) => ({ ...prev, [field]: file }))
|
||||
if (errors[field as keyof FormErrors])
|
||||
setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||
setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||
}
|
||||
|
||||
// ── Step navigation ────────────────────────────────────────────────────────
|
||||
|
||||
const updateStatus = (index: number, status: StepStatus) => {
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]
|
||||
next[index] = status
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
const goToStep = (index: number) => {
|
||||
updateStatus(currentStep, stepStatuses[currentStep] === 'error' ? 'error' : 'done')
|
||||
updateStatus(index, 'active')
|
||||
setCurrentStep(index)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const handleNext = () => {
|
||||
const stepErrors = validate(form, files, mode, t, currentStep)
|
||||
if (Object.keys(stepErrors).length > 0) {
|
||||
setErrors((prev) => ({ ...prev, ...stepErrors }))
|
||||
updateStatus(currentStep, 'error')
|
||||
toast.error(t('Fix errors', '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)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const handlePrev = () => {
|
||||
const prev = currentStep - 1
|
||||
updateStatus(currentStep, stepStatuses[currentStep] === 'error' ? 'error' : 'idle')
|
||||
updateStatus(prev, 'active')
|
||||
setCurrentStep(prev)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
// ── Submit ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const validationErrors = validate(form, files, mode, t)
|
||||
if (Object.keys(validationErrors).length > 0) {
|
||||
setErrors(validationErrors)
|
||||
const allErrors = validate(form, files, mode, t)
|
||||
if (Object.keys(allErrors).length > 0) {
|
||||
setErrors(allErrors)
|
||||
const newStatuses = stepStatuses.map((s, i) => {
|
||||
const stepKeys = STEP_FORM_FIELDS[i]
|
||||
const hasError = stepKeys.some((k) => allErrors[k as keyof FormErrors])
|
||||
if (i === currentStep) return hasError ? 'error' : 'active'
|
||||
if (hasError) return 'error'
|
||||
return s === 'idle' ? 'idle' : 'done'
|
||||
}) as StepStatus[]
|
||||
setStepStatuses(newStatuses)
|
||||
toast.error(t('Fix errors', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -269,233 +355,316 @@ export function CardRequisiteForm({
|
||||
|
||||
const branchOptions = BRANCH_OPTIONS[form.province_id] ?? []
|
||||
|
||||
// ── Step bar items ─────────────────────────────────────────────────────────
|
||||
|
||||
const stepDefs = [
|
||||
{
|
||||
id: 'card',
|
||||
title: t('Card', 'Kart'),
|
||||
subtitle: t('Type & location', 'Görnüş & lokasiýa'),
|
||||
icon: CreditCard,
|
||||
},
|
||||
{
|
||||
id: 'personal',
|
||||
title: t('Personal', 'Şahsy'),
|
||||
subtitle: t('Name & contact', 'At & telefon'),
|
||||
icon: User,
|
||||
},
|
||||
{
|
||||
id: 'passport',
|
||||
title: t('Passport', 'Pasport'),
|
||||
subtitle: t('Docs & files', 'Resminamalar'),
|
||||
icon: FileText,
|
||||
},
|
||||
]
|
||||
|
||||
const stepItems: StepCardItem[] = stepDefs.map((def, i) => ({
|
||||
...def,
|
||||
status: stepStatuses[i],
|
||||
}))
|
||||
|
||||
const isFirstStep = currentStep === 0
|
||||
const isLastStep = currentStep === stepDefs.length - 1
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="space-y-0">
|
||||
{/* ── General ── */}
|
||||
<div className="rounded-lg border border-border bg-card p-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Status', 'Status')}
|
||||
value={form.status}
|
||||
onChange={setField('status')}
|
||||
options={STATUS_OPTIONS}
|
||||
error={errors.status}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Note', 'Bellik')}
|
||||
value={form.note}
|
||||
onChange={setField('note')}
|
||||
placeholder={t('Note', 'Bellik')}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-5">
|
||||
|
||||
{/* ── Step Bar ─────────────────────────────────────────────────────── */}
|
||||
<div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
|
||||
<StepBarCards steps={stepItems} onGoTo={goToStep} />
|
||||
</div>
|
||||
|
||||
{/* ── Kart ── */}
|
||||
<SectionTitle>{t('Card', 'Kart')}</SectionTitle>
|
||||
<div className="rounded-lg border border-border bg-card p-6">
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Card type', 'Görnüşi')}
|
||||
value={form.card_type}
|
||||
onChange={setField('card_type')}
|
||||
options={CARD_TYPE_OPTIONS}
|
||||
placeholder="—"
|
||||
error={errors.card_type}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Card number', 'Kart belgisi')}
|
||||
value={form.card_number}
|
||||
onChange={setField('card_number')}
|
||||
placeholder={t('Card number', 'Kart belgisi')}
|
||||
error={errors.card_number}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Card expiry month', 'Kart Möhleti (aý)')}
|
||||
value={form.card_expiry_month}
|
||||
onChange={setField('card_expiry_month')}
|
||||
options={MONTH_OPTIONS}
|
||||
placeholder={t('Select', 'Saýlamak üçin basyň')}
|
||||
error={errors.card_expiry_month}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Card expiry year', 'Kart Möhleti (ýyl)')}
|
||||
value={form.card_expiry_year}
|
||||
onChange={setField('card_expiry_year')}
|
||||
options={YEAR_OPTIONS}
|
||||
placeholder={t('Select', 'Saýlamak üçin basyň')}
|
||||
error={errors.card_expiry_year}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/* ── Step 0: Kart & Lokasiýa ──────────────────────────────────────── */}
|
||||
{currentStep === 0 && (
|
||||
<>
|
||||
<Section>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div id="field-status">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Status', 'Status')}
|
||||
value={form.status}
|
||||
onChange={setField('status')}
|
||||
options={STATUS_OPTIONS}
|
||||
error={errors.status}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Note', 'Bellik')}
|
||||
value={form.note}
|
||||
onChange={setField('note')}
|
||||
placeholder={t('Note', 'Bellik')}
|
||||
/>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* ── Lokasiýa ── */}
|
||||
<SectionTitle>{t('Location', 'Lokasiýa')}</SectionTitle>
|
||||
<div className="rounded-lg border border-border bg-card p-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Province', 'Welaýat')}
|
||||
value={form.province_id}
|
||||
onChange={setField('province_id')}
|
||||
options={PROVINCE_OPTIONS}
|
||||
placeholder={t('Ashgabat', 'Aşgabat')}
|
||||
error={errors.province_id}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Branch', 'Şahamça')}
|
||||
value={form.branch_id}
|
||||
onChange={setField('branch_id')}
|
||||
options={branchOptions}
|
||||
placeholder={t('Select', 'Saýlamak üçin basyň')}
|
||||
error={errors.branch_id}
|
||||
disabled={!form.province_id}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Section title={t('Card', 'Kart')}>
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div id="field-card_type">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Card type', 'Görnüşi')}
|
||||
value={form.card_type}
|
||||
onChange={setField('card_type')}
|
||||
options={CARD_TYPE_OPTIONS}
|
||||
placeholder="—"
|
||||
error={errors.card_type}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-card_number">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Card number', 'Kart belgisi')}
|
||||
value={form.card_number}
|
||||
onChange={setField('card_number')}
|
||||
placeholder={t('Card number', 'Kart belgisi')}
|
||||
error={errors.card_number}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-card_expiry_month">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Card expiry month', 'Kart Möhleti (aý)')}
|
||||
value={form.card_expiry_month}
|
||||
onChange={setField('card_expiry_month')}
|
||||
options={MONTH_OPTIONS}
|
||||
placeholder={t('Select', 'Saýlamak üçin basyň')}
|
||||
error={errors.card_expiry_month}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-card_expiry_year">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Card expiry year', 'Kart Möhleti (ýyl)')}
|
||||
value={form.card_expiry_year}
|
||||
onChange={setField('card_expiry_year')}
|
||||
options={YEAR_OPTIONS}
|
||||
placeholder={t('Select', 'Saýlamak üçin basyň')}
|
||||
error={errors.card_expiry_year}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* ── Şahsy maglumatlar ── */}
|
||||
<SectionTitle>{t('Personal information', 'Şahsy maglumatlar')}</SectionTitle>
|
||||
<div className="rounded-lg border border-border bg-card p-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('First name', 'Ady')}
|
||||
value={form.first_name}
|
||||
onChange={setField('first_name')}
|
||||
placeholder={t('First name', 'Ady')}
|
||||
error={errors.first_name}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Last name', 'Familiýasy')}
|
||||
value={form.last_name}
|
||||
onChange={setField('last_name')}
|
||||
placeholder={t('Last name', 'Familiýasy')}
|
||||
error={errors.last_name}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Father's name", 'Atasynyň ady')}
|
||||
value={form.middle_name}
|
||||
onChange={setField('middle_name')}
|
||||
placeholder={t("Father's name", 'Atasynyň ady')}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
|
||||
<FormInput
|
||||
type="date"
|
||||
label={t('Birth date', 'Doglan güni')}
|
||||
value={form.birth_date}
|
||||
onChange={setField('birth_date')}
|
||||
error={errors.birth_date}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="phone"
|
||||
label={t('Phone', 'Telefon')}
|
||||
value={form.phone}
|
||||
onChange={setField('phone')}
|
||||
placeholder="63 21 87 04"
|
||||
error={errors.phone}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Section title={t('Location', 'Lokasiýa')}>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div id="field-province_id">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('Province', 'Welaýat')}
|
||||
value={form.province_id}
|
||||
onChange={setField('province_id')}
|
||||
options={PROVINCE_OPTIONS}
|
||||
placeholder={t('Ashgabat', 'Aşgabat')}
|
||||
error={errors.province_id}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-branch_id">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Branch', 'Şahamça')}
|
||||
value={form.branch_id}
|
||||
onChange={setField('branch_id')}
|
||||
options={branchOptions}
|
||||
placeholder={t('Select', 'Saýlamak üçin basyň')}
|
||||
error={errors.branch_id}
|
||||
disabled={!form.province_id}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ── Pasport ── */}
|
||||
<SectionTitle>{t('Passport', 'Pasport')}</SectionTitle>
|
||||
<div className="rounded-lg border border-border bg-card p-6 space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Passport series', 'Pasport seriýasy')}
|
||||
value={form.passport_series}
|
||||
onChange={setField('passport_series')}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder={t('Select', 'Saýlamak üçin basyň')}
|
||||
error={errors.passport_series}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Passport number', 'Pasport belgisi')}
|
||||
value={form.passport_number}
|
||||
onChange={setField('passport_number')}
|
||||
placeholder={t('Passport number', 'Pasport belgisi')}
|
||||
error={errors.passport_number}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
{/* ── Step 1: Şahsy maglumatlar ─────────────────────────────────────── */}
|
||||
{currentStep === 1 && (
|
||||
<Section title={t('Personal information', 'Şahsy maglumatlar')}>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div id="field-first_name">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('First name', 'Ady')}
|
||||
value={form.first_name}
|
||||
onChange={setField('first_name')}
|
||||
placeholder={t('First name', 'Ady')}
|
||||
error={errors.first_name}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-last_name">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Last name', 'Familiýasy')}
|
||||
value={form.last_name}
|
||||
onChange={setField('last_name')}
|
||||
placeholder={t('Last name', 'Familiýasy')}
|
||||
error={errors.last_name}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Father's name", 'Atasynyň ady')}
|
||||
value={form.middle_name}
|
||||
onChange={setField('middle_name')}
|
||||
placeholder={t("Father's name", 'Atasynyň ady')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('Passport (page 1)', 'Pasport (sahypa 1)')}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={files.passport_page1}
|
||||
onFileChange={setFile('passport_page1')}
|
||||
error={errors.passport_page1}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('Passport (pages 2-3)', 'Pasport (2-3-nji sahypa)')}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={files.passport_page2_3}
|
||||
onFileChange={setFile('passport_page2_3')}
|
||||
error={errors.passport_page2_3}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('Passport (pages 8-9)', 'Pasport (8-9 sahypa)')}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={files.passport_page8_9}
|
||||
onFileChange={setFile('passport_page8_9')}
|
||||
error={errors.passport_page8_9}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('Passport (page 32)', 'Pasport (32-nji sahypa)')}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={files.passport_page32}
|
||||
onFileChange={setFile('passport_page32')}
|
||||
error={errors.passport_page32}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
|
||||
<div id="field-birth_date">
|
||||
<FormInput
|
||||
type="date"
|
||||
label={t('Birth date', 'Doglan güni')}
|
||||
value={form.birth_date}
|
||||
onChange={setField('birth_date')}
|
||||
error={errors.birth_date}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-phone">
|
||||
<FormInput
|
||||
type="phone"
|
||||
label={t('Phone', 'Telefon')}
|
||||
value={form.phone}
|
||||
onChange={setField('phone')}
|
||||
placeholder="63 21 87 04"
|
||||
error={errors.phone}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{/* ── Actions ── */}
|
||||
<div className="flex justify-end gap-3 mt-6">
|
||||
<Button variant="ghost" onClick={handleCancel} disabled={isPending}>
|
||||
{t('Cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} disabled={isPending}>
|
||||
{isPending
|
||||
? t('Saving...', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
{/* ── Step 2: Pasport & Faýllar ─────────────────────────────────────── */}
|
||||
{currentStep === 2 && (
|
||||
<Section title={t('Passport', 'Pasport')}>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div id="field-passport_series">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('Passport series', 'Pasport seriýasy')}
|
||||
value={form.passport_series}
|
||||
onChange={setField('passport_series')}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder={t('Select', 'Saýlamak üçin basyň')}
|
||||
error={errors.passport_series}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div id="field-passport_number">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('Passport number', 'Pasport belgisi')}
|
||||
value={form.passport_number}
|
||||
onChange={setField('passport_number')}
|
||||
placeholder={t('Passport number', 'Pasport belgisi')}
|
||||
error={errors.passport_number}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
|
||||
<div id="field-passport_page1">
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('Passport (page 1)', 'Pasport (sahypa 1)')}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={files.passport_page1}
|
||||
onFileChange={setFile('passport_page1')}
|
||||
error={errors.passport_page1}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-passport_page2_3">
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('Passport (pages 2-3)', 'Pasport (2-3-nji sahypa)')}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={files.passport_page2_3}
|
||||
onFileChange={setFile('passport_page2_3')}
|
||||
error={errors.passport_page2_3}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-passport_page8_9">
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('Passport (pages 8-9)', 'Pasport (8-9 sahypa)')}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={files.passport_page8_9}
|
||||
onFileChange={setFile('passport_page8_9')}
|
||||
error={errors.passport_page8_9}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
</div>
|
||||
<div id="field-passport_page32">
|
||||
<FormInput
|
||||
type="file"
|
||||
label={t('Passport (page 32)', 'Pasport (32-nji sahypa)')}
|
||||
accept="image/*,.pdf"
|
||||
fileValue={files.passport_page32}
|
||||
onFileChange={setFile('passport_page32')}
|
||||
error={errors.passport_page32}
|
||||
required={mode === 'create'}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{/* ── Form Actions ──────────────────────────────────────────────────── */}
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onCancel={handleCancel}
|
||||
cancelVariant="ghost"
|
||||
cancelLabel={t('Cancel', 'Ýatyr')}
|
||||
loadingLabel={t('Saving...', 'Saklanýar...')}
|
||||
onPrev={!isFirstStep ? handlePrev : undefined}
|
||||
prevLabel={t('Back', 'Yza')}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
nextLabel={t('Next', 'Indiki')}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={handleSubmit}
|
||||
submitLabel={
|
||||
mode === 'create'
|
||||
? t('Create card requisite order', 'Kart rekwiziti üçin sargyt dörediň')
|
||||
: t('Save changes', 'Üýtgetmeleri sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
: t('Save changes', 'Üýtgetmeleri sakla')
|
||||
}
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import type { CardTransaction } from '../api/cardTransactionsApi'
|
||||
import { useCreateCardTransaction, useUpdateCardTransaction } from '../hooks/useCardTransactions'
|
||||
|
||||
@@ -200,19 +200,18 @@ export function CardTransactionForm({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex justify-end gap-3 mt-6">
|
||||
<Button variant="ghost" onClick={handleCancel} disabled={isPending}>
|
||||
{t('Cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} disabled={isPending}>
|
||||
{isPending
|
||||
? t('Saving...', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('Create card transaction', 'Kart herekedi dörediň')
|
||||
: t('Save changes', 'Üýtgetmeleri sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={handleCancel}
|
||||
cancelVariant="ghost"
|
||||
cancelLabel={t('Cancel', 'Ýatyr')}
|
||||
loadingLabel={t('Saving...', 'Saklanýar...')}
|
||||
submitLabel={mode === 'create'
|
||||
? t('Create card transaction', 'Kart herekedi dörediň')
|
||||
: t('Save changes', 'Üýtgetmeleri sakla')}
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import type { CardType, CreateCardTypePayload } from '../api/cardTypesApi'
|
||||
import { useCreateCardType, useUpdateCardType } from '../hooks/useCardTypes'
|
||||
@@ -196,29 +196,16 @@ export function CardTypeForm({ mode, initialData, cardTypeId }: CardTypeFormProp
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center justify-end gap-3 mt-6">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => navigate('/settings/card/card-types')}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('cardTypes.actions.create', 'Kart görnüşi döretdiň')
|
||||
: t('cardTypes.actions.update', 'Täzelemek')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate('/settings/card/card-types')}
|
||||
cancelVariant="ghost"
|
||||
submitLabel={mode === 'create'
|
||||
? t('cardTypes.actions.create', 'Kart görnüşi döretdiň')
|
||||
: t('cardTypes.actions.update', 'Täzelemek')}
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { useCreateClient, useUpdateClient } from '../hooks/useClients'
|
||||
import type { Client, CreateClientPayload, UpdateClientPayload } from '../api/clientsApi'
|
||||
@@ -227,29 +227,16 @@ export function ClientForm({ mode, initialData, clientId }: ClientFormProps) {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border bg-muted/20">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => navigate(-1)}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
className="bg-primary hover:bg-primary/90 text-primary-foreground min-w-[160px]"
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('clients.createBtn', 'Müşderi döredin')
|
||||
: t('clients.updateBtn', 'Üýtgetmeleri sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate(-1)}
|
||||
cancelVariant="ghost"
|
||||
submitLabel={mode === 'create'
|
||||
? t('clients.createBtn', 'Müşderi döredin')
|
||||
: t('clients.updateBtn', 'Üýtgetmeleri sakla')}
|
||||
className="px-6 py-4 border-t border-border bg-muted/20"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { CURRENCY_OPTIONS, type CurrencyCode, type CurrencyRate } from '../api/currencyRatesApi'
|
||||
import { useCreateCurrencyRate, useUpdateCurrencyRate } from '../hooks/useCurrencyRates'
|
||||
|
||||
@@ -175,29 +175,16 @@ export function CurrencyRateForm({ mode, initialData, rateId }: CurrencyRateForm
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer Actions */}
|
||||
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={handleCancel}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('currencyRates.actions.create', 'Walýuta kursy dörediň')
|
||||
: t('currencyRates.actions.update', 'Ýatda sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={handleCancel}
|
||||
cancelVariant="ghost"
|
||||
submitLabel={mode === 'create'
|
||||
? t('currencyRates.actions.create', 'Walýuta kursy dörediň')
|
||||
: t('currencyRates.actions.update', 'Ýatda sakla')}
|
||||
className="px-6 py-4 border-t border-border"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import type { District, CreateDistrictPayload } from '../api/districtsApi'
|
||||
import { useCreateDistrict, useUpdateDistrict } from '../hooks/useDistricts'
|
||||
@@ -165,28 +165,16 @@ export function DistrictForm({ mode, initialData, districtId }: DistrictFormProp
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-end gap-3 mt-6">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => navigate('/settings/location/districts')}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('districts.actions.create', 'Etrap döret')
|
||||
: t('districts.actions.update', 'Täzelemek')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate('/settings/location/districts')}
|
||||
cancelVariant="ghost"
|
||||
submitLabel={mode === 'create'
|
||||
? t('districts.actions.create', 'Etrap döret')
|
||||
: t('districts.actions.update', 'Täzelemek')}
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,10 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
|
||||
import {
|
||||
useCreateLoanRemaining,
|
||||
@@ -99,8 +98,8 @@ export function LoanRemainingForm({
|
||||
return Object.keys(newErrors).length === 0
|
||||
}
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
const handleSubmit = (e?: React.FormEvent) => {
|
||||
e?.preventDefault()
|
||||
setSubmitted(true)
|
||||
|
||||
if (!validate()) {
|
||||
@@ -168,22 +167,14 @@ export function LoanRemainingForm({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => navigate('/loan-remaining')}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button type="submit" disabled={isPending}>
|
||||
{isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
{mode === 'create'
|
||||
? t('common.create', 'Döret')
|
||||
: t('common.save', 'Ýatda sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate('/loan-remaining')}
|
||||
submitLabel={mode === 'create'
|
||||
? t('common.create', 'Döret')
|
||||
: t('common.save', 'Ýatda sakla')}
|
||||
/>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { useCreateLoanType, useUpdateLoanType } from '../hooks/useLoanTypes'
|
||||
import type { LoanType, CreateLoanTypePayload } from '../api/loanTypesApi'
|
||||
@@ -241,28 +241,16 @@ export function LoanTypeForm({ mode, initialData, loanTypeId }: LoanTypeFormProp
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center justify-end gap-3 pt-4">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={handleCancel}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('loanTypes.actions.create', 'Karz görnüşi dörediň')
|
||||
: t('loanTypes.actions.save', 'Ýatda sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={handleCancel}
|
||||
cancelVariant="ghost"
|
||||
submitLabel={mode === 'create'
|
||||
? t('loanTypes.actions.create', 'Karz görnüşi dörediň')
|
||||
: t('loanTypes.actions.save', 'Ýatda sakla')}
|
||||
className="pt-4"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { useCreateOperator, useUpdateOperator } from '../hooks/useOperators'
|
||||
import type { Operator, CreateOperatorPayload, UpdateOperatorPayload } from '../api/operatorsApi'
|
||||
@@ -225,29 +225,16 @@ export function OperatorForm({ mode, initialData, operatorId }: OperatorFormProp
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border bg-muted/20">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => navigate(-1)}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
className="bg-primary hover:bg-primary/90 text-primary-foreground min-w-[160px]"
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('operators.createBtn', 'Operator döredin')
|
||||
: t('operators.updateBtn', 'Üýtgetmeleri sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate(-1)}
|
||||
cancelVariant="ghost"
|
||||
submitLabel={mode === 'create'
|
||||
? t('operators.createBtn', 'Operator döredin')
|
||||
: t('operators.updateBtn', 'Üýtgetmeleri sakla')}
|
||||
className="px-6 py-4 border-t border-border bg-muted/20"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@ import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { useCreatePermission, useUpdatePermission } from '../hooks/usePermissions'
|
||||
import type { Permission, PermissionPayload } from '../api/permissionsApi'
|
||||
|
||||
@@ -175,28 +175,15 @@ export function PermissionForm({ mode, initialData, permissionId }: PermissionFo
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center justify-end gap-3 px-5 py-4 border-t border-border bg-muted/20">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => navigate('/settings/users/permissions')}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Ýüklenýär...')
|
||||
: mode === 'create'
|
||||
? t('permissions.actions.create', 'Rugsat dörediň')
|
||||
: t('permissions.actions.save', 'Ýatda sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate('/settings/users/permissions')}
|
||||
submitLabel={mode === 'create'
|
||||
? t('permissions.actions.create', 'Rugsat dörediň')
|
||||
: t('permissions.actions.save', 'Ýatda sakla')}
|
||||
className="px-5 py-4 border-t border-border bg-muted/20"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
} from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { useCreateRequiredDocument, useUpdateRequiredDocument } from '../hooks/useRequiredDocuments'
|
||||
import type { LoanDocument, LoanDocumentPayload, LoanDocumentTranslation } from '../api/requiredDocumentsApi'
|
||||
|
||||
@@ -222,8 +222,8 @@ export function RequiredDocumentForm({ mode, initialData, requiredDocumentId }:
|
||||
|
||||
// ── Submit ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
const handleSubmit = async (e?: React.FormEvent) => {
|
||||
e?.preventDefault()
|
||||
if (!validate()) return
|
||||
|
||||
const payload: LoanDocumentPayload = { name, description }
|
||||
@@ -292,20 +292,15 @@ export function RequiredDocumentForm({ mode, initialData, requiredDocumentId }:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Actions ──────────────────────────────────────────────────────────── */}
|
||||
<div className="flex items-center justify-end gap-3 mt-4">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => navigate('/settings/loan/loan-documents')}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button type="submit" disabled={isPending} className="bg-primary text-primary-foreground hover:bg-primary/90">
|
||||
{isPending ? t('common.saving', 'Saklanylýar...') : submitLabel}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate('/settings/loan/loan-documents')}
|
||||
cancelVariant="ghost"
|
||||
loadingLabel={t('common.saving', 'Saklanylýar...')}
|
||||
submitLabel={submitLabel}
|
||||
className="mt-4"
|
||||
/>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { useCreateRole, useUpdateRole } from '../hooks/useRoles'
|
||||
import type { Role, RolePayload } from '../api/rolesApi'
|
||||
|
||||
@@ -176,28 +176,16 @@ export function RoleForm({ mode, initialData, roleId }: RoleFormProps) {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center justify-end gap-3 px-5 py-4 border-t border-border bg-muted/20">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => navigate('/settings/users/roles')}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Ýüklenýär...')
|
||||
: mode === 'create'
|
||||
? t('roles.actions.create', 'Rol dörediň')
|
||||
: t('roles.actions.save', 'Ýatda sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={() => navigate('/settings/users/roles')}
|
||||
loadingLabel={t('common.saving', 'Ýüklenýär...')}
|
||||
submitLabel={mode === 'create'
|
||||
? t('roles.actions.create', 'Rol dörediň')
|
||||
: t('roles.actions.save', 'Ýatda sakla')}
|
||||
className="px-5 py-4 border-t border-border bg-muted/20"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,15 +1,24 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { toast } from 'sonner'
|
||||
import { Plus } from 'lucide-react'
|
||||
import { User, MapPin, IdCard, CreditCard, Files } from 'lucide-react'
|
||||
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import { useCreateSberPayment, useUpdateSberPayment } from '@/features/sberPayments/hooks/useSberPayments'
|
||||
import { WELAYATLAR, SAHAMCALAR, STATUSES, type SberPaymentOrder, type SberPaymentFormData, type PaymentStatus } from '@/features/sberPayments/api/sberPaymentsApi'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
|
||||
import type { StepStatus } from '@/components/stepBar'
|
||||
import {
|
||||
useCreateSberPayment,
|
||||
useUpdateSberPayment,
|
||||
} from '@/features/sberPayments/hooks/useSberPayments'
|
||||
import {
|
||||
WELAYATLAR,
|
||||
SAHAMCALAR,
|
||||
STATUSES,
|
||||
type SberPaymentOrder,
|
||||
type SberPaymentFormData,
|
||||
type PaymentStatus,
|
||||
} from '@/features/sberPayments/api/sberPaymentsApi'
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -19,376 +28,604 @@ interface SberPaymentFormProps {
|
||||
orderId?: string
|
||||
}
|
||||
|
||||
// ─── Document Labels ──────────────────────────────────────────────────────────
|
||||
// ─── Document lists ───────────────────────────────────────────────────────────
|
||||
|
||||
const acceptedDocumentLabels = [
|
||||
'Talyba degisli walýuta "SBERBANK" kartyň rekwizitleri',
|
||||
'Talybýň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwanamasy',
|
||||
'Talybýň bildirisli göcürmesi',
|
||||
'Talyba degisli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi',
|
||||
'Talybýň Türkmenistandan çykmak we Türkmenistana girmek üçin (zagran) pasportynyň göçürmesi',
|
||||
'Talybýň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportyndaky daşary ýurda göýberilmegi barada beriim miiletti hereket edijan rughsatnamasyniyň (wizasynyň) bellenen sahypasynyň göçürmesi',
|
||||
'Talybýň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportyndaky Türkmenistandan çykanday we daşary ýurt döwletine girenligi baradaky ştamplaryň (belgi ştamply) bellenen sahypasynyň göçürmesi',
|
||||
'Talybýň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwanamasynyň doly takyk dili wýagdayýnda talyk dili magumatyň sebäpleri baradaky daşary ýurt döwletiniň ýokary okuw mekdebinden haty',
|
||||
type AcceptedDocKey =
|
||||
| 'acc_sberbank_card' | 'acc_enrollment' | 'acc_summons'
|
||||
| 'acc_passport_tm' | 'acc_zagran_passport' | 'acc_visa_page'
|
||||
| 'acc_entry_stamp' | 'acc_school_letter'
|
||||
|
||||
type SentDocKey =
|
||||
| 'snt_passport_tm' | 'snt_zagran_passport' | 'snt_entry_stamp'
|
||||
| 'snt_relation_doc' | 'snt_new_passport_series' | 'snt_old_passport_series'
|
||||
|
||||
const ACCEPTED_DOCS: { key: AcceptedDocKey; label: string }[] = [
|
||||
{ key: 'acc_sberbank_card', label: 'Talýba degişli SBERBANK kartynyň rekwizitleri' },
|
||||
{ key: 'acc_enrollment', label: 'Daşary ýurt ÝOM-da okaýandygy baradaky güwänamasy' },
|
||||
{ key: 'acc_summons', label: 'Çagyrylma hatynyn göçürmesi' },
|
||||
{ key: 'acc_passport_tm', label: 'TM içki pasportynyň asyl görnüşi we göçürmesi' },
|
||||
{ key: 'acc_zagran_passport', label: 'Daşary ýurt (zagran) pasportynyň göçürmesi' },
|
||||
{ key: 'acc_visa_page', label: 'Daşary ýurda rugsat (wizasy) bellenen sahypasynyň göçürmesi' },
|
||||
{ key: 'acc_entry_stamp', label: 'Daşary ýurt döwletine girenliği baradaky ştamply sahypasynyň göçürmesi' },
|
||||
{ key: 'acc_school_letter', label: 'ÝOM-dan hat (daşary ýurt dilinde maglumatly)' },
|
||||
]
|
||||
|
||||
const sentDocumentLabels = [
|
||||
'Ugradyjy degisli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi',
|
||||
'Ugradyjy degisli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň asyl görnüşi we göçürmesi',
|
||||
'Ugradyjy degisli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportyndaky daşary döwletine girenliği we daşary döwlete baradaky ştamply bellenen sahypasynyň göçürmesi',
|
||||
'Ugradyjynýň we kabul edijinin (talybýň) özara garyndaşlyk denjesini tassyklaýjy resminamalarynýň göçürmesi',
|
||||
'Ugradyjy we kabul ediji (talyp) 2015-nji ýyldan soňra Türkmenistanyň raýatynýň pasportyny kiriş gerek alan bolsa, onda birnji gerek alan pasportynyň seriyasy baradaky maglumat',
|
||||
'Ugradyjy we kabul ediji (talyp) 2015-nji ýyldan soňra Türkmenistanyň raýatynýň pasportyny kiriş gerek alandan soňra birnji gerek alan pasportynyň seriyasy baradaky magumatý bilmeýän, balsa onda polisijyenyň degisli ekedasynýdan birnji alan pasportynyň seriyasy baradaky güwanamasy',
|
||||
const SENT_DOCS: { key: SentDocKey; label: string }[] = [
|
||||
{ key: 'snt_passport_tm', label: 'Ugradyjynyň TM içki pasportynyň asyl görnüşi we göçürmesi' },
|
||||
{ key: 'snt_zagran_passport', label: 'Ugradyjynyň daşary ýurt pasportynyň asyl görnüşi we göçürmesi' },
|
||||
{ key: 'snt_entry_stamp', label: 'Ugradyjynyň daşary döwletine girenliği ştamply sahypasynyň göçürmesi' },
|
||||
{ key: 'snt_relation_doc', label: 'Ugradyjy we kabul edijiniň garyndaşlyk tassyklaýjy resminamasynyn göçürmesi' },
|
||||
{ key: 'snt_new_passport_series', label: 'Ugradyjy/kabul ediji täze (2015+) pasport seriýasy maglumaty' },
|
||||
{ key: 'snt_old_passport_series', label: 'Ugradyjy/kabul ediji köne pasport seriýasy baradaky güwänamasy' },
|
||||
]
|
||||
|
||||
// ─── Shared Form Component ────────────────────────────────────────────────────
|
||||
|
||||
export function SberPaymentForm({ mode, initialData, orderId }: SberPaymentFormProps) {
|
||||
const router = useNavigate()
|
||||
const createMutation = useCreateSberPayment()
|
||||
const updateMutation = useUpdateSberPayment()
|
||||
|
||||
const isLoading = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
// Form state
|
||||
const [formData, setFormData] = useState<SberPaymentFormData>({
|
||||
welayat: '',
|
||||
sahamca: '',
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
address: '',
|
||||
status: 'GARASYLYYAR',
|
||||
bellik: '',
|
||||
accountNumber: '',
|
||||
passportSeries: '',
|
||||
passportNumber: '',
|
||||
fullName: '',
|
||||
})
|
||||
|
||||
// ─── FormState ────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
// Validation errors
|
||||
const [errors, setErrors] = useState<Partial<Record<keyof SberPaymentFormData, string>>>({})
|
||||
|
||||
// Populate form with initial data in edit mode
|
||||
useEffect(() => {
|
||||
if (mode === 'edit' && initialData) {
|
||||
setFormData({
|
||||
welayat: initialData.welayat,
|
||||
sahamca: initialData.sahamca,
|
||||
firstName: initialData.firstName,
|
||||
lastName: initialData.lastName,
|
||||
phone: initialData.phone,
|
||||
email: initialData.email,
|
||||
address: initialData.address,
|
||||
status: initialData.status,
|
||||
bellik: initialData.bellik,
|
||||
accountNumber: initialData.accountNumber,
|
||||
passportSeries: initialData.passportSeries,
|
||||
passportNumber: initialData.passportNumber,
|
||||
fullName: initialData.fullName,
|
||||
})
|
||||
}
|
||||
}, [mode, initialData])
|
||||
|
||||
// Get available branches based on selected welayat
|
||||
const availableBranches = formData.welayat ? SAHAMCALAR[formData.welayat] ?? [] : []
|
||||
|
||||
// Update field helper
|
||||
const updateField = <K extends keyof SberPaymentFormData>(
|
||||
field: K,
|
||||
value: SberPaymentFormData[K]
|
||||
) => {
|
||||
setFormData((prev) => ({ ...prev, [field]: value }))
|
||||
if (errors[field]) {
|
||||
setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||
}
|
||||
}
|
||||
|
||||
// Validate form
|
||||
const validate = (): boolean => {
|
||||
const newErrors: Partial<Record<keyof SberPaymentFormData, string>> = {}
|
||||
|
||||
if (!formData.welayat) newErrors.welayat = 'Welayat saylanmaly'
|
||||
if (!formData.sahamca) newErrors.sahamca = 'Sahamca saylanmaly'
|
||||
if (!formData.firstName) newErrors.firstName = 'Ady girizmeli'
|
||||
if (!formData.lastName) newErrors.lastName = 'Familiyasy girizmeli'
|
||||
if (!formData.phone) newErrors.phone = 'Telefon girizmeli'
|
||||
if (!formData.address) newErrors.address = 'Salgy girizmeli'
|
||||
if (!formData.passportSeries) newErrors.passportSeries = 'Pasport seriyasy girizmeli'
|
||||
if (!formData.passportNumber) newErrors.passportNumber = 'Pasport nomeri girizmeli'
|
||||
if (!formData.fullName) newErrors.fullName = 'Doly ady girizmeli'
|
||||
if (!formData.accountNumber) newErrors.accountNumber = 'Goyum hasaby girizmeli'
|
||||
|
||||
setErrors(newErrors)
|
||||
return Object.keys(newErrors).length === 0
|
||||
}
|
||||
|
||||
// Submit handler
|
||||
const handleSubmit = async () => {
|
||||
if (!validate()) {
|
||||
toast.error('Meydanlary dolduryň')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (mode === 'create') {
|
||||
await createMutation.mutateAsync(formData)
|
||||
toast.success('Toleg ustunlikli doredildi')
|
||||
router('/sber-payments')
|
||||
} else if (orderId) {
|
||||
await updateMutation.mutateAsync({ ...formData, id: orderId })
|
||||
toast.success('Toleg ustunlikli tazelendi')
|
||||
router(`/sber-payments/${orderId}`)
|
||||
}
|
||||
} catch {
|
||||
toast.error('Yalnyshlyk yuze cykdy')
|
||||
}
|
||||
}
|
||||
|
||||
interface FormState extends SberPaymentFormData {
|
||||
client_id: string
|
||||
// file fields
|
||||
acc_sberbank_card: File | null
|
||||
acc_enrollment: File | null
|
||||
acc_summons: File | null
|
||||
acc_passport_tm: File | null
|
||||
acc_zagran_passport: File | null
|
||||
acc_visa_page: File | null
|
||||
acc_entry_stamp: File | null
|
||||
acc_school_letter: File | null
|
||||
snt_passport_tm: File | null
|
||||
snt_zagran_passport: File | null
|
||||
snt_entry_stamp: File | null
|
||||
snt_relation_doc: File | null
|
||||
snt_new_passport_series: File | null
|
||||
snt_old_passport_series: File | null
|
||||
}
|
||||
|
||||
type FormErrors = Partial<Record<keyof FormState, string>>
|
||||
|
||||
// ─── Default state ────────────────────────────────────────────────────────────
|
||||
|
||||
const defaultState: FormState = {
|
||||
client_id: '',
|
||||
welayat: '',
|
||||
sahamca: '',
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
address: '',
|
||||
status: 'GARASYLYYAR',
|
||||
bellik: '',
|
||||
accountNumber: '',
|
||||
passportSeries: '',
|
||||
passportNumber: '',
|
||||
fullName: '',
|
||||
acc_sberbank_card: null,
|
||||
acc_enrollment: null,
|
||||
acc_summons: null,
|
||||
acc_passport_tm: null,
|
||||
acc_zagran_passport: null,
|
||||
acc_visa_page: null,
|
||||
acc_entry_stamp: null,
|
||||
acc_school_letter: null,
|
||||
snt_passport_tm: null,
|
||||
snt_zagran_passport: null,
|
||||
snt_entry_stamp: null,
|
||||
snt_relation_doc: null,
|
||||
snt_new_passport_series: null,
|
||||
snt_old_passport_series: null,
|
||||
}
|
||||
|
||||
// ─── Step definitions ─────────────────────────────────────────────────────────
|
||||
|
||||
type StepId = 'general' | 'location' | 'personal' | 'payment' | 'docs'
|
||||
|
||||
const STEPS: { id: StepId; title: string; subtitle: string }[] = [
|
||||
{ id: 'general', title: 'Esasy', subtitle: 'Status, müşderi' },
|
||||
{ id: 'location', title: 'Lokasiýa', subtitle: 'Welaýat, şahamça' },
|
||||
{ id: 'personal', title: 'Şahsy', subtitle: 'Pasport, kontakt' },
|
||||
{ id: 'payment', title: 'Töleg', subtitle: 'Hasap, ugradyjy' },
|
||||
{ id: 'docs', title: 'Resminamalar', subtitle: '14 resminama' },
|
||||
]
|
||||
|
||||
const STEP_REQUIRED: Partial<Record<StepId, (keyof FormState)[]>> = {
|
||||
general: ['status'],
|
||||
location: ['welayat', 'sahamca'],
|
||||
personal: ['firstName', 'lastName', 'phone', 'address'],
|
||||
payment: ['passportSeries', 'passportNumber', 'fullName', 'accountNumber'],
|
||||
}
|
||||
|
||||
const ERROR_LABELS: Partial<Record<keyof FormState, string>> = {
|
||||
status: 'Status hökmany',
|
||||
welayat: 'Welaýat hökmany',
|
||||
sahamca: 'Şahamça hökmany',
|
||||
firstName: 'Ady hökmany',
|
||||
lastName: 'Familiýasy hökmany',
|
||||
phone: 'Telefon hökmany',
|
||||
address: 'Salgy hökmany',
|
||||
passportSeries:'Pasport seriýasy hökmany',
|
||||
passportNumber:'Pasport nomeri hökmany',
|
||||
fullName: 'Doly ady hökmany',
|
||||
accountNumber: 'Goýum hasaby hökmany',
|
||||
}
|
||||
|
||||
// ─── Bento primitives ─────────────────────────────────────────────────────────
|
||||
|
||||
function BentoGrid({ cols = 2, children }: { cols?: 1 | 2; children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="space-y-8 pb-8">
|
||||
{/* Status Section */}
|
||||
<section className="space-y-4">
|
||||
<h2 className="text-base font-semibold text-foreground">Status</h2>
|
||||
<div className="grid gap-4">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Ulanyjy"
|
||||
required
|
||||
placeholder="Saylamak ucin basyn"
|
||||
value=""
|
||||
onChange={() => {}}
|
||||
options={[]}
|
||||
/>
|
||||
<FormInput
|
||||
type="select"
|
||||
label="Status"
|
||||
required
|
||||
value={formData.status}
|
||||
onChange={(val) => updateField('status', val as PaymentStatus)}
|
||||
options={STATUSES}
|
||||
error={errors.status}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Bellik"
|
||||
value={formData.bellik}
|
||||
onChange={(val) => updateField('bellik', val)}
|
||||
placeholder="Bellik"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Location Section */}
|
||||
<section className="space-y-4">
|
||||
<h2 className="text-base font-semibold text-foreground">Lokasiya</h2>
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
<FormInput
|
||||
type="select"
|
||||
label="Welayat"
|
||||
required
|
||||
value={formData.welayat}
|
||||
onChange={(val) => {
|
||||
updateField('welayat', val)
|
||||
updateField('sahamca', '') // Reset branch when region changes
|
||||
}}
|
||||
options={WELAYATLAR.map((w) => ({ value: w, label: w }))}
|
||||
placeholder="Asgabat"
|
||||
error={errors.welayat}
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Sahamca"
|
||||
required
|
||||
value={formData.sahamca}
|
||||
onChange={(val) => updateField('sahamca', val)}
|
||||
options={availableBranches.map((b) => ({ value: b, label: b }))}
|
||||
placeholder="Saylamak ucin basyn"
|
||||
disabled={!formData.welayat}
|
||||
error={errors.sahamca}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Personal Info Section */}
|
||||
<section className="space-y-4">
|
||||
<h2 className="text-base font-semibold text-foreground">Sahsy maglumatlar</h2>
|
||||
<div className="grid gap-4">
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasportdaky ady"
|
||||
required
|
||||
value={formData.firstName}
|
||||
onChange={(val) => updateField('firstName', val)}
|
||||
placeholder="Pasportdaky ady"
|
||||
error={errors.firstName}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasportdaky familiya"
|
||||
required
|
||||
value={formData.lastName}
|
||||
onChange={(val) => updateField('lastName', val)}
|
||||
placeholder="Pasportdaky familiya"
|
||||
error={errors.lastName}
|
||||
/>
|
||||
<FormInput
|
||||
type="phone"
|
||||
label="Telefon"
|
||||
required
|
||||
value={formData.phone}
|
||||
onChange={(val) => updateField('phone', val)}
|
||||
placeholder="61 097 651"
|
||||
error={errors.phone}
|
||||
/>
|
||||
<FormInput
|
||||
type="email"
|
||||
label="E-pocta"
|
||||
value={formData.email}
|
||||
onChange={(val) => updateField('email', val)}
|
||||
placeholder="E-pocta"
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Hazirki yasayys yeri"
|
||||
required
|
||||
value={formData.address}
|
||||
onChange={(val) => updateField('address', val)}
|
||||
placeholder="Hazirki yasayys yeri"
|
||||
error={errors.address}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Payment Info Section */}
|
||||
<section className="space-y-4">
|
||||
<h2 className="text-base font-semibold text-foreground">Tolegi ugradyjynyn maglumatlary</h2>
|
||||
<div className="grid gap-4">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Pasport seriyasy"
|
||||
required
|
||||
value={formData.passportSeries}
|
||||
onChange={(val) => updateField('passportSeries', val)}
|
||||
options={[
|
||||
{ value: 'II-MA', label: 'II-MA' },
|
||||
{ value: 'II-MB', label: 'II-MB' },
|
||||
{ value: 'II-MC', label: 'II-MC' },
|
||||
{ value: 'II-MD', label: 'II-MD' },
|
||||
]}
|
||||
placeholder="Saylamak ucin basyn"
|
||||
error={errors.passportSeries}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasport nomeri"
|
||||
required
|
||||
value={formData.passportNumber}
|
||||
onChange={(val) => updateField('passportNumber', val)}
|
||||
placeholder="Pasport nomeri"
|
||||
error={errors.passportNumber}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Ady Familiyasy Atasynyn ady"
|
||||
required
|
||||
value={formData.fullName}
|
||||
onChange={(val) => updateField('fullName', val)}
|
||||
placeholder="Ady Familiyasy Atasynyn ady"
|
||||
error={errors.fullName}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Goyum hasaby"
|
||||
required
|
||||
value={formData.accountNumber}
|
||||
onChange={(val) => updateField('accountNumber', val)}
|
||||
placeholder="Goyum hasaby"
|
||||
error={errors.accountNumber}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Recipient Info Section */}
|
||||
<section className="space-y-4">
|
||||
<h2 className="text-base font-semibold text-foreground">Tolegi kabul edijinin maglumatlary</h2>
|
||||
<div className="bg-card rounded-lg border border-border p-4">
|
||||
<div className="flex items-start gap-4">
|
||||
<span className="text-sm text-muted-foreground shrink-0 w-48">
|
||||
Tolegi kabul edijinin maglumatlary
|
||||
</span>
|
||||
<Button variant="default" className="bg-primary text-primary-foreground">
|
||||
Setir gos
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Accepted Documents Section */}
|
||||
<section className="space-y-4">
|
||||
<h2 className="text-base font-semibold text-foreground">
|
||||
Kabul ediji talyp boyunca resminamalary
|
||||
</h2>
|
||||
<div className="space-y-3">
|
||||
{acceptedDocumentLabels.map((label, index) => (
|
||||
<div key={index} className="flex items-start gap-4 py-3">
|
||||
<span className="w-80 shrink-0 text-sm text-muted-foreground leading-relaxed">
|
||||
{label}
|
||||
</span>
|
||||
<Button variant="outline" size="sm" className="gap-2">
|
||||
<Plus size={14} />
|
||||
Add New File
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Sent Documents Section */}
|
||||
<section className="space-y-4">
|
||||
<h2 className="text-base font-semibold text-foreground">
|
||||
Ugradyjy boyunca resminamalary
|
||||
</h2>
|
||||
<div className="space-y-3">
|
||||
{sentDocumentLabels.map((label, index) => (
|
||||
<div key={index} className="flex items-start gap-4 py-3">
|
||||
<span className="w-80 shrink-0 text-sm text-muted-foreground leading-relaxed">
|
||||
{label}
|
||||
</span>
|
||||
<Button variant="outline" size="sm" className="gap-2">
|
||||
<Plus size={14} />
|
||||
Add New File
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center justify-end gap-3 pt-4 border-t border-border">
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={isLoading}
|
||||
>
|
||||
Yatyr
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={isLoading}
|
||||
className="min-w-[180px]"
|
||||
>
|
||||
{isLoading ? (
|
||||
<Spinner className="w-4 h-4" />
|
||||
) : mode === 'create' ? (
|
||||
'Sber toleg (talyplar ucin) doredih'
|
||||
) : (
|
||||
'Yatda sakla'
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
<div className={`grid gap-4 ${cols === 2 ? 'grid-cols-1 sm:grid-cols-2' : 'grid-cols-1'}`}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BentoCard({
|
||||
title,
|
||||
span,
|
||||
children,
|
||||
}: {
|
||||
title?: string
|
||||
span?: 'full'
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={`bg-card border border-border rounded-xl p-5 space-y-4${
|
||||
span === 'full' ? ' sm:col-span-2' : ''
|
||||
}`}
|
||||
>
|
||||
{title && (
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
|
||||
function StepGeneral({
|
||||
form, errors, set,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Müşderi">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Ulanyjy"
|
||||
value={form.client_id}
|
||||
onChange={(v) => set('client_id', v)}
|
||||
options={[]}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Status">
|
||||
<FormInput
|
||||
type="select"
|
||||
label="Status"
|
||||
value={form.status}
|
||||
onChange={(v) => set('status', v as PaymentStatus)}
|
||||
options={STATUSES}
|
||||
error={errors.status}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Bellik" span="full">
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label="Bellik"
|
||||
value={form.bellik}
|
||||
onChange={(v) => set('bellik', v)}
|
||||
placeholder="Bellik..."
|
||||
rows={2}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
function StepLocation({
|
||||
form, errors, set,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
const branches = form.welayat ? (SAHAMCALAR[form.welayat] ?? []) : []
|
||||
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Welaýat">
|
||||
<FormInput
|
||||
type="select"
|
||||
label="Welaýat"
|
||||
value={form.welayat}
|
||||
onChange={(v) => { set('welayat', v); set('sahamca', '') }}
|
||||
options={WELAYATLAR.map((w) => ({ value: w, label: w }))}
|
||||
placeholder="Aşgabat"
|
||||
error={errors.welayat}
|
||||
required
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Welaýaty saýlasaňyz şahamçalar güncellenar.
|
||||
</p>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Şahamça">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Şahamça"
|
||||
value={form.sahamca}
|
||||
onChange={(v) => set('sahamca', v)}
|
||||
options={branches.map((b) => ({ value: b, label: b }))}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
disabled={!form.welayat}
|
||||
error={errors.sahamca}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
function StepPersonal({
|
||||
form, errors, set,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="At-familýa">
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasportdaky familiýa"
|
||||
value={form.lastName}
|
||||
onChange={(v) => set('lastName', v)}
|
||||
placeholder="NURYYEW"
|
||||
error={errors.lastName}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasportdaky ady"
|
||||
value={form.firstName}
|
||||
onChange={(v) => set('firstName', v)}
|
||||
placeholder="HAÝDAR"
|
||||
error={errors.firstName}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Kontakt">
|
||||
<FormInput
|
||||
type="phone"
|
||||
label="Telefon"
|
||||
value={form.phone}
|
||||
onChange={(v) => set('phone', v)}
|
||||
error={errors.phone}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="email"
|
||||
label="E-poçta"
|
||||
value={form.email}
|
||||
onChange={(v) => set('email', v)}
|
||||
placeholder="email@example.com"
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Häzirki ýaşyş ýeri" span="full">
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Salgy"
|
||||
value={form.address}
|
||||
onChange={(v) => set('address', v)}
|
||||
placeholder="Köçe, jaý belgisi..."
|
||||
error={errors.address}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
function StepPayment({
|
||||
form, errors, set,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Pasport maglumatlary">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Pasport seriýasy"
|
||||
value={form.passportSeries}
|
||||
onChange={(v) => set('passportSeries', v)}
|
||||
options={[
|
||||
{ value: 'II-MA', label: 'II-MA' },
|
||||
{ value: 'II-MB', label: 'II-MB' },
|
||||
{ value: 'II-MC', label: 'II-MC' },
|
||||
{ value: 'II-MD', label: 'II-MD' },
|
||||
]}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.passportSeries}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasport nomeri"
|
||||
value={form.passportNumber}
|
||||
onChange={(v) => set('passportNumber', v)}
|
||||
placeholder="A123456"
|
||||
error={errors.passportNumber}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Ugradyjy">
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Ady Familiýasy Atasynyň ady"
|
||||
value={form.fullName}
|
||||
onChange={(v) => set('fullName', v)}
|
||||
placeholder="Doly ady..."
|
||||
error={errors.fullName}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Goýum hasaby"
|
||||
value={form.accountNumber}
|
||||
onChange={(v) => set('accountNumber', v)}
|
||||
placeholder="1234 5678 ..."
|
||||
error={errors.accountNumber}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
function StepDocs({
|
||||
form, set,
|
||||
}: {
|
||||
form: FormState
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Kabul ediji talyp — 8 resminama">
|
||||
<div className="space-y-3">
|
||||
{ACCEPTED_DOCS.map(({ key, label }) => (
|
||||
<FormInput
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Ugradyjy — 6 resminama">
|
||||
<div className="space-y-3">
|
||||
{SENT_DOCS.map(({ key, label }) => (
|
||||
<FormInput
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function SberPaymentForm({ mode, initialData, orderId }: SberPaymentFormProps) {
|
||||
const navigate = useNavigate()
|
||||
const createMutation = useCreateSberPayment()
|
||||
const updateMutation = useUpdateSberPayment()
|
||||
const isLoading = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const [form, setForm] = useState<FormState>(defaultState)
|
||||
const [errors, setErrors] = useState<FormErrors>({})
|
||||
const [currentStep, setCurrentStep] = useState(0)
|
||||
const [stepStatuses, setStepStatuses] = useState<StepStatus[]>(
|
||||
STEPS.map((_, i) => (i === 0 ? 'active' : 'idle')),
|
||||
)
|
||||
|
||||
// ── Populate in edit mode ──
|
||||
useEffect(() => {
|
||||
if (mode === 'edit' && initialData) {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
welayat: initialData.welayat,
|
||||
sahamca: initialData.sahamca,
|
||||
firstName: initialData.firstName,
|
||||
lastName: initialData.lastName,
|
||||
phone: initialData.phone,
|
||||
email: initialData.email,
|
||||
address: initialData.address,
|
||||
status: initialData.status,
|
||||
bellik: initialData.bellik,
|
||||
accountNumber: initialData.accountNumber,
|
||||
passportSeries: initialData.passportSeries,
|
||||
passportNumber: initialData.passportNumber,
|
||||
fullName: initialData.fullName,
|
||||
}))
|
||||
// Let user jump freely to any step in edit mode
|
||||
setStepStatuses(STEPS.map((_, i) => (i === 0 ? 'active' : i < 4 ? 'done' : 'idle')))
|
||||
}
|
||||
}, [mode, initialData])
|
||||
|
||||
// ── Field setter ──
|
||||
const set = <K extends keyof FormState>(key: K, value: FormState[K]) => {
|
||||
setForm((prev) => ({ ...prev, [key]: value }))
|
||||
if (errors[key]) setErrors((prev) => ({ ...prev, [key]: undefined }))
|
||||
}
|
||||
|
||||
// ── Step validation ──
|
||||
const validateStep = (stepId: StepId): FormErrors => {
|
||||
const fields = STEP_REQUIRED[stepId] ?? []
|
||||
const errs: FormErrors = {}
|
||||
fields.forEach((f) => {
|
||||
if (!form[f]) errs[f] = ERROR_LABELS[f] ?? 'Hökmany'
|
||||
})
|
||||
return errs
|
||||
}
|
||||
|
||||
const validateAll = (): FormErrors => {
|
||||
const errs: FormErrors = {}
|
||||
Object.entries(ERROR_LABELS).forEach(([k, msg]) => {
|
||||
if (!form[k as keyof FormState]) errs[k as keyof FormState] = msg
|
||||
})
|
||||
return errs
|
||||
}
|
||||
|
||||
// ── Navigation ──
|
||||
const goStep = (idx: number) => {
|
||||
if (idx < 0 || idx >= STEPS.length) return
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]
|
||||
if (idx > currentStep) next[currentStep] = 'done'
|
||||
next[idx] = 'active'
|
||||
if (idx < currentStep) {
|
||||
for (let i = idx + 1; i <= currentStep; i++) {
|
||||
if (next[i] !== 'done') next[i] = 'idle'
|
||||
}
|
||||
}
|
||||
return next
|
||||
})
|
||||
setErrors({})
|
||||
setCurrentStep(idx)
|
||||
}
|
||||
|
||||
const handleNext = () => {
|
||||
const stepId = STEPS[currentStep].id
|
||||
const stepErrors = validateStep(stepId)
|
||||
if (Object.keys(stepErrors).length > 0) {
|
||||
setErrors(stepErrors)
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]; next[currentStep] = 'error'; return next
|
||||
})
|
||||
return
|
||||
}
|
||||
if (currentStep === STEPS.length - 1) {
|
||||
handleSubmit()
|
||||
} else {
|
||||
goStep(currentStep + 1)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Submit ──
|
||||
const handleSubmit = async () => {
|
||||
const allErrors = validateAll()
|
||||
if (Object.keys(allErrors).length > 0) {
|
||||
setErrors(allErrors)
|
||||
toast.error('Meýdanlary dolduryň')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const payload: SberPaymentFormData = {
|
||||
welayat: form.welayat,
|
||||
sahamca: form.sahamca,
|
||||
firstName: form.firstName,
|
||||
lastName: form.lastName,
|
||||
phone: form.phone,
|
||||
email: form.email,
|
||||
address: form.address,
|
||||
status: form.status,
|
||||
bellik: form.bellik,
|
||||
accountNumber: form.accountNumber,
|
||||
passportSeries: form.passportSeries,
|
||||
passportNumber: form.passportNumber,
|
||||
fullName: form.fullName,
|
||||
}
|
||||
if (mode === 'create') {
|
||||
await createMutation.mutateAsync(payload)
|
||||
toast.success('Töleg üstünlikli döredildi')
|
||||
navigate('/sber-payments')
|
||||
} else if (orderId) {
|
||||
await updateMutation.mutateAsync({ ...payload, id: orderId })
|
||||
toast.success('Töleg üstünlikli täzelendi')
|
||||
navigate(`/sber-payments/${orderId}`)
|
||||
}
|
||||
} catch {
|
||||
toast.error('Ýalňyşlyk ýüze çykdy')
|
||||
}
|
||||
}
|
||||
|
||||
// ── StepBarCards data ──
|
||||
const stepCardItems: StepCardItem[] = STEPS.map((s, i) => ({
|
||||
id: s.id,
|
||||
title: s.title,
|
||||
subtitle: s.subtitle,
|
||||
status: stepStatuses[i],
|
||||
icon: ([User, MapPin, IdCard, CreditCard, Files] as const)[i],
|
||||
}))
|
||||
|
||||
const isLastStep = currentStep === STEPS.length - 1
|
||||
|
||||
const submitLabel = mode === 'create'
|
||||
? 'Sber töleg (talyplar üçin) dörediň'
|
||||
: 'Ýatda sakla'
|
||||
|
||||
return (
|
||||
<div className="mx-auto space-y-6 pb-8">
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{mode === 'create' ? 'Sber töleg dörediň' : 'Sber töleg redaktirläň'}
|
||||
</h1>
|
||||
|
||||
{/* ── Step bar ──────────────────────────────────────────────────────── */}
|
||||
<div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
|
||||
<StepBarCards
|
||||
steps={stepCardItems}
|
||||
onGoTo={(i) => {
|
||||
if (stepStatuses[i] !== 'idle') goStep(i)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* ── Step content ─────────────────────────────────────────────────── */}
|
||||
{STEPS[currentStep].id === 'general' && <StepGeneral form={form} errors={errors} set={set} />}
|
||||
{STEPS[currentStep].id === 'location' && <StepLocation form={form} errors={errors} set={set} />}
|
||||
{STEPS[currentStep].id === 'personal' && <StepPersonal form={form} errors={errors} set={set} />}
|
||||
{STEPS[currentStep].id === 'payment' && <StepPayment form={form} errors={errors} set={set} />}
|
||||
{STEPS[currentStep].id === 'docs' && <StepDocs form={form} set={set} />}
|
||||
|
||||
{/* ── Actions ───────────────────────────────────────────────────────── */}
|
||||
<FormActions
|
||||
isPending={isLoading}
|
||||
onCancel={() => navigate('/sber-payments')}
|
||||
onPrev={currentStep > 0 ? () => goStep(currentStep - 1) : undefined}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={isLastStep ? handleNext : undefined}
|
||||
submitLabel={submitLabel}
|
||||
loadingLabel="Ýüklenýär..."
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
'use client'
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
User, MapPin, IdCard, CreditCard, Files,
|
||||
} from 'lucide-react'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import type { IntlPaymentItem, IntlPaymentCreatePayload, IntlPaymentStatus, CurrencyType } from '../api/visaMasterPaymentsApi'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { StepBarCards, type StepCardItem } from '@/components//stepBarV2'
|
||||
import type { StepStatus } from '@/components/stepBar'
|
||||
import type {
|
||||
IntlPaymentItem,
|
||||
IntlPaymentCreatePayload,
|
||||
IntlPaymentStatus,
|
||||
CurrencyType,
|
||||
} from '../api/visaMasterPaymentsApi'
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -87,29 +96,69 @@ const PROVINCE_OPTIONS = [
|
||||
{ value: 'balkan', label: 'Balkan' },
|
||||
]
|
||||
|
||||
// Kabul ediji docs — 9 sany
|
||||
const KABUL_DOCS: { key: FileKey; label: string }[] = [
|
||||
{ key: 'doc_sberbank_account', label: 'Talypyň degişli welaýata "SBERBANK" kartyň rekwizitleri' },
|
||||
{ key: 'doc_school_enrollment', label: 'Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasy' },
|
||||
{ key: 'doc_summons', label: 'Talypyň bilendiriň göçürmesi' },
|
||||
{ key: 'doc_passport_tm', label: 'Talypyň degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi' },
|
||||
{ key: 'doc_foreign_passport', label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi' },
|
||||
{ key: 'doc_foreign_passport_copy',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' },
|
||||
{ key: 'doc_exit_permission', label: 'Talypyň Türkmenistandan çykmak — we Türkmenistana girmek üçin pasportynyň dowletiniň girmesiz baradaky bellenen (goşmaç şaýmynyň) bellenen sahypasynyň göçürmesi' },
|
||||
{ key: 'doc_school_foreign_info', label: 'Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy barada doly takyk dil ulgaýynda takyk dil maglumatly sebäpleri daşary ýurt döwletiniň ýokary okuw mekdebinden haty' },
|
||||
{ key: 'doc_school_departure_info',label: 'Talypyň daşary ýurt döwletinde döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamany döwlet dili maglumatlaryny talabap doly takyk dil ulgaýynda talaby daşary ýurt döwletiniň ýokary okuw mekdebinden haty' },
|
||||
{ key: 'doc_sberbank_account', label: 'Talypyň SBERBANK kartynyň rekwizitleri' },
|
||||
{ key: 'doc_school_enrollment', label: 'Daşary ýurt ÝOM-da okaýandygy barada güwänamasy' },
|
||||
{ key: 'doc_summons', label: 'Çagyrylma hatynyn göçürmesi' },
|
||||
{ key: 'doc_passport_tm', label: 'TM içki pasportynyň asyl görnüşi we göçürmesi' },
|
||||
{ key: 'doc_foreign_passport', label: 'Daşary ýurt pasportynyň göçürmesi' },
|
||||
{ key: 'doc_foreign_passport_copy', label: 'Bakýan döwlet sahypasynyň göçürmesi' },
|
||||
{ key: 'doc_exit_permission', label: 'Çykyş-giriş rugsat bellikli sahypa göçürmesi' },
|
||||
{ key: 'doc_school_foreign_info', label: 'ÝOM-dan hat (okuw dilinde)' },
|
||||
{ key: 'doc_school_departure_info', label: 'ÝOM-dan hat (döwlet dilinde)' },
|
||||
]
|
||||
|
||||
// Upgradyý docs — 6 sany
|
||||
const UPGRAD_DOCS: { key: FileKey; label: string }[] = [
|
||||
{ key: 'upd_doc_passport_tm', label: 'Upgradyý degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi' },
|
||||
{ key: 'upd_doc_foreign_passport', label: 'Upgradyý degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi' },
|
||||
{ key: 'upd_doc_visa', label: 'Upgradyý Türkmenistandan — çykmak we Türkmenistana girmek üçin pasportynyň daşary ýurt döwletinde galýandygy we daşary ýurt döwleti baradaky şaýmynyň bellenen sahypasynyň göçürmesi' },
|
||||
{ key: 'upd_doc_acceptance_letter', label: 'Upgradyýyň we kabul edijiniň Batalyý töräre garyşdyryjy resminamalarynyň göçürmesi' },
|
||||
{ key: 'upd_doc_passport_biometric', label: 'Upgradyý we kabul ediji täze 2015-nji ýyldan soňra Türkmenistanyň raýatynyň pasportynyň tässy göreli alan bolsa, osta üstü görli 1 pasportynyň seriýasy baradaky maglumatlary' },
|
||||
{ key: 'upd_doc_passport_old', label: 'Upgradyý we kabul ediji täze 2015-nji ýyldan soňra Türkmenistanyň raýatynyň pasportynyň köp göreli alanlar soňra birleşi göreli alan bolsa, biri miwe möhüründen doglan doglan ata-enelerden biriniň alan pasportynyň seriýasy baradaky göwnamasy' },
|
||||
{ key: 'upd_doc_passport_tm', label: 'TM içki pasportynyň asyl görnüşi (upd)' },
|
||||
{ key: 'upd_doc_foreign_passport', label: 'Daşary ýurt pasportynyň göçürmesi (upd)' },
|
||||
{ key: 'upd_doc_visa', label: 'Wiza bellenen sahypasynyň göçürmesi' },
|
||||
{ key: 'upd_doc_acceptance_letter', label: 'Kabul haty we beýleki resminamalar' },
|
||||
{ key: 'upd_doc_passport_biometric', label: 'Täze (2015+) pasport seriýasy maglumatlary' },
|
||||
{ key: 'upd_doc_passport_old', label: 'Könelräk pasport seriýasy maglumatlary' },
|
||||
]
|
||||
|
||||
// ─── Step definitions ─────────────────────────────────────────────────────────
|
||||
|
||||
type StepId = 'general' | 'location' | 'personal' | 'payment' | 'docs'
|
||||
|
||||
interface Step {
|
||||
id: StepId
|
||||
title: string
|
||||
subtitle: string
|
||||
}
|
||||
|
||||
const STEPS: Step[] = [
|
||||
{ id: 'general', title: 'Esasy', subtitle: 'Status, müşderi' },
|
||||
{ id: 'location', title: 'Lokasiýa', subtitle: 'Welaýat, şahamça' },
|
||||
{ id: 'personal', title: 'Şahsy', subtitle: 'Pasport, kontakt' },
|
||||
{ id: 'payment', title: 'Töleg', subtitle: 'Töleýji, kabul ediji' },
|
||||
{ id: 'docs', title: 'Resminamalar', subtitle: '15 resminama' },
|
||||
]
|
||||
|
||||
// Per-step required fields for incremental validation
|
||||
const STEP_REQUIRED_FIELDS: Partial<Record<StepId, (keyof FormState)[]>> = {
|
||||
general: ['client_id', 'status', 'currency_type'],
|
||||
location: ['province', 'branch'],
|
||||
personal: ['passport_first_name', 'passport_last_name', 'phone'],
|
||||
payment: ['passport_series', 'passport_number', 'payer_full_name', 'payer_account_number', 'receiver_info'],
|
||||
}
|
||||
|
||||
const STEP_ERROR_LABELS: Partial<Record<keyof FormState, string>> = {
|
||||
client_id: 'Ulanyjy hökmany',
|
||||
status: 'Status hökmany',
|
||||
currency_type: 'Ýüztumanyň görnüşi hökmany',
|
||||
province: 'Welaýat hökmany',
|
||||
branch: 'Şahamça hökmany',
|
||||
passport_first_name: 'Ady hökmany',
|
||||
passport_last_name: 'Familiýasy hökmany',
|
||||
phone: 'Telefon hökmany',
|
||||
passport_series: 'Pasport seriýasy hökmany',
|
||||
passport_number: 'Pasport nomeri hökmany',
|
||||
payer_full_name: 'Doly ady hökmany',
|
||||
payer_account_number: 'Goşun hasaby hökmany',
|
||||
receiver_info: 'Kabul edijiniň maglumatlary hökmany',
|
||||
}
|
||||
|
||||
// ─── Default state ────────────────────────────────────────────────────────────
|
||||
|
||||
const defaultState: FormState = {
|
||||
@@ -130,48 +179,355 @@ const defaultState: FormState = {
|
||||
upd_doc_passport_biometric: null, upd_doc_passport_old: null,
|
||||
}
|
||||
|
||||
// ─── Validation ───────────────────────────────────────────────────────────────
|
||||
// ─── Full validation (final submit) ──────────────────────────────────────────
|
||||
|
||||
function validate(form: FormState): FormErrors {
|
||||
function validateAll(form: FormState): FormErrors {
|
||||
const errors: FormErrors = {}
|
||||
if (!form.client_id) errors.client_id = 'Ulanyjy hökmany'
|
||||
if (!form.status) errors.status = 'Status hökmany'
|
||||
if (!form.currency_type) errors.currency_type = 'Ýüztumanyň görnüşi hökmany'
|
||||
if (!form.province) errors.province = 'Welaýat hökmany'
|
||||
if (!form.branch) errors.branch = 'Şahamça hökmany'
|
||||
if (!form.passport_first_name) errors.passport_first_name = 'Ady hökmany'
|
||||
if (!form.passport_last_name) errors.passport_last_name = 'Familiýasy hökmany'
|
||||
if (!form.phone) errors.phone = 'Telefon hökmany'
|
||||
if (!form.passport_series) errors.passport_series = 'Pasport seriýasy hökmany'
|
||||
if (!form.passport_number) errors.passport_number = 'Pasport nomeri hökmany'
|
||||
if (!form.payer_full_name) errors.payer_full_name = 'Ady Familiýasy Atasnyň ady hökmany'
|
||||
if (!form.payer_account_number)errors.payer_account_number= 'Goşun hasaby hökmany'
|
||||
if (!form.receiver_info) errors.receiver_info = 'Töleg kabul edijiniň maglumatlary hökmany'
|
||||
Object.entries(STEP_ERROR_LABELS).forEach(([key, msg]) => {
|
||||
if (!form[key as keyof FormState]) errors[key as keyof FormState] = msg
|
||||
})
|
||||
return errors
|
||||
}
|
||||
|
||||
// ─── Section wrapper ──────────────────────────────────────────────────────────
|
||||
function validateStep(form: FormState, stepId: StepId): FormErrors {
|
||||
const fields = STEP_REQUIRED_FIELDS[stepId] ?? []
|
||||
const errors: FormErrors = {}
|
||||
fields.forEach((f) => {
|
||||
if (!form[f]) errors[f] = STEP_ERROR_LABELS[f] ?? 'Hökmany'
|
||||
})
|
||||
return errors
|
||||
}
|
||||
|
||||
function Section({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
// ─── Bento layout primitive ───────────────────────────────────────────────────
|
||||
|
||||
function BentoGrid({
|
||||
cols = 2,
|
||||
children,
|
||||
}: {
|
||||
cols?: 1 | 2 | 3
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const colClass = { 1: 'grid-cols-1', 2: 'grid-cols-1 sm:grid-cols-2', 3: 'grid-cols-1 sm:grid-cols-3' }[cols]
|
||||
return (
|
||||
<section className="bg-card border border-border rounded-lg p-6 space-y-4">
|
||||
<div className={`grid ${colClass} gap-4`}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BentoCard({
|
||||
title,
|
||||
children,
|
||||
span,
|
||||
}: {
|
||||
title?: string
|
||||
children: React.ReactNode
|
||||
span?: 'full'
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={`bg-card border border-border rounded-xl p-5 space-y-4${span === 'full' ? ' sm:col-span-2' : ''}`}
|
||||
>
|
||||
{title && (
|
||||
<h2 className="text-base font-semibold text-foreground">{title}</h2>
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Step content panels ──────────────────────────────────────────────────────
|
||||
|
||||
function StepGeneral({
|
||||
form, errors, set,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Müşderi">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Ulanyjy"
|
||||
value={form.client_id}
|
||||
onChange={(v) => set('client_id', v)}
|
||||
options={[]}
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.client_id}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Status">
|
||||
<FormInput
|
||||
type="select"
|
||||
label="Status"
|
||||
value={form.status}
|
||||
onChange={(v) => set('status', v)}
|
||||
options={STATUS_OPTIONS}
|
||||
error={errors.status}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Kart görnüşi" span="full">
|
||||
<FormInput
|
||||
type="select"
|
||||
label="Ýüztumanyň görnüşi"
|
||||
value={form.currency_type}
|
||||
onChange={(v) => set('currency_type', v)}
|
||||
options={CURRENCY_OPTIONS}
|
||||
error={errors.currency_type}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Bellik" span="full">
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label="Bellik"
|
||||
value={form.note}
|
||||
onChange={(v) => set('note', v)}
|
||||
placeholder="Bellik..."
|
||||
rows={2}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
function StepLocation({
|
||||
form, errors, set,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Welaýat">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Welaýat"
|
||||
value={form.province}
|
||||
onChange={(v) => { set('province', v); set('branch', '') }}
|
||||
options={PROVINCE_OPTIONS}
|
||||
error={errors.province}
|
||||
required
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Welaýaty saýlasaňyz şahamçalar güncellenar.
|
||||
</p>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Şahamça">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label="Şahamça"
|
||||
value={form.branch}
|
||||
onChange={(v) => set('branch', v)}
|
||||
options={[]} // filtered by province
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.branch}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
function StepPersonal({
|
||||
form, errors, set,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="At-familýa">
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasportdaky familýa"
|
||||
value={form.passport_last_name}
|
||||
onChange={(v) => set('passport_last_name', v)}
|
||||
placeholder="NURYYEW"
|
||||
error={errors.passport_last_name}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasportdaky ady"
|
||||
value={form.passport_first_name}
|
||||
onChange={(v) => set('passport_first_name', v)}
|
||||
placeholder="HAÝDAR"
|
||||
error={errors.passport_first_name}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Kontakt">
|
||||
<FormInput
|
||||
type="phone"
|
||||
label="Telefon"
|
||||
value={form.phone}
|
||||
onChange={(v) => set('phone', v)}
|
||||
error={errors.phone}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="email"
|
||||
label="E-poçta"
|
||||
value={form.email}
|
||||
onChange={(v) => set('email', v)}
|
||||
placeholder="email@example.com"
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Häzirki ýaşyş ýeri" span="full">
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Häzirki ýaşyş ýeri"
|
||||
value={form.home_address}
|
||||
onChange={(v) => set('home_address', v)}
|
||||
placeholder="Köçe, jaý belgisi..."
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
function StepPayment({
|
||||
form, errors, set,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Pasport maglumatlary">
|
||||
<FormInput
|
||||
type="select"
|
||||
label="Pasport seriýasy"
|
||||
value={form.passport_series}
|
||||
onChange={(v) => set('passport_series', v)}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
error={errors.passport_series}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Pasport nomeri"
|
||||
value={form.passport_number}
|
||||
onChange={(v) => set('passport_number', v)}
|
||||
placeholder="A123456"
|
||||
error={errors.passport_number}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Töleýji">
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Ady Familiýasy Atasynyň ady"
|
||||
value={form.payer_full_name}
|
||||
onChange={(v) => set('payer_full_name', v)}
|
||||
placeholder="Doly ady..."
|
||||
error={errors.payer_full_name}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label="Goşun hasaby"
|
||||
value={form.payer_account_number}
|
||||
onChange={(v) => set('payer_account_number', v)}
|
||||
placeholder="1234 5678 ..."
|
||||
error={errors.payer_account_number}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Kabul edijiniň maglumatlary" span="full">
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label="Töleg kabul edijiniň maglumatlary"
|
||||
value={form.receiver_info}
|
||||
onChange={(v) => set('receiver_info', v)}
|
||||
placeholder="Kabul ediji bank, hasap, Swift..."
|
||||
rows={3}
|
||||
error={errors.receiver_info}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
function StepDocs({
|
||||
form, set,
|
||||
}: {
|
||||
form: FormState
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
}) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title="Kabul ediji talyp — 9 resminama">
|
||||
<div className="space-y-3">
|
||||
{KABUL_DOCS.map(({ key, label }) => (
|
||||
<FormInput
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title="Upgradyý — 6 resminama">
|
||||
<div className="space-y-3">
|
||||
{UPGRAD_DOCS.map(({ key, label }) => (
|
||||
<FormInput
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Component ────────────────────────────────────────────────────────────────
|
||||
|
||||
export function IntlPaymentForm({ mode, initialData, onSubmit, isSubmitting }: IntlPaymentFormProps) {
|
||||
export function IntlPaymentForm({
|
||||
mode,
|
||||
initialData,
|
||||
onSubmit,
|
||||
isSubmitting,
|
||||
}: IntlPaymentFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [form, setForm] = useState<FormState>(defaultState)
|
||||
const [errors, setErrors] = useState<FormErrors>({})
|
||||
const [currentStep, setCurrentStep] = useState(0)
|
||||
const [stepStatuses, setStepStatuses] = useState<StepStatus[]>(
|
||||
STEPS.map((_, i) => (i === 0 ? 'active' : 'idle')),
|
||||
)
|
||||
|
||||
// ── Populate in edit mode ──
|
||||
useEffect(() => {
|
||||
if (mode === 'edit' && initialData) {
|
||||
setForm({
|
||||
@@ -200,18 +556,60 @@ export function IntlPaymentForm({ mode, initialData, onSubmit, isSubmitting }: I
|
||||
upd_doc_visa: null, upd_doc_acceptance_letter: null,
|
||||
upd_doc_passport_biometric: null, upd_doc_passport_old: null,
|
||||
})
|
||||
// Mark all non-doc steps done in edit mode so the user can jump freely
|
||||
setStepStatuses(STEPS.map((_, i) => (i === 0 ? 'active' : i < 4 ? 'done' : 'idle')))
|
||||
}
|
||||
}, [mode, initialData])
|
||||
|
||||
// ── Field setter ──
|
||||
const set = <K extends keyof FormState>(key: K, value: FormState[K]) => {
|
||||
setForm((prev) => ({ ...prev, [key]: value }))
|
||||
if (errors[key]) setErrors((prev) => ({ ...prev, [key]: undefined }))
|
||||
}
|
||||
|
||||
// ── Step navigation ──
|
||||
const goStep = (idx: number) => {
|
||||
if (idx < 0 || idx >= STEPS.length) return
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]
|
||||
// going forward: mark current done
|
||||
if (idx > currentStep) next[currentStep] = 'done'
|
||||
next[idx] = 'active'
|
||||
// going back: reset steps after target to idle (only those not yet done)
|
||||
if (idx < currentStep) {
|
||||
for (let i = idx + 1; i <= currentStep; i++) {
|
||||
if (next[i] !== 'done') next[i] = 'idle'
|
||||
}
|
||||
}
|
||||
return next
|
||||
})
|
||||
setErrors({})
|
||||
setCurrentStep(idx)
|
||||
}
|
||||
|
||||
const handleNext = () => {
|
||||
const stepId = STEPS[currentStep].id
|
||||
const stepErrors = validateStep(form, stepId)
|
||||
if (Object.keys(stepErrors).length > 0) {
|
||||
setErrors(stepErrors)
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]
|
||||
next[currentStep] = 'error'
|
||||
return next
|
||||
})
|
||||
return
|
||||
}
|
||||
if (currentStep === STEPS.length - 1) {
|
||||
handleSubmit()
|
||||
} else {
|
||||
goStep(currentStep + 1)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = () => {
|
||||
const errs = validate(form)
|
||||
if (Object.keys(errs).length > 0) {
|
||||
setErrors(errs)
|
||||
const allErrors = validateAll(form)
|
||||
if (Object.keys(allErrors).length > 0) {
|
||||
setErrors(allErrors)
|
||||
return
|
||||
}
|
||||
onSubmit({
|
||||
@@ -221,243 +619,59 @@ export function IntlPaymentForm({ mode, initialData, onSubmit, isSubmitting }: I
|
||||
})
|
||||
}
|
||||
|
||||
// ── StepBarCards data ──
|
||||
const stepCardItems: StepCardItem[] = STEPS.map((s, i) => ({
|
||||
id: s.id,
|
||||
title: s.title,
|
||||
subtitle: s.subtitle,
|
||||
status: stepStatuses[i],
|
||||
icon: [User, MapPin, IdCard, CreditCard, Files][i],
|
||||
}))
|
||||
|
||||
const isLastStep = currentStep === STEPS.length - 1
|
||||
|
||||
const title = mode === 'create'
|
||||
? t('intlPayment.createTitle', 'Visa/Master tölegler (talyplar üçin) dörediň')
|
||||
: t('intlPayment.editTitle', 'Visa/Master tölegler (talyplar üçin) redaktirläň')
|
||||
|
||||
const submitLabel = mode === 'create'
|
||||
? t('intlPayment.createBtn', 'Visa/Master tölegler (talyplar üçin) dörediň')
|
||||
: t('intlPayment.editBtn', 'Visa/Master tölegler (talyplar üçin) redaktirläň')
|
||||
const submitLabel = isLastStep
|
||||
? (mode === 'create'
|
||||
? t('intlPayment.createBtn', 'Dörediň')
|
||||
: t('intlPayment.editBtn', 'Redaktirläň'))
|
||||
: undefined // not used on non-last steps
|
||||
|
||||
return (
|
||||
<div className="mx-auto space-y-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">{title}</h1>
|
||||
|
||||
{/* ── Status ────────────────────────────────────────────────────────── */}
|
||||
<Section title="">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('intlPayment.client', 'Ulanyjy')}
|
||||
value={form.client_id}
|
||||
onChange={(v) => set('client_id', v)}
|
||||
options={[]} // Fetched from clients API
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.client_id}
|
||||
required
|
||||
{/* ── Step bar ────────────────────────────────────────────────────── */}
|
||||
<div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
|
||||
<StepBarCards
|
||||
steps={stepCardItems}
|
||||
onGoTo={(i) => {
|
||||
// Allow jumping only to done/active steps
|
||||
if (stepStatuses[i] !== 'idle') goStep(i)
|
||||
}}
|
||||
/>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('intlPayment.status', 'Status')}
|
||||
value={form.status}
|
||||
onChange={(v) => set('status', v)}
|
||||
options={STATUS_OPTIONS}
|
||||
error={errors.status}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label={t('intlPayment.note', 'Bellik')}
|
||||
value={form.note}
|
||||
onChange={(v) => set('note', v)}
|
||||
placeholder="Bellik"
|
||||
rows={2}
|
||||
/>
|
||||
</Section>
|
||||
</div>
|
||||
|
||||
{/* ── Ýüztumanyň görnüşi ───────────────────────────────────────────── */}
|
||||
<Section title={t('intlPayment.currencySection', 'Ýüztumanyň görnüşi')}>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t('intlPayment.currencyType', 'Ýüztumanyň görnüşi')}
|
||||
value={form.currency_type}
|
||||
onChange={(v) => set('currency_type', v)}
|
||||
options={CURRENCY_OPTIONS}
|
||||
error={errors.currency_type}
|
||||
required
|
||||
/>
|
||||
</Section>
|
||||
|
||||
{/* ── Lokasiýa ─────────────────────────────────────────────────────── */}
|
||||
<Section title={t('intlPayment.locationSection', 'Lokasiýa')}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('intlPayment.province', 'Welaýat')}
|
||||
value={form.province}
|
||||
onChange={(v) => { set('province', v); set('branch', '') }}
|
||||
options={PROVINCE_OPTIONS}
|
||||
error={errors.province}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('intlPayment.branch', 'Şahamça')}
|
||||
value={form.branch}
|
||||
onChange={(v) => set('branch', v)}
|
||||
options={[]} // Fetched from branches API filtered by province
|
||||
placeholder="Saýlamak üçin basyň"
|
||||
error={errors.branch}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* ── Şahsy maglumatlar ─────────────────────────────────────────────── */}
|
||||
<Section title={t('intlPayment.personalSection', 'Şahsy maglumatlar')}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('intlPayment.passportLastName', 'Pasportdaky familýa')}
|
||||
value={form.passport_last_name}
|
||||
onChange={(v) => set('passport_last_name', v)}
|
||||
options={[]}
|
||||
placeholder="Pasportdaky familýa"
|
||||
error={errors.passport_last_name}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('intlPayment.passportFirstName', 'Pasportdaky ady')}
|
||||
value={form.passport_first_name}
|
||||
onChange={(v) => set('passport_first_name', v)}
|
||||
placeholder="Pasportdaky ady"
|
||||
error={errors.passport_first_name}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="phone"
|
||||
label={t('intlPayment.phone', 'Telefon')}
|
||||
value={form.phone}
|
||||
onChange={(v) => set('phone', v)}
|
||||
error={errors.phone}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="email"
|
||||
label={t('intlPayment.email', 'E-poçta')}
|
||||
value={form.email}
|
||||
onChange={(v) => set('email', v)}
|
||||
placeholder="E-poçta"
|
||||
/>
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('intlPayment.homeAddress', 'Häzirki ýaşyş ýeri')}
|
||||
value={form.home_address}
|
||||
onChange={(v) => set('home_address', v)}
|
||||
placeholder="Häzirki ýaşyş ýeri"
|
||||
/>
|
||||
</Section>
|
||||
|
||||
{/* ── Töleg upgradyjynyň maglumatlary ──────────────────────────────── */}
|
||||
<Section title={t('intlPayment.payerSection', 'Töleg upgradyjynyň maglumatlary')}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
label={t('intlPayment.passportSeries', 'Pasport seriýasy')}
|
||||
value={form.passport_series}
|
||||
onChange={(v) => set('passport_series', v)}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
error={errors.passport_series}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('intlPayment.passportNumber', 'Pasport nomeri')}
|
||||
value={form.passport_number}
|
||||
onChange={(v) => set('passport_number', v)}
|
||||
placeholder="Pasport nomeri"
|
||||
error={errors.passport_number}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('intlPayment.payerFullName', 'Ady Familiýasy Atasnyň ady')}
|
||||
value={form.payer_full_name}
|
||||
onChange={(v) => set('payer_full_name', v)}
|
||||
placeholder="Ady Familiýasy Atasnyň ady"
|
||||
error={errors.payer_full_name}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t('intlPayment.payerAccount', 'Goşun hasaby')}
|
||||
value={form.payer_account_number}
|
||||
onChange={(v) => set('payer_account_number', v)}
|
||||
placeholder="Goşun hasaby"
|
||||
error={errors.payer_account_number}
|
||||
required
|
||||
/>
|
||||
</Section>
|
||||
|
||||
{/* ── Töleg kabul edijiniň maglumatlary ────────────────────────────── */}
|
||||
<Section title={t('intlPayment.receiverSection', 'Töleg kabul edijiniň maglumatlary')}>
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label={t('intlPayment.receiverInfo', 'Saňa ger')}
|
||||
value={form.receiver_info}
|
||||
onChange={(v) => set('receiver_info', v)}
|
||||
placeholder="Saňa ger"
|
||||
rows={3}
|
||||
error={errors.receiver_info}
|
||||
required
|
||||
/>
|
||||
</Section>
|
||||
|
||||
{/* ── Kabul ediji talyp boyunca resminamalar ────────────────────────── */}
|
||||
<Section title={t('intlPayment.kabulDocsSection', 'Kabul ediji talyp boyunca resminamalar')}>
|
||||
<div className="space-y-4">
|
||||
{KABUL_DOCS.map(({ key, label }) => (
|
||||
<FormInput
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* ── Upgradyý boyunca resminamalar ─────────────────────────────────── */}
|
||||
<Section title={t('intlPayment.upgradDocsSection', 'Upgradyý boyunca resminamalar')}>
|
||||
<div className="space-y-4">
|
||||
{UPGRAD_DOCS.map(({ key, label }) => (
|
||||
<FormInput
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</Section>
|
||||
{/* ── Step content ─────────────────────────────────────────────────── */}
|
||||
{STEPS[currentStep].id === 'general' && <StepGeneral form={form} errors={errors} set={set} />}
|
||||
{STEPS[currentStep].id === 'location' && <StepLocation form={form} errors={errors} set={set} />}
|
||||
{STEPS[currentStep].id === 'personal' && <StepPersonal form={form} errors={errors} set={set} />}
|
||||
{STEPS[currentStep].id === 'payment' && <StepPayment form={form} errors={errors} set={set} />}
|
||||
{STEPS[currentStep].id === 'docs' && <StepDocs form={form} set={set} />}
|
||||
|
||||
{/* ── Actions ───────────────────────────────────────────────────────── */}
|
||||
<div className="flex items-center justify-end gap-3 pb-6">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => navigate('/intl-payments/visa-master')}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isSubmitting}
|
||||
className="min-w-[240px]"
|
||||
>
|
||||
{isSubmitting ? <Spinner className="size-4" /> : submitLabel}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isSubmitting}
|
||||
onCancel={() => navigate('/intl-payments/visa-master')}
|
||||
onPrev={currentStep > 0 ? () => goStep(currentStep - 1) : undefined}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={isLastStep ? handleNext : undefined}
|
||||
submitLabel={submitLabel}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { type VisaMasterSetting } from '../api/visaMasterSberSettingsApi'
|
||||
import {
|
||||
useCreateVisaMasterSetting,
|
||||
@@ -162,29 +162,16 @@ export function VisaMasterSettingForm({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Footer */}
|
||||
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={handleCancel}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
||||
>
|
||||
{isPending
|
||||
? t('common.saving', 'Saklanýar...')
|
||||
: mode === 'create'
|
||||
? t('visaMasterSettings.actions.create', 'Visa/Master, Sber sazlamalar dörediň')
|
||||
: t('visaMasterSettings.actions.update', 'Ýatda sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={handleCancel}
|
||||
cancelVariant="ghost"
|
||||
submitLabel={mode === 'create'
|
||||
? t('visaMasterSettings.actions.create', 'Visa/Master, Sber sazlamalar dörediň')
|
||||
: t('visaMasterSettings.actions.update', 'Ýatda sakla')}
|
||||
className="px-6 py-4 border-t border-border"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
'use client'
|
||||
|
||||
import { SberPaymentForm } from '@/features/sberPayments/components/sberPaymentsForm'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user