graphcommerce-org / graphcommerce

GraphCommerce® is a headless storefront replacement for Magento 2 (PWA), that delivers a faster, better user experience. Fully customizable (React, Next.js) and open-source.
https://www.graphcommerce.org
Other
306 stars 71 forks source link

Step value not passed into ComposedSubmit #2389

Open JesseMaxwell opened 1 month ago

JesseMaxwell commented 1 month ago

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.