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