@@ -12,6 +12,7 @@ import DigitsOnlyField from './DigitsOnlyField';
1212import type { FormQuestion } from '@/types' ;
1313import { useMemo } from 'react' ;
1414import { useFormContext } from 'react-hook-form' ;
15+ import { shouldShowQuestion } from '@/components/multi-step-form/StepperForm' ;
1516
1617interface FormWrapperProps {
1718 form ?: UseFormReturn < Record < string , unknown > > ; // Replace any with more specific type
@@ -26,38 +27,6 @@ interface FormWrapperProps {
2627 hideSubmitButton ?: boolean ;
2728}
2829
29- // Helper function to check if a question should be shown based on dependencies
30- const shouldShowQuestion = (
31- question : FormQuestion ,
32- formValues : Record < string , unknown >
33- ) : boolean => {
34- // If the question has no showIf condition, always show it
35- if ( ! question . showIf ) return true ;
36-
37- // Check each condition to determine if the question should be shown
38- for ( const [ dependentField , requiredValue ] of Object . entries (
39- question . showIf
40- ) ) {
41- const fieldValue = formValues [ dependentField ] ;
42-
43- // If required value is an array, check if the current value is in that array
44- if ( Array . isArray ( requiredValue ) ) {
45- // Convert to string for comparison since form values are often strings
46- const strValue =
47- typeof fieldValue === 'string' ? fieldValue : String ( fieldValue || '' ) ;
48- if ( ! requiredValue . includes ( strValue ) ) {
49- return false ;
50- }
51- }
52- // Otherwise check if the current value equals the required value
53- else if ( fieldValue !== requiredValue ) {
54- return false ;
55- }
56- }
57-
58- return true ;
59- } ;
60-
6130export default function FormWrapper ( {
6231 form : formProp ,
6332 questions,
0 commit comments