diff --git a/src/pages/resources/search.tsx b/src/pages/resources/search.tsx index 438e01d..55d578d 100644 --- a/src/pages/resources/search.tsx +++ b/src/pages/resources/search.tsx @@ -1,7 +1,7 @@ -import { type PaymentType, type Platform, type RangeInput, type Skill, type SkillLevel } from "@prisma/client" -import { useState } from "react"; +import { type PaymentType, type Platform, type Skill, type SkillLevel } from "@prisma/client" +import { type Dispatch, type SetStateAction, useEffect, useState } from "react"; -type QuestionTypes = Platform | Skill | SkillLevel | PaymentType | RangeInput; +type QuestionTypes = Platform | Skill | SkillLevel | PaymentType | string; interface Option { label: string, @@ -9,29 +9,32 @@ interface Option { } interface Question { + for: string, header: string, options: Option[] } const questions: Question[] = [ { + for: "ages", header: "Age of Patient", options: [ { label: "Child", - value: {min: 0, max: 9} + value: "0-9", }, { label: "Teen", - value: {min: 10, max:20} + value: "10-20", }, { label: "Adult", - value: {min: 21, max: 100} + value: "21-100", }, ], }, { + for: "platforms", header: "Desired Platforms", options: [ { @@ -53,6 +56,7 @@ const questions: Question[] = [ ] }, { + for: "skill_levels", header: "Skill Level", options: [ { @@ -70,6 +74,7 @@ const questions: Question[] = [ ] }, { + for: "skills", header: "Skills Practiced", options: [ { @@ -100,47 +105,78 @@ const questions: Question[] = [ } ] -const ChoiceQuestion = ({question}: {question: Question}) => { - const Option = ({option}: {option: Option}) => { - const [selected, setSelected] = useState(false); - +const ChoiceQuestion = ({question, formData, updateFormData}: {question: Question, formData: Record, updateFormData: Dispatch>>}) => { + const OptionToggle = ({option}: {option: Option}) => { + const selected = formData[question.for]?.includes(option.value) ?? false; + const handleToggle = () => { - setSelected(!selected); + const newFormData = { + ...formData + }; + + if (!newFormData[question.for]) { + newFormData[question.for] = [option.value]; + } else if (newFormData[question.for]?.includes(option.value)) { + newFormData[question.for] = newFormData[question.for]?.filter(function(item) { + return item !== option.value + }) ?? []; + } else { + newFormData[question.for] = [...newFormData[question.for] ?? [], option.value]; + } + + updateFormData(newFormData); } return ( -
- -
+ ) } - const optionsComponents = question.options.map((option, index) => { - return