@medusajs/dashboard 2.22.3 → 2.22.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/AGENTS.md +1 -1
  2. package/dist/app.js +3142 -2648
  3. package/dist/app.mjs +1 -1
  4. package/dist/{chunk-GBUMG3AT.mjs → chunk-DUUYIEXV.mjs} +486 -23
  5. package/dist/{chunk-ZU7MUXFY.mjs → chunk-ODGLX5SI.mjs} +1 -1
  6. package/dist/index.d.mts +3 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/{invite-BEMJK2UX.mjs → invite-SOLUZ6PY.mjs} +33 -3
  9. package/dist/{order-detail-LCEVEUIR.mjs → order-detail-XZEJSMIZ.mjs} +1 -1
  10. package/dist/{product-attributes-44KC3O5H.mjs → product-attributes-HEJKFIWK.mjs} +1 -1
  11. package/dist/{product-create-7U2FFSX6.mjs → product-create-75A5WK7S.mjs} +1 -1
  12. package/dist/{product-detail-NDBVS3WK.mjs → product-detail-FI6SFWJD.mjs} +2 -2
  13. package/dist/{product-edit-MR7HPS4Y.mjs → product-edit-RFHTL3MQ.mjs} +1 -1
  14. package/dist/{product-options-manage-EFUX6E3S.mjs → product-options-manage-VHGM7NLR.mjs} +2 -2
  15. package/dist/{product-organization-5XNP3UM6.mjs → product-organization-KWPYEBPB.mjs} +1 -1
  16. package/package.json +12 -13
  17. package/src/components/layout/main-layout/__tests__/main-layout.spec.tsx +145 -0
  18. package/src/components/layout/main-layout/main-layout.tsx +1 -1
  19. package/src/components/layout/shell/__tests__/breadcrumbs.spec.tsx +81 -0
  20. package/src/components/layout/shell/shell.tsx +4 -2
  21. package/src/components/layout/shell/use-remembered-search.ts +22 -0
  22. package/src/i18n/translations/$schema.json +12 -0
  23. package/src/i18n/translations/ar.json +13 -0
  24. package/src/i18n/translations/bg.json +13 -0
  25. package/src/i18n/translations/bs.json +13 -0
  26. package/src/i18n/translations/cs.json +13 -0
  27. package/src/i18n/translations/de.json +13 -0
  28. package/src/i18n/translations/el.json +13 -0
  29. package/src/i18n/translations/en.json +3 -0
  30. package/src/i18n/translations/enGB.json +13 -0
  31. package/src/i18n/translations/es.json +13 -0
  32. package/src/i18n/translations/fa.json +13 -0
  33. package/src/i18n/translations/fi.json +13 -0
  34. package/src/i18n/translations/fr.json +13 -0
  35. package/src/i18n/translations/he.json +13 -0
  36. package/src/i18n/translations/hr.json +13 -0
  37. package/src/i18n/translations/hu.json +13 -0
  38. package/src/i18n/translations/id.json +13 -0
  39. package/src/i18n/translations/it.json +13 -0
  40. package/src/i18n/translations/ja.json +13 -0
  41. package/src/i18n/translations/ko.json +13 -0
  42. package/src/i18n/translations/lt.json +13 -0
  43. package/src/i18n/translations/mk.json +13 -0
  44. package/src/i18n/translations/mn.json +13 -0
  45. package/src/i18n/translations/nl.json +13 -0
  46. package/src/i18n/translations/pl.json +13 -0
  47. package/src/i18n/translations/ptBR.json +13 -0
  48. package/src/i18n/translations/ptPT.json +13 -0
  49. package/src/i18n/translations/ro.json +13 -0
  50. package/src/i18n/translations/ru.json +13 -0
  51. package/src/i18n/translations/sv.json +13 -0
  52. package/src/i18n/translations/th.json +13 -0
  53. package/src/i18n/translations/tr.json +13 -0
  54. package/src/i18n/translations/uk.json +13 -0
  55. package/src/i18n/translations/vi.json +13 -0
  56. package/src/i18n/translations/zhCN.json +13 -0
  57. package/src/i18n/translations/zhTW.json +13 -0
  58. package/src/routes/invite/invite.tsx +43 -2
  59. package/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.spec.tsx +175 -0
  60. package/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx +80 -83
