@graphcommerce/react-hook-form 3.2.0 → 3.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,23 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1544](https://github.com/graphcommerce-org/graphcommerce/pull/1544) [`5f927ebdc`](https://github.com/graphcommerce-org/graphcommerce/commit/5f927ebdc6f0331833e02b96e4f169bfe475ac6b) Thanks [@mikekeehnen](https://github.com/mikekeehnen)! - Fixed hydration errors on account, cart and wishlist
8
+
9
+ ## 3.2.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1490](https://github.com/graphcommerce-org/graphcommerce/pull/1490) [`d311ef48b`](https://github.com/graphcommerce-org/graphcommerce/commit/d311ef48bb3e97806d992af5516d6b7f183ec9cb) Thanks [@paales](https://github.com/paales)! - upgraded packages
14
+
15
+ ## 3.2.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#1495](https://github.com/graphcommerce-org/graphcommerce/pull/1495) [`ffec8800a`](https://github.com/graphcommerce-org/graphcommerce/commit/ffec8800a50ff2fe9b9fc5feeb5a0a878b573f0e) Thanks [@paales](https://github.com/paales)! - solve issue where useLazyQueryPromise didn’t always resolve
20
+
3
21
  ## 3.2.0
4
22
 
5
23
  ### Minor Changes
package/index.ts CHANGED
@@ -5,7 +5,6 @@ export * from './src/useFormAutoSubmit'
5
5
  export * from './src/useFormPersist'
6
6
  export * from './src/useFormMuiRegister'
7
7
  export * from './src/useFormValidFields'
8
- export * from './src/useLazyQueryPromise'
9
8
  export * from './src/useFormGql'
10
9
  export * from './src/validationPatterns'
11
10
  export * from './src/ComposedForm'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/react-hook-form",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "3.2.0",
5
+ "version": "3.3.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,19 +12,19 @@
12
12
  }
13
13
  },
14
14
  "devDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^4.1.7",
15
+ "@graphcommerce/eslint-config-pwa": "^4.1.8",
16
16
  "@graphcommerce/prettier-config-pwa": "^4.0.6",
17
17
  "@graphcommerce/typescript-config-pwa": "^4.0.3",
18
18
  "@playwright/test": "^1.21.1",
19
19
  "type-fest": "^2.12.2"
20
20
  },
21
21
  "dependencies": {
22
- "@apollo/client": "^3.6.0",
23
- "graphql": "16.4.0",
24
- "react-hook-form": "7.30.0"
22
+ "@apollo/client": "^3.6.9",
23
+ "graphql": "16.5.0",
24
+ "react-hook-form": "7.32.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "react": "^17.0.2",
28
- "react-dom": "^17.0.2"
27
+ "react": "^18.0.0",
28
+ "react-dom": "^18.0.0"
29
29
  }
30
30
  }
