refactored some view pages
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState, useCallback, useMemo, useEffect } from 'react'
|
||||
import { useCallback, useMemo, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
@@ -6,6 +6,7 @@ import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { MultiLangInput } from '@/components/multiLangInput'
|
||||
import type { CardReason } from '../api/cardReasonsApi'
|
||||
import { useCreateCardReason, useUpdateCardReason } from '../hooks/useCardReasons'
|
||||
import { createCardReasonFormSchema, DEFAULT_FORM_VALUES, buildPayload } from '../schemas/cardReason.schema'
|
||||
@@ -24,17 +25,6 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
return result
|
||||
}
|
||||
|
||||
type FormErrors = FlatErrors
|
||||
|
||||
// ─── Lang Tab ─────────────────────────────────────────────────────────────────
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
|
||||
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||
{ key: 'tk', label: 'Türkmen' },
|
||||
{ key: 'ru', label: 'Русский' },
|
||||
{ key: 'en', label: 'English' },
|
||||
]
|
||||
|
||||
// ─── CardReasonForm ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -79,8 +69,6 @@ export function CardReasonForm({ mode, initialData }: CardReasonFormProps) {
|
||||
const form = watch()
|
||||
const errors = useMemo(() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>), [rhfErrors])
|
||||
|
||||
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||
|
||||
const set = useCallback(<K extends keyof CardReasonFormData>(key: K, value: CardReasonFormData[K]) => {
|
||||
(setValue as (name: K, val: CardReasonFormData[K]) => void)(key, value)
|
||||
clearErrors(key)
|
||||
@@ -111,11 +99,11 @@ export function CardReasonForm({ mode, initialData }: CardReasonFormProps) {
|
||||
}
|
||||
}
|
||||
|
||||
const nameFieldKey = `name${activeLang.charAt(0).toUpperCase() + activeLang.slice(1)}` as
|
||||
| 'nameTk'
|
||||
| 'nameRu'
|
||||
| 'nameEn'
|
||||
const nameErrorKey = nameFieldKey as keyof FormErrors
|
||||
const nameFields = {
|
||||
tk: { value: form.nameTk, onChange: (v: string) => set('nameTk', v), error: errors.nameTk },
|
||||
ru: { value: form.nameRu, onChange: (v: string) => set('nameRu', v), error: errors.nameRu },
|
||||
en: { value: form.nameEn, onChange: (v: string) => set('nameEn', v), error: errors.nameEn },
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
@@ -125,39 +113,15 @@ export function CardReasonForm({ mode, initialData }: CardReasonFormProps) {
|
||||
: t('reasons.editTitle', 'Sebäp üýtgetmek')}
|
||||
</h1>
|
||||
<div>
|
||||
{/* Language tabs */}
|
||||
<div className="flex gap-3 justify-end mb-4">
|
||||
{LANG_TABS.map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => setActiveLang(tab.key)}
|
||||
className={`text-sm transition-colors ${
|
||||
activeLang === tab.key
|
||||
? 'text-primary font-semibold underline underline-offset-4'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Form rows */}
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{/* Name row */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-center py-3 px-4 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-4 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground pt-2">
|
||||
{t('CardReasons.fields.name', 'Ady')}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</span>
|
||||
<FormInput
|
||||
type="text"
|
||||
value={form[nameFieldKey]}
|
||||
onChange={(v) => set(nameFieldKey, v)}
|
||||
placeholder={t('CardReasons.fields.name', 'Ady')}
|
||||
error={errors[nameErrorKey]}
|
||||
/>
|
||||
<MultiLangInput fields={nameFields} placeholder={t('CardReasons.fields.name', 'Ady')} disabled={isPending} />
|
||||
</div>
|
||||
|
||||
{/* Value row */}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useCallback, useMemo, useEffect } from 'react'
|
||||
import { useCallback, useMemo, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
@@ -6,6 +6,7 @@ import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { MultiLangInput } from '@/components/multiLangInput'
|
||||
import type { CardType } from '../api/cardTypesApi'
|
||||
import { useCreateCardType, useUpdateCardType } from '../hooks/useCardTypes'
|
||||
import { createCardTypeFormSchema, DEFAULT_FORM_VALUES, buildPayload } from '../schemas/cardType.schema'
|
||||
@@ -18,14 +19,6 @@ export interface CardTypeFormProps {
|
||||
initialData?: CardType
|
||||
}
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
|
||||
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||
{ key: 'tk', label: 'Türkmen' },
|
||||
{ key: 'ru', label: 'Русский' },
|
||||
{ key: 'en', label: 'English' },
|
||||
]
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function mapInitial(data: CardType): CardTypeFormData {
|
||||
@@ -65,8 +58,6 @@ export function CardTypeForm({ mode, initialData }: CardTypeFormProps) {
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||
|
||||
const schema = useMemo(() => createCardTypeFormSchema(t), [t, i18n.language])
|
||||
|
||||
const {
|
||||
@@ -121,11 +112,11 @@ export function CardTypeForm({ mode, initialData }: CardTypeFormProps) {
|
||||
}
|
||||
}, [mode, initialData, createMutation, updateMutation, navigate, trigger, getValues])
|
||||
|
||||
const nameFieldKey = `name${activeLang.charAt(0).toUpperCase() + activeLang.slice(1)}` as
|
||||
| 'nameTk'
|
||||
| 'nameRu'
|
||||
| 'nameEn'
|
||||
const nameErrorKey = nameFieldKey as keyof FlatErrors
|
||||
const nameFields = {
|
||||
tk: { value: form.nameTk, onChange: (v: string) => set('nameTk')(v), error: errors.nameTk },
|
||||
ru: { value: form.nameRu, onChange: (v: string) => set('nameRu')(v), error: errors.nameRu },
|
||||
en: { value: form.nameEn, onChange: (v: string) => set('nameEn')(v), error: errors.nameEn },
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
@@ -135,39 +126,15 @@ export function CardTypeForm({ mode, initialData }: CardTypeFormProps) {
|
||||
: 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) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => setActiveLang(tab.key)}
|
||||
className={`text-sm transition-colors ${
|
||||
activeLang === tab.key
|
||||
? 'text-primary font-semibold underline underline-offset-4'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Form rows */}
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{/* Name */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-center py-3 px-4 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-4 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground pt-2">
|
||||
{t('cardTypes.fields.name', 'Ady')}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</span>
|
||||
<FormInput
|
||||
type="text"
|
||||
value={form[nameFieldKey]}
|
||||
onChange={set(nameFieldKey)}
|
||||
placeholder={t('cardTypes.fields.name', 'Ady')}
|
||||
error={errors[nameErrorKey]}
|
||||
/>
|
||||
<MultiLangInput fields={nameFields} placeholder={t('cardTypes.fields.name', 'Ady')} disabled={isPending} />
|
||||
</div>
|
||||
|
||||
{/* Value */}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useCallback, useMemo, useEffect } from 'react'
|
||||
import { useCallback, useMemo, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
@@ -6,6 +6,7 @@ import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { MultiLangInput } from '@/components/multiLangInput'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { useCreateLoanType, useUpdateLoanType } from '../hooks/useLoanTypes'
|
||||
import type { LoanType } from '../api/loanTypesApi'
|
||||
@@ -46,16 +47,6 @@ function mapInitial(data: LoanType): LoanTypeFormData {
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Language Tab ─────────────────────────────────────────────────────────────
|
||||
|
||||
type Lang = 'tk' | 'ru' | 'en'
|
||||
|
||||
const LANG_TABS: { key: Lang; label: string }[] = [
|
||||
{ key: 'tk', label: 'Türkmen' },
|
||||
{ key: 'ru', label: 'Русский' },
|
||||
{ key: 'en', label: 'English' },
|
||||
]
|
||||
|
||||
// ─── LoanTypeForm ─────────────────────────────────────────────────────────────
|
||||
|
||||
export function LoanTypeForm({ mode, initialData }: LoanTypeFormProps) {
|
||||
@@ -69,9 +60,8 @@ export function LoanTypeForm({ mode, initialData }: LoanTypeFormProps) {
|
||||
const createMutation = useCreateLoanType()
|
||||
const updateMutation = useUpdateLoanType(initialData?.id ?? 0)
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const [activeLang, setActiveLang] = useState<Lang>('tk')
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const schema = useMemo(() => createLoanTypeFormSchema(t), [t, i18n.language])
|
||||
|
||||
@@ -128,13 +118,13 @@ export function LoanTypeForm({ mode, initialData }: LoanTypeFormProps) {
|
||||
const handleCancel = () => navigate('/resources/loan-types')
|
||||
|
||||
// ── Name fields per lang ───────────────────────────────────────────────────
|
||||
const nameFields: Record<Lang, { value: string; onChange: (v: string) => void; error?: string }> = {
|
||||
const nameFields = {
|
||||
tk: { value: form.nameTk, onChange: set('nameTk'), error: errors.nameTk },
|
||||
ru: { value: form.nameRu, onChange: set('nameRu'), error: errors.nameRu },
|
||||
en: { value: form.nameEn, onChange: set('nameEn'), error: errors.nameEn },
|
||||
}
|
||||
|
||||
const notesFields: Record<Lang, { value: string; onChange: (v: string) => void }> = {
|
||||
const notesFields = {
|
||||
tk: { value: form.notesTk ?? '', onChange: set('notesTk') },
|
||||
ru: { value: form.notesRu ?? '', onChange: set('notesRu') },
|
||||
en: { value: form.notesEn ?? '', onChange: set('notesEn') },
|
||||
@@ -150,39 +140,15 @@ export function LoanTypeForm({ mode, initialData }: LoanTypeFormProps) {
|
||||
: 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) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => setActiveLang(tab.key)}
|
||||
className={`px-3 py-1 text-sm rounded-md transition-colors ${
|
||||
activeLang === tab.key
|
||||
? 'text-primary font-semibold'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Form card */}
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{/* Ady */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-center px-4 py-3">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
<div className="grid grid-cols-[220px_1fr] items-start px-4 py-4">
|
||||
<span className="text-sm text-muted-foreground pt-2">
|
||||
{t('loanTypes.fields.name', 'Ady')}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</span>
|
||||
<FormInput
|
||||
type="text"
|
||||
value={nameFields[activeLang].value}
|
||||
onChange={nameFields[activeLang].onChange}
|
||||
placeholder={t('loanTypes.fields.name', 'Ady')}
|
||||
error={nameFields[activeLang].error}
|
||||
/>
|
||||
<MultiLangInput fields={nameFields} placeholder={t('loanTypes.fields.name', 'Ady')} disabled={isPending} />
|
||||
</div>
|
||||
|
||||
{/* Salgyt */}
|
||||
@@ -216,16 +182,11 @@ export function LoanTypeForm({ mode, initialData }: LoanTypeFormProps) {
|
||||
</div>
|
||||
|
||||
{/* Bellikler */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-center px-4 py-3">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
<div className="grid grid-cols-[220px_1fr] items-start px-4 py-4">
|
||||
<span className="text-sm text-muted-foreground pt-2">
|
||||
{t('loanTypes.fields.notes', 'Bellikler')}
|
||||
</span>
|
||||
<FormInput
|
||||
type="text"
|
||||
value={notesFields[activeLang].value}
|
||||
onChange={notesFields[activeLang].onChange}
|
||||
placeholder={t('loanTypes.fields.notes', 'Bellikler')}
|
||||
/>
|
||||
<MultiLangInput fields={notesFields} placeholder={t('loanTypes.fields.notes', 'Bellikler')} disabled={isPending} />
|
||||
</div>
|
||||
|
||||
{/* Işjeň */}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { useState, useMemo, useEffect, useCallback } from 'react'
|
||||
import { useMemo, useEffect, useCallback } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { MultiLangInput } from '@/components/multiLangInput'
|
||||
import { useCreatePermission, useUpdatePermission } from '../hooks/usePermissions'
|
||||
import { createPermissionFormSchema, DEFAULT_FORM_VALUES, buildPayload } from '../schemas/permission.schema'
|
||||
import type { PermissionFormData } from '../schemas/permission.schema'
|
||||
import type { Permission } from '../api/permissionsApi'
|
||||
|
||||
import { FormInput } from '@/components/formInput'
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface PermissionFormProps {
|
||||
@@ -17,14 +17,6 @@ interface PermissionFormProps {
|
||||
initialData?: Permission
|
||||
}
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
|
||||
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||
{ key: 'tk', label: 'Türkmen' },
|
||||
{ key: 'ru', label: 'Русский' },
|
||||
{ key: 'en', label: 'English' },
|
||||
]
|
||||
|
||||
const GUARD_OPTIONS = [
|
||||
{ value: 'web', label: 'web' },
|
||||
{ value: 'api', label: 'api' },
|
||||
@@ -57,8 +49,6 @@ export function PermissionForm({ mode, initialData }: PermissionFormProps) {
|
||||
|
||||
const isPending = createPermission.isPending || updatePermission.isPending
|
||||
|
||||
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||
|
||||
const schema = useMemo(() => createPermissionFormSchema(t), [t, i18n.language])
|
||||
|
||||
const {
|
||||
@@ -88,10 +78,10 @@ export function PermissionForm({ mode, initialData }: PermissionFormProps) {
|
||||
[setValue, clearErrors],
|
||||
)
|
||||
|
||||
const setNameField = (lang: LangKey, value: string) => {
|
||||
const key = `name${lang.charAt(0).toUpperCase() + lang.slice(1)}` as 'nameTk' | 'nameRu' | 'nameEn'
|
||||
setValue(key, value)
|
||||
clearErrors(key)
|
||||
const nameFields = {
|
||||
tk: { value: form.nameTk, onChange: (v: string) => { setValue('nameTk', v); clearErrors('nameTk'); }, error: errors.nameTk },
|
||||
ru: { value: form.nameRu, onChange: (v: string) => { setValue('nameRu', v); clearErrors('nameRu'); }, error: errors.nameRu },
|
||||
en: { value: form.nameEn, onChange: (v: string) => { setValue('nameEn', v); clearErrors('nameEn'); }, error: errors.nameEn },
|
||||
}
|
||||
|
||||
// ── Re-validate on language change ──
|
||||
@@ -122,9 +112,6 @@ export function PermissionForm({ mode, initialData }: PermissionFormProps) {
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const activeNameKey = `name${activeLang.charAt(0).toUpperCase() + activeLang.slice(1)}` as 'nameTk' | 'nameRu' | 'nameEn'
|
||||
const nameError = errors[activeNameKey]
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
@@ -156,32 +143,7 @@ export function PermissionForm({ mode, initialData }: PermissionFormProps) {
|
||||
{t('permissions.fields.name', 'Ady')}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</span>
|
||||
<div className="space-y-2">
|
||||
<div className="flex gap-1 justify-end">
|
||||
{LANG_TABS.map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => setActiveLang(tab.key)}
|
||||
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||
activeLang === tab.key
|
||||
? 'text-primary border-b-2 border-primary'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
value={form[activeNameKey]}
|
||||
onChange={(v) => setNameField(activeLang, v)}
|
||||
placeholder={t('permissions.fields.name', 'Ady')}
|
||||
error={nameError}
|
||||
disabled={isPending}
|
||||
/>
|
||||
</div>
|
||||
<MultiLangInput fields={nameFields} placeholder={t('permissions.fields.name', 'Ady')} disabled={isPending} />
|
||||
</div>
|
||||
|
||||
{/* Guard name */}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { useState, useMemo, useEffect, useCallback } from 'react'
|
||||
import { useMemo, useEffect, useCallback } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { MultiLangInput } from '@/components/multiLangInput'
|
||||
import { useCreateRole, useUpdateRole } from '../hooks/useRoles'
|
||||
import { createRoleFormSchema, DEFAULT_FORM_VALUES, buildPayload } from '../schemas/role.schema'
|
||||
import type { RoleFormData } from '../schemas/role.schema'
|
||||
import type { Role } from '../api/rolesApi'
|
||||
|
||||
import { FormInput } from '@/components/formInput'
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface RoleFormProps {
|
||||
@@ -17,14 +17,6 @@ interface RoleFormProps {
|
||||
initialData?: Role
|
||||
}
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
|
||||
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||
{ key: 'tk', label: 'Türkmen' },
|
||||
{ key: 'ru', label: 'Русский' },
|
||||
{ key: 'en', label: 'English' },
|
||||
]
|
||||
|
||||
const GUARD_OPTIONS = [
|
||||
{ value: 'web', label: 'web' },
|
||||
{ value: 'api', label: 'api' },
|
||||
@@ -57,8 +49,6 @@ export function RoleForm({ mode, initialData }: RoleFormProps) {
|
||||
|
||||
const isPending = createRole.isPending || updateRole.isPending
|
||||
|
||||
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||
|
||||
const schema = useMemo(() => createRoleFormSchema(t), [t, i18n.language])
|
||||
|
||||
const {
|
||||
@@ -88,10 +78,10 @@ export function RoleForm({ mode, initialData }: RoleFormProps) {
|
||||
[setValue, clearErrors],
|
||||
)
|
||||
|
||||
const setNameField = (lang: LangKey, value: string) => {
|
||||
const key = `name${lang.charAt(0).toUpperCase() + lang.slice(1)}` as 'nameTk' | 'nameRu' | 'nameEn'
|
||||
setValue(key, value)
|
||||
clearErrors(key)
|
||||
const nameFields = {
|
||||
tk: { value: form.nameTk, onChange: (v: string) => { setValue('nameTk', v); clearErrors('nameTk'); }, error: errors.nameTk },
|
||||
ru: { value: form.nameRu, onChange: (v: string) => { setValue('nameRu', v); clearErrors('nameRu'); }, error: errors.nameRu },
|
||||
en: { value: form.nameEn, onChange: (v: string) => { setValue('nameEn', v); clearErrors('nameEn'); }, error: errors.nameEn },
|
||||
}
|
||||
|
||||
// ── Re-validate on language change ──
|
||||
@@ -122,9 +112,6 @@ export function RoleForm({ mode, initialData }: RoleFormProps) {
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const activeNameKey = `name${activeLang.charAt(0).toUpperCase() + activeLang.slice(1)}` as 'nameTk' | 'nameRu' | 'nameEn'
|
||||
const nameError = activeLang === 'tk' ? errors[activeNameKey] : undefined
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
@@ -156,32 +143,7 @@ export function RoleForm({ mode, initialData }: RoleFormProps) {
|
||||
{t('roles.fields.name', 'Ady')}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</span>
|
||||
<div className="space-y-2">
|
||||
<div className="flex gap-1 justify-end">
|
||||
{LANG_TABS.map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => setActiveLang(tab.key)}
|
||||
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||
activeLang === tab.key
|
||||
? 'text-primary border-b-2 border-primary'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
value={form[activeNameKey]}
|
||||
onChange={(v) => setNameField(activeLang, v)}
|
||||
placeholder={t('roles.fields.name', 'Ady')}
|
||||
error={nameError}
|
||||
disabled={isPending}
|
||||
/>
|
||||
</div>
|
||||
<MultiLangInput fields={nameFields} placeholder={t('roles.fields.name', 'Ady')} disabled={isPending} />
|
||||
</div>
|
||||
|
||||
{/* Guard name */}
|
||||
|
||||
Reference in New Issue
Block a user