@graphcommerce/react-hook-form 9.0.1 → 9.0.2
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 +12 -0
- package/package.json +4 -4
- package/src/useFormGql.tsx +26 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 9.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`c40c559`](https://github.com/graphcommerce-org/graphcommerce/commit/c40c5596bcc8f3c2e1e15c9e6ad85bfa1f9154b0) - Solve an issue where the payment submission would remain in a spinning state when placing an order failed: `useFormGql` will now set `root` error on the form when there is an error response on the GraphQL operation, an error is thrown in onBeforeSubmit and in onSuccess. ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
9
|
+
## 9.0.2-canary.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`c40c559`](https://github.com/graphcommerce-org/graphcommerce/commit/c40c5596bcc8f3c2e1e15c9e6ad85bfa1f9154b0) - Solve an issue where the payment submission would remain in a spinning state when placing an order failed: `useFormGql` will now set `root` error on the form when there is an error response on the GraphQL operation, an error is thrown in onBeforeSubmit and in onSuccess. ([@paales](https://github.com/paales))
|
|
14
|
+
|
|
3
15
|
## 9.0.1
|
|
4
16
|
|
|
5
17
|
## 9.0.1-canary.1
|
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.
|
|
5
|
+
"version": "9.0.2",
|
|
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.
|
|
17
|
-
"@graphcommerce/prettier-config-pwa": "^9.0.
|
|
18
|
-
"@graphcommerce/typescript-config-pwa": "^9.0.
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.2",
|
|
17
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.2",
|
|
18
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.2",
|
|
19
19
|
"@mui/utils": "^5",
|
|
20
20
|
"graphql": "^16.6.0",
|
|
21
21
|
"react": "^18.2.0",
|
package/src/useFormGql.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
ApolloError,
|
|
3
2
|
FetchResult,
|
|
4
3
|
LazyQueryHookOptions,
|
|
5
4
|
LazyQueryResultTuple,
|
|
@@ -8,7 +7,7 @@ import type {
|
|
|
8
7
|
MutationTuple,
|
|
9
8
|
TypedDocumentNode,
|
|
10
9
|
} from '@apollo/client'
|
|
11
|
-
import { isApolloError } from '@apollo/client'
|
|
10
|
+
import { ApolloError, isApolloError } from '@apollo/client'
|
|
12
11
|
import { getOperationName } from '@apollo/client/utilities'
|
|
13
12
|
import useEventCallback from '@mui/utils/useEventCallback'
|
|
14
13
|
import { useEffect, useRef } from 'react'
|
|
@@ -179,16 +178,23 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
179
178
|
if (onBeforeSubmitError) {
|
|
180
179
|
if (isApolloError(onBeforeSubmitError)) {
|
|
181
180
|
returnedError.current = onBeforeSubmitError
|
|
181
|
+
form.setError('root', { message: onBeforeSubmitError.message })
|
|
182
182
|
} else {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
const message =
|
|
184
|
+
process.env.NODE_ENV === 'development'
|
|
185
|
+
? `A non ApolloError was thrown during the onBeforeSubmit handler: ${onBeforeSubmitError.message}`
|
|
186
|
+
: 'An unexpected error occurred, please contact the store owner'
|
|
187
|
+
form.setError('root', { message })
|
|
188
|
+
returnedError.current = new ApolloError({ graphQLErrors: [{ message }] })
|
|
187
189
|
}
|
|
190
|
+
return
|
|
191
|
+
}
|
|
188
192
|
|
|
193
|
+
if (onBeforeSubmitResult === false) {
|
|
194
|
+
form.setError('root', { message: 'Form submission cancelled' })
|
|
189
195
|
return
|
|
190
196
|
}
|
|
191
|
-
|
|
197
|
+
|
|
192
198
|
variables = onBeforeSubmitResult
|
|
193
199
|
|
|
194
200
|
submittedVariables.current = variables
|
|
@@ -207,21 +213,25 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
207
213
|
},
|
|
208
214
|
})
|
|
209
215
|
|
|
210
|
-
|
|
211
|
-
if (
|
|
212
|
-
|
|
216
|
+
// If there are submission errors, set the error and return
|
|
217
|
+
if (result.errors && result.errors.length > 0) {
|
|
218
|
+
form.setError('root', { message: result.errors.map((e) => e.message).join(', ') })
|
|
213
219
|
return
|
|
214
220
|
}
|
|
221
|
+
|
|
222
|
+
const [, onCompleteError] = await complete(result, variables)
|
|
215
223
|
if (onCompleteError) {
|
|
216
224
|
if (isApolloError(onCompleteError)) {
|
|
217
225
|
returnedError.current = onCompleteError
|
|
226
|
+
form.setError('root', { message: onCompleteError.message })
|
|
218
227
|
} else {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
228
|
+
const message =
|
|
229
|
+
process.env.NODE_ENV === 'development'
|
|
230
|
+
? `A non ApolloError was thrown during the onComplete handler: ${onCompleteError.message}`
|
|
231
|
+
: 'An unexpected error occurred, please contact the store owner'
|
|
232
|
+
form.setError('root', { message })
|
|
233
|
+
returnedError.current = new ApolloError({ graphQLErrors: [{ message }] })
|
|
223
234
|
}
|
|
224
|
-
|
|
225
235
|
return
|
|
226
236
|
}
|
|
227
237
|
|
|
@@ -236,7 +246,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
236
246
|
...gqlDocumentHandler,
|
|
237
247
|
handleSubmit,
|
|
238
248
|
data,
|
|
239
|
-
error:
|
|
249
|
+
error: returnedError.current ?? error,
|
|
240
250
|
submittedVariables: submittedVariables.current,
|
|
241
251
|
}
|
|
242
252
|
}
|