@graphcommerce/react-hook-form 2.102.5 → 2.102.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/react-hook-form",
3
- "version": "2.102.5",
3
+ "version": "2.102.6",
4
4
  "sideEffects": false,
5
5
  "engines": {
6
6
  "node": "14.x"
@@ -31,5 +31,5 @@
31
31
  "react-hook-form": "^7.16.2",
32
32
  "type-fest": "^2.3.4"
33
33
  },
34
- "gitHead": "f1d0e488921787f39a260c410790ec13d32c8143"
34
+ "gitHead": "717bd3c1658e421c247c1f8b210935cdb7780197"
35
35
  }
@@ -10,6 +10,7 @@ export type ComposedSubmitProps = {
10
10
  }
11
11
 
12
12
  export function mergeErrors(errors: ApolloError[]): ApolloError | undefined {
13
+ if (!errors.length) return undefined
13
14
  return new ApolloError({
14
15
  errorMessage: 'Composed submit error',
15
16
  networkError: errors.find((error) => error.networkError)?.networkError,
@@ -42,14 +43,14 @@ export default function ComposedSubmit(props: ComposedSubmitProps) {
42
43
  /** Callback to submit all forms */
43
44
  const submitAll = async () => {
44
45
  /**
45
- * If we have forms that are have errors, we don't need to submit anything yet. We can trigger
46
- * the submission of the invalid forms and highlight those forms.
46
+ * If we have forms that are have errors, we don't need to actually submit anything yet. We can
47
+ * trigger the submission of the invalid forms and highlight the errors in those forms.
47
48
  */
48
- let formsToSubmit = formEntries.filter(
49
- ([, f]) => Object.keys(f.form?.formState.errors ?? {}).length > 0,
50
- )
49
+ let formsToSubmit = formEntries.filter(([, f]) => {
50
+ return Object.keys(f.form?.formState.errors ?? {}).length > 0
51
+ })
51
52
 
52
- // We have no errors or invalid forms
53
+ // We have no errors and no invalid forms, this means we can submit everything.
53
54
  if (!formsToSubmit.length) formsToSubmit = formEntries
54
55
 
55
56
  dispatch({ type: 'SUBMIT' })
@@ -62,12 +63,19 @@ export default function ComposedSubmit(props: ComposedSubmitProps) {
62
63
  * Todo: There might be a performance optimization by submitting multiple forms in parallel.
63
64
  */
64
65
  let canSubmit = true
65
- for (const [, { submit, form }] of formsToSubmit) {
66
+ for (const [, { submit, form, key }] of formsToSubmit) {
66
67
  // eslint-disable-next-line no-await-in-loop
67
68
  if (canSubmit) await submit?.()
68
69
  // eslint-disable-next-line no-await-in-loop
69
70
  if (!canSubmit) await form?.trigger()
70
- if (!form?.formState.isValid || (isFormGqlOperation(form) && form.error)) canSubmit = false
71
+ if (form && isFormGqlOperation(form) && form.error) {
72
+ // console.log(
73
+ // key,
74
+ // form?.formState.isValid,
75
+ // form && (isFormGqlOperation(form) ? form.error : undefined),
76
+ // )
77
+ canSubmit = false
78
+ }
71
79
  }
72
80
  dispatch({ type: 'SUBMITTING' })
73
81
  } catch (error) {
@@ -38,6 +38,22 @@ function updateFormStateIfNecessary(state: ComposedFormState): ComposedFormState
38
38
  }
39
39
 
40
40
  export const composedFormReducer: ComposedFormReducer = (state, action) => {
41
+ // if (
42
+ // process.env.NODE_ENV !== 'production' &&
43
+ // action.type !== 'ASSIGN' &&
44
+ // action.type !== 'REGISTER'
45
+ // ) {
46
+ // console.log(
47
+ // `[composedFormReducer] ${action.type}`,
48
+ // action,
49
+ // Object.fromEntries(
50
+ // Object.entries(state.forms).map(([k, v]) => {
51
+ // return [k, v.form?.formState]
52
+ // }),
53
+ // ),
54
+ // )
55
+ // }
56
+
41
57
  switch (action.type) {
42
58
  case 'REGISTER':
43
59
  return { ...state, forms: { ...state.forms, [action.key]: undefined } }