Skip to content

Commit

Permalink
feat(admin, js-sdk, types): update order forms (medusajs#10418)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fPolic authored Dec 4, 2024
1 parent a526308 commit 3407695
Show file tree
Hide file tree
Showing 27 changed files with 1,202 additions and 63 deletions.
91 changes: 69 additions & 22 deletions integration-tests/http/__tests__/order/admin/order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,41 @@ medusaIntegrationTestRunner({
version: 1,
change_type: "update_order",
status: "confirmed",
created_by: expect.any(String),
confirmed_by: expect.any(String),
confirmed_at: expect.any(String),
actions: expect.arrayContaining([
expect.objectContaining({
version: 1,
applied: true,
reference_id: addressBefore.id,
reference: "shipping_address",
action: "UPDATE_ORDER_PROPERTIES",
details: {
city: "New New York",
address_1: "New Main street 123",
},
details: expect.objectContaining({
type: "shipping_address",
old: expect.objectContaining({
address_1: addressBefore.address_1,
city: addressBefore.city,
country_code: addressBefore.country_code,
province: addressBefore.province,
postal_code: addressBefore.postal_code,
phone: addressBefore.phone,
company: addressBefore.company,
first_name: addressBefore.first_name,
last_name: addressBefore.last_name,
address_2: addressBefore.address_2,
}),
new: expect.objectContaining({
address_1: "New Main street 123",
city: "New New York",
country_code: addressBefore.country_code,
province: addressBefore.province,
postal_code: addressBefore.postal_code,
phone: addressBefore.phone,
company: addressBefore.company,
first_name: addressBefore.first_name,
last_name: addressBefore.last_name,
address_2: addressBefore.address_2,
}),
}),
}),
]),
})
Expand Down Expand Up @@ -162,18 +185,33 @@ medusaIntegrationTestRunner({
version: 1,
change_type: "update_order",
status: "confirmed",
created_by: expect.any(String),
confirmed_by: expect.any(String),
confirmed_at: expect.any(String),
actions: expect.arrayContaining([
expect.objectContaining({
version: 1,
applied: true,
reference_id: addressBefore.id,
reference: "billing_address",
action: "UPDATE_ORDER_PROPERTIES",
details: {
city: "New New York",
address_1: "New Main street 123",
},
details: expect.objectContaining({
type: "billing_address",
old: expect.objectContaining({
address_1: addressBefore.address_1,
city: addressBefore.city,
country_code: addressBefore.country_code,
province: addressBefore.province,
postal_code: addressBefore.postal_code,
phone: addressBefore.phone,
}),
new: expect.objectContaining({
address_1: "New Main street 123",
city: "New New York",
country_code: addressBefore.country_code,
province: addressBefore.province,
postal_code: addressBefore.postal_code,
phone: addressBefore.phone,
}),
}),
}),
]),
})
Expand Down Expand Up @@ -239,16 +277,23 @@ medusaIntegrationTestRunner({
change_type: "update_order",
status: "confirmed",
confirmed_at: expect.any(String),
created_by: expect.any(String),
confirmed_by: expect.any(String),
actions: expect.arrayContaining([
expect.objectContaining({
version: 1,
applied: true,
reference_id: order.shipping_address.id,
reference: "shipping_address",
action: "UPDATE_ORDER_PROPERTIES",
details: {
address_1: "New Main street 123",
},
details: expect.objectContaining({
type: "shipping_address",
old: expect.objectContaining({
address_1: order.shipping_address.address_1,
city: order.shipping_address.city,
}),
new: expect.objectContaining({
address_1: "New Main street 123",
}),
}),
}),
]),
}),
Expand All @@ -257,16 +302,18 @@ medusaIntegrationTestRunner({
change_type: "update_order",
status: "confirmed",
confirmed_at: expect.any(String),
created_by: expect.any(String),
confirmed_by: expect.any(String),
actions: expect.arrayContaining([
expect.objectContaining({
version: 1,
applied: true,
reference_id: order.email,
reference: "email",
action: "UPDATE_ORDER_PROPERTIES",
details: {
email: "new-email@example.com",
},
details: expect.objectContaining({
type: "email",
old: order.email,
new: "new-email@example.com",
}),
}),
]),
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Avatar, Text } from "@medusajs/ui"
import { Link } from "react-router-dom"
import { useUser } from "../../../hooks/api/users"

type UserLinkProps = {
id: string
Expand Down Expand Up @@ -32,3 +33,13 @@ export const UserLink = ({
</Link>
)
}

export const By = ({ id }: { id: string }) => {
const { user } = useUser(id) // todo: extend to support customers

if (!user) {
return null
}

return <UserLink {...user} />
}
31 changes: 31 additions & 0 deletions packages/admin/dashboard/src/hooks/api/orders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,37 @@ export const useOrder = (
return { ...data, ...rest }
}

export const useUpdateOrder = (
id: string,
options?: UseMutationOptions<
HttpTypes.AdminOrderResponse,
FetchError,
HttpTypes.AdminUpdateOrder
>
) => {
return useMutation({
mutationFn: (payload: HttpTypes.AdminUpdateOrder) =>
sdk.admin.order.update(id, payload),
onSuccess: (data: any, variables: any, context: any) => {
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.detail(id),
})

queryClient.invalidateQueries({
queryKey: ordersQueryKeys.changes(id),
})

// TODO: enable when needed
// queryClient.invalidateQueries({
// queryKey: ordersQueryKeys.lists(),
// })

options?.onSuccess?.(data, variables, context)
},
...options,
})
}

export const useOrderPreview = (
id: string,
query?: HttpTypes.AdminOrderFilters,
Expand Down
97 changes: 95 additions & 2 deletions packages/admin/dashboard/src/i18n/translations/$schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4146,6 +4146,65 @@
],
"additionalProperties": false
},
"edit": {
"type": "object",
"properties": {
"email": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"requestSuccess": {
"type": "string"
}
},
"required": [
"title",
"requestSuccess"
],
"additionalProperties": false
},
"shippingAddress": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"requestSuccess": {
"type": "string"
}
},
"required": [
"title",
"requestSuccess"
],
"additionalProperties": false
},
"billingAddress": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"requestSuccess": {
"type": "string"
}
},
"required": [
"title",
"requestSuccess"
],
"additionalProperties": false
}
},
"required": [
"email",
"shippingAddress",
"billingAddress"
],
"additionalProperties": false
},
"returns": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -5364,6 +5423,26 @@
"declined"
],
"additionalProperties": false
},
"update_order": {
"type": "object",
"properties": {
"shipping_address": {
"type": "string"
},
"billing_address": {
"type": "string"
},
"email": {
"type": "string"
}
},
"required": [
"shipping_address",
"billing_address",
"email"
],
"additionalProperties": false
}
},
"required": [
Expand All @@ -5377,7 +5456,8 @@
"claim",
"exchange",
"edit",
"transfer"
"transfer",
"update_order"
],
"additionalProperties": false
}
Expand Down Expand Up @@ -5426,6 +5506,7 @@
"transfer",
"payment",
"edits",
"edit",
"returns",
"claims",
"exchanges",
Expand Down Expand Up @@ -10849,6 +10930,12 @@
},
"removed": {
"type": "string"
},
"from": {
"type": "string"
},
"to": {
"type": "string"
}
},
"required": [
Expand All @@ -10857,7 +10944,9 @@
"available",
"inStock",
"added",
"removed"
"removed",
"from",
"to"
],
"additionalProperties": false
},
Expand Down Expand Up @@ -10951,6 +11040,9 @@
"subtitle": {
"type": "string"
},
"by": {
"type": "string"
},
"item": {
"type": "string"
},
Expand Down Expand Up @@ -11360,6 +11452,7 @@
"discountable",
"handle",
"subtitle",
"by",
"item",
"qty",
"limit",
Expand Down
Loading

0 comments on commit 3407695

Please sign in to comment.