Commit d96fd4e9 authored by jang dong hyeok's avatar jang dong hyeok
Browse files

type, content접근해서 바꾸기

parent 73a1e1bc
......@@ -22,7 +22,7 @@ export const QCheckbox = ({ element }: Props) => {
placeholder={element.title}
onChange={questionListChange}
></input>
<TypeChange tt="checkbox" />
<TypeChange tt="checkbox" id={element._id} />
</div>
<div className="flex w-full justify-center">
<input
......
......@@ -20,7 +20,7 @@ export const QDropdown = ({ element }: Props) => {
placeholder={element.title}
onChange={questionListChange}
></input>
<TypeChange tt="dropdown" />
<TypeChange tt="dropdown" id={element._id} />
</div>
<div className="flex w-full justify-center">
<input
......
......@@ -23,7 +23,7 @@ export const QEssay = ({ element }: Props) => {
onChange={questionListChange}
></input>
{/* <TypeChange tt={"essay"} id={element._id} /> */}
<TypeChange tt={"essay"} />
<TypeChange tt={"essay"} id={element._id} />
</div>
<div className="flex w-full justify-center">
<input
......
......@@ -21,7 +21,7 @@ export const QFile = ({ element }: Props) => {
placeholder={element.title}
onChange={questionListChange}
></input>
<TypeChange tt="file" />
<TypeChange tt="file" id={element._id} />
</div>
<div className="flex w-full justify-center">
<input
......
......@@ -20,7 +20,7 @@ export const QRadio = ({ element }: Props) => {
placeholder={element.title}
onChange={questionListChange}
></input>
<TypeChange tt="radio" />
<TypeChange tt="radio" id={element._id} />
</div>
<div className="flex w-full justify-center">
<input
......
......@@ -22,7 +22,7 @@ export const QRating = ({ element }: Props) => {
placeholder={element.title}
onChange={questionListChange}
></input>
<TypeChange tt="rating" />
<TypeChange tt="rating" id={element._id} />
</div>
<div className="flex w-full justify-center">
<input
......
......@@ -5,9 +5,14 @@ import React, {
useContext,
useState,
} from "react";
import { BasicQuestionType, SurveyType } from "../types";
import { BasicQuestionType, SurveyType, EssayType, RadioType } from "../types";
import { questionApi, surveyApi } from "../apis";
interface questionTypeChangeProp {
id: string;
tt: string;
}
interface IQuestionContext {
handleSurvey: (e: React.ChangeEvent<HTMLInputElement>) => void;
handleSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
......@@ -17,7 +22,7 @@ interface IQuestionContext {
editCompleteClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
currentId: string;
addQuestion: (e: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
questionTypeChange: (e: React.ChangeEvent<HTMLSelectElement>) => void;
questionTypeChange: ({ id, tt }: questionTypeChangeProp) => void;
}
const QuestionContext = createContext<IQuestionContext>({
......@@ -68,6 +73,7 @@ export const QuestionProvider: FC<{ children: ReactNode }> = ({ children }) => {
// setLoading(false);
}
}
//질문 Title, Comment바꾸는 함수
function questionListChange(e: React.ChangeEvent<HTMLInputElement>): void {
const newList: BasicQuestionType[] = [...questionList];
const obj: any = newList.find((a) => a._id === e.target.id); //고유 _id로 질문찾기
......@@ -75,11 +81,15 @@ export const QuestionProvider: FC<{ children: ReactNode }> = ({ children }) => {
obj[targetKey] = e.target.value;
setQuestionList(newList);
}
function questionTypeChange(e: React.ChangeEvent<HTMLSelectElement>): void {
//질문 Type 바꾸는 함수
function questionTypeChange({ id, tt }: questionTypeChangeProp): void {
const newType: BasicQuestionType[] = [...questionList];
const objType: any = newType.find((t) => t._id === e.target.id);
const targetType: string = e.target.name;
objType[targetType] = e.target.value;
const objType: any = newType.find((t) => t._id === id);
objType.type = tt;
// TODO
if ((tt = "essay")) {
objType.content;
}
setQuestionList(newType);
}
......
......@@ -2,10 +2,11 @@ import React, { ChangeEvent, useState } from "react";
import { useQuestion } from "./question.context";
type typeChangeProps = {
id: string;
tt: string;
};
export function TypeChange({ tt }: typeChangeProps) {
export function TypeChange({ tt, id }: typeChangeProps) {
const { questionTypeChange } = useQuestion();
const typeDD = new Map([
......@@ -18,10 +19,13 @@ export function TypeChange({ tt }: typeChangeProps) {
["grid", "그리드"],
["date", "날짜"],
]);
function changeDD(e: React.ChangeEvent<HTMLSelectElement>) {
const tt = e.target.value;
// questionTypeChange(e);
console.log(tt);
console.log(e.target.value);
console.log(id);
questionTypeChange({ id, tt });
//if문으로 type별로 content 바뀌게 해보기
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment