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

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,201 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.101
4
+
5
+ ## 9.0.0-canary.100
6
+
7
+ ## 9.0.0-canary.99
8
+
9
+ ## 9.0.0-canary.98
10
+
11
+ ## 9.0.0-canary.97
12
+
13
+ ## 9.0.0-canary.96
14
+
15
+ ## 9.0.0-canary.95
16
+
17
+ ## 9.0.0-canary.94
18
+
19
+ ## 9.0.0-canary.93
20
+
21
+ ## 9.0.0-canary.92
22
+
23
+ ## 9.0.0-canary.91
24
+
25
+ ## 9.0.0-canary.90
26
+
27
+ ## 9.0.0-canary.89
28
+
29
+ ## 9.0.0-canary.88
30
+
31
+ ## 9.0.0-canary.87
32
+
33
+ ## 9.0.0-canary.86
34
+
35
+ ## 9.0.0-canary.85
36
+
37
+ ## 9.0.0-canary.84
38
+
39
+ ## 9.0.0-canary.83
40
+
41
+ ## 9.0.0-canary.82
42
+
43
+ ## 9.0.0-canary.81
44
+
45
+ ## 9.0.0-canary.80
46
+
47
+ ### Minor Changes
48
+
49
+ - [#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))
50
+
51
+ ## 9.0.0-canary.79
52
+
53
+ ## 9.0.0-canary.78
54
+
55
+ ## 9.0.0-canary.77
56
+
57
+ ## 9.0.0-canary.76
58
+
59
+ ## 9.0.0-canary.75
60
+
61
+ ## 9.0.0-canary.74
62
+
63
+ ## 9.0.0-canary.73
64
+
65
+ ## 9.0.0-canary.72
66
+
67
+ ## 9.0.0-canary.71
68
+
69
+ ## 9.0.0-canary.70
70
+
71
+ ## 9.0.0-canary.69
72
+
73
+ ## 9.0.0-canary.68
74
+
75
+ ### Patch Changes
76
+
77
+ - [#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))
78
+
79
+ ## 9.0.0-canary.67
80
+
81
+ ## 9.0.0-canary.66
82
+
83
+ ## 9.0.0-canary.65
84
+
85
+ ## 9.0.0-canary.64
86
+
87
+ ## 9.0.0-canary.63
88
+
89
+ ## 9.0.0-canary.62
90
+
91
+ ## 9.0.0-canary.61
92
+
93
+ ## 9.0.0-canary.60
94
+
95
+ ## 9.0.0-canary.59
96
+
97
+ ## 9.0.0-canary.58
98
+
99
+ ## 9.0.0-canary.57
100
+
101
+ ## 9.0.0-canary.56
102
+
103
+ ## 9.0.0-canary.55
104
+
105
+ ## 9.0.0-canary.54
106
+
107
+ ## 8.1.0-canary.53
108
+
109
+ ## 8.1.0-canary.52
110
+
111
+ ## 8.1.0-canary.51
112
+
113
+ ## 8.1.0-canary.50
114
+
115
+ ## 8.1.0-canary.49
116
+
117
+ ## 8.1.0-canary.48
118
+
119
+ ## 8.1.0-canary.47
120
+
121
+ ## 8.1.0-canary.46
122
+
123
+ ## 8.1.0-canary.45
124
+
125
+ ## 8.1.0-canary.44
126
+
127
+ ## 8.1.0-canary.43
128
+
129
+ ## 8.1.0-canary.42
130
+
131
+ ## 8.1.0-canary.41
132
+
133
+ ## 8.1.0-canary.40
134
+
135
+ ## 8.1.0-canary.39
136
+
137
+ ## 8.1.0-canary.38
138
+
139
+ ## 8.1.0-canary.37
140
+
141
+ ## 8.1.0-canary.36
142
+
143
+ ## 8.1.0-canary.35
144
+
145
+ ## 8.1.0-canary.34
146
+
147
+ ## 8.1.0-canary.33
148
+
149
+ ## 8.1.0-canary.32
150
+
151
+ ## 8.1.0-canary.31
152
+
153
+ ## 8.1.0-canary.30
154
+
155
+ ## 8.1.0-canary.29
156
+
157
+ ## 8.1.0-canary.28
158
+
159
+ ## 8.1.0-canary.27
160
+
161
+ ## 8.1.0-canary.26
162
+
163
+ ## 8.1.0-canary.25
164
+
165
+ ## 8.1.0-canary.24
166
+
167
+ ## 8.1.0-canary.23
168
+
169
+ ## 8.1.0-canary.22
170
+
171
+ ## 8.1.0-canary.21
172
+
173
+ ## 8.1.0-canary.20
174
+
175
+ ## 8.1.0-canary.19
176
+
177
+ ### Patch Changes
178
+
179
+ - [#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))
180
+
181
+ ## 8.1.0-canary.18
182
+
183
+ ## 8.1.0-canary.17
184
+
185
+ ## 8.1.0-canary.16
186
+
187
+ ## 8.1.0-canary.15
188
+
189
+ ## 8.1.0-canary.14
190
+
191
+ ## 8.1.0-canary.13
192
+
193
+ ## 8.1.0-canary.12
194
+
195
+ ## 8.1.0-canary.11
196
+
197
+ ## 8.1.0-canary.10
198
+
3
199
  ## 8.1.0-canary.9
4
200
 
5
201
  ## 8.1.0-canary.8
@@ -18,8 +214,7 @@
18
214
 
19
215
  ### Patch Changes
20
216
 
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))
217
+ - [#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
218
 
24
219
  ## 8.0.6-canary.1
25
220
 
@@ -97,11 +292,9 @@
97
292
 
98
293
  ### Patch Changes
99
294
 
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))
295
+ - [#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
296
 
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))
297
+ - [#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
298
 
106
299
  ## 8.0.0-canary.100
107
300
 
@@ -1433,31 +1626,31 @@
1433
1626
  All occurences of `<Trans>` and `t` need to be replaced:
1434
1627
 
1435
1628
  ```tsx
1436
- import { Trans, t } from "@lingui/macro";
1629
+ import { Trans, t } from '@lingui/macro'
1437
1630
 
1438
1631
  function MyComponent() {
1439
- const foo = "bar";
1632
+ const foo = 'bar'
1440
1633
  return (
1441
1634
  <div aria-label={t`Account ${foo}`}>
1442
1635
  <Trans>My Translation {foo}</Trans>
1443
1636
  </div>
1444
- );
1637
+ )
1445
1638
  }
1446
1639
  ```
1447
1640
 
1448
1641
  Needs to be replaced with:
1449
1642
 
1450
1643
  ```tsx
1451
- import { Trans } from "@lingui/react";
1452
- import { i18n } from "@lingui/core";
1644
+ import { Trans } from '@lingui/react'
1645
+ import { i18n } from '@lingui/core'
1453
1646
 
1454
1647
  function MyComponent() {
1455
- const foo = "bar";
1648
+ const foo = 'bar'
1456
1649
  return (
1457
1650
  <div aria-label={i18n._(/* i18n */ `Account {foo}`, { foo })}>
1458
- <Trans key="My Translation {foo}" values={{ foo }}></Trans>
1651
+ <Trans key='My Translation {foo}' values={{ foo }}></Trans>
1459
1652
  </div>
1460
- );
1653
+ )
1461
1654
  }
1462
1655
  ```
1463
1656
 
@@ -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.101",
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.101",
16
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.101",
17
+ "@graphcommerce/framer-scroller": "^9.0.0-canary.101",
18
+ "@graphcommerce/graphql": "^9.0.0-canary.101",
19
+ "@graphcommerce/image": "^9.0.0-canary.101",
20
+ "@graphcommerce/magento-cart": "^9.0.0-canary.101",
21
+ "@graphcommerce/magento-cart-shipping-address": "^9.0.0-canary.101",
22
+ "@graphcommerce/magento-store": "^9.0.0-canary.101",
23
+ "@graphcommerce/next-ui": "^9.0.0-canary.101",
24
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.101",
25
+ "@graphcommerce/react-hook-form": "^9.0.0-canary.101",
26
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.101",
26
27
  "@lingui/core": "^4.2.1",
27
28
  "@lingui/macro": "^4.2.1",
28
29
  "@lingui/react": "^4.2.1",