fix(dashboard,core-flows,types,medusa): Allow editing Order metadata (#11285)
Resolves SUP-780
This commit is contained in:
1 parent
1185878ecd
commit
f07af7b93c
11 files changed
+75
-13
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/dashboard": patch
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
"@medusajs/types": patch
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(dashboard,core-flows,types,medusa): Allow editing Order metadata
|
||||||
@@ -355,6 +355,10 @@ export const RouteMap: RouteObject[] = [
|
|||||||
lazy: () =>
|
lazy: () =>
|
||||||
import("../../routes/orders/order-edit-billing-address"),
|
import("../../routes/orders/order-edit-billing-address"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "metadata/edit",
|
||||||
|
lazy: () => import("../../routes/orders/order-metadata"),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const DEFAULT_PROPERTIES = [
|
|||||||
"email",
|
"email",
|
||||||
"display_id",
|
"display_id",
|
||||||
"currency_code",
|
"currency_code",
|
||||||
|
"metadata",
|
||||||
// --- TOTALS ---
|
// --- TOTALS ---
|
||||||
"total",
|
"total",
|
||||||
"item_total",
|
"item_total",
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ export const OrderDetail = () => {
|
|||||||
}}
|
}}
|
||||||
data={order}
|
data={order}
|
||||||
showJSON
|
showJSON
|
||||||
|
showMetadata
|
||||||
hasOutlet
|
hasOutlet
|
||||||
>
|
>
|
||||||
<TwoColumnPage.Main>
|
<TwoColumnPage.Main>
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export { OrderMetadata as Component } from "./order-metadata"
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { useParams } from "react-router-dom"
|
||||||
|
import { MetadataForm } from "../../../components/forms/metadata-form/metadata-form"
|
||||||
|
import { useOrder, useUpdateOrder } from "../../../hooks/api"
|
||||||
|
|
||||||
|
export const OrderMetadata = () => {
|
||||||
|
const { id } = useParams()
|
||||||
|
|
||||||
|
const { order, isPending, isError, error } = useOrder(id!, {
|
||||||
|
fields: "id,metadata",
|
||||||
|
})
|
||||||
|
|
||||||
|
const { mutateAsync, isPending: isMutating } = useUpdateOrder(order?.id!)
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MetadataForm
|
||||||
|
metadata={order?.metadata}
|
||||||
|
hook={mutateAsync}
|
||||||
|
isPending={isPending}
|
||||||
|
isMutating={isMutating}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
import { OrderDTO, OrderWorkflow } from "@medusajs/framework/types"
|
import { OrderDTO, OrderWorkflow } from "@medusajs/framework/types"
|
||||||
|
import {
|
||||||
|
MedusaError,
|
||||||
|
OrderWorkflowEvents,
|
||||||
|
validateEmail,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
@@ -11,19 +16,14 @@ import {
|
|||||||
RegisterOrderChangeDTO,
|
RegisterOrderChangeDTO,
|
||||||
UpdateOrderDTO,
|
UpdateOrderDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
|
||||||
MedusaError,
|
|
||||||
OrderWorkflowEvents,
|
|
||||||
validateEmail,
|
|
||||||
} from "@medusajs/framework/utils"
|
|
||||||
|
|
||||||
import { throwIfOrderIsCancelled } from "../utils/order-validation"
|
import { emitEventStep, useQueryGraphStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
previewOrderChangeStep,
|
previewOrderChangeStep,
|
||||||
registerOrderChangesStep,
|
registerOrderChangesStep,
|
||||||
updateOrdersStep,
|
updateOrdersStep,
|
||||||
} from "../steps"
|
} from "../steps"
|
||||||
import { emitEventStep, useQueryGraphStep } from "../../common"
|
import { throwIfOrderIsCancelled } from "../utils/order-validation"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The data to validate the order update.
|
* The data to validate the order update.
|
||||||
@@ -64,10 +64,7 @@ export type UpdateOrderValidationStepInput = {
|
|||||||
*/
|
*/
|
||||||
export const updateOrderValidationStep = createStep(
|
export const updateOrderValidationStep = createStep(
|
||||||
"update-order-validation",
|
"update-order-validation",
|
||||||
async function ({
|
async function ({ order, input }: UpdateOrderValidationStepInput) {
|
||||||
order,
|
|
||||||
input,
|
|
||||||
}: UpdateOrderValidationStepInput) {
|
|
||||||
throwIfOrderIsCancelled({ order })
|
throwIfOrderIsCancelled({ order })
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -133,6 +130,7 @@ export const updateOrderWorkflow = createWorkflow(
|
|||||||
"email",
|
"email",
|
||||||
"shipping_address.*",
|
"shipping_address.*",
|
||||||
"billing_address.*",
|
"billing_address.*",
|
||||||
|
"metadata",
|
||||||
],
|
],
|
||||||
filters: { id: input.id },
|
filters: { id: input.id },
|
||||||
options: { throwIfKeyNotFound: true },
|
options: { throwIfKeyNotFound: true },
|
||||||
@@ -223,6 +221,20 @@ export const updateOrderWorkflow = createWorkflow(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.metadata !== undefined) {
|
||||||
|
changes.push({
|
||||||
|
change_type: "update_order" as const,
|
||||||
|
order_id: input.id,
|
||||||
|
created_by: input.user_id,
|
||||||
|
confirmed_by: input.user_id,
|
||||||
|
details: {
|
||||||
|
type: "metadata",
|
||||||
|
old: order.metadata,
|
||||||
|
new: input.metadata,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return changes
|
return changes
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ export interface AdminUpdateOrder {
|
|||||||
* The order's billing address.
|
* The order's billing address.
|
||||||
*/
|
*/
|
||||||
billing_address?: OrderAddress
|
billing_address?: OrderAddress
|
||||||
|
/**
|
||||||
|
* The order's metadata.
|
||||||
|
*/
|
||||||
|
metadata?: Record<string, unknown> | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AdminCreateOrderFulfillment {
|
export interface AdminCreateOrderFulfillment {
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ export type UpdateOrderWorkflowInput = {
|
|||||||
* The new email of the order.
|
* The new email of the order.
|
||||||
*/
|
*/
|
||||||
email?: string
|
email?: string
|
||||||
|
/**
|
||||||
|
* The new metadata of the order.
|
||||||
|
*/
|
||||||
|
metadata?: Record<string, unknown> | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UpdateOrderShippingAddressWorkflowInput = {
|
export type UpdateOrderShippingAddressWorkflowInput = {
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import {
|
|||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { AdminOrder, HttpTypes } from "@medusajs/framework/types"
|
import { AdminOrder, HttpTypes } from "@medusajs/framework/types"
|
||||||
|
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
AdminGetOrdersOrderParamsType,
|
AdminGetOrdersOrderParamsType,
|
||||||
AdminUpdateOrderType,
|
AdminUpdateOrderType,
|
||||||
} from "../validators"
|
} from "../validators"
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminGetOrdersOrderParamsType>,
|
req: AuthenticatedMedusaRequest<AdminGetOrdersOrderParamsType>,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
import { AddressPayload } from "../../utils/common-validators"
|
||||||
import {
|
import {
|
||||||
createFindParams,
|
createFindParams,
|
||||||
createOperatorMap,
|
createOperatorMap,
|
||||||
createSelectParams,
|
createSelectParams,
|
||||||
WithAdditionalData,
|
WithAdditionalData,
|
||||||
} from "../../utils/validators"
|
} from "../../utils/validators"
|
||||||
import { AddressPayload } from "../../utils/common-validators"
|
|
||||||
|
|
||||||
export const AdminGetOrdersOrderParams = createSelectParams().merge(
|
export const AdminGetOrdersOrderParams = createSelectParams().merge(
|
||||||
z.object({
|
z.object({
|
||||||
@@ -144,4 +144,5 @@ export const AdminUpdateOrder = z.object({
|
|||||||
email: z.string().optional(),
|
email: z.string().optional(),
|
||||||
shipping_address: AddressPayload.optional(),
|
shipping_address: AddressPayload.optional(),
|
||||||
billing_address: AddressPayload.optional(),
|
billing_address: AddressPayload.optional(),
|
||||||
|
metadata: z.record(z.unknown()).nullish(),
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user