fix(dashboard): Prevent sending off empty string as handle for product category (#10473)

This commit is contained in:
Kasper Fabricius Kristensen authored and GitHub committed 2024-12-06 12:33:18 +01:00
1 parent abdd4c9e99
commit 7e04091b49
2 files changed
+10 -2

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---
fix(dashboard): Prevent sending off empty string as handle for product category
@@ -10,6 +10,7 @@ import {
} from "../../../../../components/modals" } from "../../../../../components/modals"
import { KeyboundForm } from "../../../../../components/utilities/keybound-form" import { KeyboundForm } from "../../../../../components/utilities/keybound-form"
import { useCreateProductCategory } from "../../../../../hooks/api/categories" import { useCreateProductCategory } from "../../../../../hooks/api/categories"
import { transformNullableFormData } from "../../../../../lib/form-helpers"
import { CreateCategoryDetails } from "./create-category-details" import { CreateCategoryDetails } from "./create-category-details"
import { CreateCategoryNesting } from "./create-category-nesting" import { CreateCategoryNesting } from "./create-category-nesting"
import { CreateCategoryDetailsSchema, CreateCategorySchema } from "./schema" import { CreateCategoryDetailsSchema, CreateCategorySchema } from "./schema"
@@ -79,13 +80,15 @@ export const CreateCategoryForm = ({
const { mutateAsync, isPending } = useCreateProductCategory() const { mutateAsync, isPending } = useCreateProductCategory()
const handleSubmit = form.handleSubmit((data) => { const handleSubmit = form.handleSubmit((data) => {
const { visibility, status, parent_category_id, rank, ...rest } = data const { visibility, status, parent_category_id, rank, name, ...rest } = data
const parsedData = transformNullableFormData(rest, false)
setShouldFreeze(true) setShouldFreeze(true)
mutateAsync( mutateAsync(
{ {
...rest, name: name,
...parsedData,
parent_category_id: parent_category_id ?? undefined, parent_category_id: parent_category_id ?? undefined,
rank: rank ?? undefined, rank: rank ?? undefined,
is_active: status === "active", is_active: status === "active",