diff --git a/.changeset/wicked-adults-repair.md b/.changeset/wicked-adults-repair.md new file mode 100644 index 0000000000..7983d09ef0 --- /dev/null +++ b/.changeset/wicked-adults-repair.md @@ -0,0 +1,6 @@ +--- +"@medusajs/medusa": patch +"@medusajs/admin-ui": patch +--- + +feat(medusa, admin-ui): add description field to product categories diff --git a/integration-tests/api/__tests__/admin/product-category.ts b/integration-tests/api/__tests__/admin/product-category.ts index 8717a33fba..19cd58a77c 100644 --- a/integration-tests/api/__tests__/admin/product-category.ts +++ b/integration-tests/api/__tests__/admin/product-category.ts @@ -437,6 +437,27 @@ describe("/admin/product-categories", () => { ) }) + it("throws an error when description is not a string", async () => { + const api = useApi() + const payload = { + name: "test", + handle: "test", + description: null + } + + const error = await api.post( + `/admin/product-categories`, + payload, + adminHeaders + ).catch(e => e) + + expect(error.response.status).toEqual(400) + expect(error.response.data.type).toEqual("invalid_data") + expect(error.response.data.message).toEqual( + "description must be a string" + ) + }) + it("successfully creates a product category", async () => { const api = useApi() const payload = { @@ -444,6 +465,7 @@ describe("/admin/product-categories", () => { handle: "test", is_internal: true, parent_category_id: productCategory.id, + description: "test" } const response = await api.post( @@ -457,6 +479,7 @@ describe("/admin/product-categories", () => { expect.objectContaining({ product_category: expect.objectContaining({ name: payload.name, + description: payload.description, handle: payload.handle, is_internal: payload.is_internal, is_active: false, diff --git a/integration-tests/api/__tests__/store/product-category.ts b/integration-tests/api/__tests__/store/product-category.ts index 15bafc5834..73ab07f518 100644 --- a/integration-tests/api/__tests__/store/product-category.ts +++ b/integration-tests/api/__tests__/store/product-category.ts @@ -38,6 +38,7 @@ describe("/store/product-categories", () => { beforeEach(async () => { productCategoryParent = await simpleProductCategoryFactory(dbConnection, { name: "category parent", + description: "test description", is_active: true, is_internal: false, rank: 0, @@ -93,7 +94,7 @@ describe("/store/product-categories", () => { const api = useApi() const response = await api.get( - `/store/product-categories/${productCategory.id}?fields=handle,name`, + `/store/product-categories/${productCategory.id}?fields=handle,name,description`, ) expect(response.data.product_category).toEqual( @@ -101,10 +102,12 @@ describe("/store/product-categories", () => { id: productCategory.id, handle: productCategory.handle, name: productCategory.name, + description: "", parent_category: expect.objectContaining({ id: productCategoryParent.id, handle: productCategoryParent.handle, name: productCategoryParent.name, + description: "test description" }), category_children: [ expect.objectContaining({ diff --git a/packages/admin-ui/ui/src/domain/product-categories/modals/add-product-category.tsx b/packages/admin-ui/ui/src/domain/product-categories/modals/add-product-category.tsx index 153bc2ac82..7328e35889 100644 --- a/packages/admin-ui/ui/src/domain/product-categories/modals/add-product-category.tsx +++ b/packages/admin-ui/ui/src/domain/product-categories/modals/add-product-category.tsx @@ -10,6 +10,7 @@ import { useQueryClient } from "@tanstack/react-query" import Button from "../../../components/fundamentals/button" import CrossIcon from "../../../components/fundamentals/icons/cross-icon" import InputField from "../../../components/molecules/input" +import TextArea from "../../../components/molecules/textarea" import FocusModal from "../../../components/molecules/modal/focus-modal" import { NextSelect } from "../../../components/molecules/select/next-select" import useNotification from "../../../hooks/use-notification" @@ -44,6 +45,7 @@ function CreateProductCategory(props: CreateProductCategoryProps) { const [name, setName] = useState("") const [handle, setHandle] = useState("") + const [description, setDescription] = useState("") const [isActive, setIsActive] = useState(true) const [isPublic, setIsPublic] = useState(true) @@ -54,6 +56,7 @@ function CreateProductCategory(props: CreateProductCategoryProps) { await createProductCategory({ name, handle, + description, is_active: isActive, is_internal: !isPublic, parent_category_id: parentCategory?.id ?? null, @@ -132,6 +135,16 @@ function CreateProductCategory(props: CreateProductCategoryProps) { /> +