Skip to content

Step value not passed into ComposedSubmit #2389

@JesseMaxwell

Description

@JesseMaxwell

Describe the Bug

Files:

  1. Problem: node_modules/@graphcommerce/react-hook-form/src/ComposedForm/useFormCompose.ts
  2. Apparent: node_modules/@graphcommerce/react-hook-form/src/ComposedForm/ComposedSubmit.tsx

Description

The step key is not passed in during the ASSIGN dispatch() on Line 21 of: node_modules/@graphcommerce/react-hook-form/src/ComposedForm/useFormCompose.ts. As a result, the forms ignore the expected step ordering.

Solution:

-dispatch({ type: 'ASSIGN', key, form: form as UseFormReturn<FieldValues>, submit })
+dispatch({ type: 'ASSIGN', key, form: form as UseFormReturn<FieldValues>, submit, step })

A TypeScript modification would be necessary as well.

Here's the full.patch file that works:

diff --git a/node_modules/@graphcommerce/react-hook-form/src/ComposedForm/useFormCompose.ts b/node_modules/@graphcommerce/react-hook-form/src/ComposedForm/useFormCompose.ts
index 58aa7a1..627deae 100644
--- a/node_modules/@graphcommerce/react-hook-form/src/ComposedForm/useFormCompose.ts
+++ b/node_modules/@graphcommerce/react-hook-form/src/ComposedForm/useFormCompose.ts
@@ -18,7 +18,7 @@ export function useFormCompose<V extends Record<string, unknown>>(
   }, [dispatch, key, step])
 
   useEffect(() => {
-    dispatch({ type: 'ASSIGN', key, form: form as UseFormReturn<FieldValues>, submit })
+    dispatch({ type: 'ASSIGN', key, form: form as UseFormReturn<FieldValues>, submit, step })
   }, [dispatch, fields, form, key, submit])
 
   const error = isFormGqlOperation(form) ? form.error : undefined

Expected Behavior

The step values are used to build the array. The code is already there to handle this, it's just not receiving the info it needs.

To Reproduce

  1. Adjust the step order.
  2. Place Order with a multi-step, composed form.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions