rofactored edit and create pages

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

View File

@@ -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>
)
}