diff --git a/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionBuilder/index.tsx b/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionBuilder/index.tsx index 8f2ea3c81..3c74e77dc 100644 --- a/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionBuilder/index.tsx +++ b/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionBuilder/index.tsx @@ -1,15 +1,17 @@ import { useState } from 'react'; -import { Question, QuestionChoice, QuestionControlActionType, QuestionOptionValue } from '@customTypes/dashboard'; +import { Question, QuestionControlActionType, QuestionOptionValue } from '@customTypes/dashboard'; import InputField from '@components/common/InputField'; import Dropdown from '@components/common/Dropdown'; import ToggleSwitch from '@components/common/ToggleSwitch'; import { QUESTION_TYPE_NAME } from '@constants/constants'; + +import CheckBoxField from '@components/recruitment/CheckBoxField'; +import RadioInputField from '@components/recruitment/RadioInputField'; import QuestionController from '../QuestionController'; import S from './style'; -import QuestionChoicesBuilder from '../QuestionChoicesBuilder'; interface QuestionBuilderProps { index: number; @@ -23,10 +25,6 @@ interface QuestionBuilderProps { deleteQuestion: (index: number) => void; } -function getSortedChoices(choices: QuestionChoice[]): QuestionOptionValue[] { - return choices?.sort((a, b) => a.orderIndex - b.orderIndex).map((item) => ({ value: item.choice })); -} - export default function QuestionBuilder({ index, question, @@ -40,7 +38,6 @@ export default function QuestionBuilder({ }: QuestionBuilderProps) { const [title, setTitle] = useState(question?.question || ''); const [currentQuestionType, setCurrentQuestionType] = useState(question?.type || 'SHORT_ANSWER'); - const [choices, setChoices] = useState(getSortedChoices(question?.choices) || []); const [isRequired, setIsRequired] = useState(question?.required || true); const handleChangeTitle = (event: React.ChangeEvent) => { @@ -50,14 +47,12 @@ export default function QuestionBuilder({ const handleChangeQuestionType = (type: Question['type']) => { if (type === currentQuestionType) return; - if (type === 'SHORT_ANSWER' || type === 'LONG_ANSWER') setChoices([]); setCurrentQuestionType(type); setQuestionType(index)(type); }; const handleUpdateQuestionChoices = (newChoices: QuestionOptionValue[]) => { - setChoices(newChoices); setQuestionOptions(index)(newChoices); }; @@ -99,10 +94,17 @@ export default function QuestionBuilder({ /> - {(currentQuestionType === 'SINGLE_CHOICE' || currentQuestionType === 'MULTIPLE_CHOICE') && ( - + )} + + {currentQuestionType === 'MULTIPLE_CHOICE' && ( + )} diff --git a/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionChoicesBuilder/QuestionChoicesBuilder.stories.tsx b/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionChoicesBuilder/QuestionChoicesBuilder.stories.tsx index b417c3a1a..e5e366c29 100644 --- a/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionChoicesBuilder/QuestionChoicesBuilder.stories.tsx +++ b/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionChoicesBuilder/QuestionChoicesBuilder.stories.tsx @@ -25,9 +25,9 @@ type Story = StoryObj; export const Default: Story = { render: (args) => { const [choices, setChoices] = useState([ - { value: '첫 번째 옵션입니다.' }, - { value: '두 번째 옵션입니다.' }, - { value: '세 번째 옵션입니다.' }, + { choice: '첫 번째 옵션입니다.' }, + { choice: '두 번째 옵션입니다.' }, + { choice: '세 번째 옵션입니다.' }, ]); const onUpdate = (newChoices: QuestionOptionValue[]) => { diff --git a/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionChoicesBuilder/index.tsx b/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionChoicesBuilder/index.tsx index 2457732e2..2be689df0 100644 --- a/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionChoicesBuilder/index.tsx +++ b/frontend/src/components/dashboard/DashboardCreate/Apply/QuestionChoicesBuilder/index.tsx @@ -25,9 +25,9 @@ export default function QuestionChoicesBuilder({ choices, onUpdate }: QuestionCh const newChoices = [...choices]; if (index < newChoices.length) { - newChoices[index].value = newValue; + newChoices[index].choice = newValue; } else { - newChoices.push({ value: newValue }); + newChoices.push({ choice: newValue }); } onUpdate(newChoices); @@ -37,7 +37,7 @@ export default function QuestionChoicesBuilder({ choices, onUpdate }: QuestionCh if (event.key === 'Enter') { event.preventDefault(); if (index === choices.length - 1) { - onUpdate([...choices, { value: '' }]); + onUpdate([...choices, { choice: '' }]); setTimeout(() => inputRefs.current[index + 1]?.focus(), 0); } else { inputRefs.current[index + 1]?.focus(); @@ -50,7 +50,7 @@ export default function QuestionChoicesBuilder({ choices, onUpdate }: QuestionCh onUpdate(newChoices); }; - const choicesToRender = choices.length === 0 ? [{ value: '' }] : choices; + const choicesToRender = choices.length === 0 ? [{ choice: '' }] : choices; return ( @@ -63,7 +63,7 @@ export default function QuestionChoicesBuilder({ choices, onUpdate }: QuestionCh ref={(el) => setInputRef(el, index)} type="text" placeholder="옵션을 입력하세요." - value={choice.value} + value={choice.choice} onChange={(event) => handleInputChange(event, index)} onKeyDown={(event) => handleKeyDown(event, index)} /> diff --git a/frontend/src/components/dashboard/DashboardCreate/Apply/index.tsx b/frontend/src/components/dashboard/DashboardCreate/Apply/index.tsx index cacc633ea..d319183b3 100644 --- a/frontend/src/components/dashboard/DashboardCreate/Apply/index.tsx +++ b/frontend/src/components/dashboard/DashboardCreate/Apply/index.tsx @@ -37,6 +37,12 @@ export default function Apply({ prevStep, nextStep, }: ApplyProps) { + const isNextBtnValid = + applyState.length === DEFAULT_QUESTION_LENGTH || + applyState + .slice(DEFAULT_QUESTION_LENGTH) + .every((question) => question.question.trim() && question.choices.length !== 1); + return ( @@ -106,7 +112,7 @@ export default function Apply({