Commit c4dd6b9e authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

isEditing, SurveyLayout navLink style 수정

parent beb1fdf0
...@@ -2,14 +2,19 @@ import React from "react"; ...@@ -2,14 +2,19 @@ import React from "react";
import { NavLink, useOutletContext } from "react-router-dom"; import { NavLink, useOutletContext } from "react-router-dom";
import { Outlet, useNavigate, useParams } from "react-router-dom"; import { Outlet, useNavigate, useParams } from "react-router-dom";
import { useSurveys } from "./SurveysLayout"; import { useSurveys } from "./SurveysLayout";
import type { CreateQuestionData, ICreateSurvey, ISurvey } from "../types"; import type {
CreateQuestionData,
ICreateSurvey,
IQuestionData,
ISurvey,
} from "../types";
import { SpinnerIcon } from "../icons"; import { SpinnerIcon } from "../icons";
import { surveyApi } from "../apis"; import { surveyApi } from "../apis";
type SurveyContextType = { type SurveyContextType = {
survey: ICreateSurvey; survey: ICreateSurvey;
update: (survey: ISurvey) => Promise<any>; update: (survey: ISurvey) => Promise<any>;
createQuestion: (question: CreateQuestionData) => Promise<any>; createQuestion: (question: IQuestionData) => Promise<any>;
removeQuestion: (questionId: string) => Promise<any>; removeQuestion: (questionId: string) => Promise<any>;
updateQuestion: (question: CreateQuestionData) => Promise<any>; updateQuestion: (question: CreateQuestionData) => Promise<any>;
}; };
...@@ -17,7 +22,7 @@ type SurveyContextType = { ...@@ -17,7 +22,7 @@ type SurveyContextType = {
const activeStyle = const activeStyle =
"w-36 h-12 flex justify-center items-center bg-themeColor p-1 text-white text-center font-bold text-xl"; "w-36 h-12 flex justify-center items-center bg-themeColor p-1 text-white text-center font-bold text-xl";
const inActiveStyle = const inActiveStyle =
"w-36 h-12 flex justify-center items-center bg-white border border-themeColor p-1 text-center font-bold text-xl"; "w-36 h-12 flex justify-center items-center bg-white border border-themeColor first:border-r-0 last:border-l-0 p-1 text-center font-bold text-xl";
export const SurveyLayout = () => { export const SurveyLayout = () => {
const { surveys, update, updateLocalSurveysList } = useSurveys(); const { surveys, update, updateLocalSurveysList } = useSurveys();
...@@ -34,10 +39,10 @@ export const SurveyLayout = () => { ...@@ -34,10 +39,10 @@ export const SurveyLayout = () => {
); );
} }
const createQuestion = async (question: CreateQuestionData) => { const createQuestion = async (question: IQuestionData) => {
const newQuestion = await surveyApi.addQuestion(survey._id!, question); const newQuestion = await surveyApi.addQuestion(survey._id!, question);
console.log("new question:", newQuestion); console.log("new question:", newQuestion);
newQuestion.isEditing = true;
survey.questions.push(newQuestion); survey.questions.push(newQuestion);
updateLocalSurveysList(survey); updateLocalSurveysList(survey);
}; };
...@@ -72,21 +77,21 @@ export const SurveyLayout = () => { ...@@ -72,21 +77,21 @@ export const SurveyLayout = () => {
<div> <div>
<div className="flex justify-center items-center mt-6"> <div className="flex justify-center items-center mt-6">
<NavLink <NavLink
to={`/surveys/${surveyId}`} to={`/surveys/${surveyId}/edit`}
end={true}
className={({ isActive }) => className={({ isActive }) =>
isActive isActive
? activeStyle + " rounded-l-3xl" ? activeStyle + " rounded-l-3xl"
: inActiveStyle + " rounded-l-3xl" : inActiveStyle + " rounded-l-3xl"
} }
> >
설문 미리보기 설문지 수정
</NavLink> </NavLink>
<NavLink <NavLink
to={`/surveys/${surveyId}/edit`} to={`/surveys/${surveyId}`}
end={true}
className={({ isActive }) => (isActive ? activeStyle : inActiveStyle)} className={({ isActive }) => (isActive ? activeStyle : inActiveStyle)}
> >
설문지 수정 설문 미리보기
</NavLink> </NavLink>
<NavLink <NavLink
to={`/surveys/${surveyId}/result`} to={`/surveys/${surveyId}/result`}
......
...@@ -50,14 +50,13 @@ export const EditSurvey = () => { ...@@ -50,14 +50,13 @@ export const EditSurvey = () => {
// }; // };
const addQuestion = async () => { const addQuestion = async () => {
const question: CreateQuestionData = { const question: IQuestionData = {
order: questions.length, order: questions.length,
type: "singletext", type: "singletext",
title: "", title: "",
comment: "", comment: "",
isRequired: false, isRequired: false,
content: { choices: [] }, content: { choices: [] },
isEditing: true,
}; };
// const updatedSurvey = await surveyApi.addQuestion(survey._id!, question); // const updatedSurvey = await surveyApi.addQuestion(survey._id!, question);
await createQuestion(question); await createQuestion(question);
......
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