@@ -57,26 +57,13 @@ export function ComposedSubmit(props: ComposedSubmitProps) {
57
57
 
58
58
  let formsToProcess = formEntries
59
59
  if (invalidKeys.length === 0) {
60
- const onlyDirty = formEntries.filter(([, { form }]) => Boolean(form?.formState.isDirty))
61
-
62
60
  if (process.env.NODE_ENV !== 'production') {
63
- const all = formsToProcess.map(([, { key }]) => key).join(',')
64
- const dirtyForms = onlyDirty.map(([, { key }]) => key).join(',')
65
-
66
- if (dirtyForms.length > 0) {
67
- // eslint-disable-next-line no-console
68
- console.log(
69
- `[ComposedForm] All forms are valid (${all}), following forms are dirty (${dirtyForms}), submitting...`,
70
- )
71
- } else {
72
- // eslint-disable-next-line no-console
73
- console.log(
74
- `[ComposedForm] All forms are valid (${all}), no forms to submit, continuing...`,
75
- )
76
- }
61
+ // eslint-disable-next-line no-console
62
+ console.log(
63
+ '[ComposedForm] All forms are valid, submitting...',
64
+ formsToProcess.map(([, { key }]) => key),
65
+ )
77
66
  }
78
-
79
- formsToProcess = onlyDirty
80
67
  } else {
81
68
  formsToProcess = formEntries.filter(([, { key }]) => invalidKeys.includes(key))
82
69
  if (process.env.NODE_ENV !== 'production') {
@@ -5,11 +5,11 @@ import {
5
5
  useApolloClient,
6
6
  MutationTuple,
7
7
  ApolloError,
8
+ LazyQueryResultTuple,
8
9
  } from '@apollo/client'
9
10
  import { UseFormProps, UseFormReturn, UnpackNestedValue, DeepPartial } from 'react-hook-form'
10
11
  import diff from './diff'
11
12
  import { useGqlDocumentHandler, UseGqlDocumentHandler } from './useGqlDocumentHandler'
12
- import { LazyQueryTuple } from './useLazyQueryPromise'
13
13
 
14
14
  export type OnCompleteFn<Q> = (
15
15
  data: FetchResult<Q>,
@@ -31,7 +31,7 @@ export type UseFormGqlMethods<Q, V> = Omit<UseGqlDocumentHandler<V>, 'encode' |
31
31
  Pick<UseFormReturn<V>, 'handleSubmit'> & { data?: Q | null; error?: ApolloError }
32
32
 
33
33
  /**
34
- * Combines useMutation/useLazyQueryPromise with react-hook-form's useForm:
34
+ * Combines useMutation/useLazyQuery with react-hook-form's useForm:
35
35
  *
36
36
  * - Automatically extracts all required arguments for a query
37
37
  * - Casts Float/Int mutation input variables to a Number
@@ -42,7 +42,7 @@ export function useFormGql<Q, V>(
42
42
  options: {
43
43
  document: TypedDocumentNode<Q, V>
44
44
  form: UseFormReturn<V>
45
- tuple: MutationTuple<Q, V> | LazyQueryTuple<Q, V>
45
+ tuple: MutationTuple<Q, V> | LazyQueryResultTuple<Q, V>
46
46
  defaultValues?: UseFormProps<V>['defaultValues']
47
47
  } & UseFormGraphQLCallbacks<Q, V>,
48
48
  ): UseFormGqlMethods<Q, V> {
@@ -1,10 +1,9 @@
1
- import { LazyQueryHookOptions, TypedDocumentNode } from '@apollo/client'
1
+ import { LazyQueryHookOptions, TypedDocumentNode, useLazyQuery } from '@apollo/client'
2
2
  import { useForm } from 'react-hook-form'
3
3
  import { useFormGql, UseFormGraphQlOptions } from './useFormGql'
4
4
  import { UseFormGqlMutationReturn } from './useFormGqlMutation'
5
5
  import { useFormMuiRegister } from './useFormMuiRegister'
6
6
  import { useFormValidFields } from './useFormValidFields'
7
- import { useLazyQueryPromise } from './useLazyQueryPromise'
8
7
 
9
8
  export type UseFormGqlQueryReturn<Q, V> = UseFormGqlMutationReturn<Q, V>
10
9
 
@@ -14,7 +13,7 @@ export function useFormGqlQuery<Q, V>(
14
13
  operationOptions?: LazyQueryHookOptions<Q, V>,
15
14
  ): UseFormGqlQueryReturn<Q, V> {
16
15
  const form = useForm<V>(options)
17
- const tuple = useLazyQueryPromise(document, operationOptions)
16
+ const tuple = useLazyQuery(document, operationOptions)
18
17
  const operation = useFormGql({ document, form, tuple, ...options })
19
18
  const muiRegister = useFormMuiRegister(form)
20
19
  const valid = useFormValidFields(form, operation.required)
@@ -1,43 +0,0 @@
1
- import {
2
- DocumentNode,
3
- LazyQueryHookOptions,
4
- LazyQueryResult,
5
- QueryLazyOptions,
6
- TypedDocumentNode,
7
- useLazyQuery,
8
- } from '@apollo/client'
9
- import { useEffect, useRef } from 'react'
10
- import type { Promisable } from 'type-fest'
11
-
12
- export type LazyQueryTuple<Q, V> = [
13
- (options?: QueryLazyOptions<V>) => Promisable<LazyQueryResult<Q, V>>,
14
- LazyQueryResult<Q, V>,
15
- ]
16
-
17
- /**
18
- * Same API as useLazyQuery, except:
19
- *
20
- * - The execute method is a promise that will return the eventual result
21
- */
22
- export function useLazyQueryPromise<Q, V>(
23
- query: DocumentNode | TypedDocumentNode<Q, V>,
24
- options?: LazyQueryHookOptions<Q, V>,
25
- ): LazyQueryTuple<Q, V> {
26
- const [execute, result] = useLazyQuery<Q, V>(query, options)
27
- const ref = useRef<(value: Promisable<LazyQueryResult<Q, V>>) => void>()
28
-
29
- useEffect(() => {
30
- if (!result.called || result.loading || !ref.current) return
31
- ref.current(result)
32
- ref.current = undefined
33
- }, [result])
34
-
35
- const queryLazily = (executeOptions?: QueryLazyOptions<V>) => {
36
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
37
- execute(executeOptions)
38
- return new Promise<LazyQueryResult<Q, V>>((resolve) => {
39
- ref.current = resolve
40
- })
41
- }
42
- return [queryLazily, result]
43
- }