feat(i18n): localize item validation messages
This commit is contained in:
@@ -33,6 +33,7 @@ export default async function AddItem({
|
||||
categories={categories}
|
||||
item={item}
|
||||
formCopy={copy.form}
|
||||
schemaCopy={copy.schema}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Dictionary } from "@/i18n/dictionaries"
|
||||
import type { ItemSchemaCopy } from "@/schemas/item.schema"
|
||||
|
||||
export type ItemListCopy = Dictionary["inventory"]["items"]["list"]
|
||||
export type ItemDetailCopy = Dictionary["inventory"]["items"]["detail"]
|
||||
export type ItemFormCopy = Dictionary["inventory"]["items"]["form"]
|
||||
export type ItemDeleteCopy = Dictionary["inventory"]["items"]["delete"]
|
||||
export type { ItemSchemaCopy }
|
||||
|
||||
@@ -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 { createItemAction } from "@/actions/item.actions"
|
||||
@@ -10,23 +11,26 @@ import {
|
||||
type SubmitButtonCopy,
|
||||
} from "@/components/forms/submitButton"
|
||||
import {
|
||||
buildCreateItemSchema,
|
||||
type CreateItemFormType,
|
||||
createItemSchema,
|
||||
} from "@/schemas/item.schema"
|
||||
import type { CategorySummary } from "@/types"
|
||||
|
||||
import type { ItemFormCopy } from "./item.copy"
|
||||
import type { ItemFormCopy, ItemSchemaCopy } from "./item.copy"
|
||||
|
||||
export default function NewItemForm({
|
||||
categories,
|
||||
formCopy,
|
||||
schemaCopy,
|
||||
submitButtonCopy,
|
||||
}: {
|
||||
categories: CategorySummary[]
|
||||
formCopy: ItemFormCopy
|
||||
schemaCopy: ItemSchemaCopy
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const schema = useMemo(() => buildCreateItemSchema(schemaCopy), [schemaCopy])
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -34,7 +38,7 @@ export default function NewItemForm({
|
||||
setError,
|
||||
formState: { errors, isSubmitting, isSubmitSuccessful },
|
||||
} = useForm<CreateItemFormType>({
|
||||
resolver: zodResolver(createItemSchema),
|
||||
resolver: zodResolver(schema),
|
||||
shouldFocusError: true,
|
||||
mode: "onSubmit",
|
||||
})
|
||||
|
||||
@@ -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 { updateItemAction } from "@/actions/item.actions"
|
||||
@@ -10,25 +11,28 @@ import {
|
||||
type SubmitButtonCopy,
|
||||
} from "@/components/forms/submitButton"
|
||||
import {
|
||||
buildUpdateItemSchema,
|
||||
type UpdateItemFormType,
|
||||
updateItemSchema,
|
||||
} from "@/schemas/item.schema"
|
||||
import type { CategorySummary, ItemWithAssetCount } from "@/types"
|
||||
|
||||
import type { ItemFormCopy } from "./item.copy"
|
||||
import type { ItemFormCopy, ItemSchemaCopy } from "./item.copy"
|
||||
|
||||
export default function UpdateItemForm({
|
||||
categories,
|
||||
item,
|
||||
formCopy,
|
||||
schemaCopy,
|
||||
submitButtonCopy,
|
||||
}: {
|
||||
categories: CategorySummary[]
|
||||
item: ItemWithAssetCount
|
||||
formCopy: ItemFormCopy
|
||||
schemaCopy: ItemSchemaCopy
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const schema = useMemo(() => buildUpdateItemSchema(schemaCopy), [schemaCopy])
|
||||
|
||||
const isDisabled = !!item?._count.assets && item?._count.assets > 0
|
||||
|
||||
@@ -38,7 +42,7 @@ export default function UpdateItemForm({
|
||||
setError,
|
||||
formState: { errors, isSubmitting, isSubmitSuccessful },
|
||||
} = useForm<UpdateItemFormType>({
|
||||
resolver: zodResolver(updateItemSchema),
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
id: item?.id,
|
||||
name: item?.name,
|
||||
|
||||
@@ -16,6 +16,7 @@ export default async function NewItemPage() {
|
||||
<NewItemForm
|
||||
categories={categories}
|
||||
formCopy={copy.form}
|
||||
schemaCopy={copy.schema}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user