From 7e04091b492c1680fdf5321f512e43b90ba09e12 Mon Sep 17 00:00:00 2001 From: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:33:18 +0100 Subject: [PATCH] fix(dashboard): Prevent sending off empty string as handle for product category (#10473) --- .changeset/heavy-peaches-sniff.md | 5 +++++ .../create-category-form/create-category-form.tsx | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/heavy-peaches-sniff.md diff --git a/.changeset/heavy-peaches-sniff.md b/.changeset/heavy-peaches-sniff.md new file mode 100644 index 0000000000..d8488adf40 --- /dev/null +++ b/.changeset/heavy-peaches-sniff.md @@ -0,0 +1,5 @@ +--- +"@medusajs/dashboard": patch +--- + +fix(dashboard): Prevent sending off empty string as handle for product category diff --git a/packages/admin/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-form.tsx b/packages/admin/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-form.tsx index 91531834aa..b4a156fb63 100644 --- a/packages/admin/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-form.tsx +++ b/packages/admin/dashboard/src/routes/categories/category-create/components/create-category-form/create-category-form.tsx @@ -10,6 +10,7 @@ import { } from "../../../../../components/modals" import { KeyboundForm } from "../../../../../components/utilities/keybound-form" import { useCreateProductCategory } from "../../../../../hooks/api/categories" +import { transformNullableFormData } from "../../../../../lib/form-helpers" import { CreateCategoryDetails } from "./create-category-details" import { CreateCategoryNesting } from "./create-category-nesting" import { CreateCategoryDetailsSchema, CreateCategorySchema } from "./schema" @@ -79,13 +80,15 @@ export const CreateCategoryForm = ({ const { mutateAsync, isPending } = useCreateProductCategory() 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) mutateAsync( { - ...rest, + name: name, + ...parsedData, parent_category_id: parent_category_id ?? undefined, rank: rank ?? undefined, is_active: status === "active",