@@ -0,0 +1,175 @@
1
+ import React from "react"
2
+ import { renderToStaticMarkup } from "react-dom/server"
3
+ import { MemoryRouter } from "react-router-dom"
4
+ import { beforeEach, describe, expect, it, vi } from "vitest"
5
+ import { HttpTypes } from "@medusajs/types"
6
+
7
+ import { OrderSummarySection } from "./order-summary-section"
8
+
9
+ const mocks = vi.hoisted(() => ({
10
+ requestedReturns: [] as unknown[],
11
+ reservations: [] as unknown[],
12
+ }))
13
+
14
+ vi.mock("react-i18next", () => ({
15
+ useTranslation: () => ({
16
+ t: (key: string) => key,
17
+ }),
18
+ }))
19
+
20
+ vi.mock("../../../../../hooks/use-resource-permissions", () => {
21
+ const allowed = () => ({ canCreate: true, canUpdate: true })
22
+ return {
23
+ useOrderChangePermissions: allowed,
24
+ useOrderClaimPermissions: allowed,
25
+ useOrderExchangePermissions: allowed,
26
+ useOrderPermissions: allowed,
27
+ usePaymentCollectionPermissions: allowed,
28
+ useRefundPermissions: allowed,
29
+ useReservationItemPermissions: allowed,
30
+ useReturnPermissions: allowed,
31
+ }
32
+ })
33
+
34
+ vi.mock("../../../../../components/common/action-menu", () => ({
35
+ ActionMenu: ({ children }: { children?: React.ReactNode }) => (
36
+ <>{children}</>
37
+ ),
38
+ }))
39
+
40
+ vi.mock("../copy-payment-link/copy-payment-link", () => ({
41
+ CopyPaymentLink: () => null,
42
+ }))
43
+
44
+ vi.mock("../../../../../hooks/api/claims", () => ({
45
+ useClaims: () => ({ claims: [] }),
46
+ }))
47
+
48
+ vi.mock("../../../../../hooks/api/exchanges", () => ({
49
+ useExchanges: () => ({ exchanges: [] }),
50
+ }))
51
+
52
+ vi.mock("../../../../../hooks/api/orders", () => ({
53
+ useOrderPreview: () => ({ order: undefined }),
54
+ }))
55
+
56
+ vi.mock("../../../../../hooks/api/payment-collections", () => ({
57
+ useMarkPaymentCollectionAsPaid: () => ({ mutateAsync: vi.fn() }),
58
+ }))
59
+
60
+ vi.mock("../../../../../hooks/api/reservations", () => ({
61
+ useReservationItems: () => ({ reservations: mocks.reservations }),
62
+ }))
63
+
64
+ vi.mock("../../../../../hooks/api/returns", () => ({
65
+ useReturns: ({ status }: { status?: string }) => ({
66
+ returns: status === "requested" ? mocks.requestedReturns : [],
67
+ }),
68
+ }))
69
+
70
+ vi.mock("../../../../../hooks/use-date", () => ({
71
+ useDate: () => ({ getRelativeDate: () => "" }),
72
+ }))
73
+
74
+ const buildOrder = (
75
+ overrides: Partial<HttpTypes.AdminOrder> = {}
76
+ ): HttpTypes.AdminOrder =>
77
+ ({
78
+ id: "order_1",
79
+ status: "pending",
80
+ currency_code: "usd",
81
+ items: [],
82
+ shipping_methods: [],
83
+ payment_collections: [],
84
+ credit_lines: [],
85
+ summary: { pending_difference: 0 },
86
+ item_subtotal: 0,
87
+ shipping_subtotal: 0,
88
+ original_tax_total: 0,
89
+ original_total: 0,
90
+ discount_total: 0,
91
+ total: 0,
92
+ ...overrides,
93
+ }) as unknown as HttpTypes.AdminOrder
94
+
95
+ const renderSection = (order: HttpTypes.AdminOrder) =>
96
+ renderToStaticMarkup(
97
+ <MemoryRouter>
98
+ <OrderSummarySection order={order} plugins={[]} />
99
+ </MemoryRouter>
100
+ )
101
+
102
+ describe("OrderSummarySection footer", () => {
103
+ beforeEach(() => {
104
+ mocks.requestedReturns = []
105
+ mocks.reservations = []
106
+ })
107
+
108
+ it("should render the receive return button when a return is requested", () => {
109
+ mocks.requestedReturns = [{ id: "ret_1", canceled_at: null }]
110
+
111
+ const html = renderSection(buildOrder())
112
+
113
+ expect(html).toContain("orders.returns.receive.action")
114
+ })
115
+
116
+ it("should render the allocate items button when an item has no reservation", () => {
117
+ const html = renderSection(
118
+ buildOrder({
119
+ items: [
120
+ {
121
+ id: "item_1",
122
+ title: "Item",
123
+ quantity: 1,
124
+ unit_price: 10,
125
+ subtotal: 10,
126
+ variant: { manage_inventory: true, options: [] },
127
+ detail: {
128
+ fulfilled_quantity: 0,
129
+ shipped_quantity: 0,
130
+ return_requested_quantity: 0,
131
+ return_received_quantity: 0,
132
+ return_dismissed_quantity: 0,
133
+ written_off_quantity: 0,
134
+ },
135
+ },
136
+ ] as unknown as HttpTypes.AdminOrder["items"],
137
+ })
138
+ )
139
+
140
+ expect(html).toContain("orders.allocateItems.action")
141
+ })
142
+
143
+ it("should render the mark as paid button when a payment collection is not paid", () => {
144
+ const html = renderSection(
145
+ buildOrder({
146
+ payment_collections: [
147
+ {
148
+ id: "paycol_1",
149
+ status: "not_paid",
150
+ amount: 100,
151
+ captured_amount: 0,
152
+ refunded_amount: 0,
153
+ },
154
+ ] as unknown as HttpTypes.AdminOrder["payment_collections"],
155
+ summary: {
156
+ pending_difference: 100,
157
+ } as unknown as HttpTypes.AdminOrder["summary"],
158
+ })
159
+ )
160
+
161
+ expect(html).toContain("orders.payment.markAsPaid")
162
+ })
163
+
164
+ it("should render the refund button when the order has a negative pending difference", () => {
165
+ const html = renderSection(
166
+ buildOrder({
167
+ summary: {
168
+ pending_difference: -100,
169
+ } as unknown as HttpTypes.AdminOrder["summary"],
170
+ })
171
+ )
172
+
173
+ expect(html).toContain("orders.payment.refundAmount")
174
+ })
175
+ })
@@ -226,95 +226,92 @@ export const OrderSummarySection = ({
226
226
  <DiscountAndTotalBreakdown order={order} plugins={plugins} />
227
227
  <Total order={order} />
228
228
 
229
- {showReturns ||
230
- showAllocateButton ||
231
- showPayment ||
232
- (showRefund && (
233
- <div className="flex items-center justify-end gap-x-2 rounded-b-xl bg-ui-bg-subtle px-4 py-4">
234
- {showReturns &&
235
- (receivableReturns.length === 1 ? (
236
- <Button asChild variant="secondary" size="small">
237
- <Link
238
- to={`/orders/${order.id}/returns/${receivableReturns[0].id}/receive`}
239
- >
240
- {t("orders.returns.receive.action")}
241
- </Link>
242
- </Button>
243
- ) : (
244
- <ActionMenu
245
- groups={[
246
- {
247
- actions: receivableReturns.map((r) => {
248
- let id = r.id
249
- let returnType = "Return"
250
-
251
- if (r.exchange_id) {
252
- id = r.exchange_id
253
- returnType = "Exchange"
254
- }
255
-
256
- if (r.claim_id) {
257
- id = r.claim_id
258
- returnType = "Claim"
259
- }
260
-
261
- return {
262
- label: t("orders.returns.receive.receiveItems", {
263
- id: `#${id.slice(-7)}`,
264
- returnType,
265
- }),
266
- icon: <ArrowLongRight />,
267
- to: `/orders/${order.id}/returns/${r.id}/receive`,
268
- }
269
- }),
270
- },
271
- ]}
272
- >
273
- <Button variant="secondary" size="small">
274
- {t("orders.returns.receive.action")}
275
- </Button>
276
- </ActionMenu>
277
- ))}
278
-
279
- {showAllocateButton && (
229
+ {(showReturns || showAllocateButton || showPayment || showRefund) && (
230
+ <div className="flex items-center justify-end gap-x-2 rounded-b-xl bg-ui-bg-subtle px-4 py-4">
231
+ {showReturns &&
232
+ (receivableReturns.length === 1 ? (
280
233
  <Button asChild variant="secondary" size="small">
281
- <Link to="allocate-items">
282
- {t("orders.allocateItems.action")}
234
+ <Link
235
+ to={`/orders/${order.id}/returns/${receivableReturns[0].id}/receive`}
236
+ >
237
+ {t("orders.returns.receive.action")}
283
238
  </Link>
284
239
  </Button>
285
- )}
240
+ ) : (
241
+ <ActionMenu
242
+ groups={[
243
+ {
244
+ actions: receivableReturns.map((r) => {
245
+ let id = r.id
246
+ let returnType = "Return"
247
+
248
+ if (r.exchange_id) {
249
+ id = r.exchange_id
250
+ returnType = "Exchange"
251
+ }
252
+
253
+ if (r.claim_id) {
254
+ id = r.claim_id
255
+ returnType = "Claim"
256
+ }
257
+
258
+ return {
259
+ label: t("orders.returns.receive.receiveItems", {
260
+ id: `#${id.slice(-7)}`,
261
+ returnType,
262
+ }),
263
+ icon: <ArrowLongRight />,
264
+ to: `/orders/${order.id}/returns/${r.id}/receive`,
265
+ }
266
+ }),
267
+ },
268
+ ]}
269
+ >
270
+ <Button variant="secondary" size="small">
271
+ {t("orders.returns.receive.action")}
272
+ </Button>
273
+ </ActionMenu>
274
+ ))}
275
+
276
+ {showAllocateButton && (
277
+ <Button asChild variant="secondary" size="small">
278
+ <Link to="allocate-items">
279
+ {t("orders.allocateItems.action")}
280
+ </Link>
281
+ </Button>
282
+ )}
286
283
 
287
- {showPayment && (
288
- <CopyPaymentLink
289
- paymentCollection={unpaidPaymentCollection}
290
- order={order}
291
- />
292
- )}
284
+ {showPayment && (
285
+ <CopyPaymentLink
286
+ paymentCollection={unpaidPaymentCollection}
287
+ order={order}
288
+ />
289
+ )}
293
290
 
294
- {showPayment && (
295
- <Button
296
- size="small"
297
- variant="secondary"
298
- onClick={() => handleMarkAsPaid(unpaidPaymentCollection)}
299
- >
300
- {t("orders.payment.markAsPaid")}
301
- </Button>
302
- )}
291
+ {showPayment && (
292
+ <Button
293
+ size="small"
294
+ variant="secondary"
295
+ onClick={() => handleMarkAsPaid(unpaidPaymentCollection)}
296
+ >
297
+ {t("orders.payment.markAsPaid")}
298
+ </Button>
299
+ )}
303
300
 
304
- {showRefund && (
305
- <Button size="small" variant="secondary" asChild>
306
- <Link to={`/orders/${order.id}/refund`}>
307
- {t("orders.payment.refundAmount", {
308
- amount: getStylizedAmount(
309
- pendingDifference * -1,
310
- order?.currency_code
311
- ),
312
- })}
313
- </Link>
314
- </Button>
315
- )}
316
- </div>
317
- ))}
301
+ {showRefund && (
302
+ <Button size="small" variant="secondary" asChild>
303
+ <Link to={`/orders/${order.id}/refund`}>
304
+ {t("orders.payment.refundAmount", {
305
+ amount: getStylizedAmount(
306
+ pendingDifference * -1,
307
+ order?.currency_code
308
+ ),
309
+ })}
310
+ </Link>
311
+ </Button>
312
+ )}
313
+ </div>
314
+ )}
318
315
  </Container>
319
316
  )
320
317
  }