feat(i18n): localize submit button states
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use server"
|
||||
|
||||
import { getI18n } from "@/i18n/server"
|
||||
import { AssetService } from "@/services/asset.service"
|
||||
import { ItemService } from "@/services/item.service"
|
||||
import { RecipientService } from "@/services/recipient.service"
|
||||
@@ -16,6 +17,7 @@ export default async function EditAssetPage({
|
||||
const items = await ItemService.findAll()
|
||||
const recipients = await RecipientService.findAll()
|
||||
const asset = await AssetService.findById(assetId)
|
||||
const { dictionary } = await getI18n()
|
||||
|
||||
if (!asset) {
|
||||
return <div>Asset not found</div>
|
||||
@@ -30,6 +32,7 @@ export default async function EditAssetPage({
|
||||
items={items}
|
||||
recipients={recipients}
|
||||
asset={asset as unknown as AssetWithAssignment}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -5,7 +5,10 @@ import { useRouter } from "next/navigation"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { toast } from "sonner"
|
||||
import { updateAssetAction } from "@/actions/asset.actions"
|
||||
import { SubmitButton } from "@/components/forms/submitButton"
|
||||
import {
|
||||
SubmitButton,
|
||||
type SubmitButtonCopy,
|
||||
} from "@/components/forms/submitButton"
|
||||
import { ITEM_STATUS } from "@/lib/constants"
|
||||
import {
|
||||
type UpdateAssetFormType,
|
||||
@@ -22,12 +25,14 @@ interface EditAssetFormProps {
|
||||
asset: AssetWithAssignment
|
||||
items: Item[]
|
||||
recipients: Recipient[]
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}
|
||||
|
||||
export default function EditAssetForm({
|
||||
asset,
|
||||
items,
|
||||
recipients,
|
||||
submitButtonCopy,
|
||||
}: EditAssetFormProps) {
|
||||
const router = useRouter()
|
||||
|
||||
@@ -170,6 +175,7 @@ export default function EditAssetForm({
|
||||
</div>
|
||||
)}
|
||||
<SubmitButton
|
||||
copy={submitButtonCopy}
|
||||
isSubmitting={isSubmitting}
|
||||
isSubmitSuccessful={isSubmitSuccessful}
|
||||
>
|
||||
|
||||
@@ -5,7 +5,10 @@ import { useRouter } from "next/navigation"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { toast } from "sonner"
|
||||
import { createAssetAction } from "@/actions/asset.actions"
|
||||
import { SubmitButton } from "@/components/forms/submitButton"
|
||||
import {
|
||||
SubmitButton,
|
||||
type SubmitButtonCopy,
|
||||
} from "@/components/forms/submitButton"
|
||||
import { ITEM_STATUS } from "@/lib/constants"
|
||||
import {
|
||||
type CreateAssetFormType,
|
||||
@@ -16,9 +19,14 @@ import type { ItemWithoutStock, Recipient } from "@/types"
|
||||
interface NewAssetFormProps {
|
||||
items: ItemWithoutStock[]
|
||||
recipients: Recipient[]
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}
|
||||
|
||||
export default function NewAssetForm({ items, recipients }: NewAssetFormProps) {
|
||||
export default function NewAssetForm({
|
||||
items,
|
||||
recipients,
|
||||
submitButtonCopy,
|
||||
}: NewAssetFormProps) {
|
||||
const router = useRouter()
|
||||
|
||||
const {
|
||||
@@ -155,6 +163,7 @@ export default function NewAssetForm({ items, recipients }: NewAssetFormProps) {
|
||||
</div>
|
||||
)}
|
||||
<SubmitButton
|
||||
copy={submitButtonCopy}
|
||||
isSubmitting={isSubmitting}
|
||||
isSubmitSuccessful={isSubmitSuccessful}
|
||||
>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use server"
|
||||
|
||||
import { getI18n } from "@/i18n/server"
|
||||
import { ItemService } from "@/services/item.service"
|
||||
import { RecipientService } from "@/services/recipient.service"
|
||||
|
||||
@@ -8,13 +9,18 @@ import NewAssetForm from "../_components/new.asset.form"
|
||||
export default async function NewAssetPage() {
|
||||
const items = await ItemService.findAllAssignable()
|
||||
const recipients = await RecipientService.findAll()
|
||||
const { dictionary } = await getI18n()
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<h1 className="text-2xl font-bold">New Asset</h1>
|
||||
</div>
|
||||
<NewAssetForm items={items} recipients={recipients} />
|
||||
<NewAssetForm
|
||||
items={items}
|
||||
recipients={recipients}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { getI18n } from "@/i18n/server"
|
||||
import { CategoryService } from "@/services/category.service"
|
||||
|
||||
import EditCategoryForm from "../../_components/edit.category.form"
|
||||
@@ -11,6 +12,7 @@ export default async function EditCategoryPage({
|
||||
}) {
|
||||
const { categoryId } = await params
|
||||
const category = await CategoryService.findById(categoryId)
|
||||
const { dictionary } = await getI18n()
|
||||
|
||||
if (!category) {
|
||||
notFound()
|
||||
@@ -21,7 +23,10 @@ export default async function EditCategoryPage({
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<h1 className="text-2xl font-bold">Edit Category</h1>
|
||||
</div>
|
||||
<EditCategoryForm category={category} />
|
||||
<EditCategoryForm
|
||||
category={category}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ import { useRouter } from "next/navigation"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { toast } from "sonner"
|
||||
import { updateCategoryAction } from "@/actions/category.actions"
|
||||
import { SubmitButton } from "@/components/forms/submitButton"
|
||||
import {
|
||||
SubmitButton,
|
||||
type SubmitButtonCopy,
|
||||
} from "@/components/forms/submitButton"
|
||||
import {
|
||||
type UpdateCategoryFormType,
|
||||
updateCategorySchema,
|
||||
@@ -14,8 +17,10 @@ import type { CategorySummary } from "@/types"
|
||||
|
||||
export default function EditCategoryForm({
|
||||
category,
|
||||
submitButtonCopy,
|
||||
}: {
|
||||
category: CategorySummary
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}) {
|
||||
const router = useRouter()
|
||||
|
||||
@@ -73,6 +78,7 @@ export default function EditCategoryForm({
|
||||
{errors.name && <p className="text-error">{errors.name.message}</p>}
|
||||
</div>
|
||||
<SubmitButton
|
||||
copy={submitButtonCopy}
|
||||
isSubmitting={isSubmitting}
|
||||
isSubmitSuccessful={isSubmitSuccessful}
|
||||
>
|
||||
|
||||
@@ -5,13 +5,20 @@ import { useRouter } from "next/navigation"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { toast } from "sonner"
|
||||
import { createCategoryAction } from "@/actions/category.actions"
|
||||
import { SubmitButton } from "@/components/forms/submitButton"
|
||||
import {
|
||||
SubmitButton,
|
||||
type SubmitButtonCopy,
|
||||
} from "@/components/forms/submitButton"
|
||||
import {
|
||||
type CreateCategoryFormType,
|
||||
createCategorySchema,
|
||||
} from "@/schemas/category.schema"
|
||||
|
||||
export default function NewCategoryForm() {
|
||||
export default function NewCategoryForm({
|
||||
submitButtonCopy,
|
||||
}: {
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}) {
|
||||
const router = useRouter()
|
||||
|
||||
const {
|
||||
@@ -63,6 +70,7 @@ export default function NewCategoryForm() {
|
||||
{errors.name && <p className="text-error">{errors.name.message}</p>}
|
||||
</div>
|
||||
<SubmitButton
|
||||
copy={submitButtonCopy}
|
||||
isSubmitting={isSubmitting}
|
||||
isSubmitSuccessful={isSubmitSuccessful}
|
||||
>
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { getI18n } from "@/i18n/server"
|
||||
|
||||
import NewCategoryForm from "../_components/new.category.form"
|
||||
|
||||
export default function NewCategoryPage() {
|
||||
export default async function NewCategoryPage() {
|
||||
const { dictionary } = await getI18n()
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<h1 className="text-2xl font-bold">New Category</h1>
|
||||
</div>
|
||||
<NewCategoryForm />
|
||||
<NewCategoryForm submitButtonCopy={dictionary.common.submitButton} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { getI18n } from "@/i18n/server"
|
||||
import { CategoryService } from "@/services/category.service"
|
||||
import { ItemService } from "@/services/item.service"
|
||||
|
||||
@@ -11,6 +12,7 @@ export default async function AddItem({
|
||||
const { itemId } = await params
|
||||
const categories = await CategoryService.findAll()
|
||||
const item = await ItemService.findByIdWithAssetCount(itemId)
|
||||
const { dictionary } = await getI18n()
|
||||
|
||||
if (!item) {
|
||||
return <div>Item not found</div>
|
||||
@@ -26,7 +28,11 @@ export default async function AddItem({
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<h1 className="text-2xl font-bold">Edit Item</h1>
|
||||
</div>
|
||||
<UpdateItemForm categories={categories} item={item} />
|
||||
<UpdateItemForm
|
||||
categories={categories}
|
||||
item={item}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ import { useRouter } from "next/navigation"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { toast } from "sonner"
|
||||
import { createItemAction } from "@/actions/item.actions"
|
||||
import { SubmitButton } from "@/components/forms/submitButton"
|
||||
import {
|
||||
SubmitButton,
|
||||
type SubmitButtonCopy,
|
||||
} from "@/components/forms/submitButton"
|
||||
import {
|
||||
type CreateItemFormType,
|
||||
createItemSchema,
|
||||
@@ -14,8 +17,10 @@ import type { CategorySummary } from "@/types"
|
||||
|
||||
export default function NewItemForm({
|
||||
categories,
|
||||
submitButtonCopy,
|
||||
}: {
|
||||
categories: CategorySummary[]
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}) {
|
||||
const router = useRouter()
|
||||
|
||||
@@ -115,6 +120,7 @@ export default function NewItemForm({
|
||||
{errors?.stock && <p className="text-error">{errors.stock.message}</p>}
|
||||
</div>
|
||||
<SubmitButton
|
||||
copy={submitButtonCopy}
|
||||
isSubmitting={isSubmitting}
|
||||
isSubmitSuccessful={isSubmitSuccessful}
|
||||
>
|
||||
|
||||
@@ -5,7 +5,10 @@ import { useRouter } from "next/navigation"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { toast } from "sonner"
|
||||
import { updateItemAction } from "@/actions/item.actions"
|
||||
import { SubmitButton } from "@/components/forms/submitButton"
|
||||
import {
|
||||
SubmitButton,
|
||||
type SubmitButtonCopy,
|
||||
} from "@/components/forms/submitButton"
|
||||
import {
|
||||
type UpdateItemFormType,
|
||||
updateItemSchema,
|
||||
@@ -15,9 +18,11 @@ import type { CategorySummary, ItemWithAssetCount } from "@/types"
|
||||
export default function UpdateItemForm({
|
||||
categories,
|
||||
item,
|
||||
submitButtonCopy,
|
||||
}: {
|
||||
categories: CategorySummary[]
|
||||
item: ItemWithAssetCount
|
||||
submitButtonCopy: SubmitButtonCopy
|
||||
}) {
|
||||
const router = useRouter()
|
||||
|
||||
@@ -130,6 +135,7 @@ export default function UpdateItemForm({
|
||||
{errors?.stock && <p className="text-error">{errors.stock.message}</p>}
|
||||
</div>
|
||||
<SubmitButton
|
||||
copy={submitButtonCopy}
|
||||
isSubmitting={isSubmitting}
|
||||
isSubmitSuccessful={isSubmitSuccessful}
|
||||
>
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
import { getI18n } from "@/i18n/server"
|
||||
import { CategoryService } from "@/services/category.service"
|
||||
|
||||
import NewItemForm from "../_components/new.item.form"
|
||||
|
||||
export default async function NewItemPage() {
|
||||
const categories = await CategoryService.findAll()
|
||||
const { dictionary } = await getI18n()
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<h1 className="text-2xl font-bold">New Item</h1>
|
||||
</div>
|
||||
<NewItemForm categories={categories} />
|
||||
<NewItemForm
|
||||
categories={categories}
|
||||
submitButtonCopy={dictionary.common.submitButton}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user