feat(i18n): localize recipient validation messages
This commit is contained in:
@@ -26,6 +26,7 @@ export default async function RecipientEditPage({
|
||||
initialData={recipient}
|
||||
mode="edit"
|
||||
formCopy={copy.form}
|
||||
schemaCopy={copy.schema}
|
||||
departmentCopy={copy.departments}
|
||||
fallbackCopy={copy.fallback}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useMemo } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { toast } from "sonner"
|
||||
import {
|
||||
@@ -14,8 +15,10 @@ import {
|
||||
} from "@/components/forms/submitButton"
|
||||
import { RECIPIENT_DEPARTMENTS } from "@/lib/constants"
|
||||
import {
|
||||
buildCreateRecipientSchema,
|
||||
buildUpdateRecipientSchema,
|
||||
type CreateRecipientFormType,
|
||||
recipientSchema,
|
||||
type RecipientSchemaCopy,
|
||||
type UpdateRecipientFormType,
|
||||
} from "@/schemas/recipient.schema"
|
||||
import type { Recipient } from "@/types"
|
||||
@@ -31,6 +34,7 @@ interface RecipientFormProps {
|
||||
initialData?: Recipient
|
||||
mode?: "create" | "edit"
|
||||
formCopy: RecipientFormCopy
|
||||
schemaCopy: RecipientSchemaCopy
|
||||
departmentCopy: RecipientDepartmentCopy
|
||||
fallbackCopy: RecipientFallbackCopy
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
@@ -40,11 +44,19 @@ export default function RecipientForm({
|
||||
initialData,
|
||||
mode = "create",
|
||||
formCopy,
|
||||
schemaCopy,
|
||||
departmentCopy,
|
||||
fallbackCopy,
|
||||
submitButtonCopy,
|
||||
}: RecipientFormProps) {
|
||||
const router = useRouter()
|
||||
const schema = useMemo(
|
||||
() =>
|
||||
mode === "create"
|
||||
? buildCreateRecipientSchema(schemaCopy)
|
||||
: buildUpdateRecipientSchema(schemaCopy),
|
||||
[mode, schemaCopy],
|
||||
)
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -52,7 +64,7 @@ export default function RecipientForm({
|
||||
setError,
|
||||
formState: { errors, isSubmitting, isSubmitSuccessful },
|
||||
} = useForm<CreateRecipientFormType>({
|
||||
resolver: zodResolver(recipientSchema),
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
id: initialData?.id || "",
|
||||
username: initialData?.username || "",
|
||||
|
||||
@@ -14,6 +14,7 @@ export default async function NewRecipientPage() {
|
||||
<RecipientForm
|
||||
mode="create"
|
||||
formCopy={copy.form}
|
||||
schemaCopy={copy.schema}
|
||||
departmentCopy={copy.departments}
|
||||
fallbackCopy={copy.fallback}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
|
||||
Reference in New Issue
Block a user