@graphcommerce/magento-cart-shipping-address 10.0.0-canary.65 → 10.0.0-canary.67

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 10.0.0-canary.67
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2540](https://github.com/graphcommerce-org/graphcommerce/pull/2540) [`36e2bac`](https://github.com/graphcommerce-org/graphcommerce/commit/36e2bacb4fe765ce1fcd24dc36736e90bb17a7dc) - Add billingAddress permission (EDITABLE | READONLY) that controls whether the end user can update their billing address in the account section and checkout. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
8
+
9
+ ## 10.0.0-canary.66
10
+
3
11
  ## 10.0.0-canary.65
4
12
 
5
13
  ## 10.0.0-canary.64
@@ -12,7 +12,7 @@ import {
12
12
  useCartQuery,
13
13
  useFormGqlMutationCart,
14
14
  } from '@graphcommerce/magento-cart'
15
- import { CustomerDocument } from '@graphcommerce/magento-customer'
15
+ import { CustomerDocument, useBillingAddressPermission } from '@graphcommerce/magento-customer'
16
16
  import { customerAddressNoteEnable } from '@graphcommerce/next-config/config'
17
17
  import { filterNonNullableKeys, FormRow } from '@graphcommerce/next-ui'
18
18
  import { t } from '@lingui/core/macro'
@@ -44,6 +44,8 @@ export function CustomerAddressForm(props: CustomerAddressListProps) {
44
44
  const cart = cartQuery.data?.cart
45
45
  const isVirtual = cart?.is_virtual ?? false
46
46
 
47
+ const billingAddressReadonly = useBillingAddressPermission() === 'READONLY'
48
+
47
49
  const customerAddresses = filterNonNullableKeys(customer.data?.customer?.addresses, ['id'])
48
50
 
49
51
  const cartShipping = cart?.shipping_addresses?.[0]
@@ -80,6 +82,13 @@ export function CustomerAddressForm(props: CustomerAddressListProps) {
80
82
  mode = 'billing'
81
83
  }
82
84
 
85
+ // If the billingAddress permission is READONLY we are never allowed to update the billing address.
86
+ if (billingAddressReadonly) {
87
+ Mutation = SetCustomerShippingAddressOnCartDocument
88
+ cartAddressId = cartShippingId
89
+ mode = 'shipping'
90
+ }
91
+
83
92
  const form = useFormGqlMutationCart<
84
93
  SetCustomerShippingBillingAddressOnCartMutation,
85
94
  SetCustomerShippingBillingAddressOnCartMutationVariables & {
@@ -19,6 +19,7 @@ import {
19
19
  CompanyFields,
20
20
  CustomerDocument,
21
21
  NameFields,
22
+ useBillingAddressPermission,
22
23
  useCustomerQuery,
23
24
  } from '@graphcommerce/magento-customer'
24
25
  import { CountryRegionsDocument, StoreConfigDocument } from '@graphcommerce/magento-store'
@@ -45,6 +46,7 @@ export type ShippingAddressFormProps = Pick<UseFormComposeOptions, 'step'> & {
45
46
  sx?: SxProps<Theme>
46
47
  }
47
48
 
49
+ // eslint-disable-next-line react/display-name
48
50
  export const ShippingAddressForm = React.memo<ShippingAddressFormProps>((props) => {
49
51
  const { step, sx } = props
50
52
  const { data: cartQuery } = useCartQuery(GetAddressesDocument)
@@ -53,6 +55,8 @@ export const ShippingAddressForm = React.memo<ShippingAddressFormProps>((props)
53
55
  const countries = countryQuery.data?.countries ?? countryQuery.previousData?.countries
54
56
  const { data: customerQuery } = useCustomerQuery(CustomerDocument)
55
57
 
58
+ const billingAddressReadonly = useBillingAddressPermission() === 'READONLY'
59
+
56
60
  const shopCountry = config?.storeConfig?.locale?.split('_')?.[1].toUpperCase()
57
61
 
58
62
  const shippingAddress = cartQuery?.cart?.shipping_addresses?.[0]
@@ -86,6 +90,11 @@ export const ShippingAddressForm = React.memo<ShippingAddressFormProps>((props)
86
90
  Mutation = SetBillingAddressDocument
87
91
  }
88
92
 
93
+ // If the billingAddress permission is READONLY we are never allowed to update the billing address.
94
+ if (billingAddressReadonly) {
95
+ Mutation = SetShippingAddressDocument
96
+ }
97
+
89
98
  const form = useFormGqlMutationCart(Mutation, {
90
99
  defaultValues: isCartAddressACustomerAddress(customerQuery?.customer?.addresses, currentAddress)
91
100
  ? { saveInAddressBook: true, isCompany: false }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-cart-shipping-address",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "10.0.0-canary.65",
5
+ "version": "10.0.0-canary.67",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -15,17 +15,17 @@
15
15
  ".": "./index.ts"
16
16
  },
17
17
  "peerDependencies": {
18
- "@graphcommerce/ecommerce-ui": "^10.0.0-canary.65",
19
- "@graphcommerce/eslint-config-pwa": "^10.0.0-canary.65",
20
- "@graphcommerce/graphql": "^10.0.0-canary.65",
21
- "@graphcommerce/graphql-mesh": "^10.0.0-canary.65",
22
- "@graphcommerce/image": "^10.0.0-canary.65",
23
- "@graphcommerce/magento-cart": "^10.0.0-canary.65",
24
- "@graphcommerce/magento-customer": "^10.0.0-canary.65",
25
- "@graphcommerce/magento-store": "^10.0.0-canary.65",
26
- "@graphcommerce/next-ui": "^10.0.0-canary.65",
27
- "@graphcommerce/prettier-config-pwa": "^10.0.0-canary.65",
28
- "@graphcommerce/typescript-config-pwa": "^10.0.0-canary.65",
18
+ "@graphcommerce/ecommerce-ui": "^10.0.0-canary.67",
19
+ "@graphcommerce/eslint-config-pwa": "^10.0.0-canary.67",
20
+ "@graphcommerce/graphql": "^10.0.0-canary.67",
21
+ "@graphcommerce/graphql-mesh": "^10.0.0-canary.67",
22
+ "@graphcommerce/image": "^10.0.0-canary.67",
23
+ "@graphcommerce/magento-cart": "^10.0.0-canary.67",
24
+ "@graphcommerce/magento-customer": "^10.0.0-canary.67",
25
+ "@graphcommerce/magento-store": "^10.0.0-canary.67",
26
+ "@graphcommerce/next-ui": "^10.0.0-canary.67",
27
+ "@graphcommerce/prettier-config-pwa": "^10.0.0-canary.67",
28
+ "@graphcommerce/typescript-config-pwa": "^10.0.0-canary.67",
29
29
  "@lingui/core": "^5",
30
30
  "@lingui/macro": "^5",
31
31
  "@lingui/react": "^5",