added confirm dialog, some translations
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useState, useMemo } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { toast } from 'sonner'
|
||||
import { User, MapPin, IdCard, CreditCard, Files } from 'lucide-react'
|
||||
@@ -406,6 +407,7 @@ function mapInitialData(data: SberPaymentOrder): Partial<SberPaymentFormData> {
|
||||
// ─── Main component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function SberPaymentForm({ mode, initialData, orderId }: SberPaymentFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const createMutation = useCreateSberPayment()
|
||||
const updateMutation = useUpdateSberPayment()
|
||||
@@ -481,22 +483,18 @@ export function SberPaymentForm({ mode, initialData, orderId }: SberPaymentFormP
|
||||
const handleSubmit = async () => {
|
||||
const allErrors = doValidateAll()
|
||||
if (Object.keys(allErrors).length > 0) {
|
||||
toast.error('Meýdanlary dolduryň')
|
||||
toast.error(t('common.errors.requiredFieldsMissing', 'Meýdanlary dolduryň'))
|
||||
return
|
||||
}
|
||||
try {
|
||||
const payload = buildPayload(getValues())
|
||||
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')
|
||||
const payload = buildPayload(getValues())
|
||||
if (mode === 'create') {
|
||||
await createMutation.mutateAsync(payload)
|
||||
toast.success(t('sberPayments.toast.created', 'Töleg üstünlikli döredildi'))
|
||||
navigate('/sber-payments')
|
||||
} else if (orderId) {
|
||||
await updateMutation.mutateAsync({ ...payload, id: orderId })
|
||||
toast.success(t('sberPayments.toast.updated', 'Töleg üstünlikli täzelendi'))
|
||||
navigate(`/sber-payments/${orderId}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
import { z } from 'zod'
|
||||
import i18next from 'i18next'
|
||||
import type { CreateSberPaymentPayload, PaymentStatus } from '@/features/sberPayments/api/sberPaymentsApi'
|
||||
|
||||
// ─── File helper ─────────────────────────────────────────────────────
|
||||
const t = i18next.t.bind(i18next)
|
||||
|
||||
const fileField = z.custom<File | null>((val) => val === null || val instanceof File).nullable()
|
||||
|
||||
// ─── Full form schema ─────────────────────────────────────────────────
|
||||
|
||||
export const sberPaymentFormSchema = z.object({
|
||||
// From SberPaymentFormData
|
||||
welayat: z.string().min(1, 'Welaýat hökmany'),
|
||||
sahamca: z.string().min(1, 'Şahamça hökmany'),
|
||||
firstName: z.string().min(1, 'Ady hökmany'),
|
||||
lastName: z.string().min(1, 'Familiýasy hökmany'),
|
||||
phone: z.string().min(1, 'Telefon hökmany'),
|
||||
welayat: z.string().min(1, t('validation.required', '')),
|
||||
sahamca: z.string().min(1, t('validation.required', '')),
|
||||
firstName: z.string().min(1, t('validation.required', '')),
|
||||
lastName: z.string().min(1, t('validation.required', '')),
|
||||
phone: z.string().min(1, t('validation.required', '')),
|
||||
email: z.string(),
|
||||
address: z.string().min(1, 'Salgy hökmany'),
|
||||
status: z.string().min(1, 'Status hökmany'),
|
||||
address: z.string().min(1, t('validation.required', '')),
|
||||
status: z.string().min(1, t('validation.required', '')),
|
||||
bellik: z.string(),
|
||||
accountNumber: z.string().min(1, 'Goýum hasaby hökmany'),
|
||||
passportSeries: z.string().min(1, 'Pasport seriýasy hökmany'),
|
||||
passportNumber: z.string().min(1, 'Pasport nomeri hökmany'),
|
||||
fullName: z.string().min(1, 'Doly ady hökmany'),
|
||||
// Client id
|
||||
accountNumber: z.string().min(1, t('validation.required', '')),
|
||||
passportSeries: z.string().min(1, t('validation.required', '')),
|
||||
passportNumber: z.string().min(1, t('validation.required', '')),
|
||||
fullName: z.string().min(1, t('validation.required', '')),
|
||||
client_id: z.string().optional(),
|
||||
// File fields
|
||||
acc_sberbank_card: fileField,
|
||||
acc_enrollment: fileField,
|
||||
acc_summons: fileField,
|
||||
@@ -43,8 +39,6 @@ export const sberPaymentFormSchema = z.object({
|
||||
|
||||
export type SberPaymentFormData = z.infer<typeof sberPaymentFormSchema>
|
||||
|
||||
// ─── Step schemas ─────────────────────────────────────────────────────
|
||||
|
||||
export const stepSchemas: Record<number, z.ZodType<Partial<SberPaymentFormData>>> = {
|
||||
0: sberPaymentFormSchema.pick({ status: true }),
|
||||
1: sberPaymentFormSchema.pick({ welayat: true, sahamca: true }),
|
||||
@@ -52,8 +46,6 @@ export const stepSchemas: Record<number, z.ZodType<Partial<SberPaymentFormData>>
|
||||
3: sberPaymentFormSchema.pick({ passportSeries: true, passportNumber: true, fullName: true, accountNumber: true }),
|
||||
}
|
||||
|
||||
// ─── validateStep ─────────────────────────────────────────────────────
|
||||
|
||||
export function validateStep(
|
||||
stepIndex: number,
|
||||
form: SberPaymentFormData,
|
||||
@@ -72,8 +64,6 @@ export function validateStep(
|
||||
return errors
|
||||
}
|
||||
|
||||
// ─── Default values ───────────────────────────────────────────────────
|
||||
|
||||
export const DEFAULT_FORM_VALUES: SberPaymentFormData = {
|
||||
client_id: '',
|
||||
welayat: '',
|
||||
@@ -105,8 +95,6 @@ export const DEFAULT_FORM_VALUES: SberPaymentFormData = {
|
||||
snt_old_passport_series: null,
|
||||
}
|
||||
|
||||
// ─── buildPayload ─────────────────────────────────────────────────────
|
||||
|
||||
export function buildPayload(data: SberPaymentFormData): CreateSberPaymentPayload {
|
||||
return {
|
||||
welayat: data.welayat,
|
||||
|
||||
Reference in New Issue
Block a user