diff --git a/app/gyeol/components/Q3Step.tsx b/app/gyeol/components/Q3Step.tsx new file mode 100644 index 0000000..49d5a3d --- /dev/null +++ b/app/gyeol/components/Q3Step.tsx @@ -0,0 +1,89 @@ +'use client'; + +import { useState } from 'react'; +import { TOOLS_OPTIONS } from '@/lib/survey/questions'; +import type { SurveyResponse } from '@/lib/survey/types'; +import QuestionLayout from './QuestionLayout'; + +interface Props { + initial: Partial; + onPrev: () => void; + onNext: (partial: Partial) => void; +} + +export default function Q3Step({ initial, onPrev, onNext }: Props) { + const [selected, setSelected] = useState(initial.tools_used ?? []); + const [other, setOther] = useState(initial.tools_other ?? ''); + + function toggle(option: string) { + setSelected((prev) => + prev.includes(option) ? prev.filter((x) => x !== option) : [...prev, option] + ); + } + + // validation: 최소 1개 체크 또는 기타 입력 있음 + const valid = selected.length > 0 || other.trim().length > 0; + + return ( + + onNext({ + tools_used: selected, + tools_other: other.trim() || undefined, + }) + } + nextDisabled={!valid} + > +
+ {TOOLS_OPTIONS.map((option) => { + const checked = selected.includes(option); + return ( + + ); + })} + +
+ + setOther(e.target.value)} + placeholder="예: 명상, 운동" + maxLength={100} + className="w-full px-4 py-3 rounded-xl bg-white/[0.04] border border-white/15 text-white placeholder:text-white/30 focus:border-white/40 focus:outline-none" + /> +
+
+
+ ); +}