fix(ui,types): Add Metadata form for collection (#11300)
**What** - Adds missing Metadata form for collections - Fixes type of metadata in update payload - Fixes an issue where deleting the last row of a metadata form would prevent adding new ones. Resolves SUP-784
This commit is contained in:
committed by
GitHub
parent
4be327819f
commit
6db96c80d0
6
.changeset/blue-files-work.md
Normal file
6
.changeset/blue-files-work.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/dashboard": patch
|
||||
"@medusajs/types": patch
|
||||
---
|
||||
|
||||
fix(ui,types): Add Metadata form for collection
|
||||
@@ -113,6 +113,15 @@ const InnerForm = <TRes,>({
|
||||
|
||||
function deleteRow(index: number) {
|
||||
remove(index)
|
||||
|
||||
// If the last row is deleted, add a new blank row
|
||||
if (fields.length === 1) {
|
||||
insert(0, {
|
||||
key: "",
|
||||
value: "",
|
||||
disabled: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function insertRow(index: number, position: "above" | "below") {
|
||||
|
||||
@@ -520,6 +520,11 @@ export const RouteMap: RouteObject[] = [
|
||||
"../../routes/collections/collection-add-products"
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "metadata/edit",
|
||||
lazy: () =>
|
||||
import("../../routes/collections/collection-metadata"),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useParams } from "react-router-dom"
|
||||
import { MetadataForm } from "../../../components/forms/metadata-form/metadata-form"
|
||||
import { useCollection, useUpdateCollection } from "../../../hooks/api"
|
||||
|
||||
export const CollectionMetadata = () => {
|
||||
const { id } = useParams()
|
||||
|
||||
const { collection, isPending, isError, error } = useCollection(id!)
|
||||
|
||||
const { mutateAsync, isPending: isMutating } = useUpdateCollection(
|
||||
collection?.id!
|
||||
)
|
||||
|
||||
if (isError) {
|
||||
throw error
|
||||
}
|
||||
|
||||
return (
|
||||
<MetadataForm
|
||||
metadata={collection?.metadata}
|
||||
hook={mutateAsync}
|
||||
isPending={isPending}
|
||||
isMutating={isMutating}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { CollectionMetadata as Component } from "./collection-metadata"
|
||||
@@ -25,7 +25,7 @@ export interface AdminUpdateCollection {
|
||||
/**
|
||||
* Key-value pairs of custom data.
|
||||
*/
|
||||
metadata?: Record<string, any>
|
||||
metadata?: Record<string, any> | null
|
||||
}
|
||||
|
||||
export interface AdminUpdateCollectionProducts {
|
||||
|
||||
Reference in New Issue
Block a user