feat(i18n): localize assignment validation messages
This commit is contained in:
@@ -42,6 +42,7 @@ export default async function EditAssignmentPage({
|
||||
assets={assets}
|
||||
initialData={assignment as UpdateAssignmentFormType}
|
||||
formCopy={copy.form}
|
||||
schemaCopy={copy.schema}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -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 { updateAssignment } from "@/actions/assignment.actions"
|
||||
@@ -11,12 +12,13 @@ import {
|
||||
} from "@/components/forms/submitButton"
|
||||
import type { Dictionary } from "@/i18n/dictionaries"
|
||||
import {
|
||||
buildUpdateAssignmentSchema,
|
||||
type UpdateAssignmentFormType,
|
||||
updateAssignmentSchema,
|
||||
} from "@/schemas/assignment.schema"
|
||||
import type { Asset, Item, Recipient } from "@/types"
|
||||
|
||||
type AssignmentFormCopy = Dictionary["inventory"]["assignments"]["form"]
|
||||
type AssignmentSchemaCopy = Dictionary["inventory"]["assignments"]["schema"]
|
||||
|
||||
interface Props {
|
||||
recipients: Recipient[]
|
||||
@@ -24,6 +26,7 @@ interface Props {
|
||||
assets: Asset[]
|
||||
initialData: UpdateAssignmentFormType
|
||||
formCopy: AssignmentFormCopy
|
||||
schemaCopy: AssignmentSchemaCopy
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}
|
||||
|
||||
@@ -33,17 +36,23 @@ export default function EditAssignmentForm({
|
||||
assets,
|
||||
initialData,
|
||||
formCopy,
|
||||
schemaCopy,
|
||||
submitButtonCopy,
|
||||
}: Props) {
|
||||
const router = useRouter()
|
||||
|
||||
const schema = useMemo(
|
||||
() => buildUpdateAssignmentSchema(schemaCopy),
|
||||
[schemaCopy],
|
||||
)
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors, isSubmitting, isSubmitSuccessful },
|
||||
watch,
|
||||
} = useForm<UpdateAssignmentFormType>({
|
||||
resolver: zodResolver(updateAssignmentSchema),
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
...initialData,
|
||||
id: initialData.id || undefined,
|
||||
|
||||
@@ -12,18 +12,20 @@ import {
|
||||
} from "@/components/forms/submitButton"
|
||||
import type { Dictionary } from "@/i18n/dictionaries"
|
||||
import {
|
||||
buildCreateAssignmentSchema,
|
||||
type CreateAssignmentFormType,
|
||||
createAssignmentSchema,
|
||||
} from "@/schemas/assignment.schema"
|
||||
import type { Asset, Item, Recipient } from "@/types"
|
||||
|
||||
type AssignmentFormCopy = Dictionary["inventory"]["assignments"]["form"]
|
||||
type AssignmentSchemaCopy = Dictionary["inventory"]["assignments"]["schema"]
|
||||
|
||||
interface Props {
|
||||
recipients: Recipient[]
|
||||
items: Item[]
|
||||
assets: Asset[]
|
||||
formCopy: AssignmentFormCopy
|
||||
schemaCopy: AssignmentSchemaCopy
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}
|
||||
|
||||
@@ -32,17 +34,23 @@ export default function CreateAssignmentForm({
|
||||
items,
|
||||
assets,
|
||||
formCopy,
|
||||
schemaCopy,
|
||||
submitButtonCopy,
|
||||
}: Props) {
|
||||
const router = useRouter()
|
||||
|
||||
const schema = useMemo(
|
||||
() => buildCreateAssignmentSchema(schemaCopy),
|
||||
[schemaCopy],
|
||||
)
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors, isSubmitting, isSubmitSuccessful },
|
||||
watch,
|
||||
} = useForm<CreateAssignmentFormType>({
|
||||
resolver: zodResolver(createAssignmentSchema),
|
||||
resolver: zodResolver(schema),
|
||||
mode: "onSubmit",
|
||||
})
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ export default async function NewAssignmentPage() {
|
||||
items={items}
|
||||
assets={assets}
|
||||
formCopy={copy.form}
|
||||
schemaCopy={copy.schema}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user