added lang support to create pages
This commit is contained in:
1 parent
35164d16d3
commit
a0ed9a702c
34 files changed
+1456
-639
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useMemo } from 'react'
|
||||
import { useCallback, useEffect, useMemo } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
useUpdateVisaMasterSetting,
|
||||
} from '../hooks/useVisaMasterSettings'
|
||||
import {
|
||||
visaMasterSettingFormSchema,
|
||||
createVisaMasterSettingFormSchema,
|
||||
DEFAULT_FORM_VALUES,
|
||||
buildPayload,
|
||||
} from '../schemas/visaMasterSberSetting.schema'
|
||||
@@ -56,7 +56,11 @@ export function VisaMasterSettingForm({
|
||||
initialData,
|
||||
settingId,
|
||||
}: VisaMasterSettingFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t],
|
||||
)
|
||||
|
||||
const errMsg = (msg: string | undefined) =>
|
||||
!msg ? undefined : msg.startsWith('validation.') ? t(msg, msg) : msg
|
||||
@@ -67,6 +71,12 @@ export function VisaMasterSettingForm({
|
||||
|
||||
const isPending = createMutation.isPending || updateMutation.isPending
|
||||
|
||||
const schema = useMemo(
|
||||
() => createVisaMasterSettingFormSchema(t),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[i18n.language],
|
||||
)
|
||||
|
||||
const {
|
||||
watch,
|
||||
setValue,
|
||||
@@ -75,7 +85,7 @@ export function VisaMasterSettingForm({
|
||||
trigger,
|
||||
getValues,
|
||||
} = useForm<VisaMasterSettingFormData>({
|
||||
resolver: zodResolver(visaMasterSettingFormSchema),
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: initialData
|
||||
? { ...DEFAULT_FORM_VALUES, ...mapInitial(initialData) }
|
||||
: DEFAULT_FORM_VALUES,
|
||||
@@ -87,6 +97,13 @@ export function VisaMasterSettingForm({
|
||||
[rhfErrors],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (Object.keys(rhfErrors).length > 0) {
|
||||
trigger()
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [i18n.language])
|
||||
|
||||
const set = useCallback(
|
||||
(key: keyof VisaMasterSettingFormData) => (value: string) => {
|
||||
setValue(key, value)
|
||||
@@ -111,7 +128,7 @@ export function VisaMasterSettingForm({
|
||||
await updateMutation.mutateAsync(payload)
|
||||
navigate('/resources/visa-master-settings')
|
||||
}
|
||||
}, [mode, createMutation, updateMutation, navigate, trigger, getValues])
|
||||
}, [mode, createMutation, updateMutation, navigate, trigger, getValues, t])
|
||||
|
||||
const handleCancel = () => navigate('/resources/visa-master-settings')
|
||||
|
||||
|
||||
Reference in new issue
Block a user