rofactored edit and create pages

This commit is contained in:
@jcarymuhammedow committed 2026-05-21 19:11:36 +05:00
1 parent 2f13d424e1
commit 4adc153503
79 files changed
+1663 -2333

No files matched your search

@@ -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...'}