@graphcommerce/magento-customer 10.0.0-canary.66 → 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,11 @@
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
+
3
9
  ## 10.0.0-canary.66
4
10
 
5
11
  ## 10.0.0-canary.65
@@ -2,6 +2,7 @@ import { extendableComponent } from '@graphcommerce/next-ui'
2
2
  import { Trans } from '@lingui/react/macro'
3
3
  import type { SxProps, Theme } from '@mui/material'
4
4
  import { Box, Link } from '@mui/material'
5
+ import { useBillingAddressPermission } from '../../hooks'
5
6
  import { AddressMultiLine } from '../AddressMultiLine/AddressMultiLine'
6
7
  import { DeleteCustomerAddressForm } from '../DeleteCustomerAddressForm/DeleteCustomerAddressForm'
7
8
  import { UpdateDefaultAddressForm } from '../UpdateDefaultAddressForm/UpdateDefaultAddressForm'
@@ -16,6 +17,8 @@ const { classes } = extendableComponent(name, parts)
16
17
  export function AccountAddress(props: AccountAddressProps) {
17
18
  const { id, sx = [], ...addressProps } = props
18
19
 
20
+ const billingAddressReadonly = useBillingAddressPermission() === 'READONLY'
21
+
19
22
  return (
20
23
  <Box
21
24
  className={classes.root}
@@ -48,7 +51,9 @@ export function AccountAddress(props: AccountAddressProps) {
48
51
  <Link href={`/account/addresses/edit?addressId=${id}`} color='primary' underline='hover'>
49
52
  <Trans>Edit</Trans>
50
53
  </Link>
51
- <DeleteCustomerAddressForm addressId={id ?? undefined} />
54
+ {!(billingAddressReadonly && addressProps.default_billing) && (
55
+ <DeleteCustomerAddressForm addressId={id ?? undefined} />
56
+ )}
52
57
  </Box>
53
58
  </Box>
54
59
  )
@@ -6,6 +6,7 @@ import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
6
6
  import { Trans } from '@lingui/react/macro'
7
7
  import type { SxProps, Theme } from '@mui/material'
8
8
  import { useRouter } from 'next/router'
9
+ import { useBillingAddressPermission } from '../../hooks'
9
10
  import type { AccountAddressFragment } from '../AccountAddress/AccountAddress.gql'
10
11
  import { AddressFields } from '../AddressFields/AddressFields'
11
12
  import { CompanyFields } from '../CompanyFields'
@@ -24,10 +25,12 @@ export function EditAddressForm(props: EditAddressFormProps) {
24
25
  const { address, sx } = props
25
26
 
26
27
  const router = useRouter()
28
+ const billingAddressReadonly = useBillingAddressPermission() === 'READONLY'
27
29
 
28
30
  const form = useFormGqlMutation(
29
31
  UpdateCustomerAddressDocument,
30
32
  {
33
+ disabled: billingAddressReadonly && (address?.default_billing ?? false),
31
34
  defaultValues: {
32
35
  id: address?.id ?? undefined,
33
36
  firstname: address?.firstname,
@@ -97,17 +100,24 @@ export function EditAddressForm(props: EditAddressFormProps) {
97
100
  />
98
101
  </FormRow>
99
102
 
100
- <FormActions sx={{ paddingBottom: 0 }}>
101
- <Button
102
- type='submit'
103
- variant='pill'
104
- color='primary'
105
- size='large'
106
- loading={formState.isSubmitting}
107
- >
108
- <Trans>Save changes</Trans>
109
- </Button>
110
- </FormActions>
103
+ {billingAddressReadonly && address?.default_billing ? (
104
+ <Trans>
105
+ You can not change this address as it is your billing address. Not correct? Please
106
+ contact our support to update this.
107
+ </Trans>
108
+ ) : (
109
+ <FormActions sx={{ paddingBottom: 0 }}>
110
+ <Button
111
+ type='submit'
112
+ variant='pill'
113
+ color='primary'
114
+ size='large'
115
+ loading={formState.isSubmitting}
116
+ >
117
+ <Trans>Save changes</Trans>
118
+ </Button>
119
+ </FormActions>
120
+ )}
111
121
  </Form>
112
122
 
113
123
  <ApolloErrorSnackbar error={error} />
@@ -3,6 +3,7 @@ import { Trans } from '@lingui/react/macro'
3
3
  // eslint-disable-next-line @typescript-eslint/no-restricted-imports
4
4
  import { FormControl, FormControlLabel, FormHelperText, Switch } from '@mui/material'
5
5
  import React, { useEffect, useMemo } from 'react'
6
+ import { useBillingAddressPermission } from '../../hooks'
6
7
  import type { AccountAddressFragment } from '../AccountAddress/AccountAddress.gql'
7
8
  import { UpdateDefaultAddressDocument } from '../AccountAddresses/UpdateDefaultAddress.gql'
8
9
  import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
@@ -33,6 +34,8 @@ export function UpdateDefaultAddressForm(props: UpdateDefaultAddressFormProps) {
33
34
 
34
35
  const submit = handleSubmit(() => {})
35
36
 
37
+ const billingAddressReadonly = useBillingAddressPermission() === 'READONLY'
38
+
36
39
  useEffect(() => {
37
40
  reset(defaultValues)
38
41
  }, [defaultValues, reset])
@@ -74,6 +77,7 @@ export function UpdateDefaultAddressForm(props: UpdateDefaultAddressFormProps) {
74
77
  onBlur={onBlur}
75
78
  name={name}
76
79
  onChange={(e) => onChange((e as React.ChangeEvent<HTMLInputElement>).target.checked)}
80
+ disabled={billingAddressReadonly}
77
81
  />
78
82
 
79
83
  {formState.errors.defaultBilling?.message && (
@@ -4,9 +4,18 @@ enum CustomerAccountPermissions {
4
4
  DISABLED
5
5
  }
6
6
 
7
+ enum BillingAddressPermissions {
8
+ EDITABLE
9
+ READONLY
10
+ }
11
+
7
12
  extend input GraphCommercePermissions {
8
13
  """
9
14
  Enables / disabled the account section of the website. DISABLE_REGISTRATION will only disable the registration page.
10
15
  """
11
16
  customerAccount: CustomerAccountPermissions
17
+ """
18
+ Allows customers to change their billing address or locks it down.
19
+ """
20
+ billingAddress: BillingAddressPermissions
12
21
  }
package/hooks/index.ts CHANGED
@@ -4,12 +4,13 @@ export * from './CustomerToken.gql'
4
4
  export * from './IsEmailAvailable.gql'
5
5
  export * from './OrderCardItemImage.gql'
6
6
  export * from './OrderCardItemImages.gql'
7
- export * from './UseOrderCardItemImages.gql'
8
7
  export * from './useAccountSignInUpForm'
9
8
  export * from './useCustomerPermissions'
10
9
  export * from './useCustomerQuery'
11
10
  export * from './useCustomerSession'
12
11
  export * from './UseCustomerValidateToken.gql'
13
12
  export * from './useGuestQuery'
13
+ export * from './useBillingAddressPermission'
14
14
  export { default as useOrderCardItemImages } from './useOrderCardItemImages'
15
+ export * from './UseOrderCardItemImages.gql'
15
16
  export * from './useSignInForm'
@@ -0,0 +1,8 @@
1
+ import { permissions } from '@graphcommerce/next-config/config'
2
+ import { useStorefrontConfig } from '@graphcommerce/next-ui'
3
+
4
+ export function useBillingAddressPermission() {
5
+ return (
6
+ useStorefrontConfig().permissions?.billingAddress ?? permissions?.billingAddress ?? 'EDITABLE'
7
+ )
8
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-customer",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "10.0.0-canary.66",
5
+ "version": "10.0.0-canary.67",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -21,19 +21,20 @@
21
21
  "./plugins/magentoCustomerPrivateQueryContext": "./plugins/magentoCustomerPrivateQueryContext.ts"
22
22
  },
23
23
  "peerDependencies": {
24
- "@graphcommerce/ecommerce-ui": "^10.0.0-canary.66",
25
- "@graphcommerce/eslint-config-pwa": "^10.0.0-canary.66",
26
- "@graphcommerce/framer-next-pages": "^10.0.0-canary.66",
27
- "@graphcommerce/framer-utils": "^10.0.0-canary.66",
28
- "@graphcommerce/graphql": "^10.0.0-canary.66",
29
- "@graphcommerce/graphql-mesh": "^10.0.0-canary.66",
30
- "@graphcommerce/image": "^10.0.0-canary.66",
31
- "@graphcommerce/magento-graphql": "^10.0.0-canary.66",
32
- "@graphcommerce/magento-store": "^10.0.0-canary.66",
33
- "@graphcommerce/next-ui": "^10.0.0-canary.66",
34
- "@graphcommerce/prettier-config-pwa": "^10.0.0-canary.66",
35
- "@graphcommerce/react-hook-form": "^10.0.0-canary.66",
36
- "@graphcommerce/typescript-config-pwa": "^10.0.0-canary.66",
24
+ "@graphcommerce/ecommerce-ui": "^10.0.0-canary.67",
25
+ "@graphcommerce/eslint-config-pwa": "^10.0.0-canary.67",
26
+ "@graphcommerce/framer-next-pages": "^10.0.0-canary.67",
27
+ "@graphcommerce/framer-utils": "^10.0.0-canary.67",
28
+ "@graphcommerce/graphql": "^10.0.0-canary.67",
29
+ "@graphcommerce/graphql-mesh": "^10.0.0-canary.67",
30
+ "@graphcommerce/image": "^10.0.0-canary.67",
31
+ "@graphcommerce/magento-graphql": "^10.0.0-canary.67",
32
+ "@graphcommerce/magento-store": "^10.0.0-canary.67",
33
+ "@graphcommerce/next-config": "^10.0.0-canary.67",
34
+ "@graphcommerce/next-ui": "^10.0.0-canary.67",
35
+ "@graphcommerce/prettier-config-pwa": "^10.0.0-canary.67",
36
+ "@graphcommerce/react-hook-form": "^10.0.0-canary.67",
37
+ "@graphcommerce/typescript-config-pwa": "^10.0.0-canary.67",
37
38
  "@lingui/core": "^5",
38
39
  "@lingui/macro": "^5",
39
40
  "@lingui/react": "^5",
@@ -0,0 +1,10 @@
1
+ import { permissions } from '@graphcommerce/next-config/config'
2
+ import { storefrontConfig } from '@graphcommerce/next-ui'
3
+
4
+ export function getBillingAddressPermission(locale: string | undefined) {
5
+ return (
6
+ storefrontConfig(locale)?.permissions?.billingAddress ??
7
+ permissions?.billingAddress ??
8
+ 'EDITABLE'
9
+ )
10
+ }
package/utils/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './customerPermissions'
2
+ export * from './billingAddressPermission'
2
3
  export * from './orderState'