@graphcommerce/react-hook-form 6.0.1-canary.1 → 6.0.1-canary.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 6.0.1-canary.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1859](https://github.com/graphcommerce-org/graphcommerce/pull/1859) [`08ea612a1`](https://github.com/graphcommerce-org/graphcommerce/commit/08ea612a1d26166b8e55f20525c1004642cc85aa) - Resolved multiple onSubmitSuccessful callbacks in ComposedForm, when we have multiple ComposedForm Components on a page ([@mikekeehnen](https://github.com/mikekeehnen))
8
+
3
9
  ## 6.0.1-canary.1
4
10
 
5
11
  ## 6.0.1-canary.0
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": "6.0.1-canary.1",
5
+ "version": "6.0.1-canary.2",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -17,9 +17,9 @@
17
17
  "react-hook-form": "7.43.5"
18
18
  },
19
19
  "devDependencies": {
20
- "@graphcommerce/eslint-config-pwa": "6.0.1-canary.1",
21
- "@graphcommerce/prettier-config-pwa": "6.0.1-canary.1",
22
- "@graphcommerce/typescript-config-pwa": "6.0.1-canary.1",
20
+ "@graphcommerce/eslint-config-pwa": "6.0.1-canary.2",
21
+ "@graphcommerce/prettier-config-pwa": "6.0.1-canary.2",
22
+ "@graphcommerce/typescript-config-pwa": "6.0.1-canary.2",
23
23
  "@testing-library/react": "^14.0.0"
24
24
  },
25
25
  "peerDependencies": {
@@ -1,5 +1,5 @@
1
1
  import { ApolloError } from '@apollo/client'
2
- import React, { useContext, useEffect } from 'react'
2
+ import React, { useContext, useEffect, useRef } from 'react'
3
3
  import { isFormGqlOperation } from '../useFormGqlMutation'
4
4
  import { composedFormContext } from './context'
5
5
  import { ComposedSubmitRenderComponentProps } from './types'
@@ -22,11 +22,12 @@ export function ComposedSubmit(props: ComposedSubmitProps) {
22
22
  const { render: Render, onSubmitSuccessful } = props
23
23
  const [formContext, dispatch] = useContext(composedFormContext)
24
24
  const { formState, buttonState, isCompleting, forms } = formContext
25
+ const thisComponent = useRef(false)
25
26
 
26
27
  const formEntries = Object.entries(forms).sort((a, b) => a[1].step - b[1].step)
27
28
 
28
29
  useEffect(() => {
29
- if (isCompleting && !formState.isSubmitting) {
30
+ if (isCompleting && !formState.isSubmitting && thisComponent.current) {
30
31
  /**
31
32
  * If we have forms that are invalid, we don't need to submit anything yet. We can trigger the
32
33
  * submission of the invalid forms and highlight those forms.
@@ -37,6 +38,7 @@ export function ComposedSubmit(props: ComposedSubmitProps) {
37
38
 
38
39
  dispatch({ type: 'SUBMITTED', isSubmitSuccessful })
39
40
  if (isSubmitSuccessful) onSubmitSuccessful?.()
41
+ thisComponent.current = false
40
42
  }
41
43
  }, [isCompleting, dispatch, formEntries, formState.isSubmitting, onSubmitSuccessful])
42
44
 
@@ -105,11 +107,12 @@ export function ComposedSubmit(props: ComposedSubmitProps) {
105
107
  }
106
108
  }
107
109
 
108
- dispatch(
109
- invalidKeys.length === 0
110
- ? { type: 'SUBMITTING' }
111
- : { type: 'SUBMITTED', isSubmitSuccessful: false },
112
- )
110
+ if (invalidKeys.length === 0) {
111
+ thisComponent.current = true
112
+ dispatch({ type: 'SUBMITTING' })
113
+ } else {
114
+ dispatch({ type: 'SUBMITTED', isSubmitSuccessful: false })
115
+ }
113
116
  } catch (error) {
114
117
  dispatch({ type: 'SUBMITTED', isSubmitSuccessful: false })
115
118
  }