@graphcommerce/magento-customer 4.2.11 → 4.3.1

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,39 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1476](https://github.com/graphcommerce-org/graphcommerce/pull/1476) [`a12db31b9`](https://github.com/graphcommerce-org/graphcommerce/commit/a12db31b9db9d27d86f59c1bfe58a0879999b9d3) Thanks [@paales](https://github.com/paales)! - make sure the SignUp and SignIn forms can handle changes to the email field
8
+
9
+ ## 4.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#1463](https://github.com/graphcommerce-org/graphcommerce/pull/1463) [`7159d3ab3`](https://github.com/graphcommerce-org/graphcommerce/commit/7159d3ab31e937c9c921023c46e80db5813e789c) Thanks [@paales](https://github.com/paales)! - Make the CustomerToken injectable
14
+
15
+ * [#1466](https://github.com/graphcommerce-org/graphcommerce/pull/1466) [`ed2b67a06`](https://github.com/graphcommerce-org/graphcommerce/commit/ed2b67a0618d9db97e79ed2a8226e0ae12403943) Thanks [@FrankHarland](https://github.com/FrankHarland)! - Added a new useCustomerSession hook to allow for more fine grained control over loading data for customers.
16
+
17
+ ### Patch Changes
18
+
19
+ - [#1466](https://github.com/graphcommerce-org/graphcommerce/pull/1466) [`00f6167ff`](https://github.com/graphcommerce-org/graphcommerce/commit/00f6167ff4096bf7432f3d8e8e739ecbf6ab0dd2) Thanks [@FrankHarland](https://github.com/FrankHarland)! - Signing in requested client fields which weren't available on the server
20
+
21
+ * [#1465](https://github.com/graphcommerce-org/graphcommerce/pull/1465) [`32370574b`](https://github.com/graphcommerce-org/graphcommerce/commit/32370574bef6345b857ae911049ca27a64bc7e08) Thanks [@paales](https://github.com/paales)! - make sure the createCustomerV2 also marks the currenly registered email as known and also check the network if an email exists
22
+
23
+ - [#1461](https://github.com/graphcommerce-org/graphcommerce/pull/1461) [`4c146c682`](https://github.com/graphcommerce-org/graphcommerce/commit/4c146c68242e6edc616807fb73173cc959c26034) Thanks [@mikekeehnen](https://github.com/mikekeehnen)! - User is now able to change their email after the email check. Before the submit, the emailaddress gets checked from the props
24
+
25
+ - Updated dependencies [[`0363b9671`](https://github.com/graphcommerce-org/graphcommerce/commit/0363b9671db7c2932321d97faf6f1eb385238397), [`3ac90b57c`](https://github.com/graphcommerce-org/graphcommerce/commit/3ac90b57c68b96f9d81771d6664ed9435a28fc1d)]:
26
+ - @graphcommerce/next-ui@4.8.0
27
+ - @graphcommerce/ecommerce-ui@1.0.12
28
+ - @graphcommerce/magento-store@4.2.4
29
+
30
+ ## 4.2.12
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [[`c30893857`](https://github.com/graphcommerce-org/graphcommerce/commit/c3089385791291e812a48c2691a39a2325ee0439)]:
35
+ - @graphcommerce/magento-store@4.2.3
36
+
3
37
  ## 4.2.11
4
38
 
5
39
  ### Patch Changes
@@ -19,4 +19,5 @@ fragment CustomerAddress on CustomerAddress {
19
19
  telephone
20
20
 
21
21
  vat_id
22
+ default_shipping
22
23
  }
@@ -9,7 +9,7 @@ import { i18n } from '@lingui/core'
9
9
  import { Fab, FabProps as FabPropsType, NoSsr, SxProps, Theme } from '@mui/material'
10
10
  import PageLink from 'next/link'
11
11
  import React from 'react'
12
- import { CustomerTokenDocument, CustomerTokenQuery } from '../../hooks'
12
+ import { CustomerTokenDocument, CustomerTokenQuery, useCustomerSession } from '../../hooks'
13
13
 
14
14
  type CustomerFabContentProps = CustomerTokenQuery & {
15
15
  icon?: React.ReactNode
@@ -25,7 +25,7 @@ const { classes } = extendableComponent(name, parts)
25
25
 
26
26
  function CustomerFabContent(props: CustomerFabContentProps) {
27
27
  const { customerToken, icon, guestHref, authHref, FabProps, sx } = props
28
- const requireAuth = Boolean(!customerToken || !customerToken.valid)
28
+ const { requireAuth } = useCustomerSession()
29
29
 
30
30
  return (
31
31
  <PageLink href={requireAuth ? guestHref : authHref} passHref>
@@ -1,3 +1,4 @@
1
+ import { useGo, usePageContext } from '@graphcommerce/framer-next-pages'
1
2
  import { useQuery } from '@graphcommerce/graphql'
2
3
  import { CountryRegionsDocument } from '@graphcommerce/magento-store'
3
4
  import {
@@ -19,12 +20,18 @@ import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerE
19
20
  import { NameFields } from '../NameFields/NameFields'
20
21
  import { UpdateCustomerAddressDocument } from './UpdateCustomerAddress.gql'
21
22
 
22
- type EditAddressFormProps = { address?: AccountAddressFragment; sx?: SxProps<Theme> }
23
+ type EditAddressFormProps = {
24
+ address?: AccountAddressFragment
25
+ sx?: SxProps<Theme>
26
+ onCompleteRoute?: string
27
+ }
23
28
 
24
29
  export function EditAddressForm(props: EditAddressFormProps) {
25
30
  const countries = useQuery(CountryRegionsDocument).data?.countries
26
31
  const { address, sx } = props
27
- const router = useRouter()
32
+
33
+ const { closeSteps } = usePageContext()
34
+ const onComplete = useGo(closeSteps * -1)
28
35
 
29
36
  const form = useFormGqlMutation(
30
37
  UpdateCustomerAddressDocument,
@@ -62,10 +69,7 @@ export function EditAddressForm(props: EditAddressFormProps) {
62
69
  ...regionData,
63
70
  }
64
71
  },
65
- onComplete: () => {
66
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
67
- router.push('/account/addresses')
68
- },
72
+ onComplete,
69
73
  },
70
74
  { errorPolicy: 'all' },
71
75
  )
@@ -39,5 +39,6 @@ mutation UpdateCustomerAddress(
39
39
  }
40
40
  ) {
41
41
  id
42
+ ...CustomerAddress
42
43
  }
43
44
  }
@@ -1,5 +1,5 @@
1
1
  mutation SignIn($email: String!, $password: String!) {
2
2
  generateCustomerToken(email: $email, password: $password) {
3
- token
3
+ ...CustomerTokenFragment
4
4
  }
5
5
  }
@@ -13,7 +13,7 @@ export function SignInForm(props: SignInFormProps) {
13
13
  const { email, sx } = props
14
14
  const form = useFormGqlMutation(
15
15
  SignInDocument,
16
- { defaultValues: { email } },
16
+ { defaultValues: { email }, onBeforeSubmit: (values) => ({ ...values, email }) },
17
17
  { errorPolicy: 'all' },
18
18
  )
19
19
 
@@ -14,7 +14,7 @@ export function SignInFormInline(props: PropsWithChildren<InlineSignInFormProps>
14
14
  const { email, sx = [] } = props
15
15
  const form = useFormGqlMutation(
16
16
  SignInDocument,
17
- { defaultValues: { email } },
17
+ { defaultValues: { email }, onBeforeSubmit: (values) => ({ ...values, email }) },
18
18
  { errorPolicy: 'all' },
19
19
  )
20
20
  const { muiRegister, handleSubmit, required, formState, error } = form
@@ -25,7 +25,11 @@ export function SignUpForm(props: SignUpFormProps) {
25
25
  const form = useFormGqlMutation<
26
26
  SignUpMutation,
27
27
  SignUpMutationVariables & { confirmPassword?: string }
28
- >(Mutation, { defaultValues: { email } }, { errorPolicy: 'all' })
28
+ >(
29
+ Mutation,
30
+ { defaultValues: { email }, onBeforeSubmit: (values) => ({ ...values, email }) },
31
+ { errorPolicy: 'all' },
32
+ )
29
33
 
30
34
  const { muiRegister, handleSubmit, required, watch, formState, error } = form
31
35
  const [remainingError, inputError] = graphqlErrorByCategory({ category: 'graphql-input', error })
@@ -40,7 +40,9 @@ export function SignUpFormInline({
40
40
  firstname: firstname ?? '-',
41
41
  lastname: lastname ?? '-',
42
42
  },
43
+ onBeforeSubmit: (values) => ({ ...values, email }),
43
44
  })
45
+
44
46
  const { muiRegister, watch, handleSubmit, required, formState, error } = form
45
47
  const submitHandler = handleSubmit(onSubmitted)
46
48
  const watchPassword = watch('password')
@@ -1,4 +1,5 @@
1
1
  export * from './AccountAddress/AccountAddress'
2
+ export * from './AccountAddresses/AccountAddresses.gql'
2
3
  export * from './AccountAddresses/AccountAddresses'
3
4
  export * from './AddressFields/AddressFields'
4
5
  export * from './AddressMultiLine/AddressMultiLine'
@@ -1,8 +1,7 @@
1
1
  query CustomerToken {
2
2
  customerToken @client {
3
- __typename
4
- token
5
- valid
3
+ ...CustomerTokenFragment
6
4
  createdAt
5
+ valid
7
6
  }
8
7
  }
@@ -0,0 +1,4 @@
1
+ fragment CustomerTokenFragment on CustomerToken @injectable {
2
+ __typename
3
+ token
4
+ }
package/hooks/index.ts CHANGED
@@ -4,3 +4,5 @@ export * from './CustomerToken.gql'
4
4
  export * from './IsEmailAvailable.gql'
5
5
  export * from './useExtractCustomerErrors'
6
6
  export * from './useFormIsEmailAvailable'
7
+ export * from './useCustomerQuery'
8
+ export * from './useCustomerSession'
@@ -0,0 +1,11 @@
1
+ import { useQuery, TypedDocumentNode, QueryHookOptions } from '@graphcommerce/graphql'
2
+ import { useCustomerSession } from './useCustomerSession'
3
+
4
+ /** Will only execute when the customer is signed in. */
5
+ export function useCustomerQuery<Q, V>(
6
+ document: TypedDocumentNode<Q, V>,
7
+ queryOptions: QueryHookOptions<Q, V> = {},
8
+ ) {
9
+ const { token } = useCustomerSession()
10
+ return useQuery(document, { ...queryOptions, ssr: false, skip: !token })
11
+ }
@@ -0,0 +1,23 @@
1
+ import { useQuery } from '@graphcommerce/graphql'
2
+ import { CustomerTokenDocument } from './CustomerToken.gql'
3
+ import { CustomerTokenFragment } from './CustomerTokenFragment.gql'
4
+
5
+ export type UseCustomerTokenReturn =
6
+ | (CustomerTokenFragment & {
7
+ loggedIn: boolean
8
+ requireAuth: boolean
9
+ })
10
+ | (Partial<CustomerTokenFragment> & { loggedIn: false; requireAuth: true })
11
+
12
+ export function useCustomerSession(): UseCustomerTokenReturn {
13
+ const token = useQuery(CustomerTokenDocument, { ssr: false, fetchPolicy: 'cache-only' }).data
14
+ ?.customerToken
15
+
16
+ if (!token) return { loggedIn: false, requireAuth: true }
17
+
18
+ return {
19
+ ...token,
20
+ loggedIn: Boolean(token?.token && token.valid),
21
+ requireAuth: Boolean(!token || !token.valid),
22
+ }
23
+ }
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
4
4
  import { CustomerDocument } from './Customer.gql'
5
5
  import { CustomerTokenDocument } from './CustomerToken.gql'
6
6
  import { IsEmailAvailableDocument } from './IsEmailAvailable.gql'
7
+ import { useCustomerQuery } from './useCustomerQuery'
7
8
 
8
9
  export type UseFormIsEmailAvailableProps = {
9
10
  email?: string | null
@@ -13,15 +14,13 @@ export type UseFormIsEmailAvailableProps = {
13
14
  export function useFormIsEmailAvailable(props: UseFormIsEmailAvailableProps) {
14
15
  const { email, onSubmitted } = props
15
16
  const { data: token } = useQuery(CustomerTokenDocument)
16
- const customerQuery = useQuery(CustomerDocument, {
17
- ssr: false,
18
- skip: typeof token === 'undefined',
19
- })
17
+ const customerQuery = useCustomerQuery(CustomerDocument)
20
18
 
21
- const form = useFormGqlQuery(IsEmailAvailableDocument, {
22
- mode: 'onChange',
23
- defaultValues: { email: email ?? '' },
24
- })
19
+ const form = useFormGqlQuery(
20
+ IsEmailAvailableDocument,
21
+ { mode: 'onChange', defaultValues: { email: email ?? '' } },
22
+ { fetchPolicy: 'cache-and-network' },
23
+ )
25
24
  const { formState, data, handleSubmit } = form
26
25
 
27
26
  const submit = handleSubmit(onSubmitted || (() => {}))
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": "4.2.11",
5
+ "version": "4.3.1",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -18,13 +18,13 @@
18
18
  "@playwright/test": "^1.21.1"
19
19
  },
20
20
  "dependencies": {
21
- "@graphcommerce/ecommerce-ui": "1.0.11",
21
+ "@graphcommerce/ecommerce-ui": "1.0.12",
22
22
  "@graphcommerce/graphql": "3.1.3",
23
23
  "@graphcommerce/graphql-mesh": "4.1.3",
24
24
  "@graphcommerce/image": "3.1.5",
25
25
  "@graphcommerce/magento-graphql": "3.0.12",
26
- "@graphcommerce/magento-store": "4.2.2",
27
- "@graphcommerce/next-ui": "4.7.2",
26
+ "@graphcommerce/magento-store": "4.2.4",
27
+ "@graphcommerce/next-ui": "4.8.0",
28
28
  "@graphcommerce/react-hook-form": "3.1.3"
29
29
  },
30
30
  "peerDependencies": {
package/typePolicies.ts CHANGED
@@ -67,7 +67,7 @@ const createCustomer: FieldPolicy<Mutation['createCustomer']> = {
67
67
 
68
68
  export const customerTypePolicies: StrictTypedTypePolicies = {
69
69
  // Query: { fields: { customer } },
70
- Mutation: { fields: { generateCustomerToken, createCustomer } },
70
+ Mutation: { fields: { generateCustomerToken, createCustomer, createCustomerV2: createCustomer } },
71
71
  CustomerToken: { fields: { valid } },
72
72
  }
73
73