@graphcommerce/magento-customer 9.1.0-canary.18 → 9.1.0-canary.20

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 (96) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/components/AccountAddresses/AccountAddresses.tsx +9 -4
  3. package/components/AccountDeleteForm/AccountDeleteForm.tsx +14 -4
  4. package/components/AccountLatestOrder/AccountLatestOrder.tsx +1 -2
  5. package/components/AccountOrders/AccountOrders.tsx +1 -1
  6. package/components/CancelOrder/CancelOrderForm.tsx +2 -2
  7. package/components/CancelOrder/CancelOrderFragment.graphql +5 -0
  8. package/components/ChangeNameForm/ChangeNameForm.tsx +1 -0
  9. package/components/ContactForm/ContactUsConfig.graphql +3 -0
  10. package/components/CreditMemo/CreditMemo.graphql +43 -0
  11. package/components/CreditMemo/CreditMemoCard.graphql +12 -0
  12. package/components/CreditMemo/CreditMemoCard.tsx +66 -0
  13. package/components/CreditMemo/CreditMemoDetails.tsx +94 -0
  14. package/components/CreditMemo/CreditMemoItem.graphql +26 -0
  15. package/components/CreditMemo/CreditMemoItem.tsx +125 -0
  16. package/components/CreditMemo/CreditMemoItems.tsx +78 -0
  17. package/components/CreditMemo/CreditMemoTotals.tsx +122 -0
  18. package/components/CreditMemo/index.ts +8 -0
  19. package/components/CustomerForms/CustomerAttributeField.tsx +112 -0
  20. package/components/CustomerForms/CustomerAttributeMetadata.graphql +9 -0
  21. package/components/CustomerForms/CustomerUpdateForm.tsx +65 -0
  22. package/components/CustomerForms/UseCustomerCreateForm.graphql +7 -0
  23. package/components/CustomerForms/UseCustomerUpdateForm.graphql +7 -0
  24. package/components/CustomerForms/customerAttributeFieldHelpers.ts +127 -0
  25. package/components/CustomerForms/index.ts +8 -0
  26. package/components/CustomerForms/nameFieldset.tsx +32 -0
  27. package/components/CustomerForms/useCustomerCreateForm.ts +83 -0
  28. package/components/CustomerForms/useCustomerUpdateForm.ts +122 -0
  29. package/components/GuestOrderOverview/GuestOrderOverviewForm.tsx +28 -11
  30. package/components/Invoice/Invoice.graphql +13 -0
  31. package/components/Invoice/InvoiceCard.graphql +9 -0
  32. package/components/Invoice/InvoiceCard.tsx +66 -0
  33. package/components/Invoice/InvoiceDetails.tsx +94 -0
  34. package/components/Invoice/InvoiceItem.graphql +25 -0
  35. package/components/Invoice/InvoiceItem.tsx +125 -0
  36. package/components/Invoice/InvoiceItems.tsx +72 -0
  37. package/components/Invoice/InvoiceTotal.graphql +29 -0
  38. package/components/Invoice/InvoiceTotals.tsx +110 -0
  39. package/components/Invoice/index.ts +9 -0
  40. package/components/NameFields/NameFields.tsx +33 -18
  41. package/components/Order/OrderAdditional/OrderAdditional.graphql +16 -0
  42. package/components/Order/OrderAdditional/OrderAdditional.tsx +51 -0
  43. package/components/Order/OrderCard/OrderCard.graphql +13 -0
  44. package/components/{OrderCard → Order/OrderCard}/OrderCard.tsx +22 -18
  45. package/components/{OrderCardItem → Order/OrderCard}/OrderCardItem.graphql +1 -0
  46. package/components/Order/OrderComments/OrderComments.graphql +5 -0
  47. package/components/Order/OrderComments/SalesCommentItem.graphql +4 -0
  48. package/components/Order/OrderComments/SalesComments.tsx +28 -0
  49. package/components/Order/OrderDetails/OrderAddress.graphql +17 -0
  50. package/components/Order/OrderDetails/OrderDetails.graphql +38 -0
  51. package/components/{OrderDetails → Order/OrderDetails}/OrderDetails.tsx +70 -57
  52. package/components/Order/OrderDetails/ShippingHandling.graphql +19 -0
  53. package/components/Order/OrderDetails/TaxItem.graphql +7 -0
  54. package/components/{OrderItem → Order/OrderItem}/OrderItem.graphql +13 -0
  55. package/components/Order/OrderItem/OrderItem.tsx +144 -0
  56. package/components/Order/OrderItems/OrderItems.tsx +81 -0
  57. package/components/{OrderStateLabel → Order/OrderStateLabel}/OrderStateLabel.tsx +2 -2
  58. package/components/Order/OrderTotals/OrderTotal.graphql +32 -0
  59. package/components/Order/OrderTotals/OrderTotals.graphql +7 -0
  60. package/components/{OrderDetails → Order/OrderTotals}/OrderTotals.tsx +27 -12
  61. package/components/Order/index.ts +16 -0
  62. package/components/ReorderItems/ReorderItems.tsx +1 -1
  63. package/components/Shipment/Shipment.graphql +14 -0
  64. package/components/Shipment/ShipmentCard.graphql +8 -0
  65. package/components/Shipment/ShipmentCard.tsx +71 -0
  66. package/components/Shipment/ShipmentDetails.tsx +100 -0
  67. package/components/Shipment/ShipmentItem.graphql +19 -0
  68. package/components/Shipment/ShipmentItem.tsx +117 -0
  69. package/components/Shipment/ShipmentItems.tsx +72 -0
  70. package/components/Shipment/index.ts +7 -0
  71. package/components/SignUpForm/SignUpForm.tsx +51 -46
  72. package/components/WaitForCustomer/WaitForCustomer.tsx +12 -3
  73. package/components/index.ts +5 -8
  74. package/graphql/{AccountDashboardQueryFragment.graphql → fragments/AccountDashboardQueryFragment.graphql} +8 -3
  75. package/graphql/index.ts +10 -0
  76. package/graphql/queries/CreditMemoDetailPage.graphql +14 -0
  77. package/graphql/queries/InvoiceDetailPage.graphql +14 -0
  78. package/graphql/queries/OrderDetailPage.graphql +14 -0
  79. package/graphql/queries/ShipmentDetailPage.graphql +12 -0
  80. package/hooks/CustomerInfo.graphql +3 -3
  81. package/index.ts +1 -4
  82. package/package.json +14 -14
  83. package/utils/orderState.ts +1 -2
  84. package/components/OrderCard/OrderCard.graphql +0 -29
  85. package/components/OrderDetails/OrderDetails.graphql +0 -77
  86. package/components/OrderItem/OrderItem.tsx +0 -176
  87. package/components/OrderItems/OrderItems.tsx +0 -70
  88. package/graphql/OrderDetailPage.graphql +0 -10
  89. /package/components/{OrderItems → Order/OrderItems}/OrderItems.graphql +0 -0
  90. /package/components/{OrderStateLabel → Order/OrderStateLabel}/OrderStateLabel.graphql +0 -0
  91. /package/components/{OrderStateLabel → Order/OrderStateLabel}/OrderStateLabelInline.tsx +0 -0
  92. /package/graphql/{CustomerStoreConfig.graphql → inject/CustomerStoreConfig.graphql} +0 -0
  93. /package/graphql/{AccountDashboard.graphql → queries/AccountDashboard.graphql} +0 -0
  94. /package/graphql/{AccountDashboardAddresses.graphql → queries/AccountDashboardAddresses.graphql} +0 -0
  95. /package/graphql/{AccountDashboardCustomer.graphql → queries/AccountDashboardCustomer.graphql} +0 -0
  96. /package/graphql/{AccountDashboardOrders.graphql → queries/AccountDashboardOrders.graphql} +0 -0
