@graphcommerce/react-hook-form 7.0.2-canary.7 → 7.1.0-canary.10
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 +10 -0
- package/package.json +4 -4
- package/src/useFormGql.tsx +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 7.1.0-canary.10
|
|
4
|
+
|
|
5
|
+
## 7.1.0-canary.9
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#2007](https://github.com/graphcommerce-org/graphcommerce/pull/2007) [`f59c27660`](https://github.com/graphcommerce-org/graphcommerce/commit/f59c276605f9ed649d1197a9ba0e3f12d7c6d026) - Reconstruct crosssells behaviour. Add submitted variables & showSuccess to RHF ([@JoshuaS98](https://github.com/JoshuaS98))
|
|
10
|
+
|
|
11
|
+
## 7.1.0-canary.8
|
|
12
|
+
|
|
3
13
|
## 7.0.2-canary.7
|
|
4
14
|
|
|
5
15
|
## 7.0.2-canary.6
|
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": "7.0
|
|
5
|
+
"version": "7.1.0-canary.10",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"react-hook-form": "7.46.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@graphcommerce/eslint-config-pwa": "7.0
|
|
20
|
-
"@graphcommerce/prettier-config-pwa": "7.0
|
|
21
|
-
"@graphcommerce/typescript-config-pwa": "7.0
|
|
19
|
+
"@graphcommerce/eslint-config-pwa": "7.1.0-canary.10",
|
|
20
|
+
"@graphcommerce/prettier-config-pwa": "7.1.0-canary.10",
|
|
21
|
+
"@graphcommerce/typescript-config-pwa": "7.1.0-canary.10",
|
|
22
22
|
"@testing-library/react": "^14.0.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
package/src/useFormGql.tsx
CHANGED
|
@@ -28,7 +28,7 @@ export type UseFormGqlMethods<Q, V extends FieldValues> = Omit<
|
|
|
28
28
|
UseGqlDocumentHandler<V>,
|
|
29
29
|
'encode' | 'type'
|
|
30
30
|
> &
|
|
31
|
-
Pick<UseFormReturn<V>, 'handleSubmit'> & { data?: Q | null; error?: ApolloError }
|
|
31
|
+
Pick<UseFormReturn<V>, 'handleSubmit'> & { data?: Q | null; error?: ApolloError; submittedVariables?: V }
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Combines useMutation/useLazyQuery with react-hook-form's useForm:
|
|
@@ -50,6 +50,8 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
50
50
|
const { encode, type, ...gqlDocumentHandler } = useGqlDocumentHandler<Q, V>(document)
|
|
51
51
|
const [execute, { data, error }] = tuple
|
|
52
52
|
|
|
53
|
+
const submittedVariables = useRef<V>()
|
|
54
|
+
|
|
53
55
|
// automatically updates the default values
|
|
54
56
|
const initital = useRef(true)
|
|
55
57
|
const valuesString = JSON.stringify(defaultValues)
|
|
@@ -66,6 +68,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
66
68
|
const handleSubmit: UseFormReturn<V>['handleSubmit'] = (onValid, onInvalid) =>
|
|
67
69
|
form.handleSubmit(async (formValues, event) => {
|
|
68
70
|
// Combine defaults with the formValues and encode
|
|
71
|
+
submittedVariables.current = undefined
|
|
69
72
|
let variables = encode({ ...defaultValues, ...formValues })
|
|
70
73
|
|
|
71
74
|
// Wait for the onBeforeSubmit to complete
|
|
@@ -76,6 +79,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
76
79
|
}
|
|
77
80
|
// if (variables === false) onInvalid?.(formValues, event)
|
|
78
81
|
|
|
82
|
+
submittedVariables.current = variables
|
|
79
83
|
const result = await execute({ variables })
|
|
80
84
|
if (onComplete && result.data) await onComplete(result, variables)
|
|
81
85
|
|
|
@@ -85,5 +89,11 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
85
89
|
await onValid(formValues, event)
|
|
86
90
|
}, onInvalid)
|
|
87
91
|
|
|
88
|
-
return {
|
|
92
|
+
return {
|
|
93
|
+
...gqlDocumentHandler,
|
|
94
|
+
handleSubmit,
|
|
95
|
+
data,
|
|
96
|
+
error,
|
|
97
|
+
submittedVariables: submittedVariables.current,
|
|
98
|
+
}
|
|
89
99
|
}
|