feat(admin, js-sdk, types): update order forms (#10418)
* feat: edit shipping, billing and email forms * feat: timeline history, update change model, update tests * fix: address comments * fix: invalidation, translation schema, update label * fix: old/new
This commit is contained in:
1 parent
a5263083fa
commit
340769595a
27 files changed
+1202
-63
No files matched your search
@@ -121,45 +121,62 @@ export const updateOrderWorkflow = createWorkflow(
|
||||
return { ...input, ...update }
|
||||
})
|
||||
|
||||
updateOrdersStep({
|
||||
const updatedOrders = updateOrdersStep({
|
||||
selector: { id: input.id },
|
||||
update: updateInput,
|
||||
})
|
||||
|
||||
const orderChangeInput = transform({ input, order }, ({ input, order }) => {
|
||||
const changes: RegisterOrderChangeDTO[] = []
|
||||
if (input.shipping_address) {
|
||||
changes.push({
|
||||
change_type: "update_order" as const,
|
||||
order_id: input.id,
|
||||
reference: "shipping_address",
|
||||
reference_id: order.shipping_address?.id, // save previous address id as reference
|
||||
details: input.shipping_address as Record<string, unknown>, // save what changed on the address
|
||||
})
|
||||
}
|
||||
const orderChangeInput = transform(
|
||||
{ input, updatedOrders, order },
|
||||
({ input, updatedOrders, order }) => {
|
||||
const updatedOrder = updatedOrders[0]
|
||||
|
||||
if (input.billing_address) {
|
||||
changes.push({
|
||||
change_type: "update_order" as const,
|
||||
order_id: input.id,
|
||||
reference: "billing_address",
|
||||
reference_id: order.billing_address?.id,
|
||||
details: input.billing_address as Record<string, unknown>,
|
||||
})
|
||||
}
|
||||
const changes: RegisterOrderChangeDTO[] = []
|
||||
if (input.shipping_address) {
|
||||
changes.push({
|
||||
change_type: "update_order" as const,
|
||||
order_id: input.id,
|
||||
created_by: input.user_id,
|
||||
confirmed_by: input.user_id,
|
||||
details: {
|
||||
type: "shipping_address",
|
||||
old: order.shipping_address,
|
||||
new: updatedOrder.shipping_address,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if (input.email) {
|
||||
changes.push({
|
||||
change_type: "update_order" as const,
|
||||
order_id: input.id,
|
||||
reference: "email",
|
||||
reference_id: order.email,
|
||||
details: { email: input.email },
|
||||
})
|
||||
}
|
||||
if (input.billing_address) {
|
||||
changes.push({
|
||||
change_type: "update_order" as const,
|
||||
order_id: input.id,
|
||||
created_by: input.user_id,
|
||||
confirmed_by: input.user_id,
|
||||
details: {
|
||||
type: "billing_address",
|
||||
old: order.billing_address,
|
||||
new: updatedOrder.billing_address,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return changes
|
||||
})
|
||||
if (input.email) {
|
||||
changes.push({
|
||||
change_type: "update_order" as const,
|
||||
order_id: input.id,
|
||||
created_by: input.user_id,
|
||||
confirmed_by: input.user_id,
|
||||
details: {
|
||||
type: "email",
|
||||
old: order.email,
|
||||
new: input.email,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return changes
|
||||
}
|
||||
)
|
||||
|
||||
registerOrderChangesStep(orderChangeInput)
|
||||
|
||||
|
||||
@@ -64,6 +64,47 @@ export class Order {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method updates an order. It sends a request to the
|
||||
* [Update Order Email](https://docs.medusajs.com/api/admin#orders_postordersid)
|
||||
* API route.
|
||||
*
|
||||
* @param id - The order's ID.
|
||||
* @param body - The update details.
|
||||
* @param headers - Headers to pass in the request
|
||||
* @returns The order's details.
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.order.update(
|
||||
* "order_123",
|
||||
* {
|
||||
* email: "new_email@example.com",
|
||||
* shipping_address: {
|
||||
* first_name: "John",
|
||||
* last_name: "Doe",
|
||||
* address_1: "123 Main St",
|
||||
* }
|
||||
* }
|
||||
* )
|
||||
* .then(({ order }) => {
|
||||
* console.log(order)
|
||||
* })
|
||||
*/
|
||||
async update(
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateOrder,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminOrderResponse>(
|
||||
`/admin/orders/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method retrieves the preview of an order based on its last associated change. It sends a request to the
|
||||
* [Get Order Preview](https://docs.medusajs.com/api/admin#orders_getordersidpreview) API route.
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
export interface AdminUpdateOrder {
|
||||
/**
|
||||
* The order's email.
|
||||
*/
|
||||
email?: string
|
||||
/**
|
||||
* The order's shipping address.
|
||||
*/
|
||||
shipping_address?: OrderAddress
|
||||
/**
|
||||
* The order's billing address.
|
||||
*/
|
||||
billing_address?: OrderAddress
|
||||
}
|
||||
|
||||
export interface AdminCreateOrderFulfillment {
|
||||
/**
|
||||
* The items to add to the fulfillment.
|
||||
@@ -82,3 +97,60 @@ export interface AdminRequestOrderTransfer {
|
||||
internal_note?: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export interface OrderAddress {
|
||||
/**
|
||||
* The first name of the address.
|
||||
*/
|
||||
first_name?: string
|
||||
|
||||
/**
|
||||
* The last name of the address.
|
||||
*/
|
||||
last_name?: string
|
||||
|
||||
/**
|
||||
* The phone number of the address.
|
||||
*/
|
||||
phone?: string
|
||||
|
||||
/**
|
||||
* The company of the address.
|
||||
*/
|
||||
company?: string
|
||||
|
||||
/**
|
||||
* The first address line of the address.
|
||||
*/
|
||||
address_1?: string
|
||||
|
||||
/**
|
||||
* The second address line of the address.
|
||||
*/
|
||||
address_2?: string
|
||||
|
||||
/**
|
||||
* The city of the address.
|
||||
*/
|
||||
city?: string
|
||||
|
||||
/**
|
||||
* The country code of the address.
|
||||
*/
|
||||
country_code?: string
|
||||
|
||||
/**
|
||||
* The province/state of the address.
|
||||
*/
|
||||
province?: string
|
||||
|
||||
/**
|
||||
* The postal code of the address.
|
||||
*/
|
||||
postal_code?: string
|
||||
|
||||
/**
|
||||
* Holds custom data in key-value pairs.
|
||||
*/
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
@@ -1077,9 +1077,14 @@ export interface RegisterOrderChangeDTO {
|
||||
internal_note?: string | null
|
||||
|
||||
/**
|
||||
* The user or customer that requested the order change.
|
||||
* The user that created the order change.
|
||||
*/
|
||||
requested_by?: string
|
||||
created_by?: string
|
||||
|
||||
/**
|
||||
* The user or customer that confirmed the order change.
|
||||
*/
|
||||
confirmed_by?: string
|
||||
|
||||
/**
|
||||
* Holds custom data in key-value pairs.
|
||||
|
||||
@@ -2,6 +2,7 @@ import { UpsertOrderAddressDTO } from "../../order"
|
||||
|
||||
export type UpdateOrderWorkflowInput = {
|
||||
id: string
|
||||
user_id: string
|
||||
shipping_address?: UpsertOrderAddressDTO
|
||||
billing_address?: UpsertOrderAddressDTO
|
||||
email?: string
|
||||
|
||||
Reference in new issue
Block a user