rofactored edit and create pages
This commit is contained in:
@@ -12,10 +12,16 @@ const DashboardPage = lazy(() => import("@/pages/dashboard"));
|
||||
const LoanOrdersPage = lazy(() => import("@/pages/loanDepartment/loanOrders"));
|
||||
const LoanOrderMobilesPage = lazy(() => import("@/pages/loanDepartment/loanOrderMobile"));
|
||||
const LoanRemainingPage = lazy(() => import("@/pages/loanDepartment/loanRemaining"));
|
||||
|
||||
const LoanRemainingCreatePage = lazy(() => import("@/pages/loanDepartment/loanRemainingCreate"));
|
||||
const LoanRemainingViewPage = lazy(() => import("@/pages/loanDepartment/loanRemainingView"));
|
||||
const LoanRemainingEditPage = lazy(() => import("@/pages/loanDepartment/loanRemainingEdit"));
|
||||
|
||||
const LoanPaidOffLettersPage = lazy(() => import("@/pages/loanDepartment/loanPaidOffLetters"));
|
||||
const LoanPaidOffLettersCreatePage = lazy(() => import("@/pages/loanDepartment/loanPaidOffLettersCreate"));
|
||||
const LoanPaidOffLettersViewPage = lazy(() => import("@/pages/loanDepartment/loanPaidOffLettersView"));
|
||||
const LoanPaidOffLettersEditPage = lazy(() => import("@/pages/loanDepartment/loanPaidOffLettersEdit"));
|
||||
|
||||
const LoanOrderCreatePage = lazy(() => import("@/pages/loanDepartment/loanOrderCreate"));
|
||||
const LoanOrderViewPage = lazy(() => import("@/pages/loanDepartment/loanOrderView"));
|
||||
const LoanOrderMobileViewPage = lazy(() => import("@/pages/loanDepartment/loanOrderMobileView"));
|
||||
@@ -294,6 +300,30 @@ export const router = createBrowserRouter([
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/loan-paid-off-letters/create",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoanPaidOffLettersCreatePage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/loan-paid-off-letters/:id",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoanPaidOffLettersViewPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "/loan-paid-off-letters/:id/edit",
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoanPaidOffLettersEditPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
// Sidebar: /order-new-card
|
||||
path: "/order-new-card",
|
||||
|
||||
40
src/components/bento.tsx
Normal file
40
src/components/bento.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
interface BentoGridProps {
|
||||
cols?: 1 | 2 | 3 | 4
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
export function BentoGrid({ cols = 2, children }: BentoGridProps) {
|
||||
const colClass = {
|
||||
1: 'grid-cols-1',
|
||||
2: 'grid-cols-1 sm:grid-cols-2',
|
||||
3: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3',
|
||||
4: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-4',
|
||||
}[cols]
|
||||
return <div className={`grid ${colClass} gap-4`}>{children}</div>
|
||||
}
|
||||
|
||||
interface BentoCardProps {
|
||||
title?: string
|
||||
span?: 'full' | 2 | 3
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
export function BentoCard({ title, span, children }: BentoCardProps) {
|
||||
const spanClass =
|
||||
span === 'full' ? 'sm:col-span-full' :
|
||||
span === 2 ? 'sm:col-span-2' :
|
||||
span === 3 ? 'sm:col-span-3' : ''
|
||||
|
||||
return (
|
||||
<div className={`bg-card border border-border rounded-xl p-5 space-y-4 ${spanClass}`}>
|
||||
{title && (
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
15
src/components/pageError.tsx
Normal file
15
src/components/pageError.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
interface PageErrorProps {
|
||||
message?: string
|
||||
}
|
||||
|
||||
export function PageError({ message }: PageErrorProps) {
|
||||
const { t } = useTranslation()
|
||||
const text = message ?? t('common.notFound', 'Maglumat ýüklenilmedi. Sahypany täzeleläň.')
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<p className="text-sm text-destructive">{text}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
9
src/components/pageSpinner.tsx
Normal file
9
src/components/pageSpinner.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Loader2 } from 'lucide-react'
|
||||
|
||||
export function PageSpinner() {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Loader2 className="animate-spin text-muted-foreground" size={32} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -17,7 +17,6 @@ import type { AllUserFormData } from '../schemas/allUser.schema'
|
||||
interface UserFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: User
|
||||
userId?: number
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
@@ -35,16 +34,16 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
|
||||
// ─── UserForm ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export function UserForm({ mode, initialData, userId }: UserFormProps) {
|
||||
export function UserForm({ mode, initialData }: UserFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createUser = useCreateUser()
|
||||
const updateUser = useUpdateUser(userId ?? 0)
|
||||
const updateUser = useUpdateUser(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createUser.isPending || updateUser.isPending
|
||||
|
||||
@@ -103,12 +102,18 @@ export function UserForm({ mode, initialData, userId }: UserFormProps) {
|
||||
phoneVerified: data.phoneVerified,
|
||||
isActive: data.isActive,
|
||||
})
|
||||
navigate(`/users/${userId}`)
|
||||
navigate(`/users/${initialData!.id}`)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('users.createTitle', 'Ulanyjy dörediň')
|
||||
: t('users.editTitle', 'Ulanyjy üýtgetmek')}
|
||||
</h1>
|
||||
<div className="space-y-6">
|
||||
{/* Form card */}
|
||||
<div className="bg-card border border-border rounded-xl divide-y divide-border">
|
||||
|
||||
@@ -278,5 +283,6 @@ export function UserForm({ mode, initialData, userId }: UserFormProps) {
|
||||
: t('users.actions.save', 'Ýatda sakla')}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import { useTranslation } from 'react-i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { toast } from 'sonner'
|
||||
import { ChevronLeft, ChevronRight, Loader2, Building2, MapPin, Clock } from 'lucide-react'
|
||||
import { Building2, MapPin, Clock } from 'lucide-react'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
|
||||
import { useCreateBranch, useUpdateBranch } from '@/features/branches/hooks/useBranches'
|
||||
@@ -27,8 +27,6 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
return result
|
||||
}
|
||||
|
||||
type FormErrors = FlatErrors
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
|
||||
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||
@@ -93,7 +91,7 @@ interface StepContentProps {
|
||||
|
||||
function StepBasic({ form, errors, set, activeLang, setActiveLang }: StepContentProps) {
|
||||
const nameFieldKey = `name${activeLang.charAt(0).toUpperCase() + activeLang.slice(1)}` as 'nameTk' | 'nameRu' | 'nameEn'
|
||||
const nameErrorKey = nameFieldKey as keyof FormErrors
|
||||
const nameErrorKey = nameFieldKey as keyof FlatErrors
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
@@ -165,7 +163,7 @@ function StepBasic({ form, errors, set, activeLang, setActiveLang }: StepContent
|
||||
|
||||
function StepAddress({ form, errors, set, activeLang, setActiveLang }: StepContentProps) {
|
||||
const addrFieldKey = `address${activeLang.charAt(0).toUpperCase() + activeLang.slice(1)}` as 'addressTk' | 'addressRu' | 'addressEn'
|
||||
const addrErrorKey = addrFieldKey as keyof FormErrors
|
||||
const addrErrorKey = addrFieldKey as keyof FlatErrors
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
@@ -249,7 +247,6 @@ function StepHours({ form, errors, set }: StepContentProps) {
|
||||
export interface BranchFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: Branch
|
||||
branchId?: number
|
||||
}
|
||||
|
||||
function mapInitial(data: Branch): Partial<BranchFormData> {
|
||||
@@ -270,7 +267,7 @@ function mapInitial(data: Branch): Partial<BranchFormData> {
|
||||
}
|
||||
}
|
||||
|
||||
export function BranchForm({ mode, initialData, branchId }: BranchFormProps) {
|
||||
export function BranchForm({ mode, initialData }: BranchFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
@@ -381,9 +378,9 @@ export function BranchForm({ mode, initialData, branchId }: BranchFormProps) {
|
||||
|
||||
if (mode === 'create') {
|
||||
createMutation.mutate(payload, { onSuccess: () => navigate('/settings/location/branches') })
|
||||
} else if (branchId !== undefined) {
|
||||
} else if (initialData) {
|
||||
updateMutation.mutate(
|
||||
{ id: branchId, ...payload },
|
||||
{ id: initialData.id, ...payload },
|
||||
{ onSuccess: () => navigate('/settings/location/branches') },
|
||||
)
|
||||
}
|
||||
@@ -437,43 +434,18 @@ export function BranchForm({ mode, initialData, branchId }: BranchFormProps) {
|
||||
{currentStep === 2 && <StepHours {...stepProps} />}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between px-5 py-3.5 border-t border-border bg-muted/30">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={currentStep === 0 ? () => navigate(-1) : handleBack}
|
||||
disabled={isPending}
|
||||
>
|
||||
{currentStep === 0 ? (t('Cancel') || 'Ýatyr') : (
|
||||
<span className="flex items-center gap-1.5">
|
||||
<ChevronLeft className="w-3.5 h-3.5" />
|
||||
{t('Back') || 'Yza'}
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
|
||||
{isLastStep ? (
|
||||
<Button type="button" size="sm" onClick={doSubmit} disabled={isPending} className="min-w-[150px]">
|
||||
{isPending ? (
|
||||
<span className="flex items-center gap-2">
|
||||
<Loader2 className="w-3.5 h-3.5 animate-spin" />
|
||||
{t('common.saving', 'Saklanýar...')}
|
||||
</span>
|
||||
) : mode === 'create'
|
||||
? (t('branches.actions.create', 'Şahamça döret'))
|
||||
: (t('branches.actions.update', 'Täzelemek'))
|
||||
}
|
||||
</Button>
|
||||
) : (
|
||||
<Button type="button" size="sm" onClick={handleNext} disabled={isPending} className="min-w-[120px]">
|
||||
<span className="flex items-center gap-1.5">
|
||||
{t('Next') || 'Indiki'}
|
||||
<ChevronRight className="w-3.5 h-3.5" />
|
||||
</span>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onCancel={currentStep === 0 ? () => navigate(-1) : undefined}
|
||||
onPrev={currentStep > 0 ? handleBack : undefined}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={isLastStep ? doSubmit : undefined}
|
||||
submitLabel={mode === 'create'
|
||||
? t('branches.actions.create', 'Şahamça döret')
|
||||
: t('branches.actions.update', 'Täzelemek')}
|
||||
className="px-5 py-3.5 border-t border-border bg-muted/30"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -12,7 +12,6 @@ import type { CardBalanceFormData } from '@/features/cardBalance/schemas/cardBal
|
||||
interface CardBalanceFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: CardBalance
|
||||
cardBalanceId?: number
|
||||
}
|
||||
|
||||
type FlatErrors = Partial<Record<keyof CardBalanceFormData, string>>
|
||||
@@ -56,12 +55,12 @@ const YEAR_OPTIONS = Array.from({ length: 20 }, (_, i) => {
|
||||
|
||||
// ─── Component ────────────────────────────────────────────────────────────────
|
||||
|
||||
export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanceFormProps) {
|
||||
export function CardBalanceForm({ mode, initialData }: CardBalanceFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateCardBalance()
|
||||
const updateMutation = useUpdateCardBalance(cardBalanceId ?? 0)
|
||||
const updateMutation = useUpdateCardBalance(initialData?.id ?? 0)
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const {
|
||||
@@ -96,17 +95,23 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
|
||||
navigate('/card-balances')
|
||||
} else {
|
||||
await updateMutation.mutateAsync(payload)
|
||||
navigate(`/card-balances/${cardBalanceId}`)
|
||||
navigate(`/card-balances/${initialData!.id}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
if (mode === 'create') navigate('/card-balances')
|
||||
else navigate(`/card-balances/${cardBalanceId}`)
|
||||
else navigate(`/card-balances/${initialData!.id}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border border-border bg-card p-6">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('cardBalance.createTitle', 'Kart galyndysy dörediň')
|
||||
: t('cardBalance.editTitle', 'Kart galyndysy üýtgetmek')}
|
||||
</h1>
|
||||
<div className="rounded-lg border border-border bg-card p-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{/* Row 1 */}
|
||||
<FormInput
|
||||
@@ -177,5 +182,6 @@ export function CardBalanceForm({ mode, initialData, cardBalanceId }: CardBalanc
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -10,7 +10,9 @@ import type { LucideIcon } from 'lucide-react'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
|
||||
import { BentoGrid, BentoCard } from '@/components/bento'
|
||||
import type { CardPinItem, CardPinCreatePayload } from '@/features/cardPins/api/cardPinApi'
|
||||
import { useCreateCardPin, useUpdateCardPin } from '@/features/cardPins/hooks/useCardPins'
|
||||
import { validateStep, DEFAULT_FORM_VALUES } from '@/features/cardPins/schemas/cardPin.schema'
|
||||
import type { CardPinFormData } from '@/features/cardPins/schemas/cardPin.schema'
|
||||
|
||||
@@ -19,8 +21,6 @@ import type { CardPinFormData } from '@/features/cardPins/schemas/cardPin.schema
|
||||
interface CardPinFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: CardPinItem
|
||||
onSubmit: (payload: CardPinCreatePayload) => void
|
||||
isSubmitting: boolean
|
||||
}
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
@@ -108,50 +108,6 @@ const STEPS: StepDef[] = [
|
||||
},
|
||||
]
|
||||
|
||||
// ─── Bento primitives ─────────────────────────────────────────────────────────
|
||||
|
||||
function BentoGrid({
|
||||
cols = 2,
|
||||
children,
|
||||
}: {
|
||||
cols?: 1 | 2 | 3 | 4
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const colClass = {
|
||||
1: 'grid-cols-1',
|
||||
2: 'grid-cols-1 sm:grid-cols-2',
|
||||
3: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3',
|
||||
4: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-4',
|
||||
}[cols]
|
||||
return <div className={`grid ${colClass} gap-4`}>{children}</div>
|
||||
}
|
||||
|
||||
function BentoCard({
|
||||
title,
|
||||
span,
|
||||
children,
|
||||
}: {
|
||||
title?: string
|
||||
span?: 'full' | 2 | 3
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const spanClass =
|
||||
span === 'full' ? 'sm:col-span-full' :
|
||||
span === 2 ? 'sm:col-span-2' :
|
||||
span === 3 ? 'sm:col-span-3' : ''
|
||||
|
||||
return (
|
||||
<div className={`bg-card border border-border rounded-xl p-5 space-y-4 ${spanClass}`}>
|
||||
{title && (
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Shared step content props ────────────────────────────────────────────────
|
||||
|
||||
interface StepContentProps {
|
||||
@@ -399,9 +355,12 @@ function StepPassport({ form, errors, set, t, mode, initialData }: StepContentPr
|
||||
|
||||
// ─── Main Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardPinFormProps) {
|
||||
export function CardPinForm({ mode, initialData }: CardPinFormProps) {
|
||||
const { t, i18n } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const createMutation = useCreateCardPin()
|
||||
const updateMutation = useUpdateCardPin(initialData?.id ?? '')
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const {
|
||||
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError,
|
||||
@@ -508,7 +467,7 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
|
||||
return
|
||||
}
|
||||
|
||||
onSubmit({
|
||||
const payload: CardPinCreatePayload = {
|
||||
status: values.status as CardPinCreatePayload['status'],
|
||||
note: values.note ?? '',
|
||||
card_type: values.card_type,
|
||||
@@ -526,7 +485,13 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
|
||||
passport_file_2: values.passport_file_2,
|
||||
passport_file_3: values.passport_file_3,
|
||||
passport_file_4: values.passport_file_4,
|
||||
})
|
||||
}
|
||||
|
||||
if (mode === 'create') {
|
||||
createMutation.mutate(payload, { onSuccess: (data) => navigate(`/card-pins/${data.id}`) })
|
||||
} else {
|
||||
updateMutation.mutate(payload, { onSuccess: () => navigate('/card-pins') })
|
||||
}
|
||||
}
|
||||
|
||||
// ── StepBar items ──────────────────────────────────────────────────────────
|
||||
@@ -550,7 +515,17 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
|
||||
{/* Page header */}
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('cardPin.createTitle', 'Kart pin bukja dörediň')
|
||||
: t('cardPin.editTitle', 'Kart pin bukja redaktirläň')}
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{t('common.form.subtitle', 'Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Step bar */}
|
||||
<div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
|
||||
@@ -566,7 +541,7 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP
|
||||
|
||||
{/* Actions */}
|
||||
<FormActions
|
||||
isPending={isSubmitting}
|
||||
isPending={isPending}
|
||||
onCancel={currentStep === 0 ? () => navigate('/card-pins') : undefined}
|
||||
onPrev={currentStep > 0 ? handleBack : undefined}
|
||||
prevLabel={t('common.prev', 'Yza')}
|
||||
|
||||
@@ -41,7 +41,6 @@ const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||
interface CardReasonFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: CardReason
|
||||
CardReasonId?: number
|
||||
}
|
||||
|
||||
function mapInitial(data: CardReason): CardReasonFormData {
|
||||
@@ -55,11 +54,11 @@ function mapInitial(data: CardReason): CardReasonFormData {
|
||||
}
|
||||
}
|
||||
|
||||
export function CardReasonForm({ mode, initialData, CardReasonId }: CardReasonFormProps) {
|
||||
export function CardReasonForm({ mode, initialData }: CardReasonFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
@@ -104,9 +103,9 @@ export function CardReasonForm({ mode, initialData, CardReasonId }: CardReasonFo
|
||||
createMutation.mutate(payload, {
|
||||
onSuccess: () => navigate('/resources/card-states'),
|
||||
})
|
||||
} else if (CardReasonId !== undefined) {
|
||||
} else if (initialData) {
|
||||
updateMutation.mutate(
|
||||
{ id: CardReasonId, ...payload },
|
||||
{ id: initialData.id, ...payload },
|
||||
{ onSuccess: () => navigate('/resources/card-states') }
|
||||
)
|
||||
}
|
||||
@@ -119,7 +118,13 @@ export function CardReasonForm({ mode, initialData, CardReasonId }: CardReasonFo
|
||||
const nameErrorKey = nameFieldKey as keyof FormErrors
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('reasons.createTitle', 'Sebäp dörediň')
|
||||
: t('reasons.editTitle', 'Sebäp üýtgetmek')}
|
||||
</h1>
|
||||
<div>
|
||||
{/* Language tabs */}
|
||||
<div className="flex gap-3 justify-end mb-4">
|
||||
{LANG_TABS.map((tab) => (
|
||||
@@ -206,5 +211,6 @@ export function CardReasonForm({ mode, initialData, CardReasonId }: CardReasonFo
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { LucideIcon } from 'lucide-react'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
|
||||
import { BentoGrid, BentoCard } from '@/components/bento'
|
||||
import type { CardRequisite } from '../api/cardRequisitesApi'
|
||||
import { useCreateCardRequisite, useUpdateCardRequisite } from '../hooks/useCardRequisites'
|
||||
import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from '../schemas/cardRequisite.schema'
|
||||
@@ -20,7 +21,6 @@ import type { CardRequisiteFormData } from '../schemas/cardRequisite.schema'
|
||||
interface CardRequisiteFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: CardRequisite
|
||||
cardRequisiteId?: string
|
||||
}
|
||||
|
||||
type FlatErrors = Partial<Record<keyof CardRequisiteFormData, string>>
|
||||
@@ -150,50 +150,6 @@ const STEPS: StepDef[] = [
|
||||
},
|
||||
]
|
||||
|
||||
// ─── Bento primitives ─────────────────────────────────────────────────────────
|
||||
|
||||
function BentoGrid({
|
||||
cols = 2,
|
||||
children,
|
||||
}: {
|
||||
cols?: 1 | 2 | 3 | 4
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const colClass = {
|
||||
1: 'grid-cols-1',
|
||||
2: 'grid-cols-1 sm:grid-cols-2',
|
||||
3: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3',
|
||||
4: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-4',
|
||||
}[cols]
|
||||
return <div className={`grid ${colClass} gap-4`}>{children}</div>
|
||||
}
|
||||
|
||||
function BentoCard({
|
||||
title,
|
||||
span,
|
||||
children,
|
||||
}: {
|
||||
title?: string
|
||||
span?: 'full' | 2 | 3
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const spanClass =
|
||||
span === 'full' ? 'sm:col-span-full' :
|
||||
span === 2 ? 'sm:col-span-2' :
|
||||
span === 3 ? 'sm:col-span-3' : ''
|
||||
|
||||
return (
|
||||
<div className={`bg-card border border-border rounded-xl p-5 space-y-4 ${spanClass}`}>
|
||||
{title && (
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Shared step content props ────────────────────────────────────────────────
|
||||
|
||||
interface StepContentProps {
|
||||
@@ -471,16 +427,12 @@ function StepPassport({ form, errors, set, t, mode, initialData }: StepContentPr
|
||||
|
||||
// ─── Main Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function CardRequisiteForm({
|
||||
mode,
|
||||
initialData,
|
||||
cardRequisiteId,
|
||||
}: CardRequisiteFormProps) {
|
||||
export function CardRequisiteForm({ mode, initialData }: CardRequisiteFormProps) {
|
||||
const { t, i18n } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateCardRequisite()
|
||||
const updateMutation = useUpdateCardRequisite(cardRequisiteId ?? '')
|
||||
const updateMutation = useUpdateCardRequisite(initialData?.id ?? '')
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const {
|
||||
@@ -564,7 +516,7 @@ export function CardRequisiteForm({
|
||||
|
||||
const handleCancel = () => {
|
||||
if (mode === 'create') navigate('/card-requisites')
|
||||
else navigate(`/card-requisites/${cardRequisiteId}`)
|
||||
else navigate(`/card-requisites/${initialData?.id}`)
|
||||
}
|
||||
|
||||
// ── Submit ─────────────────────────────────────────────────────────────────
|
||||
@@ -597,7 +549,7 @@ export function CardRequisiteForm({
|
||||
navigate('/card-requisites')
|
||||
} else {
|
||||
await updateMutation.mutateAsync(payload)
|
||||
navigate(`/card-requisites/${cardRequisiteId}`)
|
||||
navigate(`/card-requisites/${initialData?.id}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,7 +574,17 @@ export function CardRequisiteForm({
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
|
||||
{/* Page header */}
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('Create card requisite order', 'Kart rekwiziti üçin sargyt dörediň')
|
||||
: t('Edit card requisite', 'Kart rekwizitini üýtget')}
|
||||
</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{t('common.form.subtitle', 'Ähli meýdanlary dolduryp, ädim-ädim öň geçiň.')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Step bar */}
|
||||
<div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
|
||||
|
||||
@@ -14,7 +14,6 @@ import type { CardTransactionFormData } from '../schemas/cardTransaction.schema'
|
||||
interface CardTransactionFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: CardTransaction
|
||||
cardTransactionId?: number
|
||||
}
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
@@ -55,7 +54,6 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
export function CardTransactionForm({
|
||||
mode,
|
||||
initialData,
|
||||
cardTransactionId,
|
||||
}: CardTransactionFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
@@ -72,7 +70,7 @@ export function CardTransactionForm({
|
||||
const errors = useMemo(() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>), [rhfErrors])
|
||||
|
||||
const createMutation = useCreateCardTransaction()
|
||||
const updateMutation = useUpdateCardTransaction(cardTransactionId ?? 0)
|
||||
const updateMutation = useUpdateCardTransaction(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
@@ -99,7 +97,7 @@ export function CardTransactionForm({
|
||||
navigate('/card-transactions')
|
||||
} else {
|
||||
await updateMutation.mutateAsync(buildPayload(result.data))
|
||||
navigate(`/card-transactions/${cardTransactionId}`)
|
||||
navigate(`/card-transactions/${initialData!.id}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,12 +105,18 @@ export function CardTransactionForm({
|
||||
if (mode === 'create') {
|
||||
navigate('/card-transactions')
|
||||
} else {
|
||||
navigate(`/card-transactions/${cardTransactionId}`)
|
||||
navigate(`/card-transactions/${initialData!.id}`)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border border-border bg-card p-6">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('cardTransaction.createTitle', 'Kart herekedi dörediň')
|
||||
: t('cardTransaction.editTitle', 'Kart herekedi üýtgetmek')}
|
||||
</h1>
|
||||
<div className="rounded-lg border border-border bg-card p-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{/* Passport Series */}
|
||||
<FormInput
|
||||
@@ -187,5 +191,6 @@ export function CardTransactionForm({
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import type { CardTypeFormData } from '../schemas/cardType.schema'
|
||||
export interface CardTypeFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: CardType
|
||||
cardTypeId?: number
|
||||
}
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
@@ -53,11 +52,11 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
|
||||
// ─── CardTypeForm ─────────────────────────────────────────────────────────────
|
||||
|
||||
export function CardTypeForm({ mode, initialData, cardTypeId }: CardTypeFormProps) {
|
||||
export function CardTypeForm({ mode, initialData }: CardTypeFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
@@ -114,13 +113,13 @@ export function CardTypeForm({ mode, initialData, cardTypeId }: CardTypeFormProp
|
||||
createMutation.mutate(payload, {
|
||||
onSuccess: () => navigate('/settings/card/card-types'),
|
||||
})
|
||||
} else if (cardTypeId !== undefined) {
|
||||
} else if (initialData) {
|
||||
updateMutation.mutate(
|
||||
{ id: cardTypeId, ...payload },
|
||||
{ id: initialData.id, ...payload },
|
||||
{ onSuccess: () => navigate('/settings/card/card-types') },
|
||||
)
|
||||
}
|
||||
}, [mode, cardTypeId, createMutation, updateMutation, navigate, trigger, getValues])
|
||||
}, [mode, initialData, createMutation, updateMutation, navigate, trigger, getValues])
|
||||
|
||||
const nameFieldKey = `name${activeLang.charAt(0).toUpperCase() + activeLang.slice(1)}` as
|
||||
| 'nameTk'
|
||||
@@ -129,7 +128,13 @@ export function CardTypeForm({ mode, initialData, cardTypeId }: CardTypeFormProp
|
||||
const nameErrorKey = nameFieldKey as keyof FlatErrors
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('cardTypes.createTitle', 'Kart görnüşi dörediň')
|
||||
: t('cardTypes.editTitle', 'Kart görnüşi üýtgetmek')}
|
||||
</h1>
|
||||
<div>
|
||||
{/* Language tabs */}
|
||||
<div className="flex gap-3 justify-end mb-4">
|
||||
{LANG_TABS.map((tab) => (
|
||||
@@ -215,5 +220,6 @@ export function CardTypeForm({ mode, initialData, cardTypeId }: CardTypeFormProp
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import type { Client } from '../api/clientsApi'
|
||||
interface ClientFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: Client
|
||||
clientId?: number
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
@@ -34,16 +33,16 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
|
||||
// ─── ClientForm ───────────────────────────────────────────────────────────────
|
||||
|
||||
export function ClientForm({ mode, initialData, clientId }: ClientFormProps) {
|
||||
export function ClientForm({ mode, initialData }: ClientFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateClient()
|
||||
const updateMutation = useUpdateClient(clientId ?? 0)
|
||||
const updateMutation = useUpdateClient(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
@@ -103,14 +102,20 @@ export function ClientForm({ mode, initialData, clientId }: ClientFormProps) {
|
||||
isActive: data.isActive,
|
||||
...(data.password.trim() ? { password: data.password } : {}),
|
||||
}, {
|
||||
onSuccess: () => navigate(`/clients/${clientId}`),
|
||||
onSuccess: () => navigate(`/clients/${initialData!.id}`),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ── Render ──────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('clients.createTitle', 'Müşderi dörediň')
|
||||
: t('clients.editTitle', 'Müşderi üýtgetmek')}
|
||||
</h1>
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{/* Username */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground pt-2">
|
||||
@@ -227,5 +232,6 @@ export function ClientForm({ mode, initialData, clientId }: ClientFormProps) {
|
||||
className="px-6 py-4 border-t border-border bg-muted/20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
export interface CurrencyRateFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: CurrencyRate
|
||||
rateId?: number
|
||||
}
|
||||
|
||||
type FlatErrors = Partial<Record<keyof CurrencyRateFormData, string>>
|
||||
@@ -37,16 +36,16 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
|
||||
// ─── CurrencyRateForm ─────────────────────────────────────────────────────────
|
||||
|
||||
export function CurrencyRateForm({ mode, initialData, rateId }: CurrencyRateFormProps) {
|
||||
export function CurrencyRateForm({ mode, initialData }: CurrencyRateFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateCurrencyRate()
|
||||
const updateMutation = useUpdateCurrencyRate(rateId ?? 0)
|
||||
const updateMutation = useUpdateCurrencyRate(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
@@ -103,7 +102,7 @@ export function CurrencyRateForm({ mode, initialData, rateId }: CurrencyRateForm
|
||||
navigate('/resources/currency-rates')
|
||||
} else {
|
||||
await updateMutation.mutateAsync(payload)
|
||||
navigate(`/resources/currency-rates/${rateId}`)
|
||||
navigate(`/resources/currency-rates/${initialData!.id}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,12 +110,18 @@ export function CurrencyRateForm({ mode, initialData, rateId }: CurrencyRateForm
|
||||
if (mode === 'create') {
|
||||
navigate('/resources/currency-rates')
|
||||
} else {
|
||||
navigate(`/resources/currency-rates/${rateId}`)
|
||||
navigate(`/resources/currency-rates/${initialData!.id}`)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('currencyRates.createTitle', 'Walýuta kursy dörediň')
|
||||
: t('currencyRates.editTitle', 'Walýuta kursy üýtgetmek')}
|
||||
</h1>
|
||||
<div className="space-y-6">
|
||||
{/* Currency From */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||
<label className="text-sm text-muted-foreground pt-1.5">
|
||||
@@ -188,5 +193,6 @@ export function CurrencyRateForm({ mode, initialData, rateId }: CurrencyRateForm
|
||||
className="px-6 py-4 border-t border-border"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -27,7 +27,6 @@ type FormErrors = FlatErrors
|
||||
export interface DistrictFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: District
|
||||
districtId?: number
|
||||
}
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
@@ -48,11 +47,11 @@ function mapInitial(data: District): DistrictFormData {
|
||||
}
|
||||
}
|
||||
|
||||
export function DistrictForm({ mode, initialData, districtId }: DistrictFormProps) {
|
||||
export function DistrictForm({ mode, initialData }: DistrictFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
@@ -97,9 +96,9 @@ export function DistrictForm({ mode, initialData, districtId }: DistrictFormProp
|
||||
createMutation.mutate(payload, {
|
||||
onSuccess: () => navigate('/settings/location/districts'),
|
||||
})
|
||||
} else if (districtId !== undefined) {
|
||||
} else if (initialData) {
|
||||
updateMutation.mutate(
|
||||
{ id: districtId, ...payload },
|
||||
{ id: initialData.id, ...payload },
|
||||
{ onSuccess: () => navigate('/settings/location/districts') },
|
||||
)
|
||||
}
|
||||
@@ -112,7 +111,13 @@ export function DistrictForm({ mode, initialData, districtId }: DistrictFormProp
|
||||
const nameErrorKey = nameFieldKey as keyof FormErrors
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('districts.createTitle', 'Etrap dörediň')
|
||||
: t('districts.editTitle', 'Etrap üýtgetmek')}
|
||||
</h1>
|
||||
<div>
|
||||
<div className="flex gap-3 justify-end mb-4">
|
||||
{LANG_TABS.map((tab) => (
|
||||
<button
|
||||
@@ -179,5 +184,6 @@ export function DistrictForm({ mode, initialData, districtId }: DistrictFormProp
|
||||
className="mt-6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import type { LucideIcon } from "lucide-react";
|
||||
import { FormInput } from "@/components/formInput";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
import {
|
||||
useCreateLoanOrderMobile,
|
||||
useUpdateLoanOrderMobile,
|
||||
@@ -86,50 +87,6 @@ const YEAR_OPTIONS = Array.from({ length: 15 }, (_, i) => ({
|
||||
label: String(new Date().getFullYear() + i),
|
||||
}));
|
||||
|
||||
// ─── BentoGrid / BentoCard ────────────────────────────────────────────────────
|
||||
|
||||
function BentoGrid({
|
||||
cols = 2,
|
||||
children,
|
||||
}: {
|
||||
cols?: 1 | 2 | 3 | 4;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const colClass = {
|
||||
1: "grid-cols-1",
|
||||
2: "grid-cols-1 sm:grid-cols-2",
|
||||
3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",
|
||||
4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4",
|
||||
}[cols];
|
||||
return <div className={`grid ${colClass} gap-4`}>{children}</div>;
|
||||
}
|
||||
|
||||
function BentoCard({
|
||||
title,
|
||||
span,
|
||||
children,
|
||||
}: {
|
||||
title?: string;
|
||||
span?: "full" | 2 | 3;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const spanClass =
|
||||
span === "full" ? "sm:col-span-full" :
|
||||
span === 2 ? "sm:col-span-2" :
|
||||
span === 3 ? "sm:col-span-3" : "";
|
||||
|
||||
return (
|
||||
<div className={`bg-card border border-border rounded-xl p-5 space-y-4 ${spanClass}`}>
|
||||
{title && (
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Form errors helper ──────────────────────────────────────────────────────
|
||||
|
||||
type FlatErrors = Partial<Record<keyof LoanOrderMobileFormData, string>>
|
||||
@@ -506,12 +463,11 @@ function StepFiles({
|
||||
interface LoanOrderMobileFormProps {
|
||||
mode: "create" | "edit";
|
||||
initialData?: LoanOrderMobile;
|
||||
loanOrderId?: string;
|
||||
}
|
||||
|
||||
// ─── Main Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrderMobileFormProps) {
|
||||
export function LoanOrderMobileForm({ mode, initialData }: LoanOrderMobileFormProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -623,9 +579,9 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
|
||||
if (mode === "create") {
|
||||
createMutation.mutate(payload, { onSuccess: () => navigate("/loan-order-mobiles") });
|
||||
} else {
|
||||
} else if (initialData) {
|
||||
updateMutation.mutate(
|
||||
{ id: loanOrderId!, payload },
|
||||
{ id: initialData.id, payload },
|
||||
{ onSuccess: () => navigate("/loan-order-mobiles") },
|
||||
);
|
||||
}
|
||||
@@ -689,7 +645,7 @@ export function LoanOrderMobileForm({ mode, initialData, loanOrderId }: LoanOrde
|
||||
submitLabel={
|
||||
mode === "create"
|
||||
? (t("loanOrderMobiles.createButton") || "Karz sargyt döredüň")
|
||||
: (t("loanOrders.saveButton") || "Ýatda sakla")
|
||||
: (t("loanOrderMobiles.saveButton") || "Ýatda sakla")
|
||||
}
|
||||
loadingLabel={t("Loading") || "Ýüklenilýär..."}
|
||||
cancelLabel={t("Cancel") || "Ýatyr"}
|
||||
|
||||
@@ -13,6 +13,7 @@ import type { LucideIcon } from 'lucide-react'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
|
||||
import { BentoGrid, BentoCard } from '@/components/bento'
|
||||
import { useCreateLoanOrder, useUpdateLoanOrder } from '@/features/loanOrders/hooks/useLoanOrders'
|
||||
import type { LoanOrder } from '@/features/loanOrders/api/loanOrdersApi'
|
||||
import { BRANCHES_BY_REGION } from '@/features/loanOrders/api/loanOrdersApi'
|
||||
@@ -167,50 +168,6 @@ const STEPS: StepDef[] = [
|
||||
},
|
||||
]
|
||||
|
||||
// ─── Bento primitives ─────────────────────────────────────────────────────────
|
||||
|
||||
function BentoGrid({
|
||||
cols = 2,
|
||||
children,
|
||||
}: {
|
||||
cols?: 1 | 2 | 3 | 4
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const colClass = {
|
||||
1: 'grid-cols-1',
|
||||
2: 'grid-cols-1 sm:grid-cols-2',
|
||||
3: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3',
|
||||
4: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-4',
|
||||
}[cols]
|
||||
return <div className={`grid ${colClass} gap-4`}>{children}</div>
|
||||
}
|
||||
|
||||
function BentoCard({
|
||||
title,
|
||||
span,
|
||||
children,
|
||||
}: {
|
||||
title?: string
|
||||
span?: 'full' | 2 | 3
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const spanClass =
|
||||
span === 'full' ? 'sm:col-span-full' :
|
||||
span === 2 ? 'sm:col-span-2' :
|
||||
span === 3 ? 'sm:col-span-3' : ''
|
||||
|
||||
return (
|
||||
<div className={`bg-card border border-border rounded-xl p-5 space-y-4 ${spanClass}`}>
|
||||
{title && (
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Shared step content props ────────────────────────────────────────────────
|
||||
|
||||
interface StepContentProps {
|
||||
@@ -574,12 +531,11 @@ function StepGuarantor({ form, errors, set, t }: StepContentProps) {
|
||||
interface LoanOrderFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: LoanOrder
|
||||
loanOrderId?: string
|
||||
}
|
||||
|
||||
// ─── Main Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormProps) {
|
||||
export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
|
||||
const { t, i18n } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
@@ -690,9 +646,9 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
|
||||
|
||||
if (mode === 'create') {
|
||||
createMutation.mutate(payload, { onSuccess: () => navigate('/loan-orders') })
|
||||
} else {
|
||||
} else if (initialData) {
|
||||
updateMutation.mutate(
|
||||
{ id: loanOrderId!, payload },
|
||||
{ id: initialData.id, payload },
|
||||
{ onSuccess: () => navigate('/loan-orders') },
|
||||
)
|
||||
}
|
||||
@@ -760,7 +716,7 @@ export function LoanOrderForm({ mode, initialData, loanOrderId }: LoanOrderFormP
|
||||
onSubmit={isLastStep ? doSubmit : undefined}
|
||||
submitLabel={
|
||||
mode === 'create'
|
||||
? (t('loanOrderMobiles.createButton') || 'Karz sargyt döredüň')
|
||||
? (t('loanOrders.createButton') || 'Karz sargyt döredüň')
|
||||
: (t('common.save') || 'Ýatda sakla')
|
||||
}
|
||||
loadingLabel={t('common.loading') || 'Ýüklenilýär...'}
|
||||
|
||||
@@ -10,6 +10,8 @@ export interface LoanPaidOffLetter {
|
||||
issuedAt: string;
|
||||
}
|
||||
|
||||
export type LoanPaidOffLetterPayload = Omit<LoanPaidOffLetter, "id">;
|
||||
|
||||
export interface LoanPaidOffLetterListParams {
|
||||
search?: string;
|
||||
page?: number;
|
||||
@@ -71,3 +73,38 @@ export async function deleteLoanPaidOffLetter(id: number): Promise<void> {
|
||||
}
|
||||
await apiClient.delete(`/loan-paid-off-letter-orders/${id}`);
|
||||
}
|
||||
|
||||
export async function fetchLoanPaidOffLetterById(id: number): Promise<LoanPaidOffLetter> {
|
||||
if (USE_MOCK) {
|
||||
const item = MOCK_DATA.find((r) => r.id === id);
|
||||
if (!item) throw new Error("Not found");
|
||||
return item;
|
||||
}
|
||||
const { data } = await apiClient.get<LoanPaidOffLetter>(`/loan-paid-off-letter-orders/${id}`);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function createLoanPaidOffLetter(payload: LoanPaidOffLetterPayload): Promise<LoanPaidOffLetter> {
|
||||
if (USE_MOCK) {
|
||||
const newItem: LoanPaidOffLetter = {
|
||||
id: Math.max(0, ...MOCK_DATA.map((d) => d.id)) + 1,
|
||||
...payload,
|
||||
};
|
||||
MOCK_DATA.unshift(newItem);
|
||||
return newItem;
|
||||
}
|
||||
const { data } = await apiClient.post<LoanPaidOffLetter>("/loan-paid-off-letter-orders", payload);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function updateLoanPaidOffLetter(id: number, payload: LoanPaidOffLetterPayload): Promise<LoanPaidOffLetter> {
|
||||
if (USE_MOCK) {
|
||||
const idx = MOCK_DATA.findIndex((r) => r.id === id);
|
||||
if (idx === -1) throw new Error("Not found");
|
||||
const updated = { ...MOCK_DATA[idx], ...payload };
|
||||
MOCK_DATA[idx] = updated;
|
||||
return updated;
|
||||
}
|
||||
const { data } = await apiClient.put<LoanPaidOffLetter>(`/loan-paid-off-letter-orders/${id}`, payload);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
import { useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { toast } from 'sonner'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
|
||||
import {
|
||||
useCreateLoanPaidOffLetter,
|
||||
useUpdateLoanPaidOffLetter,
|
||||
} from '../hooks/useLoanPaidOffLetters'
|
||||
import type { LoanPaidOffLetter } from '../api/loanPaidOffLettersApi'
|
||||
import {
|
||||
loanPaidOffLetterFormSchema,
|
||||
type LoanPaidOffLetterFormData,
|
||||
DEFAULT_FORM_VALUES,
|
||||
buildPayload,
|
||||
} from '../schemas/loanPaidOffLetter.schema'
|
||||
|
||||
interface LoanPaidOffLetterFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: LoanPaidOffLetter
|
||||
}
|
||||
|
||||
export function LoanPaidOffLetterForm({
|
||||
mode,
|
||||
initialData,
|
||||
}: LoanPaidOffLetterFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateLoanPaidOffLetter()
|
||||
const updateMutation = useUpdateLoanPaidOffLetter(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
watch,
|
||||
setValue,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useForm<LoanPaidOffLetterFormData>({
|
||||
resolver: zodResolver(loanPaidOffLetterFormSchema),
|
||||
defaultValues: DEFAULT_FORM_VALUES,
|
||||
mode: 'onSubmit',
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === 'edit' && initialData) {
|
||||
reset({
|
||||
passportSeries: initialData.passportSeries,
|
||||
passportNumber: initialData.passportNumber,
|
||||
loanAccount: initialData.loanAccount,
|
||||
issuedAt: initialData.issuedAt,
|
||||
})
|
||||
}
|
||||
}, [mode, initialData, reset])
|
||||
|
||||
const onSubmit = (data: LoanPaidOffLetterFormData) => {
|
||||
const payload = buildPayload(data)
|
||||
|
||||
if (mode === 'create') {
|
||||
createMutation.mutate(payload, {
|
||||
onSuccess: () => {
|
||||
toast.success(t('common.success.create', 'Üstünlikli döredildi'))
|
||||
navigate('/loan-paid-off-letters')
|
||||
},
|
||||
})
|
||||
} else {
|
||||
updateMutation.mutate(payload, {
|
||||
onSuccess: () => {
|
||||
toast.success(t('common.success.save', 'Üstünlikli ýatda saklandy'))
|
||||
navigate('/loan-paid-off-letters')
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const errMsg = (msg: string | undefined) =>
|
||||
msg?.startsWith('validation.') ? t(msg, msg) : msg
|
||||
|
||||
const onError = () => {
|
||||
toast.error(t('common.errors.fillRequired', 'Hökman doldurylmaly öýjükleri dolduryň'))
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('loanPaidOffLetters.createTitle', 'Karzyň ýapylandygy barada güwanama almak dörediň')
|
||||
: t('loanPaidOffLetters.editTitle', 'Karzyň ýapylandygy barada güwanama almak üýtgetmek')}
|
||||
</h1>
|
||||
<form onSubmit={handleSubmit(onSubmit, onError)} className="space-y-6">
|
||||
<div className="bg-card border border-border rounded-xl p-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<FormInput
|
||||
label={t('loanPaidOffLetters.columns.passportSeries', 'Pasport seriýasy')}
|
||||
required
|
||||
value={watch('passportSeries')}
|
||||
onChange={(v) => setValue('passportSeries', v)}
|
||||
placeholder={t('loanPaidOffLetters.placeholders.passportSeries', 'TM')}
|
||||
error={errMsg(errors.passportSeries?.message)}
|
||||
/>
|
||||
|
||||
<FormInput
|
||||
label={t('loanPaidOffLetters.columns.passportNumber', 'Pasport belgisi')}
|
||||
required
|
||||
value={watch('passportNumber')}
|
||||
onChange={(v) => setValue('passportNumber', v)}
|
||||
placeholder="A123456"
|
||||
error={errMsg(errors.passportNumber?.message)}
|
||||
/>
|
||||
|
||||
<FormInput
|
||||
label={t('loanPaidOffLetters.columns.loanAccount', 'Karz hasaby')}
|
||||
required
|
||||
value={watch('loanAccount')}
|
||||
onChange={(v) => setValue('loanAccount', v)}
|
||||
placeholder="LOAN-..."
|
||||
error={errMsg(errors.loanAccount?.message)}
|
||||
/>
|
||||
|
||||
<FormInput
|
||||
label={t('loanPaidOffLetters.columns.issuedAt', 'Berlen wagty')}
|
||||
required
|
||||
type="date"
|
||||
value={watch('issuedAt')}
|
||||
onChange={(v) => setValue('issuedAt', v)}
|
||||
error={errMsg(errors.issuedAt?.message)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit(onSubmit, onError)}
|
||||
onCancel={() => navigate('/loan-paid-off-letters')}
|
||||
submitLabel={mode === 'create'
|
||||
? t('common.create', 'Döret')
|
||||
: t('common.save', 'Ýatda sakla')}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -5,7 +5,11 @@ import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
fetchLoanPaidOffLetters,
|
||||
deleteLoanPaidOffLetter,
|
||||
fetchLoanPaidOffLetterById,
|
||||
createLoanPaidOffLetter,
|
||||
updateLoanPaidOffLetter,
|
||||
type LoanPaidOffLetterListParams,
|
||||
type LoanPaidOffLetterPayload,
|
||||
} from '../api/loanPaidOffLettersApi'
|
||||
|
||||
// ─── Query keys ────────────────────────────────────────────────────────────────
|
||||
@@ -15,6 +19,8 @@ export const loanPaidOffLetterKeys = {
|
||||
lists: () => [...loanPaidOffLetterKeys.all, 'list'] as const,
|
||||
list: (params: LoanPaidOffLetterListParams) =>
|
||||
[...loanPaidOffLetterKeys.lists(), params] as const,
|
||||
details: () => [...loanPaidOffLetterKeys.all, 'detail'] as const,
|
||||
detail: (id: number) => [...loanPaidOffLetterKeys.details(), id] as const,
|
||||
}
|
||||
|
||||
// ─── Hooks ─────────────────────────────────────────────────────────────────────
|
||||
@@ -37,4 +43,39 @@ export function useDeleteLoanPaidOffLetter() {
|
||||
toast.success(t('loanPaidOffLetters.deleteSuccess', 'Güwanama üstünlikli pozuldy'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useLoanPaidOffLetterById(id?: string) {
|
||||
return useQuery({
|
||||
queryKey: loanPaidOffLetterKeys.detail(Number(id)),
|
||||
queryFn: () => fetchLoanPaidOffLetterById(Number(id)),
|
||||
enabled: !!id,
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateLoanPaidOffLetter() {
|
||||
const queryClient = useQueryClient()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: LoanPaidOffLetterPayload) => createLoanPaidOffLetter(payload),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: loanPaidOffLetterKeys.lists() })
|
||||
toast.success(t('loanPaidOffLetters.createSuccess', 'Üstünlikli döredildi'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateLoanPaidOffLetter(id: number) {
|
||||
const queryClient = useQueryClient()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: LoanPaidOffLetterPayload) => updateLoanPaidOffLetter(id, payload),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: loanPaidOffLetterKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: loanPaidOffLetterKeys.detail(id) })
|
||||
toast.success(t('loanPaidOffLetters.updateSuccess', 'Üstünlikli üýtgedildi'))
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const loanPaidOffLetterFormSchema = z.object({
|
||||
passportSeries: z.string().min(1, 'validation.required'),
|
||||
passportNumber: z.string().min(1, 'validation.required'),
|
||||
loanAccount: z.string().min(1, 'validation.required'),
|
||||
issuedAt: z.string().min(1, 'validation.required'),
|
||||
})
|
||||
|
||||
export type LoanPaidOffLetterFormData = z.infer<typeof loanPaidOffLetterFormSchema>
|
||||
|
||||
export const DEFAULT_FORM_VALUES: LoanPaidOffLetterFormData = {
|
||||
passportSeries: '',
|
||||
passportNumber: '',
|
||||
loanAccount: '',
|
||||
issuedAt: '',
|
||||
}
|
||||
|
||||
export function buildPayload(
|
||||
data: LoanPaidOffLetterFormData,
|
||||
): { passportSeries: string; passportNumber: string; loanAccount: string; issuedAt: string } {
|
||||
return {
|
||||
passportSeries: data.passportSeries,
|
||||
passportNumber: data.passportNumber,
|
||||
loanAccount: data.loanAccount,
|
||||
issuedAt: data.issuedAt,
|
||||
}
|
||||
}
|
||||
@@ -23,19 +23,17 @@ import {
|
||||
interface LoanRemainingFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: LoanRemaining
|
||||
loanRemainingId?: string
|
||||
}
|
||||
|
||||
export function LoanRemainingForm({
|
||||
mode,
|
||||
initialData,
|
||||
loanRemainingId,
|
||||
}: LoanRemainingFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateLoanRemaining()
|
||||
const updateMutation = useUpdateLoanRemaining(Number(loanRemainingId) || 0)
|
||||
const updateMutation = useUpdateLoanRemaining(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
@@ -89,7 +87,13 @@ export function LoanRemainingForm({
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit, onError)} className="space-y-6">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('loanRemaining.createTitle', 'Karzyň galyndysy dörediň')
|
||||
: t('loanRemaining.editTitle', 'Karzyň galyndysy üýtgetmek')}
|
||||
</h1>
|
||||
<form onSubmit={handleSubmit(onSubmit, onError)} className="space-y-6">
|
||||
<div className="bg-card border border-border rounded-xl p-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<FormInput
|
||||
@@ -132,5 +136,6 @@ export function LoanRemainingForm({
|
||||
: t('common.save', 'Ýatda sakla')}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ type FormMode = 'create' | 'edit'
|
||||
interface LoanTypeFormProps {
|
||||
mode: FormMode
|
||||
initialData?: LoanType
|
||||
loanTypeId?: number
|
||||
}
|
||||
|
||||
type FlatErrors = Partial<Record<keyof LoanTypeFormData, string>>
|
||||
@@ -59,16 +58,16 @@ const LANG_TABS: { key: Lang; label: string }[] = [
|
||||
|
||||
// ─── LoanTypeForm ─────────────────────────────────────────────────────────────
|
||||
|
||||
export function LoanTypeForm({ mode, initialData, loanTypeId }: LoanTypeFormProps) {
|
||||
export function LoanTypeForm({ mode, initialData }: LoanTypeFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateLoanType()
|
||||
const updateMutation = useUpdateLoanType(loanTypeId ?? 0)
|
||||
const updateMutation = useUpdateLoanType(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
@@ -122,7 +121,7 @@ export function LoanTypeForm({ mode, initialData, loanTypeId }: LoanTypeFormProp
|
||||
navigate(`/resources/loan-types/${result.id}`)
|
||||
} else {
|
||||
await updateMutation.mutateAsync(payload)
|
||||
navigate(`/resources/loan-types/${loanTypeId}`)
|
||||
navigate(`/resources/loan-types/${initialData!.id}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +143,13 @@ export function LoanTypeForm({ mode, initialData, loanTypeId }: LoanTypeFormProp
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="space-y-0">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('loanTypes.createTitle', 'Karz görnüşi dörediň')
|
||||
: t('loanTypes.editTitle', 'Karz görnüşi üýtgetmek')}
|
||||
</h1>
|
||||
<div className="space-y-0">
|
||||
{/* Language tabs row */}
|
||||
<div className="flex items-center justify-end gap-1 mb-0 pb-0">
|
||||
{LANG_TABS.map((tab) => (
|
||||
@@ -254,5 +259,6 @@ export function LoanTypeForm({ mode, initialData, loanTypeId }: LoanTypeFormProp
|
||||
className="pt-4"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import type { Operator } from '../api/operatorsApi'
|
||||
interface OperatorFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: Operator
|
||||
operatorId?: number
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
@@ -34,16 +33,16 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
|
||||
// ─── OperatorForm ─────────────────────────────────────────────────────────────
|
||||
|
||||
export function OperatorForm({ mode, initialData, operatorId }: OperatorFormProps) {
|
||||
export function OperatorForm({ mode, initialData }: OperatorFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateOperator()
|
||||
const updateMutation = useUpdateOperator(operatorId ?? 0)
|
||||
const updateMutation = useUpdateOperator(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
@@ -103,14 +102,20 @@ export function OperatorForm({ mode, initialData, operatorId }: OperatorFormProp
|
||||
isActive: data.isActive,
|
||||
...(data.password.trim() ? { password: data.password } : {}),
|
||||
}, {
|
||||
onSuccess: () => navigate(`/operators/${operatorId}`),
|
||||
onSuccess: () => navigate(`/operators/${initialData!.id}`),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ── Render ──────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('operators.createTitle', 'Operator dörediň')
|
||||
: t('operators.editTitle', 'Operator üýtgetmek')}
|
||||
</h1>
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{/* Username */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground pt-2">
|
||||
@@ -228,5 +233,6 @@ export function OperatorForm({ mode, initialData, operatorId }: OperatorFormProp
|
||||
className="px-6 py-4 border-t border-border bg-muted/20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,6 @@ import type { Permission } from '../api/permissionsApi'
|
||||
interface PermissionFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: Permission
|
||||
permissionId?: number
|
||||
}
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
@@ -45,16 +44,16 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
|
||||
// ─── PermissionForm ───────────────────────────────────────────────────────────
|
||||
|
||||
export function PermissionForm({ mode, initialData, permissionId }: PermissionFormProps) {
|
||||
export function PermissionForm({ mode, initialData }: PermissionFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createPermission = useCreatePermission()
|
||||
const updatePermission = useUpdatePermission(permissionId ?? 0)
|
||||
const updatePermission = useUpdatePermission(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createPermission.isPending || updatePermission.isPending
|
||||
|
||||
@@ -127,7 +126,13 @@ export function PermissionForm({ mode, initialData, permissionId }: PermissionFo
|
||||
const nameError = errors[activeNameKey]
|
||||
|
||||
return (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('permissions.createTitle', 'Rugsat dörediň')
|
||||
: t('permissions.editTitle', 'Rugsat üýtgetmek')}
|
||||
</h1>
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
|
||||
{/* Code */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start p-5 border-b border-border">
|
||||
@@ -205,5 +210,6 @@ export function PermissionForm({ mode, initialData, permissionId }: PermissionFo
|
||||
className="px-5 py-4 border-t border-border bg-muted/20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -36,7 +36,6 @@ type Locale = 'tk' | 'ru' | 'en'
|
||||
interface RequiredDocumentFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: LoanDocument
|
||||
requiredDocumentId?: number
|
||||
}
|
||||
|
||||
// ─── Lang tabs ────────────────────────────────────────────────────────────────
|
||||
@@ -198,11 +197,11 @@ function flattenErrors(
|
||||
|
||||
// ─── RequiredDocumentForm ─────────────────────────────────────────────────────────
|
||||
|
||||
export function RequiredDocumentForm({ mode, initialData, requiredDocumentId }: RequiredDocumentFormProps) {
|
||||
export function RequiredDocumentForm({ mode, initialData }: RequiredDocumentFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
@@ -211,7 +210,7 @@ export function RequiredDocumentForm({ mode, initialData, requiredDocumentId }:
|
||||
const [descLang, setDescLang] = useState<Locale>('tk')
|
||||
|
||||
const createMutation = useCreateRequiredDocument()
|
||||
const updateMutation = useUpdateRequiredDocument(requiredDocumentId ?? 0)
|
||||
const updateMutation = useUpdateRequiredDocument(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
@@ -302,7 +301,13 @@ export function RequiredDocumentForm({ mode, initialData, requiredDocumentId }:
|
||||
: t('loanDocuments.form.update', 'Karz gerekli resminamalary täzele')
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} noValidate>
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('loanDocuments.createTitle', 'Karz gerekli resminama dörediň')
|
||||
: t('loanDocuments.editTitle', 'Karz gerekli resminama üýtgetmek')}
|
||||
</h1>
|
||||
<form onSubmit={handleSubmit} noValidate>
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
|
||||
{/* ── Name field ──────────────────────────────────────────────────── */}
|
||||
@@ -361,5 +366,6 @@ export function RequiredDocumentForm({ mode, initialData, requiredDocumentId }:
|
||||
className="mt-4"
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import type { Role } from '../api/rolesApi'
|
||||
interface RoleFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: Role
|
||||
roleId?: number
|
||||
}
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
@@ -45,16 +44,16 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
|
||||
// ─── RoleForm ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export function RoleForm({ mode, initialData, roleId }: RoleFormProps) {
|
||||
export function RoleForm({ mode, initialData }: RoleFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createRole = useCreateRole()
|
||||
const updateRole = useUpdateRole(roleId ?? 0)
|
||||
const updateRole = useUpdateRole(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createRole.isPending || updateRole.isPending
|
||||
|
||||
@@ -127,7 +126,13 @@ export function RoleForm({ mode, initialData, roleId }: RoleFormProps) {
|
||||
const nameError = activeLang === 'tk' ? errors[activeNameKey] : undefined
|
||||
|
||||
return (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('roles.createTitle', 'Rol dörediň')
|
||||
: t('roles.editTitle', 'Rol üýtgetmek')}
|
||||
</h1>
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
|
||||
{/* Code */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start p-5 border-b border-border">
|
||||
@@ -206,5 +211,6 @@ export function RoleForm({ mode, initialData, roleId }: RoleFormProps) {
|
||||
className="px-5 py-4 border-t border-border bg-muted/20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
import { useState, useMemo, useEffect, useCallback } from 'react'
|
||||
import { useState, useMemo, useCallback } 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'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
|
||||
import type { StepStatus } from '@/components/stepBar'
|
||||
import { BentoGrid, BentoCard } from '@/components/bento'
|
||||
import {
|
||||
useCreateSberPayment,
|
||||
useUpdateSberPayment,
|
||||
@@ -32,7 +33,6 @@ import {
|
||||
interface SberPaymentFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: SberPaymentOrder | null
|
||||
orderId?: string
|
||||
}
|
||||
|
||||
type FlatErrors = Partial<Record<keyof SberPaymentFormData, string>>
|
||||
@@ -79,42 +79,6 @@ const SENT_DOCS = (t: (key: string, fallback?: string) => string): { key: SentDo
|
||||
{ key: 'snt_old_passport_series', label: t('sberPayments.documents.sentOldPassportSeries', 'Ugradyjy/kabul ediji köne pasport seriýasy baradaky güwänamasy') },
|
||||
]
|
||||
|
||||
|
||||
// ─── Bento primitives ─────────────────────────────────────────────────────────
|
||||
|
||||
function BentoGrid({ cols = 2, children }: { cols?: 1 | 2; children: React.ReactNode }) {
|
||||
return (
|
||||
<div className={`grid gap-4 ${cols === 2 ? 'grid-cols-1 sm:grid-cols-2' : 'grid-cols-1'}`}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BentoCard({
|
||||
title,
|
||||
span,
|
||||
children,
|
||||
}: {
|
||||
title?: string
|
||||
span?: 'full'
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={`bg-card border border-border rounded-xl p-5 space-y-4${
|
||||
span === 'full' ? ' sm:col-span-2' : ''
|
||||
}`}
|
||||
>
|
||||
{title && (
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
|
||||
function StepGeneral({
|
||||
@@ -351,7 +315,7 @@ function StepDocs({
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
onFileChange={(f) => set(key, f as SberPaymentFormData[typeof key])}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
@@ -366,7 +330,7 @@ function StepDocs({
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
onFileChange={(f) => set(key, f as SberPaymentFormData[typeof key])}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
@@ -379,14 +343,22 @@ function StepDocs({
|
||||
|
||||
// ─── Step definitions ─────────────────────────────────────────────────────────
|
||||
|
||||
type StepId = 'general' | 'location' | 'personal' | 'payment' | 'docs'
|
||||
interface StepDef {
|
||||
id: string
|
||||
titleKey: string
|
||||
titleFallback: string
|
||||
subtitleKey: string
|
||||
subtitleFallback: string
|
||||
icon: LucideIcon
|
||||
validate: (form: SberPaymentFormData, mode: 'create' | 'edit', t: (key: string, fallback?: string) => string) => FlatErrors
|
||||
}
|
||||
|
||||
const getSteps = (t: (key: string, fallback?: string) => string): { id: StepId; title: string; subtitle: string }[] => [
|
||||
{ id: 'general', title: t('sberPayments.steps.general.title', 'Esasy'), subtitle: t('sberPayments.steps.general.subtitle', 'Status, müşderi') },
|
||||
{ id: 'location', title: t('sberPayments.steps.location.title', 'Lokasiýa'), subtitle: t('sberPayments.steps.location.subtitle', 'Welaýat, şahamça') },
|
||||
{ id: 'personal', title: t('sberPayments.steps.personal.title', 'Şahsy'), subtitle: t('sberPayments.steps.personal.subtitle', 'Pasport, kontakt') },
|
||||
{ id: 'payment', title: t('sberPayments.steps.payment.title', 'Töleg'), subtitle: t('sberPayments.steps.payment.subtitle', 'Hasap, ugradyjy') },
|
||||
{ id: 'docs', title: t('sberPayments.steps.docs.title', 'Resminamalar'), subtitle: t('sberPayments.steps.docs.subtitle', '14 resminama') },
|
||||
const STEPS: StepDef[] = [
|
||||
{ id: 'general', titleKey: 'sberPayments.steps.general.title', titleFallback: 'Esasy', subtitleKey: 'sberPayments.steps.general.subtitle', subtitleFallback: 'Status, müşderi', icon: User, validate: (f, m, t) => validateStep(0, f, m, t) },
|
||||
{ id: 'location', titleKey: 'sberPayments.steps.location.title', titleFallback: 'Lokasiýa', subtitleKey: 'sberPayments.steps.location.subtitle', subtitleFallback: 'Welaýat, şahamça', icon: MapPin, validate: (f, m, t) => validateStep(1, f, m, t) },
|
||||
{ id: 'personal', titleKey: 'sberPayments.steps.personal.title', titleFallback: 'Şahsy', subtitleKey: 'sberPayments.steps.personal.subtitle', subtitleFallback: 'Pasport, kontakt', icon: IdCard, validate: (f, m, t) => validateStep(2, f, m, t) },
|
||||
{ id: 'payment', titleKey: 'sberPayments.steps.payment.title', titleFallback: 'Töleg', subtitleKey: 'sberPayments.steps.payment.subtitle', subtitleFallback: 'Hasap, ugradyjy', icon: CreditCard, validate: (f, m, t) => validateStep(3, f, m, t) },
|
||||
{ id: 'docs', titleKey: 'sberPayments.steps.docs.title', titleFallback: 'Resminamalar', subtitleKey: 'sberPayments.steps.docs.subtitle', subtitleFallback: '14 resminama', icon: Files, validate: () => ({}) },
|
||||
]
|
||||
|
||||
// ─── Initial data mapper ──────────────────────────────────────────────────────
|
||||
@@ -411,7 +383,7 @@ function mapInitialData(data: SberPaymentOrder): Partial<SberPaymentFormData> {
|
||||
|
||||
// ─── Main component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function SberPaymentForm({ mode, initialData, orderId }: SberPaymentFormProps) {
|
||||
export function SberPaymentForm({ mode, initialData }: SberPaymentFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
@@ -420,10 +392,10 @@ export function SberPaymentForm({ mode, initialData, orderId }: SberPaymentFormP
|
||||
const navigate = useNavigate()
|
||||
const createMutation = useCreateSberPayment()
|
||||
const updateMutation = useUpdateSberPayment()
|
||||
const isLoading = createMutation.isPending || updateMutation.isPending
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const {
|
||||
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors,
|
||||
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError,
|
||||
} = useForm<SberPaymentFormData>({
|
||||
defaultValues: mode === 'edit' && initialData
|
||||
? { ...DEFAULT_FORM_VALUES, ...mapInitialData(initialData) }
|
||||
@@ -431,125 +403,124 @@ export function SberPaymentForm({ mode, initialData, orderId }: SberPaymentFormP
|
||||
})
|
||||
|
||||
const form = watch()
|
||||
const [validationErrors, setValidationErrors] = useState<FlatErrors>({})
|
||||
|
||||
const rhfFlat = useMemo(
|
||||
() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>),
|
||||
[rhfErrors],
|
||||
)
|
||||
const errors = useMemo(
|
||||
() => ({ ...rhfFlat, ...validationErrors }),
|
||||
[rhfFlat, validationErrors],
|
||||
)
|
||||
|
||||
const steps = useMemo(() => getSteps(t), [i18n.language])
|
||||
|
||||
const [currentStep, setCurrentStep] = useState(0)
|
||||
const [stepStatuses, setStepStatuses] = useState<StepStatus[]>(
|
||||
() => mode === 'edit'
|
||||
? steps.map((_, i) => (i === 0 ? 'active' : i < 4 ? 'done' : 'idle'))
|
||||
: steps.map((_, i) => (i === 0 ? 'active' : 'idle')),
|
||||
const [visited, setVisited] = useState<Set<number>>(
|
||||
() => mode === 'edit' ? new Set(STEPS.map((_, i) => i)) : new Set<number>(),
|
||||
)
|
||||
const [submittedSteps, setSubmittedSteps] = useState<Set<number>>(new Set())
|
||||
|
||||
// ── Field setter ──
|
||||
const set = <K extends keyof SberPaymentFormData>(key: K, value: SberPaymentFormData[K]) => {
|
||||
const stepsWithErrors = useMemo(() => {
|
||||
const out = new Set<number>()
|
||||
visited.forEach((i) => {
|
||||
if (Object.keys(STEPS[i].validate(form, mode, t)).length > 0) out.add(i)
|
||||
})
|
||||
return out
|
||||
}, [form, mode, visited, i18n.language, t])
|
||||
|
||||
const set = useCallback(<K extends keyof SberPaymentFormData>(key: K, value: SberPaymentFormData[K]) => {
|
||||
(setValue as (name: K, val: SberPaymentFormData[K]) => void)(key, value)
|
||||
clearErrors(key)
|
||||
setValidationErrors((prev) => {
|
||||
const next = { ...prev }
|
||||
delete next[key]
|
||||
return next
|
||||
})
|
||||
}
|
||||
}, [setValue, clearErrors])
|
||||
|
||||
// ── Step validation ──
|
||||
const doValidateAll = (): FlatErrors => {
|
||||
const errs: FlatErrors = {}
|
||||
for (let i = 0; i <= 3; i++) {
|
||||
Object.assign(errs, validateStep(i, form, mode, t))
|
||||
const allSubmittedErrors = useMemo(() => {
|
||||
const result: FlatErrors = {}
|
||||
for (const stepIdx of submittedSteps) {
|
||||
Object.assign(result, STEPS[stepIdx].validate(form, mode, t))
|
||||
}
|
||||
setValidationErrors(errs)
|
||||
return errs
|
||||
}
|
||||
return result
|
||||
}, [form, mode, submittedSteps, i18n.language, t])
|
||||
|
||||
// ── Re-validate on language change ──
|
||||
useEffect(() => {
|
||||
const hasErrors = Object.keys(validationErrors).length > 0 || Object.keys(rhfErrors).length > 0
|
||||
if (hasErrors) {
|
||||
doValidateAll()
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [i18n.language])
|
||||
const errors = useMemo(() => {
|
||||
const fromRHF = flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>)
|
||||
return { ...fromRHF, ...allSubmittedErrors }
|
||||
}, [rhfErrors, allSubmittedErrors])
|
||||
|
||||
// ── 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
|
||||
})
|
||||
clearErrors()
|
||||
setValidationErrors({})
|
||||
setCurrentStep(idx)
|
||||
}
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
|
||||
const markVisited = (i: number) =>
|
||||
setVisited((prev) => new Set([...prev, i]))
|
||||
|
||||
const markSubmitted = (i: number) =>
|
||||
setSubmittedSteps((prev) => new Set([...prev, i]))
|
||||
|
||||
const handleNext = () => {
|
||||
const stepErrors = validateStep(currentStep, form, mode, t)
|
||||
if (Object.keys(stepErrors).length > 0) {
|
||||
setValidationErrors(stepErrors)
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]; next[currentStep] = 'error'; return next
|
||||
markVisited(currentStep)
|
||||
markSubmitted(currentStep)
|
||||
const errs = STEPS[currentStep].validate(form, mode, t)
|
||||
if (Object.keys(errs).length > 0) {
|
||||
Object.entries(errs).forEach(([key, msg]) => {
|
||||
setError(key as keyof SberPaymentFormData, { type: 'manual', message: msg })
|
||||
})
|
||||
toast.error(t('common.errors.fillRequiredCorrectly', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
|
||||
return
|
||||
}
|
||||
setValidationErrors({})
|
||||
if (currentStep === steps.length - 1) {
|
||||
handleSubmit()
|
||||
} else {
|
||||
goStep(currentStep + 1)
|
||||
if (currentStep < STEPS.length - 1) {
|
||||
setCurrentStep(currentStep + 1)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
}
|
||||
|
||||
// ── Submit ──
|
||||
const handleSubmit = async () => {
|
||||
const allErrors = doValidateAll()
|
||||
const handleBack = () => {
|
||||
if (currentStep > 0) {
|
||||
markVisited(currentStep)
|
||||
setCurrentStep(currentStep - 1)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
}
|
||||
|
||||
const handleGoTo = (i: number) => {
|
||||
markVisited(currentStep)
|
||||
setCurrentStep(i)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
// ── Submit ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const doSubmit = () => {
|
||||
setVisited(new Set(STEPS.map((_, i) => i)))
|
||||
setSubmittedSteps(new Set(STEPS.map((_, i) => i)))
|
||||
|
||||
const allErrors: FlatErrors = {}
|
||||
for (const step of STEPS) Object.assign(allErrors, step.validate(form, mode, t))
|
||||
|
||||
if (Object.keys(allErrors).length > 0) {
|
||||
toast.error(t('common.errors.requiredFieldsMissing', 'Meýdanlary dolduryň'))
|
||||
Object.entries(allErrors).forEach(([key, msg]) => {
|
||||
setError(key as keyof SberPaymentFormData, { type: 'manual', message: msg })
|
||||
})
|
||||
toast.error(t('common.errors.requiredFieldsMissing', 'Käbir hökmany meýdanlar doldurylan däldir.'))
|
||||
for (let i = 0; i < STEPS.length; i++) {
|
||||
if (Object.keys(STEPS[i].validate(form, mode, t)).length > 0) {
|
||||
setCurrentStep(i); break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
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}`)
|
||||
createMutation.mutate(payload, { onSuccess: () => navigate('/sber-payments') })
|
||||
} else if (initialData) {
|
||||
updateMutation.mutate({ ...payload, id: initialData.id }, { onSuccess: () => navigate('/sber-payments') })
|
||||
}
|
||||
}
|
||||
|
||||
// ── 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 stepBarItems: StepCardItem[] = STEPS.map((s, i) => {
|
||||
const isActive = i === currentStep
|
||||
const hasErrors = stepsWithErrors.has(i)
|
||||
const isDone = visited.has(i) && !hasErrors
|
||||
return {
|
||||
id: s.id,
|
||||
title: t(s.titleKey) || s.titleFallback,
|
||||
subtitle: t(s.subtitleKey) || s.subtitleFallback,
|
||||
icon: s.icon,
|
||||
status: isActive ? 'active' : hasErrors ? 'error' : isDone ? 'done' : 'idle',
|
||||
}
|
||||
})
|
||||
|
||||
const submitLabel = mode === 'create'
|
||||
? t('sberPayments.buttons.create', 'Sber töleg (talyplar üçin) dörediň')
|
||||
: t('sberPayments.buttons.update', 'Ýatda sakla')
|
||||
const isLastStep = currentStep === STEPS.length - 1
|
||||
|
||||
return (
|
||||
<div className="mx-auto space-y-6 pb-8">
|
||||
@@ -559,32 +530,31 @@ export function SberPaymentForm({ mode, initialData, orderId }: SberPaymentFormP
|
||||
: t('sberPayments.formTitle.edit', 'Sber töleg redaktirläň')}
|
||||
</h1>
|
||||
|
||||
{/* ── Step bar ──────────────────────────────────────────────────────── */}
|
||||
{/* 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)
|
||||
}}
|
||||
/>
|
||||
<StepBarCards steps={stepBarItems} onGoTo={handleGoTo} />
|
||||
</div>
|
||||
|
||||
{/* ── Step content ─────────────────────────────────────────────────── */}
|
||||
{steps[currentStep].id === 'general' && <StepGeneral form={form} errors={errors} set={set} t={t} />}
|
||||
{steps[currentStep].id === 'location' && <StepLocation form={form} errors={errors} set={set} t={t} />}
|
||||
{steps[currentStep].id === 'personal' && <StepPersonal form={form} errors={errors} set={set} t={t} />}
|
||||
{steps[currentStep].id === 'payment' && <StepPayment form={form} errors={errors} set={set} t={t} />}
|
||||
{steps[currentStep].id === 'docs' && <StepDocs form={form} set={set} t={t} />}
|
||||
{/* Step content */}
|
||||
{STEPS[currentStep].id === 'general' && <StepGeneral form={form} errors={errors} set={set} t={t} />}
|
||||
{STEPS[currentStep].id === 'location' && <StepLocation form={form} errors={errors} set={set} t={t} />}
|
||||
{STEPS[currentStep].id === 'personal' && <StepPersonal form={form} errors={errors} set={set} t={t} />}
|
||||
{STEPS[currentStep].id === 'payment' && <StepPayment form={form} errors={errors} set={set} t={t} />}
|
||||
{STEPS[currentStep].id === 'docs' && <StepDocs form={form} set={set} t={t} />}
|
||||
|
||||
{/* ── Actions ───────────────────────────────────────────────────────── */}
|
||||
{/* Actions */}
|
||||
<FormActions
|
||||
isPending={isLoading}
|
||||
isPending={isPending}
|
||||
onCancel={() => navigate('/sber-payments')}
|
||||
onPrev={currentStep > 0 ? () => goStep(currentStep - 1) : undefined}
|
||||
onPrev={currentStep > 0 ? handleBack : undefined}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={isLastStep ? handleNext : undefined}
|
||||
submitLabel={submitLabel}
|
||||
onSubmit={isLastStep ? doSubmit : undefined}
|
||||
submitLabel={
|
||||
mode === 'create'
|
||||
? t('sberPayments.buttons.create', 'Sber töleg (talyplar üçin) dörediň')
|
||||
: t('sberPayments.buttons.update', 'Ýatda sakla')
|
||||
}
|
||||
loadingLabel={t('sberPayments.buttons.loading', 'Ýüklenýär...')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,73 +1,30 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useState, useCallback, useMemo } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import type { TFunction } from 'i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { toast } from 'sonner'
|
||||
import {
|
||||
User, MapPin, IdCard, CreditCard, Files,
|
||||
} from 'lucide-react'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { StepBarCards, type StepCardItem } from '@/components//stepBarV2'
|
||||
import type { StepStatus } from '@/components/stepBar'
|
||||
import type {
|
||||
IntlPaymentItem,
|
||||
IntlPaymentCreatePayload,
|
||||
IntlPaymentStatus,
|
||||
CurrencyType,
|
||||
} from '../api/visaMasterPaymentsApi'
|
||||
import { StepBarCards, type StepCardItem } from '@/components/stepBarV2'
|
||||
import { BentoGrid, BentoCard } from '@/components/bento'
|
||||
import type { IntlPaymentItem, IntlPaymentCreatePayload } from '../api/visaMasterPaymentsApi'
|
||||
import { useCreateIntlPayment, useUpdateIntlPayment } from '../hooks/useVisaMasterPayments'
|
||||
import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from '../schemas/visaMasterPayment.schema'
|
||||
import type { IntlPaymentFormData } from '../schemas/visaMasterPayment.schema'
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface IntlPaymentFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: IntlPaymentItem
|
||||
onSubmit: (payload: IntlPaymentCreatePayload) => void
|
||||
isSubmitting: boolean
|
||||
}
|
||||
|
||||
type FileKey =
|
||||
| 'doc_sberbank_account' | 'doc_school_enrollment' | 'doc_summons'
|
||||
| 'doc_passport_tm' | 'doc_foreign_passport' | 'doc_foreign_passport_copy'
|
||||
| 'doc_exit_permission' | 'doc_school_foreign_info' | 'doc_school_departure_info'
|
||||
| 'upd_doc_passport_tm' | 'upd_doc_foreign_passport' | 'upd_doc_visa'
|
||||
| 'upd_doc_acceptance_letter' | 'upd_doc_passport_biometric' | 'upd_doc_passport_old'
|
||||
|
||||
interface FormState {
|
||||
client_id: string
|
||||
status: string
|
||||
note: string
|
||||
currency_type: string
|
||||
province: string
|
||||
branch: string
|
||||
passport_first_name: string
|
||||
passport_last_name: string
|
||||
phone: string
|
||||
email: string
|
||||
home_address: string
|
||||
passport_series: string
|
||||
passport_number: string
|
||||
payer_full_name: string
|
||||
payer_account_number: string
|
||||
receiver_info: string
|
||||
doc_sberbank_account: File | null
|
||||
doc_school_enrollment: File | null
|
||||
doc_summons: File | null
|
||||
doc_passport_tm: File | null
|
||||
doc_foreign_passport: File | null
|
||||
doc_foreign_passport_copy: File | null
|
||||
doc_exit_permission: File | null
|
||||
doc_school_foreign_info: File | null
|
||||
doc_school_departure_info: File | null
|
||||
upd_doc_passport_tm: File | null
|
||||
upd_doc_foreign_passport: File | null
|
||||
upd_doc_visa: File | null
|
||||
upd_doc_acceptance_letter: File | null
|
||||
upd_doc_passport_biometric: File | null
|
||||
upd_doc_passport_old: File | null
|
||||
}
|
||||
|
||||
type FormErrors = Partial<Record<keyof FormState, string>>
|
||||
type FlatErrors = Partial<Record<keyof IntlPaymentFormData, string>>
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -98,7 +55,7 @@ const PROVINCE_OPTIONS = [
|
||||
{ value: 'balkan', label: 'Balkan' },
|
||||
]
|
||||
|
||||
const KABUL_DOCS: { key: FileKey; label: string }[] = [
|
||||
const KABUL_DOCS: { key: keyof IntlPaymentFormData; label: string }[] = [
|
||||
{ key: 'doc_sberbank_account', label: 'Talypyň SBERBANK kartynyň rekwizitleri' },
|
||||
{ key: 'doc_school_enrollment', label: 'Daşary ýurt ÝOM-da okaýandygy barada güwänamasy' },
|
||||
{ key: 'doc_summons', label: 'Çagyrylma hatynyn göçürmesi' },
|
||||
@@ -110,7 +67,7 @@ const KABUL_DOCS: { key: FileKey; label: string }[] = [
|
||||
{ key: 'doc_school_departure_info', label: 'ÝOM-dan hat (döwlet dilinde)' },
|
||||
]
|
||||
|
||||
const UPGRAD_DOCS: { key: FileKey; label: string }[] = [
|
||||
const UPGRAD_DOCS: { key: keyof IntlPaymentFormData; label: string }[] = [
|
||||
{ key: 'upd_doc_passport_tm', label: 'TM içki pasportynyň asyl görnüşi (upd)' },
|
||||
{ key: 'upd_doc_foreign_passport', label: 'Daşary ýurt pasportynyň göçürmesi (upd)' },
|
||||
{ key: 'upd_doc_visa', label: 'Wiza bellenen sahypasynyň göçürmesi' },
|
||||
@@ -123,138 +80,45 @@ const UPGRAD_DOCS: { key: FileKey; label: string }[] = [
|
||||
|
||||
type StepId = 'general' | 'location' | 'personal' | 'payment' | 'docs'
|
||||
|
||||
interface Step {
|
||||
interface StepDef {
|
||||
id: StepId
|
||||
titleKey: string
|
||||
titleFallback: string
|
||||
subtitleKey: string
|
||||
subtitleFallback: string
|
||||
icon: LucideIcon
|
||||
validate: (form: IntlPaymentFormData, mode: 'create' | 'edit') => FlatErrors
|
||||
}
|
||||
|
||||
const STEPS: Step[] = [
|
||||
{ id: 'general', titleKey: 'intlPaymentForm.steps.general.title', titleFallback: 'Esasy', subtitleKey: 'intlPaymentForm.steps.general.subtitle', subtitleFallback: 'Status, müşderi' },
|
||||
{ id: 'location', titleKey: 'intlPaymentForm.steps.location.title', titleFallback: 'Lokasiýa', subtitleKey: 'intlPaymentForm.steps.location.subtitle', subtitleFallback: 'Welaýat, şahamça' },
|
||||
{ id: 'personal', titleKey: 'intlPaymentForm.steps.personal.title', titleFallback: 'Şahsy', subtitleKey: 'intlPaymentForm.steps.personal.subtitle', subtitleFallback: 'Pasport, kontakt' },
|
||||
{ id: 'payment', titleKey: 'intlPaymentForm.steps.payment.title', titleFallback: 'Töleg', subtitleKey: 'intlPaymentForm.steps.payment.subtitle', subtitleFallback: 'Töleýji, kabul ediji' },
|
||||
{ id: 'docs', titleKey: 'intlPaymentForm.steps.docs.title', titleFallback: 'Resminamalar', subtitleKey: 'intlPaymentForm.steps.docs.subtitle', subtitleFallback: '15 resminama' },
|
||||
const STEPS: StepDef[] = [
|
||||
{ id: 'general', titleKey: 'intlPaymentForm.steps.general.title', titleFallback: 'Esasy', subtitleKey: 'intlPaymentForm.steps.general.subtitle', subtitleFallback: 'Status, müşderi', icon: User, validate: (f, m) => validateStep(0, f, m) },
|
||||
{ id: 'location', titleKey: 'intlPaymentForm.steps.location.title', titleFallback: 'Lokasiýa', subtitleKey: 'intlPaymentForm.steps.location.subtitle', subtitleFallback: 'Welaýat, şahamça', icon: MapPin, validate: (f, m) => validateStep(1, f, m) },
|
||||
{ id: 'personal', titleKey: 'intlPaymentForm.steps.personal.title', titleFallback: 'Şahsy', subtitleKey: 'intlPaymentForm.steps.personal.subtitle', subtitleFallback: 'Pasport, kontakt', icon: IdCard, validate: (f, m) => validateStep(2, f, m) },
|
||||
{ id: 'payment', titleKey: 'intlPaymentForm.steps.payment.title', titleFallback: 'Töleg', subtitleKey: 'intlPaymentForm.steps.payment.subtitle', subtitleFallback: 'Töleýji, kabul ediji', icon: CreditCard, validate: (f, m) => validateStep(3, f, m) },
|
||||
{ id: 'docs', titleKey: 'intlPaymentForm.steps.docs.title', titleFallback: 'Resminamalar', subtitleKey: 'intlPaymentForm.steps.docs.subtitle', subtitleFallback: '15 resminama', icon: Files, validate: () => ({}) },
|
||||
]
|
||||
|
||||
// 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'],
|
||||
// ─── Form errors helper ──────────────────────────────────────────────────────
|
||||
|
||||
function flattenErrors(errors: Record<string, { message?: string } | undefined>): FlatErrors {
|
||||
const result: FlatErrors = {}
|
||||
for (const key of Object.keys(errors)) {
|
||||
const msg = errors[key]?.message
|
||||
if (msg) result[key as keyof IntlPaymentFormData] = msg
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const STEP_ERROR_LABELS: Partial<Record<keyof FormState, string>> = {
|
||||
client_id: 'validation.required',
|
||||
status: 'validation.required',
|
||||
currency_type: 'validation.required',
|
||||
province: 'validation.required',
|
||||
branch: 'validation.required',
|
||||
passport_first_name: 'validation.required',
|
||||
passport_last_name: 'validation.required',
|
||||
phone: 'validation.required',
|
||||
passport_series: 'validation.required',
|
||||
passport_number: 'validation.required',
|
||||
payer_full_name: 'validation.required',
|
||||
payer_account_number: 'validation.required',
|
||||
receiver_info: 'validation.required',
|
||||
}
|
||||
// ─── Step content components ──────────────────────────────────────────────────
|
||||
|
||||
// ─── Default state ────────────────────────────────────────────────────────────
|
||||
|
||||
const defaultState: FormState = {
|
||||
client_id: '', status: 'pending', note: '',
|
||||
currency_type: '', province: '', branch: '',
|
||||
passport_first_name: '', passport_last_name: '',
|
||||
phone: '', email: '', home_address: '',
|
||||
passport_series: '', passport_number: '',
|
||||
payer_full_name: '', payer_account_number: '',
|
||||
receiver_info: '',
|
||||
doc_sberbank_account: null, doc_school_enrollment: null,
|
||||
doc_summons: null, doc_passport_tm: null,
|
||||
doc_foreign_passport: null, doc_foreign_passport_copy: null,
|
||||
doc_exit_permission: null, doc_school_foreign_info: null,
|
||||
doc_school_departure_info: null,
|
||||
upd_doc_passport_tm: null, upd_doc_foreign_passport: null,
|
||||
upd_doc_visa: null, upd_doc_acceptance_letter: null,
|
||||
upd_doc_passport_biometric: null, upd_doc_passport_old: null,
|
||||
}
|
||||
|
||||
// ─── Full validation (final submit) ──────────────────────────────────────────
|
||||
|
||||
function validateAll(form: FormState): FormErrors {
|
||||
const errors: FormErrors = {}
|
||||
Object.entries(STEP_ERROR_LABELS).forEach(([key, msg]) => {
|
||||
if (!form[key as keyof FormState]) errors[key as keyof FormState] = msg
|
||||
})
|
||||
return errors
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// ─── 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 (
|
||||
<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 && (
|
||||
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
{title}
|
||||
</p>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Step content panels ──────────────────────────────────────────────────────
|
||||
|
||||
function StepGeneral({
|
||||
form, errors, set, t,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
interface StepContentProps {
|
||||
form: IntlPaymentFormData
|
||||
errors: FlatErrors
|
||||
set: <K extends keyof IntlPaymentFormData>(k: K, v: IntlPaymentFormData[K]) => void
|
||||
t: TFunction
|
||||
}) {
|
||||
const errMsg = (msg: string | undefined) =>
|
||||
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
|
||||
}
|
||||
|
||||
function StepGeneral({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t('intlPaymentForm.titles.general.client') || 'Müşderi'}>
|
||||
@@ -265,7 +129,7 @@ function StepGeneral({
|
||||
onChange={(v) => set('client_id', v)}
|
||||
options={[]}
|
||||
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
|
||||
error={errMsg(errors.client_id)}
|
||||
error={errors.client_id}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -277,7 +141,7 @@ function StepGeneral({
|
||||
value={form.status}
|
||||
onChange={(v) => set('status', v)}
|
||||
options={STATUS_OPTIONS}
|
||||
error={errMsg(errors.status)}
|
||||
error={errors.status}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -289,7 +153,7 @@ function StepGeneral({
|
||||
value={form.currency_type}
|
||||
onChange={(v) => set('currency_type', v)}
|
||||
options={CURRENCY_OPTIONS}
|
||||
error={errMsg(errors.currency_type)}
|
||||
error={errors.currency_type}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -308,17 +172,7 @@ function StepGeneral({
|
||||
)
|
||||
}
|
||||
|
||||
function StepLocation({
|
||||
form, errors, set, t,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
t: TFunction
|
||||
}) {
|
||||
const errMsg = (msg: string | undefined) =>
|
||||
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
|
||||
|
||||
function StepLocation({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t('Region') || 'Welaýat'}>
|
||||
@@ -328,7 +182,7 @@ function StepLocation({
|
||||
value={form.province}
|
||||
onChange={(v) => { set('province', v); set('branch', '') }}
|
||||
options={PROVINCE_OPTIONS}
|
||||
error={errMsg(errors.province)}
|
||||
error={errors.province}
|
||||
required
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
@@ -344,7 +198,7 @@ function StepLocation({
|
||||
onChange={(v) => set('branch', v)}
|
||||
options={[]}
|
||||
placeholder={t('loanOrderForm.placeholders.searchableSelect') || 'Saýlamak üçin basyň'}
|
||||
error={errMsg(errors.branch)}
|
||||
error={errors.branch}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -352,17 +206,7 @@ function StepLocation({
|
||||
)
|
||||
}
|
||||
|
||||
function StepPersonal({
|
||||
form, errors, set, t,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
t: TFunction
|
||||
}) {
|
||||
const errMsg = (msg: string | undefined) =>
|
||||
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
|
||||
|
||||
function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t('intlPaymentForm.titles.personal.name') || 'At-familýa'}>
|
||||
@@ -372,7 +216,7 @@ function StepPersonal({
|
||||
value={form.passport_last_name}
|
||||
onChange={(v) => set('passport_last_name', v)}
|
||||
placeholder="NURYYEW"
|
||||
error={errMsg(errors.passport_last_name)}
|
||||
error={errors.passport_last_name}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
@@ -381,7 +225,7 @@ function StepPersonal({
|
||||
value={form.passport_first_name}
|
||||
onChange={(v) => set('passport_first_name', v)}
|
||||
placeholder="HAÝDAR"
|
||||
error={errMsg(errors.passport_first_name)}
|
||||
error={errors.passport_first_name}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -392,7 +236,7 @@ function StepPersonal({
|
||||
label={t('Phone') || 'Telefon'}
|
||||
value={form.phone}
|
||||
onChange={(v) => set('phone', v)}
|
||||
error={errMsg(errors.phone)}
|
||||
error={errors.phone}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
@@ -417,17 +261,7 @@ function StepPersonal({
|
||||
)
|
||||
}
|
||||
|
||||
function StepPayment({
|
||||
form, errors, set, t,
|
||||
}: {
|
||||
form: FormState
|
||||
errors: FormErrors
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
t: TFunction
|
||||
}) {
|
||||
const errMsg = (msg: string | undefined) =>
|
||||
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
|
||||
|
||||
function StepPayment({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t('Passport') || 'Pasport maglumatlary'}>
|
||||
@@ -437,7 +271,7 @@ function StepPayment({
|
||||
value={form.passport_series}
|
||||
onChange={(v) => set('passport_series', v)}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
error={errMsg(errors.passport_series)}
|
||||
error={errors.passport_series}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
@@ -446,7 +280,7 @@ function StepPayment({
|
||||
value={form.passport_number}
|
||||
onChange={(v) => set('passport_number', v)}
|
||||
placeholder="A123456"
|
||||
error={errMsg(errors.passport_number)}
|
||||
error={errors.passport_number}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -458,7 +292,7 @@ function StepPayment({
|
||||
value={form.payer_full_name}
|
||||
onChange={(v) => set('payer_full_name', v)}
|
||||
placeholder={t('intlPaymentForm.placeholders.payerFullName') || 'Doly ady...'}
|
||||
error={errMsg(errors.payer_full_name)}
|
||||
error={errors.payer_full_name}
|
||||
required
|
||||
/>
|
||||
<FormInput
|
||||
@@ -467,7 +301,7 @@ function StepPayment({
|
||||
value={form.payer_account_number}
|
||||
onChange={(v) => set('payer_account_number', v)}
|
||||
placeholder={t('intlPaymentForm.placeholders.payerAccount') || '1234 5678 ...'}
|
||||
error={errMsg(errors.payer_account_number)}
|
||||
error={errors.payer_account_number}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -480,7 +314,7 @@ function StepPayment({
|
||||
onChange={(v) => set('receiver_info', v)}
|
||||
placeholder={t('intlPaymentForm.placeholders.receiverInfo') || 'Kabul ediji bank, hasap, Swift...'}
|
||||
rows={3}
|
||||
error={errMsg(errors.receiver_info)}
|
||||
error={errors.receiver_info}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -488,13 +322,7 @@ function StepPayment({
|
||||
)
|
||||
}
|
||||
|
||||
function StepDocs({
|
||||
form, set, t,
|
||||
}: {
|
||||
form: FormState
|
||||
set: <K extends keyof FormState>(k: K, v: FormState[K]) => void
|
||||
t: TFunction
|
||||
}) {
|
||||
function StepDocs({ form, set, t }: StepContentProps) {
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t('intlPaymentForm.titles.docs.kabul') || 'Kabul ediji talyp — 9 resminama'}>
|
||||
@@ -504,7 +332,7 @@ function StepDocs({
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
onFileChange={(f) => set(key, f as IntlPaymentFormData[typeof key])}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
@@ -519,7 +347,7 @@ function StepDocs({
|
||||
key={key}
|
||||
type="file"
|
||||
label={label}
|
||||
onFileChange={(f) => set(key, f)}
|
||||
onFileChange={(f) => set(key, f as IntlPaymentFormData[typeof key])}
|
||||
fileValue={form[key] as File | null}
|
||||
accept="image/*,.pdf"
|
||||
/>
|
||||
@@ -530,171 +358,206 @@ function StepDocs({
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Component ────────────────────────────────────────────────────────────────
|
||||
// ─── Initial data mapper ──────────────────────────────────────────────────────
|
||||
|
||||
export function IntlPaymentForm({
|
||||
mode,
|
||||
initialData,
|
||||
onSubmit,
|
||||
isSubmitting,
|
||||
}: IntlPaymentFormProps) {
|
||||
const { t } = useTranslation()
|
||||
function mapInitial(data: IntlPaymentItem): Partial<IntlPaymentFormData> {
|
||||
return {
|
||||
client_id: data.client_id,
|
||||
status: data.status,
|
||||
note: data.note ?? '',
|
||||
currency_type: data.currency_type,
|
||||
province: data.province,
|
||||
branch: data.branch,
|
||||
passport_first_name: data.passport_first_name,
|
||||
passport_last_name: data.passport_last_name,
|
||||
phone: data.phone,
|
||||
email: data.email ?? '',
|
||||
home_address: data.home_address ?? '',
|
||||
passport_series: data.passport_series,
|
||||
passport_number: data.passport_number,
|
||||
payer_full_name: data.payer_full_name,
|
||||
payer_account_number: data.payer_account_number,
|
||||
receiver_info: data.receiver_info,
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Main Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export function IntlPaymentForm({ mode, initialData }: IntlPaymentFormProps) {
|
||||
const { t, i18n } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const createMutation = useCreateIntlPayment()
|
||||
const updateMutation = useUpdateIntlPayment(initialData?.id ?? '')
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const [form, setForm] = useState<FormState>(defaultState)
|
||||
const [errors, setErrors] = useState<FormErrors>({})
|
||||
const {
|
||||
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, setError,
|
||||
} = useForm<IntlPaymentFormData>({
|
||||
defaultValues: initialData ? { ...DEFAULT_FORM_VALUES, ...mapInitial(initialData) } : DEFAULT_FORM_VALUES,
|
||||
})
|
||||
|
||||
const form = watch()
|
||||
const [currentStep, setCurrentStep] = useState(0)
|
||||
const [stepStatuses, setStepStatuses] = useState<StepStatus[]>(
|
||||
STEPS.map((_, i) => (i === 0 ? 'active' : 'idle')),
|
||||
const [visited, setVisited] = useState<Set<number>>(
|
||||
() => mode === 'edit' ? new Set(STEPS.map((_, i) => i)) : new Set<number>(),
|
||||
)
|
||||
const [submittedSteps, setSubmittedSteps] = useState<Set<number>>(new Set())
|
||||
|
||||
// ── Populate in edit mode ──
|
||||
useEffect(() => {
|
||||
if (mode === 'edit' && initialData) {
|
||||
setForm({
|
||||
client_id: initialData.client_id,
|
||||
status: initialData.status,
|
||||
note: initialData.note ?? '',
|
||||
currency_type: initialData.currency_type,
|
||||
province: initialData.province,
|
||||
branch: initialData.branch,
|
||||
passport_first_name: initialData.passport_first_name,
|
||||
passport_last_name: initialData.passport_last_name,
|
||||
phone: initialData.phone,
|
||||
email: initialData.email ?? '',
|
||||
home_address: initialData.home_address ?? '',
|
||||
passport_series: initialData.passport_series,
|
||||
passport_number: initialData.passport_number,
|
||||
payer_full_name: initialData.payer_full_name,
|
||||
payer_account_number: initialData.payer_account_number,
|
||||
receiver_info: initialData.receiver_info,
|
||||
doc_sberbank_account: null, doc_school_enrollment: null,
|
||||
doc_summons: null, doc_passport_tm: null,
|
||||
doc_foreign_passport: null, doc_foreign_passport_copy: null,
|
||||
doc_exit_permission: null, doc_school_foreign_info: null,
|
||||
doc_school_departure_info: null,
|
||||
upd_doc_passport_tm: null, upd_doc_foreign_passport: null,
|
||||
upd_doc_visa: null, upd_doc_acceptance_letter: null,
|
||||
upd_doc_passport_biometric: null, upd_doc_passport_old: null,
|
||||
})
|
||||
// Mark all non-doc steps done in edit mode so the user can jump freely
|
||||
setStepStatuses(STEPS.map((_, i) => (i === 0 ? 'active' : i < 4 ? 'done' : 'idle')))
|
||||
}
|
||||
}, [mode, initialData])
|
||||
|
||||
// ── Field setter ──
|
||||
const set = <K extends keyof FormState>(key: K, value: FormState[K]) => {
|
||||
setForm((prev) => ({ ...prev, [key]: value }))
|
||||
if (errors[key]) setErrors((prev) => ({ ...prev, [key]: undefined }))
|
||||
}
|
||||
|
||||
// ── Step navigation ──
|
||||
const goStep = (idx: number) => {
|
||||
if (idx < 0 || idx >= STEPS.length) return
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]
|
||||
// going forward: mark current done
|
||||
if (idx > currentStep) next[currentStep] = 'done'
|
||||
next[idx] = 'active'
|
||||
// going back: reset steps after target to idle (only those not yet done)
|
||||
if (idx < currentStep) {
|
||||
for (let i = idx + 1; i <= currentStep; i++) {
|
||||
if (next[i] !== 'done') next[i] = 'idle'
|
||||
}
|
||||
}
|
||||
return next
|
||||
const stepsWithErrors = useMemo(() => {
|
||||
const out = new Set<number>()
|
||||
visited.forEach((i) => {
|
||||
if (Object.keys(STEPS[i].validate(form, mode)).length > 0) out.add(i)
|
||||
})
|
||||
setErrors({})
|
||||
setCurrentStep(idx)
|
||||
}
|
||||
return out
|
||||
}, [form, mode, visited, i18n.language])
|
||||
|
||||
const set = useCallback(<K extends keyof IntlPaymentFormData>(key: K, value: IntlPaymentFormData[K]) => {
|
||||
(setValue as (name: K, val: IntlPaymentFormData[K]) => void)(key, value)
|
||||
clearErrors(key)
|
||||
}, [setValue, clearErrors])
|
||||
|
||||
const allSubmittedErrors = useMemo(() => {
|
||||
const result: FlatErrors = {}
|
||||
for (const stepIdx of submittedSteps) {
|
||||
Object.assign(result, STEPS[stepIdx].validate(form, mode))
|
||||
}
|
||||
return result
|
||||
}, [form, mode, submittedSteps, i18n.language])
|
||||
|
||||
const errors = useMemo(() => {
|
||||
const fromRHF = flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>)
|
||||
return { ...fromRHF, ...allSubmittedErrors }
|
||||
}, [rhfErrors, allSubmittedErrors])
|
||||
|
||||
const stepProps = useMemo(() => ({ form, errors, set, t }), [form, errors, set, t])
|
||||
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
|
||||
const markVisited = (i: number) =>
|
||||
setVisited((prev) => new Set([...prev, i]))
|
||||
|
||||
const markSubmitted = (i: number) =>
|
||||
setSubmittedSteps((prev) => new Set([...prev, i]))
|
||||
|
||||
const handleNext = () => {
|
||||
const stepId = STEPS[currentStep].id
|
||||
const stepErrors = validateStep(form, stepId)
|
||||
if (Object.keys(stepErrors).length > 0) {
|
||||
setErrors(stepErrors)
|
||||
toast.error(t('common.errors.fillRequiredCorrectly', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
|
||||
setStepStatuses((prev) => {
|
||||
const next = [...prev]
|
||||
next[currentStep] = 'error'
|
||||
return next
|
||||
markVisited(currentStep)
|
||||
markSubmitted(currentStep)
|
||||
const errs = STEPS[currentStep].validate(form, mode)
|
||||
if (Object.keys(errs).length > 0) {
|
||||
Object.entries(errs).forEach(([key, msg]) => {
|
||||
setError(key as keyof IntlPaymentFormData, { type: 'manual', message: msg })
|
||||
})
|
||||
toast.error(t('common.errors.fillRequiredCorrectly', 'Dogry maglumat girizmegiňizi haýyş edýäris.'))
|
||||
return
|
||||
}
|
||||
if (currentStep === STEPS.length - 1) {
|
||||
handleSubmit()
|
||||
} else {
|
||||
goStep(currentStep + 1)
|
||||
if (currentStep < STEPS.length - 1) {
|
||||
setCurrentStep(currentStep + 1)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = () => {
|
||||
const allErrors = validateAll(form)
|
||||
const handleBack = () => {
|
||||
if (currentStep > 0) {
|
||||
markVisited(currentStep)
|
||||
setCurrentStep(currentStep - 1)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
}
|
||||
|
||||
const handleGoTo = (i: number) => {
|
||||
markVisited(currentStep)
|
||||
setCurrentStep(i)
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
// ── Submit ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const doSubmit = () => {
|
||||
setVisited(new Set(STEPS.map((_, i) => i)))
|
||||
setSubmittedSteps(new Set(STEPS.map((_, i) => i)))
|
||||
|
||||
const allErrors: FlatErrors = {}
|
||||
for (const step of STEPS) Object.assign(allErrors, step.validate(form, mode))
|
||||
|
||||
if (Object.keys(allErrors).length > 0) {
|
||||
setErrors(allErrors)
|
||||
Object.entries(allErrors).forEach(([key, msg]) => {
|
||||
setError(key as keyof IntlPaymentFormData, { type: 'manual', message: msg })
|
||||
})
|
||||
toast.error(t('common.errors.requiredFieldsMissing', 'Käbir hökmany meýdanlar doldurylan däldir.'))
|
||||
for (let i = 0; i < STEPS.length; i++) {
|
||||
if (Object.keys(STEPS[i].validate(form, mode)).length > 0) {
|
||||
setCurrentStep(i); break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
onSubmit({
|
||||
...form,
|
||||
status: form.status as IntlPaymentStatus,
|
||||
currency_type: form.currency_type as CurrencyType,
|
||||
})
|
||||
|
||||
const payload = buildPayload(getValues())
|
||||
|
||||
if (mode === 'create') {
|
||||
createMutation.mutate(payload as IntlPaymentCreatePayload, {
|
||||
onSuccess: (data) => navigate(`/intl-payments/visa-master/${data.id}`),
|
||||
})
|
||||
} else if (initialData) {
|
||||
updateMutation.mutate(payload as IntlPaymentCreatePayload, {
|
||||
onSuccess: () => navigate(`/intl-payments/visa-master/${initialData.id}`),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ── StepBarCards data ──
|
||||
const stepCardItems: StepCardItem[] = STEPS.map((s, i) => ({
|
||||
id: s.id,
|
||||
title: t(s.titleKey) || s.titleFallback,
|
||||
subtitle: t(s.subtitleKey) || s.subtitleFallback,
|
||||
status: stepStatuses[i],
|
||||
icon: [User, MapPin, IdCard, CreditCard, Files][i],
|
||||
}))
|
||||
// ── StepBar items ──────────────────────────────────────────────────────────
|
||||
|
||||
const stepBarItems: StepCardItem[] = STEPS.map((s, i) => {
|
||||
const isActive = i === currentStep
|
||||
const hasErrors = stepsWithErrors.has(i)
|
||||
const isDone = visited.has(i) && !hasErrors
|
||||
return {
|
||||
id: s.id,
|
||||
title: t(s.titleKey) || s.titleFallback,
|
||||
subtitle: t(s.subtitleKey) || s.subtitleFallback,
|
||||
icon: s.icon,
|
||||
status: isActive ? 'active' : hasErrors ? 'error' : isDone ? 'done' : 'idle',
|
||||
}
|
||||
})
|
||||
|
||||
const isLastStep = currentStep === STEPS.length - 1
|
||||
|
||||
const title = mode === 'create'
|
||||
? t('intlPayment.createTitle', 'Visa/Master tölegler (talyplar üçin) dörediň')
|
||||
: t('intlPayment.editTitle', 'Visa/Master tölegler (talyplar üçin) redaktirläň')
|
||||
|
||||
const submitLabel = isLastStep
|
||||
? (mode === 'create'
|
||||
? t('intlPayment.createBtn', 'Dörediň')
|
||||
: t('intlPayment.editBtn', 'Redaktirläň'))
|
||||
: undefined // not used on non-last steps
|
||||
// ── Render ──────────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<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">
|
||||
{mode === 'create'
|
||||
? t('intlPayment.createTitle', 'Visa/Master tölegler (talyplar üçin) dörediň')
|
||||
: t('intlPayment.editTitle', 'Visa/Master tölegler (talyplar üçin) redaktirläň')}
|
||||
</h1>
|
||||
|
||||
{/* ── Step bar ────────────────────────────────────────────────────── */}
|
||||
{/* Step bar */}
|
||||
<div className="bg-card border border-border rounded-xl p-3 overflow-x-auto">
|
||||
<StepBarCards
|
||||
steps={stepCardItems}
|
||||
onGoTo={(i) => {
|
||||
// Allow jumping only to done/active steps
|
||||
if (stepStatuses[i] !== 'idle') goStep(i)
|
||||
}}
|
||||
/>
|
||||
<StepBarCards steps={stepBarItems} onGoTo={handleGoTo} />
|
||||
</div>
|
||||
|
||||
{/* ── Step content ─────────────────────────────────────────────────── */}
|
||||
{STEPS[currentStep].id === 'general' && <StepGeneral form={form} errors={errors} set={set} t={t} />}
|
||||
{STEPS[currentStep].id === 'location' && <StepLocation form={form} errors={errors} set={set} t={t} />}
|
||||
{STEPS[currentStep].id === 'personal' && <StepPersonal form={form} errors={errors} set={set} t={t} />}
|
||||
{STEPS[currentStep].id === 'payment' && <StepPayment form={form} errors={errors} set={set} t={t} />}
|
||||
{STEPS[currentStep].id === 'docs' && <StepDocs form={form} set={set} t={t} />}
|
||||
{/* Step content */}
|
||||
{STEPS[currentStep].id === 'general' && <StepGeneral {...stepProps} />}
|
||||
{STEPS[currentStep].id === 'location' && <StepLocation {...stepProps} />}
|
||||
{STEPS[currentStep].id === 'personal' && <StepPersonal {...stepProps} />}
|
||||
{STEPS[currentStep].id === 'payment' && <StepPayment {...stepProps} />}
|
||||
{STEPS[currentStep].id === 'docs' && <StepDocs {...stepProps} />}
|
||||
|
||||
{/* ── Actions ───────────────────────────────────────────────────────── */}
|
||||
{/* Actions */}
|
||||
<FormActions
|
||||
isPending={isSubmitting}
|
||||
isPending={isPending}
|
||||
onCancel={() => navigate('/intl-payments/visa-master')}
|
||||
onPrev={currentStep > 0 ? () => goStep(currentStep - 1) : undefined}
|
||||
onPrev={currentStep > 0 ? handleBack : undefined}
|
||||
onNext={!isLastStep ? handleNext : undefined}
|
||||
showSubmit={isLastStep}
|
||||
onSubmit={isLastStep ? handleNext : undefined}
|
||||
submitLabel={submitLabel}
|
||||
onSubmit={isLastStep ? doSubmit : undefined}
|
||||
submitLabel={
|
||||
mode === 'create'
|
||||
? t('intlPayment.createBtn', 'Dörediň')
|
||||
: t('intlPayment.editBtn', 'Redaktirläň')
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import type { VisaMasterSettingFormData } from '../schemas/visaMasterSberSetting
|
||||
export interface VisaMasterSettingFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: VisaMasterSetting
|
||||
settingId?: number
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
@@ -54,12 +53,11 @@ function flattenErrors(
|
||||
export function VisaMasterSettingForm({
|
||||
mode,
|
||||
initialData,
|
||||
settingId,
|
||||
}: VisaMasterSettingFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
[_t, i18n.language],
|
||||
)
|
||||
|
||||
const errMsg = (msg: string | undefined) =>
|
||||
@@ -67,7 +65,7 @@ export function VisaMasterSettingForm({
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createMutation = useCreateVisaMasterSetting()
|
||||
const updateMutation = useUpdateVisaMasterSetting(settingId ?? 0)
|
||||
const updateMutation = useUpdateVisaMasterSetting(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
@@ -135,7 +133,13 @@ export function VisaMasterSettingForm({
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="space-y-0">
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('visaMasterSettings.createTitle', 'Visa/Master, Sber sazlamalar dörediň')
|
||||
: t('visaMasterSettings.editTitle', 'Visa/Master, Sber sazlamalar üýtgetmek')}
|
||||
</h1>
|
||||
<div className="space-y-0">
|
||||
{/* Kod */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||
<label className="text-sm text-muted-foreground pt-1.5">
|
||||
@@ -196,5 +200,6 @@ export function VisaMasterSettingForm({
|
||||
className="px-6 py-4 border-t border-border"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardBalanceForm } from '@/features/cardBalance/components/cardBalanceForm'
|
||||
|
||||
export default function CardBalanceCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('Create card balance', 'Kart galyndysy dörediň')}
|
||||
</h1>
|
||||
|
||||
<CardBalanceForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <CardBalanceForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,47 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CardBalanceForm } from '@/features/cardBalance/components/cardBalanceForm'
|
||||
import { useCardBalance } from '@/features/cardBalance/hooks/useCardBalance'
|
||||
|
||||
|
||||
export default function CardBalanceEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading } = useCardBalance(numericId)
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-4 max-w-3xl">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t('Not found', 'Tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('Edit card balance', 'Kart galyndysyny düzetmek')}:{' '}
|
||||
<span className="text-primary font-mono">{data.id}</span>
|
||||
</h1>
|
||||
|
||||
<CardBalanceForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
cardBalanceId={numericId}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
return <CardBalanceForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { CardPinForm } from '@/features/cardPins/components/cardPinForm'
|
||||
import { useCreateCardPin } from '@/features/cardPins/hooks/useCardPins'
|
||||
import type { CardPinCreatePayload } from '@/features/cardPins/api/cardPinApi'
|
||||
|
||||
export default function CardPinCreatePage() {
|
||||
const navigate = useNavigate()
|
||||
const { mutate: createPin, isPending } = useCreateCardPin()
|
||||
|
||||
const handleSubmit = (payload: CardPinCreatePayload) => {
|
||||
createPin(payload, {
|
||||
onSuccess: (data) => navigate(`/card-pins/${data.id}`),
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<CardPinForm
|
||||
mode="create"
|
||||
onSubmit={handleSubmit}
|
||||
isSubmitting={isPending}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return <CardPinForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,46 +1,17 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CardPinForm } from '@/features/cardPins/components/cardPinForm'
|
||||
import { useCardPin, useUpdateCardPin } from '@/features/cardPins/hooks/useCardPins'
|
||||
import type { CardPinUpdatePayload } from '@/features/cardPins/api/cardPinApi'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import { useCardPin } from '@/features/cardPins/hooks/useCardPins'
|
||||
|
||||
export default function CardPinEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
const { data, isLoading, isError } = useCardPin(id ?? '')
|
||||
|
||||
const { data, isLoading, isError } = useCardPin(id!)
|
||||
const { mutate: updatePin, isPending } = useUpdateCardPin(id!)
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Maglumat tapylmady')} />
|
||||
|
||||
const handleSubmit = (payload: CardPinUpdatePayload) => {
|
||||
updatePin(payload, {
|
||||
onSuccess: () => navigate(`/card-pins/${id}`),
|
||||
})
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-8 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !data) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24 text-muted-foreground">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<CardPinForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
onSubmit={handleSubmit}
|
||||
isSubmitting={isPending}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return <CardPinForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardRequisiteForm } from '@/features/cardRequisites/components/cardRequisiteForm'
|
||||
|
||||
export default function CardRequisiteCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Create card requisite order', 'Kart rekwiziti üçin sargyt dörediň dörediň')}
|
||||
</h1>
|
||||
<CardRequisiteForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <CardRequisiteForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,41 +1,17 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CardRequisiteForm } from '@/features/cardRequisites/components/cardRequisiteForm'
|
||||
import { useCardRequisite } from '@/features/cardRequisites/hooks/useCardRequisites'
|
||||
|
||||
export default function CardRequisiteEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
|
||||
const { t } = useTranslation()
|
||||
const { data, isLoading } = useCardRequisite(id ?? '')
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-7 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t('Not found', 'Tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Edit card requisite', 'Kart rekwizitini üýtget')}
|
||||
</h1>
|
||||
<CardRequisiteForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
cardRequisiteId={data.id}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
return <CardRequisiteForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardTransactionForm } from '@/features/cardTransactions/components/cardTransactionForm'
|
||||
|
||||
export default function CardTransactionCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('Create card transaction', 'Kart herekedi dörediň')}
|
||||
</h1>
|
||||
<CardTransactionForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <CardTransactionForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,42 +1,18 @@
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { CardTransactionForm } from "@/features/cardTransactions/components/cardTransactionForm";
|
||||
import { useCardTransaction } from "@/features/cardTransactions/hooks/useCardTransactions";
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CardTransactionForm } from '@/features/cardTransactions/components/cardTransactionForm'
|
||||
import { useCardTransaction } from '@/features/cardTransactions/hooks/useCardTransactions'
|
||||
|
||||
export default function CardTransactionEditPage() {
|
||||
const { t } = useTranslation();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const numericId = Number(id);
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading } = useCardTransaction(numericId)
|
||||
|
||||
const { data, isLoading } = useCardTransaction(numericId);
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-7 text-primary" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="text-center py-24 text-muted-foreground">
|
||||
{t("Not found", "Tapylmady")}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("Edit card transaction", "Kart herekedini üýtget")}
|
||||
</h1>
|
||||
<CardTransactionForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
cardTransactionId={numericId}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
return <CardTransactionForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,24 +1,5 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardOrderForm } from '@/features/orderNewCard/components/orderNewCardForm'
|
||||
|
||||
|
||||
export default function CardOrderCreatePage() {
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('cardOrder.createTitle', 'Kart sargyt dörediň')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<CardOrderForm
|
||||
mode="create"
|
||||
onSuccess={() => navigate('/order-new-card')}
|
||||
onCancel={() => navigate('/order-new-card')}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <CardOrderForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,51 +1,17 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { CardOrderForm } from '@/features/orderNewCard/components/orderNewCardForm'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CardOrderForm } from '@/features/orderNewCard/components/orderNewCardForm'
|
||||
import { useCardOrderById } from '@/features/orderNewCard/hooks/useOrderNewCard'
|
||||
|
||||
|
||||
export default function CardOrderEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
const { data: order, isLoading } = useCardOrderById(id ?? '')
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-4 max-w-3xl">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!order) {
|
||||
return (
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{t('common.notFound', 'Tapylmady')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6">
|
||||
<h1 className="text-xl font-semibold text-foreground tracking-tight">
|
||||
{t('cardOrder.editTitle', 'Düzetmek')}:{' '}
|
||||
<span className="text-primary font-mono">{order.id}</span>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<CardOrderForm
|
||||
mode="edit"
|
||||
initialData={order}
|
||||
cardOrderId={id}
|
||||
onSuccess={() => navigate(`/order-new-card/${id}`)}
|
||||
onCancel={() => navigate(`/order-new-card/${id}`)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!order) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
return <CardOrderForm mode="edit" initialData={order} />
|
||||
}
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
// pages/CurrencyRateCreatePage.tsx
|
||||
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CurrencyRateForm } from '@/features/currencyRates/components/currencyRatesForm'
|
||||
|
||||
// ─── CurrencyRateCreatePage ───────────────────────────────────────────────────
|
||||
|
||||
export default function CurrencyRateCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('currencyRates.actions.create', 'Walýuta kursy dörediň')}
|
||||
</h1>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<CurrencyRateForm mode="create" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <CurrencyRateForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,57 +1,18 @@
|
||||
// pages/CurrencyRateEditPage.tsx
|
||||
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CurrencyRateForm } from '@/features/currencyRates/components/currencyRatesForm'
|
||||
import { useGetCurrencyRateById } from '@/features/currencyRates/hooks/useCurrencyRates'
|
||||
|
||||
// ─── CurrencyRateEditPage ─────────────────────────────────────────────────────
|
||||
|
||||
export default function CurrencyRateEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
const numericId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data: rate, isLoading } = useGetCurrencyRateById(numericId)
|
||||
|
||||
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!rate) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="h-6 w-64 bg-muted rounded animate-pulse" />
|
||||
<div className="h-48 bg-muted rounded-xl animate-pulse" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!rate) {
|
||||
return (
|
||||
<div>
|
||||
<p className="text-muted-foreground">
|
||||
{t('currencyRates.notFound', 'Walýuta kursy tapylmady')}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('currencyRates.detail.editTitle', 'Walýuta kursyny üýtgetmek')}: {rate.id}
|
||||
</h1>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<CurrencyRateForm
|
||||
mode="edit"
|
||||
initialData={rate}
|
||||
rateId={numericId}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <CurrencyRateForm mode="edit" initialData={rate} />
|
||||
}
|
||||
|
||||
@@ -1,24 +1,5 @@
|
||||
// pages/VisaMasterSettingCreatePage.tsx
|
||||
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { VisaMasterSettingForm } from '@/features/visaMasterSberSettings/components/visaMasterSberSettingsForm'
|
||||
|
||||
// ─── VisaMasterSettingCreatePage ──────────────────────────────────────────────
|
||||
|
||||
export default function VisaMasterSettingCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('visaMasterSettings.actions.create', 'Visa/Master, Sber sazlamalar dörediň')}
|
||||
</h1>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<VisaMasterSettingForm mode="create" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <VisaMasterSettingForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,57 +1,18 @@
|
||||
// pages/VisaMasterSettingEditPage.tsx
|
||||
|
||||
import {useParams } from 'react-router-dom'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { VisaMasterSettingForm } from '@/features/visaMasterSberSettings/components/visaMasterSberSettingsForm'
|
||||
import { useGetVisaMasterSettingById } from '@/features/visaMasterSberSettings/hooks/useVisaMasterSettings'
|
||||
|
||||
// ─── VisaMasterSettingEditPage ────────────────────────────────────────────────
|
||||
|
||||
export default function VisaMasterSettingEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
const numericId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data: setting, isLoading } = useGetVisaMasterSettingById(numericId)
|
||||
|
||||
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!setting) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="h-6 w-72 bg-muted rounded animate-pulse" />
|
||||
<div className="h-56 bg-muted rounded-xl animate-pulse" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!setting) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<p className="text-muted-foreground">
|
||||
{t('visaMasterSettings.notFound', 'Sazlama tapylmady')}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('visaMasterSettings.detail.editTitle', 'Sazlamany üýtgetmek')}: {setting.id}
|
||||
</h1>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<VisaMasterSettingForm
|
||||
mode="edit"
|
||||
initialData={setting}
|
||||
settingId={numericId}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <VisaMasterSettingForm mode="edit" initialData={setting} />
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
|
||||
import { SberPaymentForm } from '@/features/sberPayments/components/sberPaymentsForm'
|
||||
|
||||
export default function SberPaymentCreatePage() {
|
||||
return (
|
||||
<div>
|
||||
<SberPaymentForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <SberPaymentForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,30 +1,17 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { SberPaymentForm } from '@/features/sberPayments/components/sberPaymentsForm'
|
||||
import { useSberPaymentOrder } from '@/features/sberPayments/hooks/useSberPayments'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
|
||||
export default function SberPaymentEditPage() {
|
||||
const params = useParams()
|
||||
const id = params.id as string
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data: order, isLoading } = useSberPaymentOrder(id)
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Spinner className="w-8 h-8" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold text-foreground mb-6">
|
||||
{t('sberPayments.formTitle.edit', 'Sber töleg redaktirläň')}: {id}
|
||||
</h1>
|
||||
<SberPaymentForm mode="edit" initialData={order} orderId={id} />
|
||||
</div>
|
||||
)
|
||||
const { data: order, isLoading } = useSberPaymentOrder(id ?? '')
|
||||
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!order) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
return <SberPaymentForm mode="edit" initialData={order} />
|
||||
}
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { IntlPaymentForm } from '@/features/visaMasterPayments/components/intlPaymentForm'
|
||||
import { useCreateIntlPayment } from '@/features/visaMasterPayments/hooks/useVisaMasterPayments'
|
||||
import type { IntlPaymentCreatePayload } from '@/features/visaMasterPayments/api/visaMasterPaymentsApi'
|
||||
|
||||
export default function IntlPaymentCreatePage() {
|
||||
const navigate = useNavigate()
|
||||
const { mutate: createPayment, isPending } = useCreateIntlPayment()
|
||||
|
||||
const handleSubmit = (payload: IntlPaymentCreatePayload) => {
|
||||
createPayment(payload, {
|
||||
onSuccess: (data) => navigate(`/intl-payments/visa-master/${data.id}`),
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<IntlPaymentForm
|
||||
mode="create"
|
||||
onSubmit={handleSubmit}
|
||||
isSubmitting={isPending}
|
||||
/>
|
||||
)
|
||||
return <IntlPaymentForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,46 +1,17 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { IntlPaymentForm } from '@/features/visaMasterPayments/components/intlPaymentForm'
|
||||
import { useIntlPayment, useUpdateIntlPayment } from '@/features/visaMasterPayments/hooks/useVisaMasterPayments'
|
||||
import type { IntlPaymentUpdatePayload } from '@/features/visaMasterPayments/api/visaMasterPaymentsApi'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import { useIntlPayment } from '@/features/visaMasterPayments/hooks/useVisaMasterPayments'
|
||||
|
||||
export default function IntlPaymentEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
const { data, isLoading, isError } = useIntlPayment(id ?? '')
|
||||
|
||||
const { data, isLoading, isError } = useIntlPayment(id!)
|
||||
const { mutate: updatePayment, isPending } = useUpdateIntlPayment(id!)
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Maglumat tapylmady')} />
|
||||
|
||||
const handleSubmit = (payload: IntlPaymentUpdatePayload) => {
|
||||
updatePayment(payload, {
|
||||
onSuccess: () => navigate(`/intl-payments/visa-master/${id}`),
|
||||
})
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24">
|
||||
<Spinner className="size-8 text-primary" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !data) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-24 text-muted-foreground">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<IntlPaymentForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
onSubmit={handleSubmit}
|
||||
isSubmitting={isPending}
|
||||
/>
|
||||
)
|
||||
return <IntlPaymentForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,29 +1,17 @@
|
||||
import { useParams } from "react-router-dom";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PageSpinner } from "@/components/pageSpinner";
|
||||
import { PageError } from "@/components/pageError";
|
||||
import { LoanOrderForm } from "@/features/loanOrders/components/loanOrderForm";
|
||||
import { useLoanOrderById } from "@/features/loanOrders/hooks/useLoanOrders";
|
||||
|
||||
export default function LoanOrderEditPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { t } = useTranslation();
|
||||
const { data, isLoading, isError } = useLoanOrderById(id ?? "");
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Loader2 className="animate-spin text-muted-foreground" size={32} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (isLoading) return <PageSpinner />;
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Maglumat ýüklenilmedi')} />;
|
||||
|
||||
if (isError || !data) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<p className="text-sm text-destructive">
|
||||
Maglumat ýüklenilmedi. Sahypany täzeleläň.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <LoanOrderForm mode="edit" initialData={data} loanOrderId={id} />;
|
||||
return <LoanOrderForm mode="edit" initialData={data} />;
|
||||
}
|
||||
|
||||
@@ -1,31 +1,17 @@
|
||||
import { useParams } from "react-router-dom";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PageSpinner } from "@/components/pageSpinner";
|
||||
import { PageError } from "@/components/pageError";
|
||||
import { LoanOrderMobileForm } from "@/features/loanOrderMobiles/components/loanOrderMobileForm";
|
||||
import { useLoanOrderMobileById } from "@/features/loanOrderMobiles/hooks/useLoanOrderMobiles";
|
||||
|
||||
export default function LoanOrderMobilesEditPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { t } = useTranslation();
|
||||
const { data, isLoading, isError } = useLoanOrderMobileById(id ?? "");
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Loader2 className="animate-spin text-muted-foreground" size={32} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (isLoading) return <PageSpinner />;
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Maglumat ýüklenilmedi')} />;
|
||||
|
||||
if (isError || !data) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<p className="text-sm text-destructive">
|
||||
Maglumat ýüklenilmedi. Sahypany täzeleläň.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<LoanOrderMobileForm mode="edit" initialData={data} loanOrderId={id} />
|
||||
);
|
||||
return <LoanOrderMobileForm mode="edit" initialData={data} />;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Eye, Pencil, Trash2, TableProperties } from "lucide-react";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
@@ -41,6 +42,7 @@ function EmptyState({ onCreate }: { onCreate: () => void }) {
|
||||
|
||||
export default function LoanPaidOffLettersPage() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const deleteMutation = useDeleteLoanPaidOffLetter();
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
|
||||
@@ -81,8 +83,8 @@ export default function LoanPaidOffLettersPage() {
|
||||
}, [deleteId, deleteMutation]);
|
||||
|
||||
const handleCreate = useCallback(() => {
|
||||
// navigate to create page or open modal
|
||||
}, []);
|
||||
navigate("/loan-paid-off-letters/create");
|
||||
}, [navigate]);
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns = useMemo<ColumnDef<LoanPaidOffLetter>[]>(
|
||||
@@ -128,12 +130,14 @@ export default function LoanPaidOffLettersPage() {
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1.5 justify-end">
|
||||
<button
|
||||
onClick={() => navigate(`/loan-paid-off-letters/${row.original.id}`)}
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate(`/loan-paid-off-letters/${row.original.id}/edit`)}
|
||||
className="p-1.5 cursor-pointer rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t("common.edit", "Üýtgetmek")}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { LoanPaidOffLetterForm } from '@/features/loanPaidOffLetters/components/LoanPaidOffLetterForm'
|
||||
|
||||
export default function LoanPaidOffLettersCreatePage() {
|
||||
return <LoanPaidOffLetterForm mode="create" />
|
||||
}
|
||||
18
src/pages/loanDepartment/loanPaidOffLettersEdit/index.tsx
Normal file
18
src/pages/loanDepartment/loanPaidOffLettersEdit/index.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { LoanPaidOffLetterForm } from '@/features/loanPaidOffLetters/components/LoanPaidOffLetterForm'
|
||||
import { useLoanPaidOffLetterById } from '@/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters'
|
||||
|
||||
export default function LoanPaidOffLettersEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
|
||||
const { data, isLoading } = useLoanPaidOffLetterById(id)
|
||||
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
return <LoanPaidOffLetterForm mode="edit" initialData={data} />
|
||||
}
|
||||
107
src/pages/loanDepartment/loanPaidOffLettersView/index.tsx
Normal file
107
src/pages/loanDepartment/loanPaidOffLettersView/index.tsx
Normal file
@@ -0,0 +1,107 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Trash2, Pencil } from "lucide-react";
|
||||
import {
|
||||
useLoanPaidOffLetterById,
|
||||
useDeleteLoanPaidOffLetter,
|
||||
} from "@/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { InfoRow, Section } from "@/components/viewPageComponents";
|
||||
import { ConfirmDialog } from "@/components/confirmDialog";
|
||||
|
||||
function LoanPaidOffLetterViewSkeleton() {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Skeleton className="h-7 w-64" />
|
||||
<div className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3">
|
||||
{[...Array(5)].map((_, j) => (
|
||||
<Skeleton key={j} className="h-4 w-full" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function LoanPaidOffLettersViewPage() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const deleteMutation = useDeleteLoanPaidOffLetter();
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||
|
||||
const { data: record, isLoading } = useLoanPaidOffLetterById(id!);
|
||||
|
||||
const confirmDelete = () => {
|
||||
deleteMutation.mutate(Number(id!), {
|
||||
onSuccess: () => navigate("/loan-paid-off-letters"),
|
||||
});
|
||||
};
|
||||
|
||||
if (isLoading) return <LoanPaidOffLetterViewSkeleton />;
|
||||
|
||||
if (!record) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-64 text-muted-foreground text-sm">
|
||||
{t("common.notFound", "Tapylmady")}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
<div className="flex items-center justify-between mb-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("loanPaidOffLetters.view.title", "Güwanama maglumaty")}:{" "}
|
||||
{record.id}
|
||||
</h1>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<button
|
||||
onClick={() => setShowDeleteDialog(true)}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="p-2 rounded-md cursor-pointer hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
|
||||
title={t("common.delete", "Poz")}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => navigate(`/loan-paid-off-letters/${record.id}/edit`)}
|
||||
className="p-2 rounded-md cursor-pointer hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
title={t("common.edit", "Redaktirle")}
|
||||
>
|
||||
<Pencil size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Section title={t("loanPaidOffLetters.sections.info", "Esasy maglumatlar")}>
|
||||
<InfoRow label={t("common.id", "ID")} value={String(record.id)} />
|
||||
<InfoRow
|
||||
label={t("loanPaidOffLetters.columns.passportSeries", "Pasport seriýasy")}
|
||||
value={record.passportSeries}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanPaidOffLetters.columns.passportNumber", "Pasport belgisi")}
|
||||
value={record.passportNumber}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanPaidOffLetters.columns.loanAccount", "Karz hasaby")}
|
||||
value={record.loanAccount}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("loanPaidOffLetters.columns.issuedAt", "Berlen wagty")}
|
||||
value={record.issuedAt}
|
||||
/>
|
||||
</Section>
|
||||
|
||||
<ConfirmDialog
|
||||
open={showDeleteDialog}
|
||||
onOpenChange={setShowDeleteDialog}
|
||||
title={t("loanPaidOffLetters.deleteConfirm", "Bu ýazgy pozulsynmy?")}
|
||||
confirmLabel={t("common.delete", "Poz")}
|
||||
onConfirm={confirmDelete}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,18 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { LoanRemainingForm } from '@/features/loanRemaining/components/LoanRemainingForm'
|
||||
|
||||
export default function LoanRemainingCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('loanRemaining.create.title', 'Täze karz galyndysy')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<LoanRemainingForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <LoanRemainingForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { LoanRemainingForm } from '@/features/loanRemaining/components/LoanRemainingForm'
|
||||
import { useLoanRemainingById } from '@/features/loanRemaining/hooks/useLoanRemaining'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
function LoanRemainingEditSkeleton() {
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<Skeleton className="h-8 w-64" />
|
||||
<div className="bg-card border border-border rounded-xl p-6 h-[250px]">
|
||||
<Skeleton className="h-full w-full" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function LoanRemainingEditPage() {
|
||||
const { t } = useTranslation()
|
||||
@@ -21,25 +11,8 @@ export default function LoanRemainingEditPage() {
|
||||
|
||||
const { data, isLoading } = useLoanRemainingById(id)
|
||||
|
||||
if (isLoading) return <LoanRemainingEditSkeleton />
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-64 text-muted-foreground">
|
||||
{t('common.notFound', 'Tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t('loanRemaining.edit.title', 'Karz galyndysyny üýtget')}: {data.id}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<LoanRemainingForm mode="edit" initialData={data} loanRemainingId={id} />
|
||||
</div>
|
||||
)
|
||||
return <LoanRemainingForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardTypeForm } from '@/features/cardTypes/components/cardTypesForm'
|
||||
|
||||
export default function CardTypeCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('cardTypes.create.title', 'Kart görnüşi döretmek')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<CardTypeForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <CardTypeForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,46 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CardTypeForm } from '@/features/cardTypes/components/cardTypesForm'
|
||||
import { useCardTypeById } from '@/features/cardTypes/hooks/useCardTypes'
|
||||
|
||||
export default function CardTypeEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading, isError } = useCardTypeById(numericId)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6">
|
||||
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? '...'
|
||||
: `${t('cardTypes.edit.title', 'Kart görnüşini üýtgetmek')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="grid grid-cols-[220px_1fr] items-center py-3 px-4 border-b border-border last:border-0"
|
||||
>
|
||||
<div className="h-4 w-24 bg-muted rounded animate-pulse" />
|
||||
<div className="h-8 w-full bg-muted rounded animate-pulse" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : isError || !data ? (
|
||||
<div className="flex items-center justify-center py-20 text-destructive text-sm">
|
||||
{t('common.error', 'Ýalňyşlyk ýüze çykdy')}
|
||||
</div>
|
||||
) : (
|
||||
<CardTypeForm mode="edit" initialData={data} cardTypeId={numericId} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
return <CardTypeForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardReasonForm } from '@/features/cardReasons/components/reasonForm'
|
||||
|
||||
export function CardReasonCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6">
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('CardReasons.create.title', 'Kartyň çykarylmagynyň sebäbi dörediň')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<CardReasonForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
export default function CardReasonCreatePage() {
|
||||
return <CardReasonForm mode="create" />
|
||||
}
|
||||
|
||||
export default CardReasonCreatePage
|
||||
|
||||
@@ -1,49 +1,18 @@
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { CardReasonForm } from "@/features/cardReasons/components/reasonForm";
|
||||
import { useCardReasonById } from "@/features/cardReasons/hooks/useCardReasons";
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { CardReasonForm } from '@/features/cardReasons/components/reasonForm'
|
||||
import { useCardReasonById } from '@/features/cardReasons/hooks/useCardReasons'
|
||||
|
||||
// ─── CardReasonEditPage ────────────────────────────────────────────────────────
|
||||
export default function CardReasonEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading } = useCardReasonById(numericId)
|
||||
|
||||
export function CardReasonEditPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { t } = useTranslation();
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
const numericId = Number(id);
|
||||
const { data, isLoading } = useCardReasonById(numericId);
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6">
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? "..."
|
||||
: `${t("CardReasons.edit.title", "Kartyň çykarylmagynyň sebäbini üýtgetmek")}: ${data?.name.tk ?? ""}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="grid grid-cols-[220px_1fr] items-center py-3 px-4 border-b border-border last:border-0"
|
||||
>
|
||||
<div className="h-4 w-24 bg-muted rounded animate-pulse" />
|
||||
<div className="h-8 w-full bg-muted rounded animate-pulse" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<CardReasonForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
CardReasonId={numericId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
return <CardReasonForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
export default CardReasonEditPage
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
// pages/LoanTypeCreatePage.tsx
|
||||
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { LoanTypeForm } from '@/features/loanTypes/components/loanTypesForm'
|
||||
|
||||
export default function LoanTypeCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{t('loanTypes.actions.create', 'Karz görnüşi dörediň')}
|
||||
</h1>
|
||||
|
||||
<LoanTypeForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <LoanTypeForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,47 +1,18 @@
|
||||
// pages/LoanTypeEditPage.tsx
|
||||
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { LoanTypeForm } from '@/features/loanTypes/components/loanTypesForm'
|
||||
import { useGetLoanTypeById } from '@/features/loanTypes/hooks/useLoanTypes'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function LoanTypeEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const loanTypeId = Number(id)
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading, isError } = useGetLoanTypeById(numericId)
|
||||
|
||||
const { data, isLoading, isError } = useGetLoanTypeById(loanTypeId)
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{isLoading
|
||||
? t('common.loading', 'Ýüklenýär...')
|
||||
: `${t('loanTypes.editTitle', 'Karz görnüşi redaktirle')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center px-4 py-3">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-8 w-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : isError ? (
|
||||
<div className="flex items-center justify-center py-20 text-destructive text-sm">
|
||||
{t('common.error', 'Ýalňyşlyk ýüze çykdy')}
|
||||
</div>
|
||||
) : (
|
||||
<LoanTypeForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
loanTypeId={loanTypeId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <LoanTypeForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { RequiredDocumentForm } from '@/features/requiredDocuments/components/requiredDocumentsForm'
|
||||
|
||||
export default function RequiredDocumentsCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{t('loanDocuments.createBtn', 'Karz gerekli resminamalary dörediň')}
|
||||
</h1>
|
||||
|
||||
<RequiredDocumentForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <RequiredDocumentForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,47 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { RequiredDocumentForm } from '@/features/requiredDocuments/components/requiredDocumentsForm'
|
||||
import { useGetRequiredDocumentById } from '@/features/requiredDocuments/hooks/useRequiredDocuments'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function RequiredDocumentsEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const documentId = Number(id)
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading, isError } = useGetRequiredDocumentById(numericId)
|
||||
|
||||
const { data, isLoading, isError } = useGetRequiredDocumentById(documentId)
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
return (
|
||||
<div >
|
||||
<h1 className="text-xl font-semibold text-foreground mb-5">
|
||||
{isLoading
|
||||
? t('common.loading', 'Ýüklenýär...')
|
||||
: `${t('loanDocuments.editTitle', 'Karz gerekli resminamalary redaktirle')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 2 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-start px-4 py-4">
|
||||
<Skeleton className="h-4 w-24 mt-2" />
|
||||
<div>
|
||||
<Skeleton className="h-10 w-full mb-2" />
|
||||
<Skeleton className="h-32 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : isError ? (
|
||||
<div className="flex items-center justify-center py-20 text-destructive text-sm">
|
||||
{t('common.error', 'Ýalňyşlyk ýüze çykdy')}
|
||||
</div>
|
||||
) : (
|
||||
<RequiredDocumentForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
requiredDocumentId={documentId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
return <RequiredDocumentForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { BranchForm } from '@/features/branches/components/branchesForm'
|
||||
|
||||
export default function BranchCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div >
|
||||
<div className="mb-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('branches.create.title', 'Şahamça döretmek')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<BranchForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <BranchForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,40 +1,18 @@
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PageSpinner } from "@/components/pageSpinner";
|
||||
import { PageError } from "@/components/pageError";
|
||||
import { BranchForm } from "@/features/branches/components/branchesForm";
|
||||
import { useBranchById } from "@/features/branches/hooks/useBranches";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
export default function BranchEditPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const numericId = Number(id);
|
||||
const { data, isLoading, isError } = useBranchById(numericId);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? "..."
|
||||
: `${t("branches.edit.title", "Şahamçany üýtgetmek")}: ${data?.name.tk ?? ""}`}
|
||||
</h1>
|
||||
</div>
|
||||
if (isLoading) return <PageSpinner />;
|
||||
if (isError || !data) return <PageError message={t("common.error", "Maglumat ýüklenilmedi")} />;
|
||||
|
||||
{isLoading ? (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Loader2 className="animate-spin text-muted-foreground" size={32} />
|
||||
</div>
|
||||
) : isError || !data ? (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<p className="text-sm text-destructive">
|
||||
{t("common.error", "Maglumat ýüklenilmedi. Sahypany täzeleläň.")}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<BranchForm mode="edit" initialData={data} branchId={numericId} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
return <BranchForm mode="edit" initialData={data} />;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { DistrictForm } from '@/features/districts/components/districtsForm'
|
||||
|
||||
export default function DistrictCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div >
|
||||
<div className="mb-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('districts.create.title', 'Etrap döretmek')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<DistrictForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <DistrictForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,46 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { DistrictForm } from '@/features/districts/components/districtsForm'
|
||||
import { useDistrictById } from '@/features/districts/hooks/useDistricts'
|
||||
|
||||
export default function DistrictEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading, isError } = useDistrictById(numericId)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6">
|
||||
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !data) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? '...'
|
||||
: `${t('districts.edit.title', 'Etrapy üýtgetmek')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="grid grid-cols-[220px_1fr] items-center py-3 px-4 border-b border-border last:border-0"
|
||||
>
|
||||
<div className="h-4 w-24 bg-muted rounded animate-pulse" />
|
||||
<div className="h-8 w-full bg-muted rounded animate-pulse" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : isError || !data ? (
|
||||
<div className="flex items-center justify-center py-20 text-destructive text-sm">
|
||||
{t('common.error', 'Ýalňyşlyk ýüze çykdy')}
|
||||
</div>
|
||||
) : (
|
||||
<DistrictForm mode="edit" initialData={data} districtId={numericId} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
return <DistrictForm mode="edit" initialData={data} />
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { RoleForm } from '@/features/roles/components/roleForm'
|
||||
|
||||
export default function RoleCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||
{t('roles.actions.create', 'Rol dörediň')}
|
||||
</h1>
|
||||
<RoleForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <RoleForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,46 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { RoleForm } from '@/features/roles/components/roleForm'
|
||||
import { useRole } from '@/features/roles/hooks/useRoles'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function RoleEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const roleId = Number(id)
|
||||
|
||||
const { data: role, isLoading, isError } = useRole(roleId)
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div>
|
||||
<Skeleton className="h-8 w-48 mb-6" />
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center p-5">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-9 w-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !role) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
if (isError || !role) {
|
||||
return (
|
||||
<p className="text-destructive text-sm">
|
||||
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||
{t('roles.editTitle', 'Rol üýtget')}: {role.name?.tk}
|
||||
</h1>
|
||||
<RoleForm mode="edit" initialData={role} roleId={roleId} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <RoleForm mode="edit" initialData={role} />
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PermissionForm } from '@/features/permissions/components/permissionsForm'
|
||||
|
||||
export default function PermissionCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||
{t('permissions.actions.create', 'Rugsat dörediň')}
|
||||
</h1>
|
||||
<PermissionForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <PermissionForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,46 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { PermissionForm } from '@/features/permissions/components/permissionsForm'
|
||||
import { usePermission } from '@/features/permissions/hooks/usePermissions'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function PermissionEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const permissionId = Number(id)
|
||||
const numericId = Number(id)
|
||||
const { data: permission, isLoading, isError } = usePermission(numericId)
|
||||
|
||||
const { data: permission, isLoading, isError } = usePermission(permissionId)
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !permission) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div>
|
||||
<Skeleton className="h-8 w-56 mb-6" />
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center p-5">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-9 w-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !permission) {
|
||||
return (
|
||||
<p className="text-destructive text-sm">
|
||||
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||
{t('permissions.editTitle', 'Rugsaty üýtget')}: {permission.name?.tk}
|
||||
</h1>
|
||||
<PermissionForm mode="edit" initialData={permission} permissionId={permissionId} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <PermissionForm mode="edit" initialData={permission} />
|
||||
}
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { UserForm } from '@/features/allUsers/components/allUsersForm'
|
||||
|
||||
// ─── UserCreatePage ───────────────────────────────────────────────────────────
|
||||
|
||||
export default function UserCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div >
|
||||
|
||||
{/* Title */}
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('users.actions.create', 'Ulanyjy dörediň')}
|
||||
</h1>
|
||||
|
||||
{/* Shared form — create mode */}
|
||||
<UserForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <UserForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,45 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { UserForm } from '@/features/allUsers/components/allUsersForm'
|
||||
import { useUser } from '@/features/allUsers/hooks/useAllUsers'
|
||||
|
||||
// ─── UserEditPage ─────────────────────────────────────────────────────────────
|
||||
|
||||
export default function UserEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const userId = Number(id)
|
||||
const numericId = Number(id)
|
||||
const { data: user, isLoading, isError } = useUser(numericId)
|
||||
|
||||
const { data: user, isLoading, isError } = useUser(userId)
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (isError || !user) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[300px]">
|
||||
<Loader2 size={24} className="animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !user) {
|
||||
return (
|
||||
<div className="p-6 text-center text-muted-foreground">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4 max-w-4xl">
|
||||
|
||||
|
||||
{/* Title */}
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('users.editTitle', 'Ulanyjy giňişleýin')}: {user.name} ({user.username})
|
||||
</h1>
|
||||
|
||||
{/* Shared form — edit mode, passes fetched data */}
|
||||
<UserForm mode="edit" initialData={user} userId={userId} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <UserForm mode="edit" initialData={user} />
|
||||
}
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { ClientForm } from '@/features/clients/components/clientForm'
|
||||
|
||||
export default function ClientCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div >
|
||||
|
||||
|
||||
{/* Page heading */}
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('clients.createTitle', 'Müşderi dörediň')}
|
||||
</h1>
|
||||
|
||||
<ClientForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
return <ClientForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,37 +1,18 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { ClientForm } from '@/features/clients/components/clientForm'
|
||||
import { useClient } from '@/features/clients/hooks/useClients'
|
||||
|
||||
export default function ClientEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const clientId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
const numericId = Number(id)
|
||||
const { data: client, isLoading } = useClient(numericId)
|
||||
|
||||
const { data: client, isLoading } = useClient(clientId)
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!client) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
|
||||
{/* Page heading */}
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('clients.editTitle', 'Müşderi üýtget')}: {client?.name ?? ''}
|
||||
</h1>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<div key={i} className="h-14 bg-muted rounded-xl animate-pulse" />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<ClientForm
|
||||
mode="edit"
|
||||
initialData={client}
|
||||
clientId={clientId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
return <ClientForm mode="edit" initialData={client} />
|
||||
}
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
// ─── OperatorCreatePage.tsx ───────────────────────────────────────────────────
|
||||
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { OperatorForm } from '@/features/operators/components/operatorForms'
|
||||
|
||||
export default function OperatorCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Page heading */}
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('operators.createTitle', 'Operator döredin')}
|
||||
</h1>
|
||||
|
||||
<OperatorForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <OperatorForm mode="create" />
|
||||
}
|
||||
|
||||
@@ -1,37 +1,18 @@
|
||||
// ─── OperatorEditPage.tsx ─────────────────────────────────────────────────────
|
||||
|
||||
import { useParams, } from 'react-router-dom'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PageSpinner } from '@/components/pageSpinner'
|
||||
import { PageError } from '@/components/pageError'
|
||||
import { OperatorForm } from '@/features/operators/components/operatorForms'
|
||||
import { useOperator } from '@/features/operators/hooks/useOperators'
|
||||
|
||||
export default function OperatorEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const operatorId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
const numericId = Number(id)
|
||||
const { data: operator, isLoading } = useOperator(numericId)
|
||||
|
||||
const { data: operator, isLoading } = useOperator(operatorId)
|
||||
if (isLoading) return <PageSpinner />
|
||||
if (!operator) return <PageError message={t('common.notFound', 'Tapylmady')} />
|
||||
|
||||
return (
|
||||
<div >
|
||||
{/* Page heading */}
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('operators.editTitle', 'Operator üýtget')}: {operator?.name ?? ''}
|
||||
</h1>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<div key={i} className="h-14 bg-muted rounded-xl animate-pulse" />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<OperatorForm
|
||||
mode="edit"
|
||||
initialData={operator}
|
||||
operatorId={operatorId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <OperatorForm mode="edit" initialData={operator} />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user