@graphcommerce/react-hook-form 9.0.4-canary.12 → 9.0.4-canary.14

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
+ ## 9.0.4-canary.14
4
+
5
+ ## 9.0.4-canary.13
6
+
7
+ ### Patch Changes
8
+
9
+ - [`9aa9a3c`](https://github.com/graphcommerce-org/graphcommerce/commit/9aa9a3cc25c121e217f64efc0cfd19e3b90d15aa) - useFormGql and all derivivatives now get the form as an argument in onComplete for easier form resets. ([@paales](https://github.com/paales))
10
+
3
11
  ## 9.0.4-canary.12
4
12
 
5
13
  ## 9.0.4-canary.11
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": "9.0.4-canary.12",
5
+ "version": "9.0.4-canary.14",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -13,9 +13,9 @@
13
13
  },
14
14
  "peerDependencies": {
15
15
  "@apollo/client": "*",
16
- "@graphcommerce/eslint-config-pwa": "^9.0.4-canary.12",
17
- "@graphcommerce/prettier-config-pwa": "^9.0.4-canary.12",
18
- "@graphcommerce/typescript-config-pwa": "^9.0.4-canary.12",
16
+ "@graphcommerce/eslint-config-pwa": "^9.0.4-canary.14",
17
+ "@graphcommerce/prettier-config-pwa": "^9.0.4-canary.14",
18
+ "@graphcommerce/typescript-config-pwa": "^9.0.4-canary.14",
19
19
  "@mui/utils": "^5",
20
20
  "graphql": "^16.6.0",
21
21
  "react": "^18.2.0",
@@ -17,12 +17,7 @@ import type { UseGqlDocumentHandler } from './useGqlDocumentHandler'
17
17
  import { useGqlDocumentHandler } from './useGqlDocumentHandler'
18
18
  import { tryAsync } from './utils/tryTuple'
19
19
 
20
- export type OnCompleteFn<Q, V> = (
21
- data: FetchResult<MaybeMasked<Q>>,
22
- variables: V,
23
- ) => void | Promise<void>
24
-
25
- type UseFormGraphQLCallbacks<Q, V> = {
20
+ type UseFormGraphQLCallbacks<Q, V extends FieldValues> = {
26
21
  /**
27
22
  * Allows you to modify the variablels computed by the form to make it compatible with the GraphQL
28
23
  * Mutation.
@@ -30,13 +25,17 @@ type UseFormGraphQLCallbacks<Q, V> = {
30
25
  * When returning false, it will silently stop the submission. When an error is thrown, it will be
31
26
  * set as an ApolloError
32
27
  */
33
- onBeforeSubmit?: (variables: V) => V | false | Promise<V | false>
28
+ onBeforeSubmit?: (variables: V, form?: UseFormReturn<V>) => V | false | Promise<V | false>
34
29
  /**
35
30
  * Called after the mutation has been executed. Allows you to handle the result of the mutation.
36
31
  *
37
32
  * When an error is thrown, it will be set as an ApolloError
38
33
  */
39
- onComplete?: OnCompleteFn<Q, V>
34
+ onComplete?: (
35
+ data: FetchResult<MaybeMasked<Q>>,
36
+ variables: V,
37
+ form?: UseFormReturn<V>,
38
+ ) => void | Promise<void>
40
39
 
41
40
  /**
42
41
  * @deprecated Not used anymore, is now the default
@@ -174,7 +173,7 @@ export function useFormGql<Q, V extends FieldValues>(
174
173
  let variables = !deprecated_useV1 ? formValues : encode({ ...defaultValues, ...formValues })
175
174
 
176
175
  // Wait for the onBeforeSubmit to complete
177
- const [onBeforeSubmitResult, onBeforeSubmitError] = await beforeSubmit(variables)
176
+ const [onBeforeSubmitResult, onBeforeSubmitError] = await beforeSubmit(variables, form)
178
177
  if (onBeforeSubmitError) {
179
178
  if (isApolloError(onBeforeSubmitError)) {
180
179
  returnedError.current = onBeforeSubmitError
@@ -219,7 +218,7 @@ export function useFormGql<Q, V extends FieldValues>(
219
218
  return
220
219
  }
221
220
 
222
- const [, onCompleteError] = await complete(result, variables)
221
+ const [, onCompleteError] = await complete(result, variables, form)
223
222
  if (onCompleteError) {
224
223
  if (isApolloError(onCompleteError)) {
225
224
  returnedError.current = onCompleteError