diff --git a/src/@types/index.d.ts b/src/@types/index.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/components/forms/CheckBoxWithLabelForm.tsx b/src/components/forms/CheckBoxWithLabelForm.tsx index 47a6ca4..e366074 100644 --- a/src/components/forms/CheckBoxWithLabelForm.tsx +++ b/src/components/forms/CheckBoxWithLabelForm.tsx @@ -1,10 +1,10 @@ import { Checkbox } from "@/components/ui/checkbox"; -import { FormState, Question } from "./Form"; +import { FormState, Question } from "./FormRenderer"; // prettier-ignore export type CheckBoxWithLabelFormProps = - Omit, "questionType" | "dataType"> & + Omit & FormState; export const CheckBoxWithLabelForm = ({ @@ -24,7 +24,9 @@ export const CheckBoxWithLabelForm = ({ data-testid={`checkbox_${option}`} id={`checkbox_${option}`} className="block w-5 h-5" - checked={(formState[questionText] as Array).includes(option)} + checked={(formState[questionText] as Array).includes( + option as string, + )} onCheckedChange={(isChecked) => { if (isChecked) { setFormState({ @@ -44,7 +46,7 @@ export const CheckBoxWithLabelForm = ({ } }} /> - + ); })} diff --git a/src/components/forms/Form.tsx b/src/components/forms/Form.tsx deleted file mode 100644 index 2c2a1cc..0000000 --- a/src/components/forms/Form.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { useState } from "react"; - -import { FormFactory } from "./FormFactory"; - -export const QuestionTypes = { - checkbox: "checkbox", - selector: "selector", - slider: "slider", - doubleSlider: "doubleSlider", -} as const; - -export interface Question { - questionText: string; - questionType: keyof typeof QuestionTypes; - dataType: string; - options: T[]; -} - -export interface FormProps { - title: string; - description: string; - questions: Question[]; -} - -export interface FormState { - formState: Record; - setFormState: React.Dispatch>>; -} - -export const Form = ({ title, description, questions }: FormProps) => { - const [formResponse, setFormResponse] = useState({}); - - const FormComponent = FormFactory({ questionType: questions[0].questionType }); - const FormComponentProps = questions[0]; - return
{FormComponent && }
; -}; diff --git a/src/components/forms/FormFactory.tsx b/src/components/forms/FormFactory.tsx index cea9985..145ca8f 100644 --- a/src/components/forms/FormFactory.tsx +++ b/src/components/forms/FormFactory.tsx @@ -1,7 +1,6 @@ import { CheckBoxWithLabelForm } from "./CheckBoxWithLabelForm"; -import { QuestionTypes } from "./Form"; +import { QuestionTypes } from "./FormRenderer"; import { SelectorWithLabelForm } from "./SelectorWithLabelForm"; -import { DoubleSliderWithLabelForm, SliderWithLabelForm } from "./SliderWithLabelForm"; export interface FormFactoryProps { questionType: keyof typeof QuestionTypes; @@ -10,9 +9,9 @@ export interface FormFactoryProps { export const FormFactory = ({ questionType }: FormFactoryProps) => { const FormElements = { [QuestionTypes.selector]: SelectorWithLabelForm, - [QuestionTypes.slider]: SliderWithLabelForm, - [QuestionTypes.doubleSlider]: DoubleSliderWithLabelForm, [QuestionTypes.checkbox]: CheckBoxWithLabelForm, + // [QuestionTypes.slider]: SliderWithLabelForm, + // [QuestionTypes.doubleSlider]: DoubleSliderWithLabelForm, }; return FormElements[questionType]; diff --git a/src/components/forms/SelectorWithLabelForm.tsx b/src/components/forms/SelectorWithLabelForm.tsx index 2ac163a..ddc4f75 100644 --- a/src/components/forms/SelectorWithLabelForm.tsx +++ b/src/components/forms/SelectorWithLabelForm.tsx @@ -8,11 +8,11 @@ import { SelectValue, } from "@/components/ui/select"; -import { FormState, Question } from "./Form"; +import { FormState, Question } from "./FormRenderer"; // prettier-ignore export type SelectorWithLabelFormProps = - Omit, "questionType" | "dataType"> & + Omit & FormState export const SelectorWithLabelForm = ({ @@ -33,22 +33,22 @@ export const SelectorWithLabelForm = ({ onValueChange={(value) => setFormState({ ...formState, - [questionText]: value, + [questionText]: [value], }) } > - + {options.map((option, index) => { return ( - {option} + {option as string} ); })}