started refactor and bento grid layout

This commit is contained in:
Jelaletdin12 committed 2026-05-14 11:28:04 +05:00
1 parent 6a85c42fde
commit ad9a93b61e
29 files changed
+4565 -3309

No files matched your search

+79
View 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
View 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
View File
@@ -1,4 +1,3 @@
'use client'
import { useEffect, useRef, type KeyboardEvent } from 'react' import { useEffect, useRef, type KeyboardEvent } from 'react'
import { Check, AlertTriangle } from 'lucide-react' import { Check, AlertTriangle } from 'lucide-react'
-1
View File
@@ -1,4 +1,3 @@
"use client"
import * as React from "react" import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority" import { cva, type VariantProps } from "class-variance-authority"
-1
View File
@@ -1,4 +1,3 @@
"use client"
import * as React from "react" import * as React from "react"
import { Tooltip as TooltipPrimitive } from "radix-ui" import { Tooltip as TooltipPrimitive } from "radix-ui"
@@ -2,10 +2,9 @@ import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox' import { Checkbox } from '@/components/ui/checkbox'
import { Label } from '@/components/ui/label' import { Label } from '@/components/ui/label'
import { Loader2 } from 'lucide-react' import { FormActions } from '@/components/formActions'
import { useCreateUser, useUpdateUser } from '../hooks/useAllUsers' import { useCreateUser, useUpdateUser } from '../hooks/useAllUsers'
import type { User, CreateUserPayload, UpdateUserPayload } from '../api/allUsersApi' import type { User, CreateUserPayload, UpdateUserPayload } from '../api/allUsersApi'
@@ -300,27 +299,14 @@ export function UserForm({ mode, initialData, userId }: UserFormProps) {
</div> </div>
</div> </div>
{/* Footer actions */} <FormActions
<div className="flex items-center justify-end gap-3"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={() => navigate(-1)}
variant="outline" submitLabel={mode === 'create'
onClick={() => navigate(-1)} ? t('users.actions.create', 'Ulanyjy dörediň')
disabled={isPending} : t('users.actions.save', 'Ýatda sakla')}
> />
{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>
</div> </div>
) )
} }
@@ -1,8 +1,8 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { FormActions } from '@/components/formActions'
import { type CardBalance } from '@/features/cardBalance/api/cardBalanceApi' import { type CardBalance } from '@/features/cardBalance/api/cardBalanceApi'
import { useCreateCardBalance, useUpdateCardBalance } from '@/features/cardBalance/hooks/useCardBalance' import { useCreateCardBalance, useUpdateCardBalance } from '@/features/cardBalance/hooks/useCardBalance'
@@ -186,19 +186,18 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
</div> </div>
</div> </div>
{/* Actions */} <FormActions
<div className="flex justify-end gap-3 mt-6"> isPending={isPending}
<Button variant="ghost" onClick={handleCancel} disabled={isPending}> onSubmit={handleSubmit}
{t('Cancel', 'Ýatyr')} onCancel={handleCancel}
</Button> cancelVariant="ghost"
<Button onClick={handleSubmit} disabled={isPending}> cancelLabel={t('Cancel', 'Ýatyr')}
{isPending loadingLabel={t('Saving...', 'Saklanýar...')}
? t('Saving...', 'Saklanýar...') submitLabel={mode === 'create'
: mode === 'create' ? t('Create card balance', 'Kart galyndysy dörediň')
? t('Create card balance', 'Kart galyndysy dörediň') : t('Save changes', 'Üýtgetmeleri sakla')}
: t('Save changes', 'Üýtgetmeleri sakla')} className="mt-6"
</Button> />
</div>
</div> </div>
) )
} }
+397 -247
View File
@@ -1,9 +1,11 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { toast } from 'sonner'
import { CreditCard, User, FileText } from 'lucide-react'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { Button } from '@/components/ui/button' import { FormActions } from '@/components/formActions'
import { Spinner } from '@/components/ui/spinner' import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
import type { CardPinItem, CardPinCreatePayload } from '@/features/cardPins/api/cardPinApi' import type { CardPinItem, CardPinCreatePayload } from '@/features/cardPins/api/cardPinApi'
// ─── Types ──────────────────────────────────────────────────────────────────── // ─── Types ────────────────────────────────────────────────────────────────────
@@ -36,6 +38,18 @@ interface FormState {
} }
type FormErrors = Partial<Record<keyof FormState, string>> 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 ──────────────────────────────────────────────────────────────── // ─── Constants ────────────────────────────────────────────────────────────────
@@ -45,7 +59,6 @@ const STATUS_OPTIONS = [
{ value: 'rejected', label: 'Ret edildi' }, { value: 'rejected', label: 'Ret edildi' },
] ]
// These would typically come from API — using static options as placeholder
const CARD_TYPE_OPTIONS = [ const CARD_TYPE_OPTIONS = [
{ value: 'altyn_asyr', label: 'Altyn Asyr' }, { value: 'altyn_asyr', label: 'Altyn Asyr' },
{ value: 'visa', label: 'Visa' }, { value: 'visa', label: 'Visa' },
@@ -53,10 +66,10 @@ const CARD_TYPE_OPTIONS = [
] ]
const PASSPORT_SERIES_OPTIONS = [ const PASSPORT_SERIES_OPTIONS = [
{ value: 'I', label: 'I' }, { value: 'I', label: 'I' },
{ value: 'II', label: 'II' }, { value: 'II', label: 'II' },
{ value: 'I-MR', label: 'I-MR' }, { value: 'I-MR', label: 'I-MR' },
{ value: 'II-MR',label: 'II-MR' }, { value: 'II-MR', label: 'II-MR' },
] ]
const PROVINCE_OPTIONS = [ const PROVINCE_OPTIONS = [
@@ -92,29 +105,57 @@ const defaultState: FormState = {
// ─── Validation ─────────────────────────────────────────────────────────────── // ─── Validation ───────────────────────────────────────────────────────────────
function validate(form: FormState, mode: 'create' | 'edit'): FormErrors { function validate(
const errors: FormErrors = {} form: FormState,
mode: 'create' | 'edit',
stepIndex?: number,
): FormErrors {
const allErrors: FormErrors = {}
if (!form.status) errors.status = 'Status hökmany' if (!form.status) allErrors.status = 'Status hökmany'
if (!form.card_type) errors.card_type = 'Kart görnüşi hökmany' if (!form.card_type) allErrors.card_type = 'Kart görnüşi hökmany'
if (!form.card_number) errors.card_number = 'Kart belgisi hökmany' if (!form.card_number) allErrors.card_number = 'Kart belgisi hökmany'
if (!form.province) errors.province = 'Welaýat hökmany' if (!form.province) allErrors.province = 'Welaýat hökmany'
if (!form.branch) errors.branch = 'Şahamça hökmany' if (!form.branch) allErrors.branch = 'Şahamça hökmany'
if (!form.first_name) errors.first_name = 'Ady hökmany' if (!form.first_name) allErrors.first_name = 'Ady hökmany'
if (!form.last_name) errors.last_name = 'Familiýasy hökmany' if (!form.last_name) allErrors.last_name = 'Familiýasy hökmany'
if (!form.birth_date) errors.birth_date = 'Doglan güni hökmany' if (!form.birth_date) allErrors.birth_date = 'Doglan güni hökmany'
if (!form.phone) errors.phone = 'Telefon hökmany' if (!form.phone) allErrors.phone = 'Telefon hökmany'
if (!form.passport_series) errors.passport_series = 'Pasport seriýasy hökmany' if (!form.passport_series) allErrors.passport_series = 'Pasport seriýasy hökmany'
if (!form.passport_number) errors.passport_number = 'Pasport belgisi hökmany' if (!form.passport_number) allErrors.passport_number = 'Pasport belgisi hökmany'
if (mode === 'create') { if (mode === 'create') {
if (!form.passport_file_1) errors.passport_file_1 = 'Pasport (sahypa 1) hökmany' if (!form.passport_file_1) allErrors.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_2) allErrors.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_3) allErrors.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_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 ──────────────────────────────────────────────────────────────── // ─── Component ────────────────────────────────────────────────────────────────
@@ -123,10 +164,11 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
const { t } = useTranslation() const { t } = useTranslation()
const navigate = useNavigate() const navigate = useNavigate()
const [form, setForm] = useState<FormState>(defaultState) const [form, setForm] = useState<FormState>(defaultState)
const [errors, setErrors] = useState<FormErrors>({}) const [errors, setErrors] = useState<FormErrors>({})
const [currentStep, setCurrentStep] = useState(0)
const [stepStatuses, setStepStatuses] = useState<StepStatus[]>(['active', 'idle', 'idle'])
// Hydrate form when editing
useEffect(() => { useEffect(() => {
if (mode === 'edit' && initialData) { if (mode === 'edit' && initialData) {
setForm({ setForm({
@@ -153,13 +195,66 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
const set = <K extends keyof FormState>(key: K, value: FormState[K]) => { const set = <K extends keyof FormState>(key: K, value: FormState[K]) => {
setForm((prev) => ({ ...prev, [key]: value })) 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 handleSubmit = () => {
const errs = validate(form, mode) const allErrors = validate(form, mode)
if (Object.keys(errs).length > 0) { if (Object.keys(allErrors).length > 0) {
setErrors(errs) 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 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' const title = mode === 'create'
? t('cardPin.create', 'Kart pin bukja dörediň') ? t('cardPin.create', 'Kart pin bukja dörediň')
: t('cardPin.edit', 'Kart pin bukja redaktirläň') : 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.createBtn', 'Kart pin bukja dörediň')
: t('cardPin.editBtn', 'Kart pin bukja redaktirläň') : t('cardPin.editBtn', 'Kart pin bukja redaktirläň')
// ── Render ─────────────────────────────────────────────────────────────────
return ( return (
<div className=" mx-auto space-y-6"> <div className="flex flex-col gap-5">
<h1 className="text-2xl font-bold text-foreground">{title}</h1> <h1 className="text-xl font-semibold text-foreground">{title}</h1>
{/* ── Status & Note ────────────────────────────────────────────────── */} {/* ── Step Bar ─────────────────────────────────────────────────────── */}
<section className="bg-card border border-border rounded-lg p-6 space-y-4"> <div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
<FormInput <StepBarCards steps={stepItems} onGoTo={goToStep} />
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>
</div> </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> </div>
) )
} }
@@ -1,8 +1,8 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox' import { Checkbox } from '@/components/ui/checkbox'
import { FormActions } from '@/components/formActions'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import type { CardReason, CreateCardReasonPayload } from '../api/cardReasonsApi' import type { CardReason, CreateCardReasonPayload } from '../api/cardReasonsApi'
import { useCreateCardReason, useUpdateCardReason } from '../hooks/useCardReasons' import { useCreateCardReason, useUpdateCardReason } from '../hooks/useCardReasons'
@@ -203,29 +203,16 @@ export function CardReasonForm({ mode, initialData, CardReasonId }: CardReasonFo
</div> </div>
</div> </div>
{/* Actions */} <FormActions
<div className="flex items-center justify-end gap-3 mt-6"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={() => navigate('/resources/card-states')}
variant="ghost" cancelVariant="ghost"
onClick={() => navigate('/resources/card-states')} submitLabel={mode === 'create'
disabled={isPending} ? t('CardReasons.actions.create', 'Kartyň çykarylmagynyň sebäbini döretdiň')
> : t('CardReasons.actions.update', 'Täzelemek')}
{t('common.cancel', 'Ýatyr')} className="mt-6"
</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>
</div> </div>
) )
} }
@@ -1,8 +1,11 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' 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 { 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 type { CardRequisite, CardRequisiteStatus, CreateCardRequisitePayload } from '../api/cardRequisitesApi'
import { useCreateCardRequisite, useUpdateCardRequisite } from '../hooks/useCardRequisites' import { useCreateCardRequisite, useUpdateCardRequisite } from '../hooks/useCardRequisites'
@@ -59,6 +62,19 @@ interface FormErrors {
passport_page32?: string 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 ──────────────────────────────────────────────────────────────── // ─── Constants ────────────────────────────────────────────────────────────────
const STATUS_OPTIONS = [ const STATUS_OPTIONS = [
@@ -143,39 +159,56 @@ function validate(
files: FileState, files: FileState,
mode: 'create' | 'edit', mode: 'create' | 'edit',
t: (k: string, fallback: string) => string, t: (k: string, fallback: string) => string,
stepIndex?: number,
): FormErrors { ): FormErrors {
const errors: FormErrors = {} const allErrors: FormErrors = {}
if (!form.status) errors.status = t('Status is required', 'Status hökmanydyr') if (!form.status) allErrors.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_type) allErrors.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_number) allErrors.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_month) allErrors.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.card_expiry_year) allErrors.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.province_id) allErrors.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.branch_id) allErrors.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.first_name) allErrors.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.last_name) allErrors.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.birth_date) allErrors.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.phone) allErrors.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_series) allErrors.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.passport_number) allErrors.passport_number = t('Passport number is required', 'Pasport belgisi hökmanydyr')
// Files only required on create
if (mode === 'create') { if (mode === 'create') {
if (!files.passport_page1) errors.passport_page1 = t('Required', 'Hökmanydyr') if (!files.passport_page1) allErrors.passport_page1 = t('Required', 'Hökmanydyr')
if (!files.passport_page2_3) errors.passport_page2_3 = t('Required', 'Hökmanydyr') if (!files.passport_page2_3) allErrors.passport_page2_3 = t('Required', 'Hökmanydyr')
if (!files.passport_page8_9) errors.passport_page8_9 = t('Required', 'Hökmanydyr') if (!files.passport_page8_9) allErrors.passport_page8_9 = t('Required', 'Hökmanydyr')
if (!files.passport_page32) errors.passport_page32 = 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 ( 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 { t } = useTranslation()
const navigate = useNavigate() const navigate = useNavigate()
const [form, setForm] = useState<FormState>(EMPTY_FORM) const [form, setForm] = useState<FormState>(EMPTY_FORM)
const [files, setFiles] = useState<FileState>(EMPTY_FILES) const [files, setFiles] = useState<FileState>(EMPTY_FILES)
const [errors, setErrors] = useState<FormErrors>({}) const [errors, setErrors] = useState<FormErrors>({})
const [currentStep, setCurrentStep] = useState(0)
const [stepStatuses, setStepStatuses] = useState<StepStatus[]>(['active', 'idle', 'idle'])
const createMutation = useCreateCardRequisite() const createMutation = useCreateCardRequisite()
const updateMutation = useUpdateCardRequisite(cardRequisiteId ?? '') const updateMutation = useUpdateCardRequisite(cardRequisiteId ?? '')
const isPending = createMutation.isPending || updateMutation.isPending const isPending = createMutation.isPending || updateMutation.isPending
useEffect(() => { useEffect(() => {
@@ -220,27 +254,79 @@ export function CardRequisiteForm({
} }
}, [mode, initialData]) }, [mode, initialData])
// ── Field setters ──────────────────────────────────────────────────────────
const setField = (field: keyof FormState) => (value: string) => { const setField = (field: keyof FormState) => (value: string) => {
setForm((prev) => { setForm((prev) => {
const next = { ...prev, [field]: value } const next = { ...prev, [field]: value }
// Reset branch when province changes
if (field === 'province_id') next.branch_id = '' if (field === 'province_id') next.branch_id = ''
return next 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) => { const setFile = (field: keyof FileState) => (file: File | null) => {
setFiles((prev) => ({ ...prev, [field]: file })) 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 handleSubmit = async () => {
const validationErrors = validate(form, files, mode, t) const allErrors = validate(form, files, mode, t)
if (Object.keys(validationErrors).length > 0) { if (Object.keys(allErrors).length > 0) {
setErrors(validationErrors) 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 return
} }
@@ -269,233 +355,316 @@ export function CardRequisiteForm({
const branchOptions = BRANCH_OPTIONS[form.province_id] ?? [] 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 ( return (
<div className="space-y-0"> <div className="flex flex-col gap-5">
{/* ── General ── */}
<div className="rounded-lg border border-border bg-card p-6"> {/* ── Step Bar ─────────────────────────────────────────────────────── */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-4"> <div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
<FormInput <StepBarCards steps={stepItems} onGoTo={goToStep} />
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> </div>
{/* ── Kart ── */} {/* ── Step 0: Kart & Lokasiýa ──────────────────────────────────────── */}
<SectionTitle>{t('Card', 'Kart')}</SectionTitle> {currentStep === 0 && (
<div className="rounded-lg border border-border bg-card p-6"> <>
<div className="grid grid-cols-2 md:grid-cols-4 gap-4"> <Section>
<FormInput <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
type="select" <div id="field-status">
label={t('Card type', 'Görnüşi')} <FormInput
value={form.card_type} type="select"
onChange={setField('card_type')} label={t('Status', 'Status')}
options={CARD_TYPE_OPTIONS} value={form.status}
placeholder="—" onChange={setField('status')}
error={errors.card_type} options={STATUS_OPTIONS}
required error={errors.status}
/> required
<FormInput />
type="text" </div>
label={t('Card number', 'Kart belgisi')} <FormInput
value={form.card_number} type="text"
onChange={setField('card_number')} label={t('Note', 'Bellik')}
placeholder={t('Card number', 'Kart belgisi')} value={form.note}
error={errors.card_number} onChange={setField('note')}
required placeholder={t('Note', 'Bellik')}
/> />
<FormInput </div>
type="select" </Section>
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>
{/* ── Lokasiýa ── */} <Section title={t('Card', 'Kart')}>
<SectionTitle>{t('Location', 'Lokasiýa')}</SectionTitle> <div className="grid grid-cols-2 md:grid-cols-4 gap-4">
<div className="rounded-lg border border-border bg-card p-6"> <div id="field-card_type">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4"> <FormInput
<FormInput type="select"
type="select" label={t('Card type', 'Görnüşi')}
label={t('Province', 'Welaýat')} value={form.card_type}
value={form.province_id} onChange={setField('card_type')}
onChange={setField('province_id')} options={CARD_TYPE_OPTIONS}
options={PROVINCE_OPTIONS} placeholder="—"
placeholder={t('Ashgabat', 'Aşgabat')} error={errors.card_type}
error={errors.province_id} required
required />
/> </div>
<FormInput <div id="field-card_number">
type="searchable-select" <FormInput
label={t('Branch', 'Şahamça')} type="text"
value={form.branch_id} label={t('Card number', 'Kart belgisi')}
onChange={setField('branch_id')} value={form.card_number}
options={branchOptions} onChange={setField('card_number')}
placeholder={t('Select', 'Saýlamak üçin basyň')} placeholder={t('Card number', 'Kart belgisi')}
error={errors.branch_id} error={errors.card_number}
disabled={!form.province_id} required
required />
/> </div>
</div> <div id="field-card_expiry_month">
</div> <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 ── */} <Section title={t('Location', 'Lokasiýa')}>
<SectionTitle>{t('Personal information', 'Şahsy maglumatlar')}</SectionTitle> <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="rounded-lg border border-border bg-card p-6"> <div id="field-province_id">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4"> <FormInput
<FormInput type="select"
type="text" label={t('Province', 'Welaýat')}
label={t('First name', 'Ady')} value={form.province_id}
value={form.first_name} onChange={setField('province_id')}
onChange={setField('first_name')} options={PROVINCE_OPTIONS}
placeholder={t('First name', 'Ady')} placeholder={t('Ashgabat', 'Aşgabat')}
error={errors.first_name} error={errors.province_id}
required required
/> />
<FormInput </div>
type="text" <div id="field-branch_id">
label={t('Last name', 'Familiýasy')} <FormInput
value={form.last_name} type="searchable-select"
onChange={setField('last_name')} label={t('Branch', 'Şahamça')}
placeholder={t('Last name', 'Familiýasy')} value={form.branch_id}
error={errors.last_name} onChange={setField('branch_id')}
required options={branchOptions}
/> placeholder={t('Select', 'Saýlamak üçin basyň')}
<FormInput error={errors.branch_id}
type="text" disabled={!form.province_id}
label={t("Father's name", 'Atasynyň ady')} required
value={form.middle_name} />
onChange={setField('middle_name')} </div>
placeholder={t("Father's name", 'Atasynyň ady')} </div>
/> </Section>
</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>
{/* ── Pasport ── */} {/* ── Step 1: Şahsy maglumatlar ─────────────────────────────────────── */}
<SectionTitle>{t('Passport', 'Pasport')}</SectionTitle> {currentStep === 1 && (
<div className="rounded-lg border border-border bg-card p-6 space-y-4"> <Section title={t('Personal information', 'Şahsy maglumatlar')}>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4"> <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<FormInput <div id="field-first_name">
type="searchable-select" <FormInput
label={t('Passport series', 'Pasport seriýasy')} type="text"
value={form.passport_series} label={t('First name', 'Ady')}
onChange={setField('passport_series')} value={form.first_name}
options={PASSPORT_SERIES_OPTIONS} onChange={setField('first_name')}
placeholder={t('Select', 'Saýlamak üçin basyň')} placeholder={t('First name', 'Ady')}
error={errors.passport_series} error={errors.first_name}
required required
/> />
<FormInput </div>
type="text" <div id="field-last_name">
label={t('Passport number', 'Pasport belgisi')} <FormInput
value={form.passport_number} type="text"
onChange={setField('passport_number')} label={t('Last name', 'Familiýasy')}
placeholder={t('Passport number', 'Pasport belgisi')} value={form.last_name}
error={errors.passport_number} onChange={setField('last_name')}
required placeholder={t('Last name', 'Familiýasy')}
/> error={errors.last_name}
</div> 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"> <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
<FormInput <div id="field-birth_date">
type="file" <FormInput
label={t('Passport (page 1)', 'Pasport (sahypa 1)')} type="date"
accept="image/*,.pdf" label={t('Birth date', 'Doglan güni')}
fileValue={files.passport_page1} value={form.birth_date}
onFileChange={setFile('passport_page1')} onChange={setField('birth_date')}
error={errors.passport_page1} error={errors.birth_date}
required={mode === 'create'} required
/> />
<FormInput </div>
type="file" <div id="field-phone">
label={t('Passport (pages 2-3)', 'Pasport (2-3-nji sahypa)')} <FormInput
accept="image/*,.pdf" type="phone"
fileValue={files.passport_page2_3} label={t('Phone', 'Telefon')}
onFileChange={setFile('passport_page2_3')} value={form.phone}
error={errors.passport_page2_3} onChange={setField('phone')}
required={mode === 'create'} placeholder="63 21 87 04"
/> error={errors.phone}
<FormInput required
type="file" />
label={t('Passport (pages 8-9)', 'Pasport (8-9 sahypa)')} </div>
accept="image/*,.pdf" </div>
fileValue={files.passport_page8_9} </Section>
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>
{/* ── Actions ── */} {/* ── Step 2: Pasport & Faýllar ─────────────────────────────────────── */}
<div className="flex justify-end gap-3 mt-6"> {currentStep === 2 && (
<Button variant="ghost" onClick={handleCancel} disabled={isPending}> <Section title={t('Passport', 'Pasport')}>
{t('Cancel', 'Ýatyr')} <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
</Button> <div id="field-passport_series">
<Button onClick={handleSubmit} disabled={isPending}> <FormInput
{isPending type="searchable-select"
? t('Saving...', 'Saklanýar...') label={t('Passport series', 'Pasport seriýasy')}
: mode === 'create' 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('Create card requisite order', 'Kart rekwiziti üçin sargyt dörediň')
: t('Save changes', 'Üýtgetmeleri sakla')} : t('Save changes', 'Üýtgetmeleri sakla')
</Button> }
</div> className="mt-6"
/>
</div> </div>
) )
} }
@@ -1,8 +1,8 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { FormActions } from '@/components/formActions'
import type { CardTransaction } from '../api/cardTransactionsApi' import type { CardTransaction } from '../api/cardTransactionsApi'
import { useCreateCardTransaction, useUpdateCardTransaction } from '../hooks/useCardTransactions' import { useCreateCardTransaction, useUpdateCardTransaction } from '../hooks/useCardTransactions'
@@ -200,19 +200,18 @@ export function CardTransactionForm({
</div> </div>
</div> </div>
{/* Actions */} <FormActions
<div className="flex justify-end gap-3 mt-6"> isPending={isPending}
<Button variant="ghost" onClick={handleCancel} disabled={isPending}> onSubmit={handleSubmit}
{t('Cancel', 'Ýatyr')} onCancel={handleCancel}
</Button> cancelVariant="ghost"
<Button onClick={handleSubmit} disabled={isPending}> cancelLabel={t('Cancel', 'Ýatyr')}
{isPending loadingLabel={t('Saving...', 'Saklanýar...')}
? t('Saving...', 'Saklanýar...') submitLabel={mode === 'create'
: mode === 'create' ? t('Create card transaction', 'Kart herekedi dörediň')
? t('Create card transaction', 'Kart herekedi dörediň') : t('Save changes', 'Üýtgetmeleri sakla')}
: t('Save changes', 'Üýtgetmeleri sakla')} className="mt-6"
</Button> />
</div>
</div> </div>
) )
} }
@@ -1,8 +1,8 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox' import { Checkbox } from '@/components/ui/checkbox'
import { FormActions } from '@/components/formActions'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import type { CardType, CreateCardTypePayload } from '../api/cardTypesApi' import type { CardType, CreateCardTypePayload } from '../api/cardTypesApi'
import { useCreateCardType, useUpdateCardType } from '../hooks/useCardTypes' import { useCreateCardType, useUpdateCardType } from '../hooks/useCardTypes'
@@ -196,29 +196,16 @@ export function CardTypeForm({ mode, initialData, cardTypeId }: CardTypeFormProp
</div> </div>
</div> </div>
{/* Actions */} <FormActions
<div className="flex items-center justify-end gap-3 mt-6"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={() => navigate('/settings/card/card-types')}
variant="ghost" cancelVariant="ghost"
onClick={() => navigate('/settings/card/card-types')} submitLabel={mode === 'create'
disabled={isPending} ? t('cardTypes.actions.create', 'Kart görnüşi döretdiň')
> : t('cardTypes.actions.update', 'Täzelemek')}
{t('common.cancel', 'Ýatyr')} className="mt-6"
</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>
</div> </div>
) )
} }
+11 -24
View File
@@ -1,8 +1,8 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox' import { Checkbox } from '@/components/ui/checkbox'
import { FormActions } from '@/components/formActions'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { useCreateClient, useUpdateClient } from '../hooks/useClients' import { useCreateClient, useUpdateClient } from '../hooks/useClients'
import type { Client, CreateClientPayload, UpdateClientPayload } from '../api/clientsApi' import type { Client, CreateClientPayload, UpdateClientPayload } from '../api/clientsApi'
@@ -227,29 +227,16 @@ export function ClientForm({ mode, initialData, clientId }: ClientFormProps) {
/> />
</div> </div>
{/* Actions */} <FormActions
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border bg-muted/20"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={() => navigate(-1)}
variant="ghost" cancelVariant="ghost"
onClick={() => navigate(-1)} submitLabel={mode === 'create'
disabled={isPending} ? t('clients.createBtn', 'Müşderi döredin')
> : t('clients.updateBtn', 'Üýtgetmeleri sakla')}
{t('common.cancel', 'Ýatyr')} className="px-6 py-4 border-t border-border bg-muted/20"
</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>
</div> </div>
) )
} }
@@ -4,7 +4,7 @@ import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { FormInput } from '@/components/formInput' 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 { CURRENCY_OPTIONS, type CurrencyCode, type CurrencyRate } from '../api/currencyRatesApi'
import { useCreateCurrencyRate, useUpdateCurrencyRate } from '../hooks/useCurrencyRates' import { useCreateCurrencyRate, useUpdateCurrencyRate } from '../hooks/useCurrencyRates'
@@ -175,29 +175,16 @@ export function CurrencyRateForm({ mode, initialData, rateId }: CurrencyRateForm
</div> </div>
</div> </div>
{/* Footer Actions */} <FormActions
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={handleCancel}
variant="ghost" cancelVariant="ghost"
onClick={handleCancel} submitLabel={mode === 'create'
disabled={isPending} ? t('currencyRates.actions.create', 'Walýuta kursy dörediň')
> : t('currencyRates.actions.update', 'Ýatda sakla')}
{t('common.cancel', 'Ýatyr')} className="px-6 py-4 border-t border-border"
</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>
</div> </div>
) )
} }
@@ -1,8 +1,8 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox' import { Checkbox } from '@/components/ui/checkbox'
import { FormActions } from '@/components/formActions'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import type { District, CreateDistrictPayload } from '../api/districtsApi' import type { District, CreateDistrictPayload } from '../api/districtsApi'
import { useCreateDistrict, useUpdateDistrict } from '../hooks/useDistricts' import { useCreateDistrict, useUpdateDistrict } from '../hooks/useDistricts'
@@ -165,28 +165,16 @@ export function DistrictForm({ mode, initialData, districtId }: DistrictFormProp
</div> </div>
</div> </div>
<div className="flex items-center justify-end gap-3 mt-6"> <FormActions
<Button isPending={isPending}
type="button" onSubmit={handleSubmit}
variant="ghost" onCancel={() => navigate('/settings/location/districts')}
onClick={() => navigate('/settings/location/districts')} cancelVariant="ghost"
disabled={isPending} submitLabel={mode === 'create'
> ? t('districts.actions.create', 'Etrap döret')
{t('common.cancel', 'Ýatyr')} : t('districts.actions.update', 'Täzelemek')}
</Button> className="mt-6"
<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>
</div> </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 { useState, useEffect, useCallback } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { Loader2 } from 'lucide-react'
import { toast } from 'sonner' import { toast } from 'sonner'
import { Button } from '@/components/ui/button'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { FormActions } from '@/components/formActions'
import { import {
useCreateLoanRemaining, useCreateLoanRemaining,
@@ -99,8 +98,8 @@ export function LoanRemainingForm({
return Object.keys(newErrors).length === 0 return Object.keys(newErrors).length === 0
} }
const handleSubmit = (e: React.FormEvent) => { const handleSubmit = (e?: React.FormEvent) => {
e.preventDefault() e?.preventDefault()
setSubmitted(true) setSubmitted(true)
if (!validate()) { if (!validate()) {
@@ -168,22 +167,14 @@ export function LoanRemainingForm({
</div> </div>
</div> </div>
<div className="flex justify-end gap-3"> <FormActions
<Button isPending={isPending}
type="button" onSubmit={handleSubmit}
variant="outline" onCancel={() => navigate('/loan-remaining')}
onClick={() => navigate('/loan-remaining')} submitLabel={mode === 'create'
disabled={isPending} ? t('common.create', 'Döret')
> : t('common.save', 'Ýatda sakla')}
{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>
</form> </form>
) )
} }
@@ -4,8 +4,8 @@ import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { Button } from '@/components/ui/button'
import { Label } from '@/components/ui/label' import { Label } from '@/components/ui/label'
import { FormActions } from '@/components/formActions'
import { Checkbox } from '@/components/ui/checkbox' import { Checkbox } from '@/components/ui/checkbox'
import { useCreateLoanType, useUpdateLoanType } from '../hooks/useLoanTypes' import { useCreateLoanType, useUpdateLoanType } from '../hooks/useLoanTypes'
import type { LoanType, CreateLoanTypePayload } from '../api/loanTypesApi' import type { LoanType, CreateLoanTypePayload } from '../api/loanTypesApi'
@@ -241,28 +241,16 @@ export function LoanTypeForm({ mode, initialData, loanTypeId }: LoanTypeFormProp
</div> </div>
</div> </div>
{/* Actions */} <FormActions
<div className="flex items-center justify-end gap-3 pt-4"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={handleCancel}
variant="ghost" cancelVariant="ghost"
onClick={handleCancel} submitLabel={mode === 'create'
disabled={isPending} ? t('loanTypes.actions.create', 'Karz görnüşi dörediň')
> : t('loanTypes.actions.save', 'Ýatda sakla')}
{t('common.cancel', 'Ýatyr')} className="pt-4"
</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>
</div> </div>
) )
} }
@@ -1,8 +1,8 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox' import { Checkbox } from '@/components/ui/checkbox'
import { FormActions } from '@/components/formActions'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { useCreateOperator, useUpdateOperator } from '../hooks/useOperators' import { useCreateOperator, useUpdateOperator } from '../hooks/useOperators'
import type { Operator, CreateOperatorPayload, UpdateOperatorPayload } from '../api/operatorsApi' import type { Operator, CreateOperatorPayload, UpdateOperatorPayload } from '../api/operatorsApi'
@@ -225,29 +225,16 @@ export function OperatorForm({ mode, initialData, operatorId }: OperatorFormProp
/> />
</div> </div>
{/* Actions */} <FormActions
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border bg-muted/20"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={() => navigate(-1)}
variant="ghost" cancelVariant="ghost"
onClick={() => navigate(-1)} submitLabel={mode === 'create'
disabled={isPending} ? t('operators.createBtn', 'Operator döredin')
> : t('operators.updateBtn', 'Üýtgetmeleri sakla')}
{t('common.cancel', 'Ýatyr')} className="px-6 py-4 border-t border-border bg-muted/20"
</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>
</div> </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 { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { Button } from '@/components/ui/button' import { FormActions } from '@/components/formActions'
import { useCreatePermission, useUpdatePermission } from '../hooks/usePermissions' import { useCreatePermission, useUpdatePermission } from '../hooks/usePermissions'
import type { Permission, PermissionPayload } from '../api/permissionsApi' import type { Permission, PermissionPayload } from '../api/permissionsApi'
@@ -175,28 +175,15 @@ export function PermissionForm({ mode, initialData, permissionId }: PermissionFo
/> />
</div> </div>
{/* Actions */} <FormActions
<div className="flex items-center justify-end gap-3 px-5 py-4 border-t border-border bg-muted/20"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={() => navigate('/settings/users/permissions')}
variant="outline" submitLabel={mode === 'create'
onClick={() => navigate('/settings/users/permissions')} ? t('permissions.actions.create', 'Rugsat dörediň')
disabled={isPending} : t('permissions.actions.save', 'Ýatda sakla')}
> className="px-5 py-4 border-t border-border bg-muted/20"
{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>
</div> </div>
) )
} }
@@ -21,7 +21,7 @@ import {
} from 'lucide-react' } from 'lucide-react'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { Button } from '@/components/ui/button' import { FormActions } from '@/components/formActions'
import { useCreateRequiredDocument, useUpdateRequiredDocument } from '../hooks/useRequiredDocuments' import { useCreateRequiredDocument, useUpdateRequiredDocument } from '../hooks/useRequiredDocuments'
import type { LoanDocument, LoanDocumentPayload, LoanDocumentTranslation } from '../api/requiredDocumentsApi' import type { LoanDocument, LoanDocumentPayload, LoanDocumentTranslation } from '../api/requiredDocumentsApi'
@@ -222,8 +222,8 @@ export function RequiredDocumentForm({ mode, initialData, requiredDocumentId }:
// ── Submit ────────────────────────────────────────────────────────────────── // ── Submit ──────────────────────────────────────────────────────────────────
const handleSubmit = async (e: React.FormEvent) => { const handleSubmit = async (e?: React.FormEvent) => {
e.preventDefault() e?.preventDefault()
if (!validate()) return if (!validate()) return
const payload: LoanDocumentPayload = { name, description } const payload: LoanDocumentPayload = { name, description }
@@ -292,20 +292,15 @@ export function RequiredDocumentForm({ mode, initialData, requiredDocumentId }:
</div> </div>
</div> </div>
{/* ── Actions ──────────────────────────────────────────────────────────── */} <FormActions
<div className="flex items-center justify-end gap-3 mt-4"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={() => navigate('/settings/loan/loan-documents')}
variant="ghost" cancelVariant="ghost"
onClick={() => navigate('/settings/loan/loan-documents')} loadingLabel={t('common.saving', 'Saklanylýar...')}
disabled={isPending} submitLabel={submitLabel}
> className="mt-4"
{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>
</form> </form>
) )
} }
+11 -23
View File
@@ -2,7 +2,7 @@ import { useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { Button } from '@/components/ui/button' import { FormActions } from '@/components/formActions'
import { useCreateRole, useUpdateRole } from '../hooks/useRoles' import { useCreateRole, useUpdateRole } from '../hooks/useRoles'
import type { Role, RolePayload } from '../api/rolesApi' import type { Role, RolePayload } from '../api/rolesApi'
@@ -176,28 +176,16 @@ export function RoleForm({ mode, initialData, roleId }: RoleFormProps) {
/> />
</div> </div>
{/* Actions */} <FormActions
<div className="flex items-center justify-end gap-3 px-5 py-4 border-t border-border bg-muted/20"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={() => navigate('/settings/users/roles')}
variant="outline" loadingLabel={t('common.saving', 'Ýüklenýär...')}
onClick={() => navigate('/settings/users/roles')} submitLabel={mode === 'create'
disabled={isPending} ? t('roles.actions.create', 'Rol dörediň')
> : t('roles.actions.save', 'Ýatda sakla')}
{t('common.cancel', 'Ýatyr')} className="px-5 py-4 border-t border-border bg-muted/20"
</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>
</div> </div>
) )
} }
@@ -1,15 +1,24 @@
'use client'
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import { toast } from 'sonner' import { toast } from 'sonner'
import { Plus } from 'lucide-react' import { User, MapPin, IdCard, CreditCard, Files } from 'lucide-react'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { Button } from '@/components/ui/button' import { FormActions } from '@/components/formActions'
import { Spinner } from '@/components/ui/spinner' import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
import { useCreateSberPayment, useUpdateSberPayment } from '@/features/sberPayments/hooks/useSberPayments' import type { StepStatus } from '@/components/stepBar'
import { WELAYATLAR, SAHAMCALAR, STATUSES, type SberPaymentOrder, type SberPaymentFormData, type PaymentStatus } from '@/features/sberPayments/api/sberPaymentsApi' import {
import { useNavigate } from 'react-router-dom' useCreateSberPayment,
useUpdateSberPayment,
} from '@/features/sberPayments/hooks/useSberPayments'
import {
WELAYATLAR,
SAHAMCALAR,
STATUSES,
type SberPaymentOrder,
type SberPaymentFormData,
type PaymentStatus,
} from '@/features/sberPayments/api/sberPaymentsApi'
// ─── Types ──────────────────────────────────────────────────────────────────── // ─── Types ────────────────────────────────────────────────────────────────────
@@ -19,376 +28,604 @@ interface SberPaymentFormProps {
orderId?: string orderId?: string
} }
// ─── Document Labels ────────────────────────────────────────────────────────── // ─── Document lists ───────────────────────────────────────────────────────────
const acceptedDocumentLabels = [ type AcceptedDocKey =
'Talyba degisli walýuta "SBERBANK" kartyň rekwizitleri', | 'acc_sberbank_card' | 'acc_enrollment' | 'acc_summons'
'Talybýň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwanamasy', | 'acc_passport_tm' | 'acc_zagran_passport' | 'acc_visa_page'
'Talybýň bildirisli göcürmesi', | 'acc_entry_stamp' | 'acc_school_letter'
'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', type SentDocKey =
'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', | 'snt_passport_tm' | 'snt_zagran_passport' | 'snt_entry_stamp'
'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', | 'snt_relation_doc' | 'snt_new_passport_series' | 'snt_old_passport_series'
'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',
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 = [ const SENT_DOCS: { key: SentDocKey; label: string }[] = [
'Ugradyjy degisli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi', { key: 'snt_passport_tm', label: 'Ugradyjynyň TM içki 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', { key: 'snt_zagran_passport', label: 'Ugradyjynyň daşary ýurt 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', { key: 'snt_entry_stamp', label: 'Ugradyjynyň daşary döwletine girenliği ştamply sahypasynyň göçürmesi' },
'Ugradyjynýň we kabul edijinin (talybýň) özara garyndaşlyk denjesini tassyklaýjy resminamalarynýň göçürmesi', { key: 'snt_relation_doc', label: 'Ugradyjy we kabul edijiniň garyndaşlyk tassyklaýjy resminamasynyn 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', { key: 'snt_new_passport_series', label: 'Ugradyjy/kabul ediji täze (2015+) pasport seriýasy maglumaty' },
'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', { 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) { // ─── FormState ────────────────────────────────────────────────────────────────
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: '',
})
interface FormState extends SberPaymentFormData {
// Validation errors client_id: string
const [errors, setErrors] = useState<Partial<Record<keyof SberPaymentFormData, string>>>({}) // file fields
acc_sberbank_card: File | null
// Populate form with initial data in edit mode acc_enrollment: File | null
useEffect(() => { acc_summons: File | null
if (mode === 'edit' && initialData) { acc_passport_tm: File | null
setFormData({ acc_zagran_passport: File | null
welayat: initialData.welayat, acc_visa_page: File | null
sahamca: initialData.sahamca, acc_entry_stamp: File | null
firstName: initialData.firstName, acc_school_letter: File | null
lastName: initialData.lastName, snt_passport_tm: File | null
phone: initialData.phone, snt_zagran_passport: File | null
email: initialData.email, snt_entry_stamp: File | null
address: initialData.address, snt_relation_doc: File | null
status: initialData.status, snt_new_passport_series: File | null
bellik: initialData.bellik, snt_old_passport_series: File | null
accountNumber: initialData.accountNumber, }
passportSeries: initialData.passportSeries,
passportNumber: initialData.passportNumber, type FormErrors = Partial<Record<keyof FormState, string>>
fullName: initialData.fullName,
}) // ─── Default state ────────────────────────────────────────────────────────────
}
}, [mode, initialData]) const defaultState: FormState = {
client_id: '',
// Get available branches based on selected welayat welayat: '',
const availableBranches = formData.welayat ? SAHAMCALAR[formData.welayat] ?? [] : [] sahamca: '',
firstName: '',
// Update field helper lastName: '',
const updateField = <K extends keyof SberPaymentFormData>( phone: '',
field: K, email: '',
value: SberPaymentFormData[K] address: '',
) => { status: 'GARASYLYYAR',
setFormData((prev) => ({ ...prev, [field]: value })) bellik: '',
if (errors[field]) { accountNumber: '',
setErrors((prev) => ({ ...prev, [field]: undefined })) passportSeries: '',
} passportNumber: '',
} fullName: '',
acc_sberbank_card: null,
// Validate form acc_enrollment: null,
const validate = (): boolean => { acc_summons: null,
const newErrors: Partial<Record<keyof SberPaymentFormData, string>> = {} acc_passport_tm: null,
acc_zagran_passport: null,
if (!formData.welayat) newErrors.welayat = 'Welayat saylanmaly' acc_visa_page: null,
if (!formData.sahamca) newErrors.sahamca = 'Sahamca saylanmaly' acc_entry_stamp: null,
if (!formData.firstName) newErrors.firstName = 'Ady girizmeli' acc_school_letter: null,
if (!formData.lastName) newErrors.lastName = 'Familiyasy girizmeli' snt_passport_tm: null,
if (!formData.phone) newErrors.phone = 'Telefon girizmeli' snt_zagran_passport: null,
if (!formData.address) newErrors.address = 'Salgy girizmeli' snt_entry_stamp: null,
if (!formData.passportSeries) newErrors.passportSeries = 'Pasport seriyasy girizmeli' snt_relation_doc: null,
if (!formData.passportNumber) newErrors.passportNumber = 'Pasport nomeri girizmeli' snt_new_passport_series: null,
if (!formData.fullName) newErrors.fullName = 'Doly ady girizmeli' snt_old_passport_series: null,
if (!formData.accountNumber) newErrors.accountNumber = 'Goyum hasaby girizmeli' }
setErrors(newErrors) // ─── Step definitions ─────────────────────────────────────────────────────────
return Object.keys(newErrors).length === 0
} type StepId = 'general' | 'location' | 'personal' | 'payment' | 'docs'
// Submit handler const STEPS: { id: StepId; title: string; subtitle: string }[] = [
const handleSubmit = async () => { { id: 'general', title: 'Esasy', subtitle: 'Status, müşderi' },
if (!validate()) { { id: 'location', title: 'Lokasiýa', subtitle: 'Welaýat, şahamça' },
toast.error('Meydanlary dolduryň') { id: 'personal', title: 'Şahsy', subtitle: 'Pasport, kontakt' },
return { id: 'payment', title: 'Töleg', subtitle: 'Hasap, ugradyjy' },
} { id: 'docs', title: 'Resminamalar', subtitle: '14 resminama' },
]
try {
if (mode === 'create') { const STEP_REQUIRED: Partial<Record<StepId, (keyof FormState)[]>> = {
await createMutation.mutateAsync(formData) general: ['status'],
toast.success('Toleg ustunlikli doredildi') location: ['welayat', 'sahamca'],
router('/sber-payments') personal: ['firstName', 'lastName', 'phone', 'address'],
} else if (orderId) { payment: ['passportSeries', 'passportNumber', 'fullName', 'accountNumber'],
await updateMutation.mutateAsync({ ...formData, id: orderId }) }
toast.success('Toleg ustunlikli tazelendi')
router(`/sber-payments/${orderId}`) const ERROR_LABELS: Partial<Record<keyof FormState, string>> = {
} status: 'Status hökmany',
} catch { welayat: 'Welaýat hökmany',
toast.error('Yalnyshlyk yuze cykdy') 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 ( return (
<div className="space-y-8 pb-8"> <div className={`grid gap-4 ${cols === 2 ? 'grid-cols-1 sm:grid-cols-2' : 'grid-cols-1'}`}>
{/* Status Section */} {children}
<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> </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 { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { import {
@@ -1,10 +1,19 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import {
User, MapPin, IdCard, CreditCard, Files,
} from 'lucide-react'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { Button } from '@/components/ui/button' import { FormActions } from '@/components/formActions'
import { Spinner } from '@/components/ui/spinner' import { StepBarCards, type StepCardItem } from '@/components//stepBarV2'
import type { IntlPaymentItem, IntlPaymentCreatePayload, IntlPaymentStatus, CurrencyType } from '../api/visaMasterPaymentsApi' import type { StepStatus } from '@/components/stepBar'
import type {
IntlPaymentItem,
IntlPaymentCreatePayload,
IntlPaymentStatus,
CurrencyType,
} from '../api/visaMasterPaymentsApi'
// ─── Types ──────────────────────────────────────────────────────────────────── // ─── Types ────────────────────────────────────────────────────────────────────
@@ -87,29 +96,69 @@ const PROVINCE_OPTIONS = [
{ value: 'balkan', label: 'Balkan' }, { value: 'balkan', label: 'Balkan' },
] ]
// Kabul ediji docs — 9 sany
const KABUL_DOCS: { key: FileKey; label: string }[] = [ const KABUL_DOCS: { key: FileKey; label: string }[] = [
{ key: 'doc_sberbank_account', label: 'Talypyň degişli welaýata "SBERBANK" kartyň rekwizitleri' }, { key: 'doc_sberbank_account', label: 'Talypyň SBERBANK kartynyň rekwizitleri' },
{ key: 'doc_school_enrollment', label: 'Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasy' }, { key: 'doc_school_enrollment', label: 'Daşary ýurt ÝOM-da okaýandygy barada güwänamasy' },
{ key: 'doc_summons', label: 'Talypyň bilendiriň göçürmesi' }, { key: 'doc_summons', label: 'Çagyrylma hatynyn 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_passport_tm', label: 'TM içki 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', label: 'Daşary ýurt 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_foreign_passport_copy', label: 'Bakýan döwlet 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_exit_permission', label: 'Çykyş-giriş rugsat bellikli sahypa 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_foreign_info', label: 'ÝOM-dan hat (okuw dilinde)' },
{ 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_school_departure_info', label: 'ÝOM-dan hat (döwlet dilinde)' },
] ]
// Upgradyý docs — 6 sany
const UPGRAD_DOCS: { key: FileKey; label: string }[] = [ 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_passport_tm', label: 'TM içki pasportynyň asyl görnüşi (upd)' },
{ key: 'upd_doc_foreign_passport', label: 'Upgradyý degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi' }, { key: 'upd_doc_foreign_passport', label: 'Daşary ýurt pasportynyň göçürmesi (upd)' },
{ 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_visa', label: 'Wiza 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_acceptance_letter', label: 'Kabul haty we beýleki resminamalar' },
{ 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_biometric', label: 'Täze (2015+) pasport seriýasy 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_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 ──────────────────────────────────────────────────────────── // ─── Default state ────────────────────────────────────────────────────────────
const defaultState: FormState = { const defaultState: FormState = {
@@ -130,48 +179,355 @@ const defaultState: FormState = {
upd_doc_passport_biometric: null, upd_doc_passport_old: null, 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 = {} const errors: FormErrors = {}
if (!form.client_id) errors.client_id = 'Ulanyjy hökmany' Object.entries(STEP_ERROR_LABELS).forEach(([key, msg]) => {
if (!form.status) errors.status = 'Status hökmany' if (!form[key as keyof FormState]) errors[key as keyof FormState] = msg
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'
return errors 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 ( 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 && ( {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} {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 ──────────────────────────────────────────────────────────────── // ─── Component ────────────────────────────────────────────────────────────────
export function IntlPaymentForm({ mode, initialData, onSubmit, isSubmitting }: IntlPaymentFormProps) { export function IntlPaymentForm({
mode,
initialData,
onSubmit,
isSubmitting,
}: IntlPaymentFormProps) {
const { t } = useTranslation() const { t } = useTranslation()
const navigate = useNavigate() const navigate = useNavigate()
const [form, setForm] = useState<FormState>(defaultState) const [form, setForm] = useState<FormState>(defaultState)
const [errors, setErrors] = useState<FormErrors>({}) 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(() => { useEffect(() => {
if (mode === 'edit' && initialData) { if (mode === 'edit' && initialData) {
setForm({ setForm({
@@ -200,18 +556,60 @@ export function IntlPaymentForm({ mode, initialData, onSubmit, isSubmitting }: I
upd_doc_visa: null, upd_doc_acceptance_letter: null, upd_doc_visa: null, upd_doc_acceptance_letter: null,
upd_doc_passport_biometric: null, upd_doc_passport_old: 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]) }, [mode, initialData])
// ── Field setter ──
const set = <K extends keyof FormState>(key: K, value: FormState[K]) => { const set = <K extends keyof FormState>(key: K, value: FormState[K]) => {
setForm((prev) => ({ ...prev, [key]: value })) setForm((prev) => ({ ...prev, [key]: value }))
if (errors[key]) setErrors((prev) => ({ ...prev, [key]: undefined })) 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 handleSubmit = () => {
const errs = validate(form) const allErrors = validateAll(form)
if (Object.keys(errs).length > 0) { if (Object.keys(allErrors).length > 0) {
setErrors(errs) setErrors(allErrors)
return return
} }
onSubmit({ 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' const title = mode === 'create'
? t('intlPayment.createTitle', 'Visa/Master tölegler (talyplar üçin) dörediň') ? t('intlPayment.createTitle', 'Visa/Master tölegler (talyplar üçin) dörediň')
: t('intlPayment.editTitle', 'Visa/Master tölegler (talyplar üçin) redaktirläň') : t('intlPayment.editTitle', 'Visa/Master tölegler (talyplar üçin) redaktirläň')
const submitLabel = mode === 'create' const submitLabel = isLastStep
? t('intlPayment.createBtn', 'Visa/Master tölegler (talyplar üçin) dörediň') ? (mode === 'create'
: t('intlPayment.editBtn', 'Visa/Master tölegler (talyplar üçin) redaktirläň') ? t('intlPayment.createBtn', 'Dörediň')
: t('intlPayment.editBtn', 'Redaktirläň'))
: undefined // not used on non-last steps
return ( return (
<div className="mx-auto space-y-6"> <div className="mx-auto space-y-6">
<h1 className="text-2xl font-bold text-foreground">{title}</h1> <h1 className="text-2xl font-bold text-foreground">{title}</h1>
{/* ── Status ────────────────────────────────────────────────────────── */} {/* ── Step bar ────────────────────────────────────────────────────── */}
<Section title=""> <div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
<FormInput <StepBarCards
type="searchable-select" steps={stepCardItems}
label={t('intlPayment.client', 'Ulanyjy')} onGoTo={(i) => {
value={form.client_id} // Allow jumping only to done/active steps
onChange={(v) => set('client_id', v)} if (stepStatuses[i] !== 'idle') goStep(i)
options={[]} // Fetched from clients API }}
placeholder="Saýlamak üçin basyň"
error={errors.client_id}
required
/> />
<FormInput </div>
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>
{/* ── Ýüztumanyň görnüşi ───────────────────────────────────────────── */} {/* ── Step content ─────────────────────────────────────────────────── */}
<Section title={t('intlPayment.currencySection', 'Ýüztumanyň görnüşi')}> {STEPS[currentStep].id === 'general' && <StepGeneral form={form} errors={errors} set={set} />}
<FormInput {STEPS[currentStep].id === 'location' && <StepLocation form={form} errors={errors} set={set} />}
type="select" {STEPS[currentStep].id === 'personal' && <StepPersonal form={form} errors={errors} set={set} />}
label={t('intlPayment.currencyType', 'Ýüztumanyň görnüşi')} {STEPS[currentStep].id === 'payment' && <StepPayment form={form} errors={errors} set={set} />}
value={form.currency_type} {STEPS[currentStep].id === 'docs' && <StepDocs form={form} set={set} />}
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>
{/* ── Actions ───────────────────────────────────────────────────────── */} {/* ── Actions ───────────────────────────────────────────────────────── */}
<div className="flex items-center justify-end gap-3 pb-6"> <FormActions
<Button isPending={isSubmitting}
type="button" onCancel={() => navigate('/intl-payments/visa-master')}
variant="outline" onPrev={currentStep > 0 ? () => goStep(currentStep - 1) : undefined}
onClick={() => navigate('/intl-payments/visa-master')} onNext={!isLastStep ? handleNext : undefined}
disabled={isSubmitting} showSubmit={isLastStep}
> onSubmit={isLastStep ? handleNext : undefined}
{t('common.cancel', 'Ýatyr')} submitLabel={submitLabel}
</Button> />
<Button
type="button"
onClick={handleSubmit}
disabled={isSubmitting}
className="min-w-[240px]"
>
{isSubmitting ? <Spinner className="size-4" /> : submitLabel}
</Button>
</div>
</div> </div>
) )
} }
@@ -4,7 +4,7 @@ import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { FormInput } from '@/components/formInput' import { FormInput } from '@/components/formInput'
import { Button } from '@/components/ui/button' import { FormActions } from '@/components/formActions'
import { type VisaMasterSetting } from '../api/visaMasterSberSettingsApi' import { type VisaMasterSetting } from '../api/visaMasterSberSettingsApi'
import { import {
useCreateVisaMasterSetting, useCreateVisaMasterSetting,
@@ -162,29 +162,16 @@ export function VisaMasterSettingForm({
/> />
</div> </div>
{/* Footer */} <FormActions
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border"> isPending={isPending}
<Button onSubmit={handleSubmit}
type="button" onCancel={handleCancel}
variant="ghost" cancelVariant="ghost"
onClick={handleCancel} submitLabel={mode === 'create'
disabled={isPending} ? t('visaMasterSettings.actions.create', 'Visa/Master, Sber sazlamalar dörediň')
> : t('visaMasterSettings.actions.update', 'Ýatda sakla')}
{t('common.cancel', 'Ýatyr')} className="px-6 py-4 border-t border-border"
</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>
</div> </div>
) )
} }
@@ -1,4 +1,3 @@
'use client'
import { SberPaymentForm } from '@/features/sberPayments/components/sberPaymentsForm' import { SberPaymentForm } from '@/features/sberPayments/components/sberPaymentsForm'