@@ -0,0 +1,110 @@
1
+ import { Money } from '@graphcommerce/magento-store'
2
+ import { breakpointVal, extendableComponent, sxx } from '@graphcommerce/next-ui'
3
+ import { Trans } from '@lingui/macro'
4
+ import type { SxProps, Theme } from '@mui/material'
5
+ import { Box, Divider, lighten, Typography } from '@mui/material'
6
+ import type { InvoiceFragment } from './Invoice.gql'
7
+
8
+ export type InvoiceTotalsProps = {
9
+ invoice: InvoiceFragment
10
+ sx?: SxProps<Theme>
11
+ }
12
+
13
+ const componentName = 'InvoiceTotals'
14
+ const parts = ['totalsContainer', 'totalsRow', 'totalsDivider', 'totalsVat'] as const
15
+ const { classes } = extendableComponent(componentName, parts)
16
+
17
+ export function InvoiceTotals(props: InvoiceTotalsProps) {
18
+ const { invoice, sx = [] } = props
19
+ const { total } = invoice
20
+
21
+ if (!total) return null
22
+
23
+ return (
24
+ <Box
25
+ className={classes.totalsContainer}
26
+ sx={sxx(
27
+ (theme) => ({
28
+ my: theme.spacings.md,
29
+ ...breakpointVal(
30
+ 'borderRadius',
31
+ theme.shape.borderRadius * 3,
32
+ theme.shape.borderRadius * 5,
33
+ theme.breakpoints.values,
34
+ ),
35
+ background:
36
+ theme.palette.mode === 'light'
37
+ ? theme.palette.background.default
38
+ : lighten(theme.palette.background.default, 0.15),
39
+ padding: `${theme.spacings.xs} ${theme.spacings.sm}`,
40
+ }),
41
+ sx,
42
+ )}
43
+ >
44
+ <Box className={classes.totalsRow} sx={{ display: 'flex', justifyContent: 'space-between' }}>
45
+ <Typography>
46
+ <Trans>Subtotal</Trans>
47
+ </Typography>
48
+ <Money {...total.subtotal} />
49
+ </Box>
50
+
51
+ {total.discounts?.map((discount) => (
52
+ <Box
53
+ className={classes.totalsRow}
54
+ sx={{ display: 'flex', justifyContent: 'space-between' }}
55
+ key={`discount-${discount?.label}`}
56
+ >
57
+ <Typography>{discount?.label}</Typography>
58
+ {discount?.amount && (
59
+ <Money {...discount.amount} value={(discount.amount.value ?? 0) * -1} />
60
+ )}
61
+ </Box>
62
+ ))}
63
+
64
+ {total.total_shipping && (
65
+ <Box
66
+ className={classes.totalsRow}
67
+ sx={{ display: 'flex', justifyContent: 'space-between' }}
68
+ >
69
+ <Typography>
70
+ <Trans>Shipping</Trans>
71
+ </Typography>
72
+ <Money {...total.total_shipping} />
73
+ </Box>
74
+ )}
75
+
76
+ <Divider sx={(theme) => ({ my: theme.spacings.xxs })} />
77
+
78
+ <Box
79
+ className={classes.totalsRow}
80
+ sx={(theme) => ({
81
+ display: 'flex',
82
+ justifyContent: 'space-between',
83
+ color: theme.palette.primary.main,
84
+ })}
85
+ >
86
+ <Typography>
87
+ <Trans>Grand total</Trans>
88
+ </Typography>
89
+ <Money {...total.grand_total} />
90
+ </Box>
91
+
92
+ {total.taxes?.map((tax) => (
93
+ <Box
94
+ key={tax?.title}
95
+ className={classes.totalsVat}
96
+ sx={(theme) => ({
97
+ display: 'flex',
98
+ justifyContent: 'space-between',
99
+ color: theme.palette.text.disabled,
100
+ })}
101
+ >
102
+ <Typography>
103
+ <Trans>Including {tax?.title}</Trans>
104
+ </Typography>
105
+ <Money {...tax?.amount} />
106
+ </Box>
107
+ ))}
108
+ </Box>
109
+ )
110
+ }
@@ -0,0 +1,9 @@
1
+ export * from './Invoice.gql'
2
+ export * from './InvoiceCard'
3
+ export * from './InvoiceCard.gql'
4
+ export * from './InvoiceDetails'
5
+ export * from './InvoiceItem'
6
+ export * from './InvoiceItem.gql'
7
+ export * from './InvoiceItems'
8
+ export * from './InvoiceTotal.gql'
9
+ export * from './InvoiceTotals'
@@ -1,46 +1,61 @@
1
1
  import { SelectElement, TextFieldElement } from '@graphcommerce/ecommerce-ui'
