import React, { useState } from "react"; import { BasicQuestionType, EssayType } from "../types"; import { questionApi } from "../apis"; import { EssayForm } from "./EssayForm"; import { CheckboxForm } from "./CheckboxForm"; import { RadioForm } from "./RadioForm"; import { DropdownForm } from "./DropdownForm"; import { FileForm } from "./FileForm"; import { RatingForm } from "./RatingForm"; type Props = { element: BasicQuestionType; handleQuestion: (id: string) => void; deleteQuestion: (id: string) => void; }; const typeDropDown = new Map([ ["essay", "주관식"], ["radio", "객관식"], ["dropdown", "드롭다운"], ["checkbox", "체크박스"], ["file", "파일"], ["rating", "선형"], ["grid", "그리드"], ["date", "날짜"], ]); export const Question = ({ element, handleQuestion, deleteQuestion, }: Props) => { const handleEdit = () => { //setCurrentId해주고 currentId===element._id가 같은 input들만 disabled=false }; async function handleComplete() { //db에서 element._id인 애를 findOneAndUpdate() 해준다. try { const newQuestion: BasicQuestionType = await questionApi.updateQuestion( element ); console.log(newQuestion); // setSuccess(true); // setError(""); } catch (error) { console.log("에러발생"); // catchErrors(error, setError) } finally { // setLoading(false); } } function handleSelect(event: React.ChangeEvent) { const selectedType = event.currentTarget.value; console.log(selectedType); if ( selectedType === "radio" || selectedType === "dropdown" || selectedType === "checkbox" ) { element.content = { choices: [ { text: "선택지1", value: "1" }, { text: "선택지2", value: "2" }, { text: "선택지3", value: "3" }, ], }; } else if (selectedType === "essay") { element.content = { choices: [] }; } else if (selectedType === "rating") { element.content = { minRateDescription: "가장 낮음", maxRateDescription: "가장 높음", choices: [ { text: "1", value: "1" }, { text: "2", value: "2" }, { text: "3", value: "3" }, ], }; } element.type = selectedType; handleQuestion(element._id); } function handleQuestionInfo(event: React.ChangeEvent) { const { name, value } = event.currentTarget; element[name] = value; handleQuestion(element._id); } function handleDelete() { deleteQuestion(element._id); } function getContent(element: BasicQuestionType) { switch (element.type) { case "essay": return ; case "radio": return ; case "checkbox": return ( ); case "dropdown": return ( ); case "file": return ; case "rating": return ; default: return <>; } } return (
{getContent(element)}
); };