@graphcommerce/magento-cart-shipping-method 8.1.0-canary.9 → 9.0.0-canary.100

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.
@@ -1,4 +1,4 @@
1
- fragment AvailableShippingMethods on Cart @injectable @inject(into: ["ShippingAddress"]) {
1
+ fragment AvailableShippingMethods on Cart @inject(into: ["ShippingAddress"]) {
2
2
  shipping_addresses {
3
3
  available_shipping_methods {
4
4
  ...AvailableShippingMethod
@@ -1,4 +1,4 @@
1
- fragment ShippingMethodSelected on Cart @injectable {
1
+ fragment ShippingMethodSelected on Cart {
2
2
  id
3
3
  shipping_addresses {
4
4
  selected_shipping_method {
package/CHANGELOG.md CHANGED
@@ -1,5 +1,199 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.100
4
+
5
+ ## 9.0.0-canary.99
6
+
7
+ ## 9.0.0-canary.98
8
+
9
+ ## 9.0.0-canary.97
10
+
11
+ ## 9.0.0-canary.96
12
+
13
+ ## 9.0.0-canary.95
14
+
15
+ ## 9.0.0-canary.94
16
+
17
+ ## 9.0.0-canary.93
18
+
19
+ ## 9.0.0-canary.92
20
+
21
+ ## 9.0.0-canary.91
22
+
23
+ ## 9.0.0-canary.90
24
+
25
+ ## 9.0.0-canary.89
26
+
27
+ ## 9.0.0-canary.88
28
+
29
+ ## 9.0.0-canary.87
30
+
31
+ ## 9.0.0-canary.86
32
+
33
+ ## 9.0.0-canary.85
34
+
35
+ ## 9.0.0-canary.84
36
+
37
+ ## 9.0.0-canary.83
38
+
39
+ ## 9.0.0-canary.82
40
+
41
+ ## 9.0.0-canary.81
42
+
43
+ ## 9.0.0-canary.80
44
+
45
+ ### Minor Changes
46
+
47
+ - [#2341](https://github.com/graphcommerce-org/graphcommerce/pull/2341) [`1d6512d`](https://github.com/graphcommerce-org/graphcommerce/commit/1d6512d4118cfb46602aa1f2432c3566fdb3261d) - Rename experimental_useV2 prop to deprecated_useV1 in useFromGql and enable it by default ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
48
+
49
+ ## 9.0.0-canary.79
50
+
51
+ ## 9.0.0-canary.78
52
+
53
+ ## 9.0.0-canary.77
54
+
55
+ ## 9.0.0-canary.76
56
+
57
+ ## 9.0.0-canary.75
58
+
59
+ ## 9.0.0-canary.74
60
+
61
+ ## 9.0.0-canary.73
62
+
63
+ ## 9.0.0-canary.72
64
+
65
+ ## 9.0.0-canary.71
66
+
67
+ ## 9.0.0-canary.70
68
+
69
+ ## 9.0.0-canary.69
70
+
71
+ ## 9.0.0-canary.68
72
+
73
+ ### Patch Changes
74
+
75
+ - [#2340](https://github.com/graphcommerce-org/graphcommerce/pull/2340) [`18691c7`](https://github.com/graphcommerce-org/graphcommerce/commit/18691c71e6940e8baa8f93c3b798be4d6e5a8a9a) - Select the only available shipping method as the current cart shipping method when there is only one shipping method available. ([@LaurensFranken](https://github.com/LaurensFranken))
76
+
77
+ ## 9.0.0-canary.67
78
+
79
+ ## 9.0.0-canary.66
80
+
81
+ ## 9.0.0-canary.65
82
+
83
+ ## 9.0.0-canary.64
84
+
85
+ ## 9.0.0-canary.63
86
+
87
+ ## 9.0.0-canary.62
88
+
89
+ ## 9.0.0-canary.61
90
+
91
+ ## 9.0.0-canary.60
92
+
93
+ ## 9.0.0-canary.59
94
+
95
+ ## 9.0.0-canary.58
96
+
97
+ ## 9.0.0-canary.57
98
+
99
+ ## 9.0.0-canary.56
100
+
101
+ ## 9.0.0-canary.55
102
+
103
+ ## 9.0.0-canary.54
104
+
105
+ ## 8.1.0-canary.53
106
+
107
+ ## 8.1.0-canary.52
108
+
109
+ ## 8.1.0-canary.51
110
+
111
+ ## 8.1.0-canary.50
112
+
113
+ ## 8.1.0-canary.49
114
+
115
+ ## 8.1.0-canary.48
116
+
117
+ ## 8.1.0-canary.47
118
+
119
+ ## 8.1.0-canary.46
120
+
121
+ ## 8.1.0-canary.45
122
+
123
+ ## 8.1.0-canary.44
124
+
125
+ ## 8.1.0-canary.43
126
+
127
+ ## 8.1.0-canary.42
128
+
129
+ ## 8.1.0-canary.41
130
+
131
+ ## 8.1.0-canary.40
132
+
133
+ ## 8.1.0-canary.39
134
+
135
+ ## 8.1.0-canary.38
136
+
137
+ ## 8.1.0-canary.37
138
+
139
+ ## 8.1.0-canary.36
140
+
141
+ ## 8.1.0-canary.35
142
+
143
+ ## 8.1.0-canary.34
144
+
145
+ ## 8.1.0-canary.33
146
+
147
+ ## 8.1.0-canary.32
148
+
149
+ ## 8.1.0-canary.31
150
+
151
+ ## 8.1.0-canary.30
152
+
153
+ ## 8.1.0-canary.29
154
+
155
+ ## 8.1.0-canary.28
156
+
157
+ ## 8.1.0-canary.27
158
+
159
+ ## 8.1.0-canary.26
160
+
161
+ ## 8.1.0-canary.25
162
+
163
+ ## 8.1.0-canary.24
164
+
165
+ ## 8.1.0-canary.23
166
+
167
+ ## 8.1.0-canary.22
168
+
169
+ ## 8.1.0-canary.21
170
+
171
+ ## 8.1.0-canary.20
172
+
173
+ ## 8.1.0-canary.19
174
+
175
+ ### Patch Changes
176
+
177
+ - [#2264](https://github.com/graphcommerce-org/graphcommerce/pull/2264) [`e5291a4`](https://github.com/graphcommerce-org/graphcommerce/commit/e5291a426c57635f69fb9ec44f4abe150f04c9ed) - prevent rendering 'null' when method_title is not provided ([@carlocarels90](https://github.com/carlocarels90))
178
+
179
+ ## 8.1.0-canary.18
180
+
181
+ ## 8.1.0-canary.17
182
+
183
+ ## 8.1.0-canary.16
184
+
185
+ ## 8.1.0-canary.15
186
+
187
+ ## 8.1.0-canary.14
188
+
189
+ ## 8.1.0-canary.13
190
+
191
+ ## 8.1.0-canary.12
192
+
193
+ ## 8.1.0-canary.11
194
+
195
+ ## 8.1.0-canary.10
196
+
3
197
  ## 8.1.0-canary.9
4
198
 
5
199
  ## 8.1.0-canary.8
@@ -18,8 +212,7 @@
18
212
 
19
213
  ### Patch Changes
20
214
 
21
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`530076e`](https://github.com/graphcommerce-org/graphcommerce/commit/530076e3664703cb8b577b7fcf1998a420819f60) - Moved all usages of useFormPersist to the <FormPersist/> component to prevent rerenders.
22
- ([@FrankHarland](https://github.com/FrankHarland))
215
+ - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`530076e`](https://github.com/graphcommerce-org/graphcommerce/commit/530076e3664703cb8b577b7fcf1998a420819f60) - Moved all usages of useFormPersist to the <FormPersist/> component to prevent rerenders. ([@FrankHarland](https://github.com/FrankHarland))
23
216
 
24
217
  ## 8.0.6-canary.1
25
218
 
@@ -97,11 +290,9 @@
97
290
 
98
291
  ### Patch Changes
99
292
 
100
- - [#2093](https://github.com/graphcommerce-org/graphcommerce/pull/2093) [`112b041`](https://github.com/graphcommerce-org/graphcommerce/commit/112b041f01a33fbd521ce3eb3955844f96b29917) - Created a new experimental mutation abort feature inside `useFormGql`. This will allow redundant mutations to be canceled. This is enabled when the `experimental_useV2` prop on the `useFormGql` hook is used.
101
- ([@mikekeehnen](https://github.com/mikekeehnen))
293
+ - [#2093](https://github.com/graphcommerce-org/graphcommerce/pull/2093) [`112b041`](https://github.com/graphcommerce-org/graphcommerce/commit/112b041f01a33fbd521ce3eb3955844f96b29917) - Created a new experimental mutation abort feature inside `useFormGql`. This will allow redundant mutations to be canceled. This is enabled when the `experimental_useV2` prop on the `useFormGql` hook is used. ([@mikekeehnen](https://github.com/mikekeehnen))
102
294
 
103
- - [#2115](https://github.com/graphcommerce-org/graphcommerce/pull/2115) [`105a1af`](https://github.com/graphcommerce-org/graphcommerce/commit/105a1af8b820de8873e430ae398f1922d39a9110) - Disabled ripple animations on all ActionCard ‘Select’ and ‘Change’ so the rendering is more subtle during checkout.
104
- ([@Jessevdpoel](https://github.com/Jessevdpoel))
295
+ - [#2115](https://github.com/graphcommerce-org/graphcommerce/pull/2115) [`105a1af`](https://github.com/graphcommerce-org/graphcommerce/commit/105a1af8b820de8873e430ae398f1922d39a9110) - Disabled ripple animations on all ActionCard ‘Select’ and ‘Change’ so the rendering is more subtle during checkout. ([@Jessevdpoel](https://github.com/Jessevdpoel))
105
296
 
106
297
  ## 8.0.0-canary.100
107
298
 
@@ -1433,31 +1624,31 @@
1433
1624
  All occurences of `<Trans>` and `t` need to be replaced:
1434
1625
 
1435
1626
  ```tsx
1436
- import { Trans, t } from "@lingui/macro";
1627
+ import { Trans, t } from '@lingui/macro'
1437
1628
 
1438
1629
  function MyComponent() {
1439
- const foo = "bar";
1630
+ const foo = 'bar'
1440
1631
  return (
1441
1632
  <div aria-label={t`Account ${foo}`}>
1442
1633
  <Trans>My Translation {foo}</Trans>
1443
1634
  </div>
1444
- );
1635
+ )
1445
1636
  }
1446
1637
  ```
1447
1638
 
1448
1639
  Needs to be replaced with:
1449
1640
 
1450
1641
  ```tsx
1451
- import { Trans } from "@lingui/react";
1452
- import { i18n } from "@lingui/core";
1642
+ import { Trans } from '@lingui/react'
1643
+ import { i18n } from '@lingui/core'
1453
1644
 
1454
1645
  function MyComponent() {
1455
- const foo = "bar";
1646
+ const foo = 'bar'
1456
1647
  return (
1457
1648
  <div aria-label={i18n._(/* i18n */ `Account {foo}`, { foo })}>
1458
- <Trans key="My Translation {foo}" values={{ foo }}></Trans>
1649
+ <Trans key='My Translation {foo}' values={{ foo }}></Trans>
1459
1650
  </div>
1460
- );
1651
+ )
1461
1652
  }
1462
1653
  ```
1463
1654
 
@@ -1,6 +1,7 @@
1
+ import { ActionCardItemRenderProps } from '@graphcommerce/ecommerce-ui'
1
2
  import { useDisplayInclTax } from '@graphcommerce/magento-cart/hooks'
2
3
  import { Money } from '@graphcommerce/magento-store'
3
- import { ActionCard, ActionCardItemRenderProps } from '@graphcommerce/next-ui'
4
+ import { ActionCard } from '@graphcommerce/next-ui'
4
5
  import { Trans } from '@lingui/react'
5
6
  import { Button, Chip } from '@mui/material'
6
7
  import { AvailableShippingMethodFragment } from '../../AvailableShippingMethod/AvailableShippingMethod.gql'
@@ -26,7 +27,7 @@ export function ShippingMethodActionCard(props: ShippingMethodActionCardProps) {
26
27
  const isFree = amount && amount.value === 0
27
28
 
28
29
  const title =
29
- carrier_title === 'Free Shipping' ? carrier_title : `${carrier_title} ${method_title}`
30
+ carrier_title === 'Free Shipping' ? carrier_title : `${carrier_title} ${method_title || ''}`
30
31
 
31
32
  return (
32
33
  <ActionCard
@@ -1,15 +1,14 @@
1
+ import {
2
+ ActionCardItemBase,
3
+ ActionCardItemRenderProps,
4
+ ActionCardListForm,
5
+ } from '@graphcommerce/ecommerce-ui'
1
6
  import {
2
7
  ApolloCartErrorAlert,
3
8
  useCartQuery,
4
9
  useFormGqlMutationCart,
5
10
  } from '@graphcommerce/magento-cart'
6
- import {
7
- Form,
8
- FormHeader,
9
- ActionCardItemBase,
10
- ActionCardItemRenderProps,
11
- ActionCardListForm,
12
- } from '@graphcommerce/next-ui'
11
+ import { Form, FormHeader } from '@graphcommerce/next-ui'
13
12
  import {
14
13
  FormAutoSubmit,
15
14
  FormProvider,
@@ -21,7 +20,7 @@ import {
21
20
  import { i18n } from '@lingui/core'
22
21
  import { Trans } from '@lingui/react'
23
22
  import { SxProps, Theme } from '@mui/material'
24
- import { useMemo } from 'react'
23
+ import { useEffect, useMemo } from 'react'
25
24
  import { GetShippingMethodsDocument } from './GetShippingMethods.gql'
26
25
  import { ShippingMethodActionCard } from './ShippingMethodActionCard'
27
26
  import {
@@ -45,10 +44,9 @@ function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
45
44
  export function ShippingMethodForm(props: ShippingMethodFormProps) {
46
45
  const { step, sx, children, onBeforeSubmit = (vars) => vars, ...options } = props
47
46
  const { data: cartQuery } = useCartQuery(GetShippingMethodsDocument)
48
- const availableMethods = (
49
- cartQuery?.cart?.shipping_addresses?.[0]?.available_shipping_methods ?? []
50
- ).filter(notEmpty)
51
- const selectedMethod = cartQuery?.cart?.shipping_addresses?.[0]?.selected_shipping_method
47
+
48
+ const shippingAddress = cartQuery?.cart?.shipping_addresses?.[0]
49
+ const availableMethods = (shippingAddress?.available_shipping_methods ?? []).filter(notEmpty)
52
50
 
53
51
  const items = useMemo(
54
52
  () =>
@@ -67,19 +65,18 @@ export function ShippingMethodForm(props: ShippingMethodFormProps) {
67
65
  [availableMethods],
68
66
  )
69
67
 
70
- // The default: When there is only a single shipping method, select that one.
71
- let carrierMethod: string | undefined = items.length === 1 ? items[0]?.value : undefined
72
-
73
68
  // Override with the currently selected method if there is one.
74
- if (selectedMethod?.method_code)
75
- carrierMethod = `${selectedMethod.carrier_code}-${selectedMethod.method_code}`
69
+ const selectedMethod = cartQuery?.cart?.shipping_addresses?.[0]?.selected_shipping_method
70
+ const carrierMethod = selectedMethod?.method_code
71
+ ? `${selectedMethod.carrier_code}-${selectedMethod.method_code}`
72
+ : undefined
76
73
 
77
74
  const form = useFormGqlMutationCart<
78
75
  ShippingMethodFormMutation,
79
76
  ShippingMethodFormMutationVariables & { carrierMethod?: string }
80
77
  >(ShippingMethodFormDocument, {
78
+ skipUnchanged: true,
81
79
  defaultValues: { carrierMethod },
82
- experimental_useV2: true,
83
80
  onBeforeSubmit: (variables) => {
84
81
  const [carrier, method] = (variables.carrierMethod ?? '').split('-')
85
82
  return onBeforeSubmit({ ...variables, carrier, method })
@@ -87,13 +84,14 @@ export function ShippingMethodForm(props: ShippingMethodFormProps) {
87
84
  ...options,
88
85
  })
89
86
 
90
- const { handleSubmit, control, error } = form
87
+ const { handleSubmit, control, error, setValue } = form
91
88
  const submit = handleSubmit(() => {})
92
89
 
93
90
  useFormCompose({ form, step, submit, key: 'ShippingMethodForm' })
94
91
 
95
- if (items.length === 0) {
96
- items.push({
92
+ const renderItems = [...items]
93
+ if (renderItems.length === 0) {
94
+ renderItems.push({
97
95
  disabled: true,
98
96
  value: '',
99
97
  available: false,
@@ -107,6 +105,18 @@ export function ShippingMethodForm(props: ShippingMethodFormProps) {
107
105
  })
108
106
  }
109
107
 
108
+ const firstCarrierMethod = items.length === 1 ? items[0].value : undefined
109
+ useEffect(() => {
110
+ // If there is a shipping address AND there is only one shipping method
111
+ if (shippingAddress && firstCarrierMethod) {
112
+ // AND the current carrierMethod is not the same (or not set) as the single shipping method
113
+ if (carrierMethod !== firstCarrierMethod) {
114
+ // THEN set the shipping method to the only one available.
115
+ setValue('carrierMethod', firstCarrierMethod, { shouldValidate: true })
116
+ }
117
+ }
118
+ }, [shippingAddress, firstCarrierMethod, carrierMethod, setValue])
119
+
110
120
  return (
111
121
  <FormProvider {...form}>
112
122
  <FormAutoSubmit
@@ -127,7 +137,7 @@ export function ShippingMethodForm(props: ShippingMethodFormProps) {
127
137
  size='large'
128
138
  color='secondary'
129
139
  rules={{ required: i18n._(/* i18n */ 'Please select a shipping method') }}
130
- items={items}
140
+ items={renderItems}
131
141
  render={
132
142
  ShippingMethodActionCard as React.FC<ActionCardItemRenderProps<ActionCardItemBase>>
133
143
  }
package/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './Api/AvailableShippingMethods.gql'
2
2
  export * from './Api/ShippingMethodSelected.gql'
3
3
  export * from './components/ShippingMethodForm/ShippingMethodForm'
4
+ export * from './components/ShippingMethodForm/ShippingMethodForm.gql'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-cart-shipping-method",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.1.0-canary.9",
5
+ "version": "9.0.0-canary.100",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,17 +12,18 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.9",
16
- "@graphcommerce/framer-scroller": "^8.1.0-canary.9",
17
- "@graphcommerce/graphql": "^8.1.0-canary.9",
18
- "@graphcommerce/image": "^8.1.0-canary.9",
19
- "@graphcommerce/magento-cart": "^8.1.0-canary.9",
20
- "@graphcommerce/magento-cart-shipping-address": "^8.1.0-canary.9",
21
- "@graphcommerce/magento-store": "^8.1.0-canary.9",
22
- "@graphcommerce/next-ui": "^8.1.0-canary.9",
23
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.9",
24
- "@graphcommerce/react-hook-form": "^8.1.0-canary.9",
25
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.9",
15
+ "@graphcommerce/ecommerce-ui": "^9.0.0-canary.100",
16
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.100",
17
+ "@graphcommerce/framer-scroller": "^9.0.0-canary.100",
18
+ "@graphcommerce/graphql": "^9.0.0-canary.100",
19
+ "@graphcommerce/image": "^9.0.0-canary.100",
20
+ "@graphcommerce/magento-cart": "^9.0.0-canary.100",
21
+ "@graphcommerce/magento-cart-shipping-address": "^9.0.0-canary.100",
22
+ "@graphcommerce/magento-store": "^9.0.0-canary.100",
23
+ "@graphcommerce/next-ui": "^9.0.0-canary.100",
24
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.100",
25
+ "@graphcommerce/react-hook-form": "^9.0.0-canary.100",
26
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.100",
26
27
  "@lingui/core": "^4.2.1",
27
28
  "@lingui/macro": "^4.2.1",
28
29
  "@lingui/react": "^4.2.1",