2
2
  import { FormRow } from '@graphcommerce/next-ui'
3
- import type { UseFormReturn } from '@graphcommerce/react-hook-form'
3
+ import type {
4
+ FieldPath,
5
+ FieldValues,
6
+ PathValue,
7
+ UseFormReturn,
8
+ } from '@graphcommerce/react-hook-form'
4
9
  import { assertFormGqlOperation } from '@graphcommerce/react-hook-form'
5
10
  import { i18n } from '@lingui/core'
6
11
  import { Trans } from '@lingui/react'
7
12
 
8
13
  // eslint-disable-next-line @typescript-eslint/no-restricted-imports
9
14
 
10
- type NameFieldValues = {
11
- firstname?: string
12
- lastname?: string
13
- prefix?: string
14
- }
15
-
16
- export type NameFieldProps = {
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- form: UseFormReturn<any>
15
+ export type NameFieldProps<TFieldValues extends FieldValues = FieldValues> = {
16
+ form: UseFormReturn<TFieldValues>
17
+ names?: {
18
+ firstname: FieldPath<TFieldValues>
19
+ lastname: FieldPath<TFieldValues>
20
+ prefix?: FieldPath<TFieldValues>
21
+ }
19
22
  readOnly?: boolean
20
23
  prefix?: boolean
21
24
  prefixes?: string[]
22
25
  }
23
26
 
24
- export function NameFields(props: NameFieldProps) {
27
+ export function NameFields<TFieldValues extends FieldValues = FieldValues>(
28
+ props: NameFieldProps<TFieldValues>,
29
+ ) {
25
30
  const mr = i18n._(/* i18n */ 'Mr')
26
31
  const mrs = i18n._(/* i18n */ 'Mrs')
27
32
  const other = i18n._(/* i18n */ 'Other')
28
33
 
29
- const { prefix, form, readOnly, prefixes = [mr, mrs, other] } = props
30
- assertFormGqlOperation<NameFieldValues>(form)
34
+ const {
35
+ form,
36
+ readOnly,
37
+ prefixes = [mr, mrs, other],
38
+ prefix,
39
+ names = {
40
+ firstname: 'firstname' as FieldPath<TFieldValues>,
41
+ lastname: 'lastname' as FieldPath<TFieldValues>,
42
+ prefix: prefix ? ('prefix' as FieldPath<TFieldValues>) : undefined,
43
+ },
44
+ } = props
45
+ assertFormGqlOperation<TFieldValues>(form)
31
46
 
32
47
  const { control, required } = form
33
48
 
34
49
  return (
35
50
  <>
36
- {prefix && (
51
+ {names.prefix && (
37
52
  <FormRow>
38
53
  <SelectElement
39
54
  variant='outlined'
40
- defaultValue={prefixes[0]}
55
+ defaultValue={prefixes[0] as PathValue<TFieldValues, FieldPath<TFieldValues>>}
41
56
  control={control}
42
57
  required={required.prefix}
43
- name='prefix'
58
+ name={names.prefix}
44
59
  label={<Trans id='Prefix' />}
45
60
  showValid
46
61
  InputProps={{ readOnly }}
@@ -51,7 +66,7 @@ export function NameFields(props: NameFieldProps) {
51
66
  <FormRow>
52
67
  <TextFieldElement
53
68
  control={control}
54
- name='firstname'
69
+ name={names.firstname}
55
70
  required={required.firstname}
56
71
  variant='outlined'
57
72
  type='text'
@@ -61,7 +76,7 @@ export function NameFields(props: NameFieldProps) {
61
76
  />
62
77
  <TextFieldElement
63
78
  control={control}
64
- name='lastname'
79
+ name={names.lastname}
65
80
  required={required.lastname}
66
81
  variant='outlined'
67
82
  type='text'
@@ -0,0 +1,16 @@
1
+ fragment OrderAdditional on CustomerOrder {
2
+ ...CancelOrderFragment
3
+ number
4
+ invoices {
5
+ ...InvoiceCard
6
+ }
7
+ credit_memos {
8
+ ...CreditMemoCard
9
+ }
10
+ shipments {
11
+ ...ShipmentCard
12
+ }
13
+ comments {
14
+ ...SalesCommentItem
15
+ }
16
+ }
@@ -0,0 +1,51 @@
1
+ import { filterNonNullableKeys, SectionContainer, sxx } from '@graphcommerce/next-ui'
2
+ import { Box, type SxProps, type Theme } from '@mui/material'
3
+ import { CancelOrderForm } from '../../CancelOrder/CancelOrderForm'
4
+ import { CreditMemoCard } from '../../CreditMemo/CreditMemoCard'
5
+ import { InvoiceCard } from '../../Invoice/InvoiceCard'
6
+ import { ShipmentCard } from '../../Shipment/ShipmentCard'
7
+ import { SalesComments } from '../OrderComments/SalesComments'
8
+ import type { OrderAdditionalFragment } from './OrderAdditional.gql'
9
+
10
+ export type OrderAdditionalProps = {
11
+ order: OrderAdditionalFragment
12
+ sx?: SxProps<Theme>
13
+ children?: React.ReactNode
14
+ additionalForms?: React.ReactNode
15
+ }
16
+
17
+ export function OrderAdditional(props: OrderAdditionalProps) {
18
+ const { order, children, sx, additionalForms } = props
19
+ const comments = filterNonNullableKeys(order.comments)
20
+ const invoices = filterNonNullableKeys(order.invoices)
21
+ const shipments = filterNonNullableKeys(order.shipments)
22
+ const creditMemos = filterNonNullableKeys(order.credit_memos)
23
+
24
+ return (
25
+ <Box
26
+ sx={sxx(
27
+ (theme) => ({ mb: theme.spacings.lg, display: 'grid', rowGap: theme.spacings.xs }),
28
+ sx,
29
+ )}
30
+ >
31
+ {comments.length > 0 ? <SalesComments comments={comments} /> : null}
32
+
33
+ {shipments.map((shipment) => (
34
+ <ShipmentCard key={shipment.id} shipment={shipment} orderNumber={order.number} />
35
+ ))}
36
+
37
+ {invoices.map((invoice) => (
38
+ <InvoiceCard key={invoice.id} invoice={invoice} orderNumber={order.number} />
39
+ ))}
40
+
41
+ {creditMemos.map((creditMemo) => (
42
+ <CreditMemoCard key={creditMemo.id} creditMemo={creditMemo} orderNumber={order.number} />
43
+ ))}
44
+
45
+ {children}
46
+
47
+ <CancelOrderForm order={order} />
48
+ {additionalForms}
49
+ </Box>
50
+ )
51
+ }
@@ -0,0 +1,13 @@
1
+ fragment OrderCard on CustomerOrder {
2
+ number
3
+ order_date
4
+ total {
5
+ grand_total {
6
+ ...Money
7
+ }
8
+ }
9
+ items {
10
+ ...OrderCardItem
11
+ }
12
+ ...OrderStateLabel
13
+ }
@@ -12,7 +12,7 @@ import {
12
12
  } from '@graphcommerce/next-ui'
13
13
  import { Trans } from '@lingui/macro'
14
14
  import type { SxProps, Theme } from '@mui/material'
15
- import { Box, lighten, Paper, Skeleton } from '@mui/material'
15
+ import { Avatar, Box, lighten, Paper, Skeleton } from '@mui/material'
16
16
  import { OrderStateLabel } from '../OrderStateLabel/OrderStateLabel'
17
17
  import type { OrderCardFragment } from './OrderCard.gql'
18
18
 
@@ -32,7 +32,7 @@ export function OrderCard(props: OrderCardProps) {
32
32
  const itemsWithImages = filterNonNullableKeys(items, ['product_url_key', 'product'])
33
33
  .map((item) => {
34
34
  const img = item.product.thumbnail
35
- if (!img?.url || img.url.includes('/placeholder/')) return null
35
+ if (!img?.url) return null
36
36
  return { ...img, url: img.url }
37
37
  })
38
38
  .filter((v) => !!v)
@@ -94,22 +94,26 @@ export function OrderCard(props: OrderCardProps) {
94
94
  gap: 1,
95
95
  }}
96
96
  >
97
- {itemsWithImages.slice(0, maxItemsToShow).map((item) => (
98
- <Image
99
- key={item.url}
100
- alt={item.label ?? ''}
101
- layout='fill'
102
- src={item.url}
103
- width={96}
104
- height={96}
105
- sx={{ borderRadius: 4, objectFit: 'contain' }}
106
- pictureProps={{
107
- sx: {
108
- gridArea: itemsWithImages.length === 1 ? '1 / 1 / 3 / 3' : undefined,
109
- },
110
- }}
111
- />
112
- ))}
97
+ {itemsWithImages.slice(0, maxItemsToShow).map((item, index) => {
98
+ const key = `${item.url}-${index}`
99
+
100
+ return (
101
+ <Image
102
+ key={key}
103
+ alt={item.label ?? ''}
104
+ layout='fill'
105
+ src={item.url}
106
+ width={96}
107
+ height={96}
108
+ sx={{ borderRadius: 4, objectFit: 'contain' }}
109
+ pictureProps={{
110
+ sx: {
111
+ gridArea: itemsWithImages.length === 1 ? '1 / 1 / 3 / 3' : undefined,
112
+ },
113
+ }}
114
+ />
115
+ )
116
+ })}
113
117
 
114
118
  {totalItems > 4 && (
115
119
  <Box
@@ -1,4 +1,5 @@
1
1
  fragment OrderCardItem on OrderItemInterface {
2
+ id
2
3
  product_sku
3
4
  product_url_key
4
5
  product {
@@ -0,0 +1,5 @@
1
+ fragment OrderComments on CustomerOrder {
2
+ comments {
3
+ ...SalesCommentItem
4
+ }
5
+ }
@@ -0,0 +1,4 @@
1
+ fragment SalesCommentItem on SalesCommentItem {
2
+ message
3
+ timestamp
4
+ }
@@ -0,0 +1,28 @@
1
+ import {
2
+ filterNonNullableKeys,
3
+ RelativeToTimeFormat,
4
+ SectionContainer,
5
+ } from '@graphcommerce/next-ui'
6
+ import type { SxProps, Theme } from '@mui/material'
7
+ import type { SalesCommentItemFragment } from './SalesCommentItem.gql'
8
+
9
+ export type SalesCommentsProps = {
10
+ comments: (SalesCommentItemFragment | null | undefined)[] | null | undefined
11
+ sx?: SxProps<Theme>
12
+ }
13
+
14
+ export function SalesComments(props: SalesCommentsProps) {
15
+ const { comments, sx } = props
16
+
17
+ if (!comments?.length) return null
18
+
19
+ return (
20
+ <SectionContainer labelLeft='Comments' sx={sx}>
21
+ {filterNonNullableKeys(comments).map((comment) => (
22
+ <div key={comment.message}>
23
+ {comment.message} <RelativeToTimeFormat date={comment.timestamp} />
24
+ </div>
25
+ ))}
26
+ </SectionContainer>
27
+ )
28
+ }
@@ -0,0 +1,17 @@
1
+ fragment OrderAddress on OrderAddress {
2
+ company
3
+ fax
4
+ middlename
5
+ prefix
6
+ region
7
+ suffix
8
+ telephone
9
+ vat_id
10
+ city
11
+ postcode
12
+ firstname
13
+ lastname
14
+ street
15
+ country_code
16
+ region_id
17
+ }
@@ -0,0 +1,38 @@
1
+ fragment OrderDetails on CustomerOrder {
2
+ id
3
+ number
4
+ order_date
5
+ status
6
+ invoices {
7
+ id
8
+ number
9
+ }
10
+ shipping_method
11
+ shipments {
12
+ id
13
+ tracking {
14
+ ...TrackingLink
15
+ }
16
+ }
17
+ # applied_coupons {
18
+ # ...AppliedCoupon
19
+ # }
20
+ payment_methods {
21
+ name
22
+ type
23
+ additional_data {
24
+ name
25
+ value
26
+ }
27
+ }
28
+ billing_address {
29
+ ...OrderAddress
30
+ }
31
+ shipping_address {
32
+ ...OrderAddress
33
+ }
34
+ carrier
35
+ total {
36
+ ...OrderTotal
37
+ }
38
+ }
@@ -2,18 +2,17 @@ import {
2
2
  breakpointVal,
3
3
  DateTimeFormat,
4
4
  extendableComponent,
5
- iconInvoice,
6
- IconSvg,
7
5
  SectionContainer,
8
6
  } from '@graphcommerce/next-ui'
9
7
  import { Trans } from '@lingui/macro'
10
8
  import type { SxProps, Theme } from '@mui/material'
11
9
  import { Box, lighten, Typography } from '@mui/material'
12
- import { AddressMultiLine } from '../AddressMultiLine/AddressMultiLine'
13
- import { TrackingLink } from '../TrackingLink/TrackingLink'
10
+ import { AddressMultiLine } from '../../AddressMultiLine/AddressMultiLine'
11
+ import { TrackingLink } from '../../TrackingLink/TrackingLink'
14
12
  import type { OrderDetailsFragment } from './OrderDetails.gql'
15
13
 
16
- export type OrderDetailsProps = Partial<OrderDetailsFragment> & {
14
+ export type OrderDetailsProps = {
15
+ order: OrderDetailsFragment
17
16
  sx?: SxProps<Theme>
18
17
  }
19
18
 
@@ -28,6 +27,7 @@ const parts = [
28
27
  const { classes } = extendableComponent(componentName, parts)
29
28
 
30
29
  export function OrderDetails(props: OrderDetailsProps) {
30
+ const { order, sx = [] } = props
31
31
  const {
32
32
  number,
33
33
  order_date,
@@ -37,29 +37,27 @@ export function OrderDetails(props: OrderDetailsProps) {
37
37
  shipments,
38
38
  shipping_method,
39
39
  invoices,
40
- sx = [],
41
- } = props
40
+ } = order
42
41
 
43
42
  return (
44
- <SectionContainer
45
- labelLeft={<Trans>Order details</Trans>}
43
+ <Box
46
44
  sx={[
47
45
  (theme) => ({
48
- padding: theme.spacings.sm,
49
- marginBottom: theme.spacings.md,
50
- background:
51
- theme.palette.mode === 'light'
52
- ? theme.palette.background.default
53
- : lighten(theme.palette.background.default, 0.15),
54
- ...breakpointVal(
55
- 'borderRadius',
56
- theme.shape.borderRadius * 2,
57
- theme.shape.borderRadius * 3,
58
- theme.breakpoints.values,
59
- ),
60
- '& .SectionHeader-root': {
61
- mt: 0,
62
- mb: theme.spacings.xs,
46
+ margin: `${theme.spacings.sm} 0`,
47
+ '& > div:last-of-type': {
48
+ borderRadius: '0',
49
+ ...breakpointVal(
50
+ 'borderBottomLeftRadius',
51
+ theme.shape.borderRadius * 2,
52
+ theme.shape.borderRadius * 3,
53
+ theme.breakpoints.values,
54
+ ),
55
+ ...breakpointVal(
56
+ 'borderBottomRightRadius',
57
+ theme.shape.borderRadius * 2,
58
+ theme.shape.borderRadius * 3,
59
+ theme.breakpoints.values,
60
+ ),
63
61
  },
64
62
  }),
65
63
  ...(Array.isArray(sx) ? sx : [sx]),
@@ -67,25 +65,39 @@ export function OrderDetails(props: OrderDetailsProps) {
67
65
  >
68
66
  <Box
69
67
  className={classes.orderDetailContainer}
70
- sx={[
71
- (theme) => ({
72
- gridColumnGap: theme.spacings.xxl,
73
- gridRowGap: theme.spacings.md,
74
- display: 'grid',
75
- [theme.breakpoints.up('sm')]: {
76
- gridTemplateColumns: '1fr 1fr',
77
- marginTop: theme.spacings.xxs,
78
- },
79
- }),
80
- ...(Array.isArray(sx) ? sx : [sx]),
81
- ]}
68
+ sx={(theme) => ({
69
+ ...breakpointVal(
70
+ 'borderTopLeftRadius',
71
+ theme.shape.borderRadius * 2,
72
+ theme.shape.borderRadius * 3,
73
+ theme.breakpoints.values,
74
+ ),
75
+ ...breakpointVal(
76
+ 'borderTopRightRadius',
77
+ theme.shape.borderRadius * 2,
78
+ theme.shape.borderRadius * 3,
79
+ theme.breakpoints.values,
80
+ ),
81
+ background:
82
+ theme.palette.mode === 'light'
83
+ ? theme.palette.background.default
84
+ : lighten(theme.palette.background.default, 0.15),
85
+ padding: theme.spacings.sm,
86
+ gridColumnGap: theme.spacings.xxl,
87
+ gridRowGap: theme.spacings.sm,
88
+ display: 'grid',
89
+ [theme.breakpoints.up('sm')]: {
90
+ gridTemplateColumns: '1fr 1fr',
91
+ marginTop: theme.spacings.xxs,
92
+ },
93
+ })}
82
94
  >
83
95
  <Box className={classes.orderDetailRow}>
84
96
  <SectionContainer
85
97
  variantLeft='h5'
86
98
  labelLeft={<Trans>Order number</Trans>}
87
99
  className={classes.orderDetailTitle}
88
- sx={{ '& .SectionHeader-root': { marginTop: 0, paddingBottom: '4px' } }}
100
+ sx={{ '& .SectionHeader-root': { marginTop: 0, paddingBottom: '8px' } }}
89
101
  >
90
102
  <Typography>{number}</Typography>
91
103
  </SectionContainer>
@@ -96,7 +108,7 @@ export function OrderDetails(props: OrderDetailsProps) {
96
108
  variantLeft='h5'
97
109
  labelLeft={<Trans>Order date</Trans>}
98
110
  className={classes.orderDetailTitle}
99
- sx={{ '& .SectionHeader-root': { marginTop: 0, paddingBottom: '4px' } }}
111
+ sx={{ '& .SectionHeader-root': { marginTop: 0, paddingBottom: '8px' } }}
100
112
  >
101
113
  <DateTimeFormat date={order_date} />
102
114
  </SectionContainer>
@@ -138,22 +150,7 @@ export function OrderDetails(props: OrderDetailsProps) {
138
150
  )}
139
151
 
140
152
  {payment_methods && payment_methods[0] && (
141
- <>
142
- <Typography>{payment_methods[0].name}</Typography>
143
- {invoices && invoices?.length > 0 && (
144
- <Box
145
- className={classes.invoice}
146
- sx={{
147
- display: 'flex',
148
- justifyContent: 'flex-start',
149
- alignItems: 'center',
150
- }}
151
- >
152
- <IconSvg src={iconInvoice} size='small' />
153
- {invoices?.[0]?.number}
154
- </Box>
155
- )}
156
- </>
153
+ <Typography>{payment_methods[0].name}</Typography>
157
154
  )}
158
155
  </SectionContainer>
159
156
  </Box>
@@ -166,7 +163,14 @@ export function OrderDetails(props: OrderDetailsProps) {
166
163
  className={classes.orderDetailTitle}
167
164
  sx={{ '& .SectionHeader-root': { marginTop: 0, paddingBottom: '4px' } }}
168
165
  >
169
- <AddressMultiLine {...shipping_address} />
166
+ <AddressMultiLine
167
+ {...shipping_address}
168
+ region={{
169
+ region: shipping_address.region,
170
+ region_id: shipping_address.region_id ? Number(shipping_address.region_id) : null,
171
+ }}
172
+ // custom_attributesV2={[]}
173
+ />
170
174
  </SectionContainer>
171
175
  </Box>
172
176
  )}
@@ -178,10 +182,19 @@ export function OrderDetails(props: OrderDetailsProps) {
178
182
  className={classes.orderDetailTitle}
179
183
  sx={{ '& .SectionHeader-root': { marginTop: 0, paddingBottom: '4px' } }}
180
184
  >
181
- <AddressMultiLine {...billing_address} />
185
+ {billing_address && (
186
+ <AddressMultiLine
187
+ {...billing_address}
188
+ region={{
189
+ region: billing_address.region,
190
+ region_id: billing_address.region_id ? Number(billing_address.region_id) : null,
191
+ }}
192
+ // custom_attributesV2={[]}
193
+ />
194
+ )}
182
195
  </SectionContainer>
183
196
  </Box>
184
197
  </Box>
185
- </SectionContainer>
198
+ </Box>
186
199
  )
187
200
  }