feat(dashboard,medusa): Add updated Metadata Form (#8084)

**What**
- Adds new Metadata form component.
- Adds the Metadata section as an option to the Page layouts

<img width="576" alt="Skærmbillede 2024-07-11 kl  11 34 06" src="https://github.com/medusajs/medusa/assets/45367945/417810ee-26e2-4c8a-86e3-58ef327054af">
<img width="580" alt="Skærmbillede 2024-07-11 kl  11 34 33" src="https://github.com/medusajs/medusa/assets/45367945/437a5e01-01e2-4ff7-8c7e-42a86d1ce2b3">


**Note**
- When Metadata contains non-primitive data, we disable those rows, and show a placeholder value, a tooltip and an alert describing that the row can be edited through the API. I want to add a JSON editor to allow editing these things in admin, but awaiting approval on that.
- This PR only adds the new form to a couple of pages, to keep the PR light, especially since metadata is not implemented correctly in all validators so also needs some changes to the core. This still show some examples of how its used with the new Page layout components. Will follow up with more pages in future PRs. 
- We try to convert the inputs to the best fitting primitive, so if a user types "true" then we save the value as a boolean, "130" as number, "testing" as a string, etc.
This commit is contained in:
Kasper Fabricius Kristensen
2024-07-11 15:54:59 +02:00
committed by GitHub
parent 66acb3023e
commit b5a44ef6b1
28 changed files with 823 additions and 386 deletions

View File

@@ -1,3 +1,4 @@
import { FetchError } from "@medusajs/js-sdk"
import { DeleteResponse, HttpTypes, PaginatedResponse } from "@medusajs/types"
import {
QueryKey,
@@ -19,7 +20,7 @@ export const useCustomer = (
options?: Omit<
UseQueryOptions<
{ customer: HttpTypes.AdminCustomer },
Error,
FetchError,
{ customer: HttpTypes.AdminCustomer },
QueryKey
>,
@@ -40,7 +41,7 @@ export const useCustomers = (
options?: Omit<
UseQueryOptions<
PaginatedResponse<{ customers: HttpTypes.AdminCustomer[] }>,
Error,
FetchError,
PaginatedResponse<{ customers: HttpTypes.AdminCustomer[] }>,
QueryKey
>,
@@ -59,7 +60,7 @@ export const useCustomers = (
export const useCreateCustomer = (
options?: UseMutationOptions<
{ customer: HttpTypes.AdminCustomer },
Error,
FetchError,
HttpTypes.AdminCreateCustomer
>
) => {
@@ -77,7 +78,7 @@ export const useUpdateCustomer = (
id: string,
options?: UseMutationOptions<
{ customer: HttpTypes.AdminCustomer },
Error,
FetchError,
HttpTypes.AdminUpdateCustomer
>
) => {
@@ -95,7 +96,7 @@ export const useUpdateCustomer = (
export const useDeleteCustomer = (
id: string,
options?: UseMutationOptions<DeleteResponse<"customer">, Error, void>
options?: UseMutationOptions<DeleteResponse<"customer">, FetchError, void>
) => {
return useMutation({
mutationFn: () => sdk.admin.customer.delete(id),

View File

@@ -268,15 +268,14 @@ export const useProducts = (
export const useCreateProduct = (
options?: UseMutationOptions<
{ product: HttpTypes.AdminProduct },
Error,
HttpTypes.AdminProductResponse,
FetchError,
HttpTypes.AdminCreateProduct
>
) => {
return useMutation({
mutationFn: (payload: HttpTypes.AdminCreateProduct) =>
sdk.admin.product.create(payload),
onSuccess: (data: any, variables: any, context: any) => {
mutationFn: (payload) => sdk.admin.product.create(payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() })
// if `manage_inventory` is true on created variants that will create inventory items automatically
queryClient.invalidateQueries({
@@ -290,12 +289,15 @@ export const useCreateProduct = (
export const useUpdateProduct = (
id: string,
options?: UseMutationOptions<HttpTypes.AdminProductResponse, Error, any>
options?: UseMutationOptions<
HttpTypes.AdminProductResponse,
FetchError,
HttpTypes.AdminUpdateProduct
>
) => {
return useMutation({
mutationFn: (payload: HttpTypes.AdminUpdateProduct) =>
sdk.admin.product.update(id, payload),
onSuccess: (data: any, variables: any, context: any) => {
mutationFn: (payload) => sdk.admin.product.update(id, payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() })
queryClient.invalidateQueries({ queryKey: productsQueryKeys.detail(id) })
@@ -309,7 +311,7 @@ export const useDeleteProduct = (
id: string,
options?: UseMutationOptions<
HttpTypes.AdminProductDeleteResponse,
Error,
FetchError,
void
>
) => {