@graphcommerce/magento-customer 4.2.12 → 4.3.0

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,26 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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
8
+
9
+ * [#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.
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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
14
+
15
+ * [#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
16
+
17
+ - [#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
18
+
19
+ - Updated dependencies [[`0363b9671`](https://github.com/graphcommerce-org/graphcommerce/commit/0363b9671db7c2932321d97faf6f1eb385238397), [`3ac90b57c`](https://github.com/graphcommerce-org/graphcommerce/commit/3ac90b57c68b96f9d81771d6664ed9435a28fc1d)]:
20
+ - @graphcommerce/next-ui@4.8.0
21
+ - @graphcommerce/ecommerce-ui@1.0.12
22
+ - @graphcommerce/magento-store@4.2.4
23
+
3
24
  ## 4.2.12
4
25
 
5
26
  ### 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,13 @@ export function SignInForm(props: SignInFormProps) {
13
13
  const { email, sx } = props
14
14
  const form = useFormGqlMutation(
15
15
  SignInDocument,
16
- { defaultValues: { email } },
16
+ {
17
+ defaultValues: { email },
18
+ onBeforeSubmit: (values) => ({
19
+ ...values,
20
+ email,
21
+ }),
22
+ },
17
23
  { errorPolicy: 'all' },
18
24
  )
19
25
 
@@ -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.12",
5
+ "version": "4.3.0",
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.3",
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