diff --git a/app/api/forms/[role]/route.ts b/app/api/forms/[role]/route.ts index 9d861031..159050e1 100644 --- a/app/api/forms/[role]/route.ts +++ b/app/api/forms/[role]/route.ts @@ -53,7 +53,8 @@ export async function POST( // Get role and questions - const roleSlug = context.params.role; + const params = await context.params; + const roleSlug = params.role; console.log(`Processing application for role: ${roleSlug}`); diff --git a/components/forms/FormWrapper.tsx b/components/forms/FormWrapper.tsx index aece2f51..c316894b 100644 --- a/components/forms/FormWrapper.tsx +++ b/components/forms/FormWrapper.tsx @@ -12,6 +12,7 @@ import DigitsOnlyField from './DigitsOnlyField'; import type { FormQuestion } from '@/types'; import { useMemo } from 'react'; import { useFormContext } from 'react-hook-form'; +import { shouldShowQuestion } from '@/components/multi-step-form/StepperForm'; interface FormWrapperProps { form?: UseFormReturn>; // Replace any with more specific type @@ -26,38 +27,6 @@ interface FormWrapperProps { hideSubmitButton?: boolean; } -// Helper function to check if a question should be shown based on dependencies -const shouldShowQuestion = ( - question: FormQuestion, - formValues: Record -): boolean => { - // If the question has no showIf condition, always show it - if (!question.showIf) return true; - - // Check each condition to determine if the question should be shown - for (const [dependentField, requiredValue] of Object.entries( - question.showIf - )) { - const fieldValue = formValues[dependentField]; - - // If required value is an array, check if the current value is in that array - if (Array.isArray(requiredValue)) { - // Convert to string for comparison since form values are often strings - const strValue = - typeof fieldValue === 'string' ? fieldValue : String(fieldValue || ''); - if (!requiredValue.includes(strValue)) { - return false; - } - } - // Otherwise check if the current value equals the required value - else if (fieldValue !== requiredValue) { - return false; - } - } - - return true; -}; - export default function FormWrapper({ form: formProp, questions, diff --git a/components/forms/SelectField.tsx b/components/forms/SelectField.tsx index 21b7bd3c..954c3327 100644 --- a/components/forms/SelectField.tsx +++ b/components/forms/SelectField.tsx @@ -68,7 +68,7 @@ const SelectField = memo(function SelectField({