Commit 9cbfffe1 authored by Lee SeoYeon's avatar Lee SeoYeon
Browse files

route 설정

parent 9e1cd4c9
...@@ -16,7 +16,7 @@ export const MySurveyCard = ({ data }: Props) => { ...@@ -16,7 +16,7 @@ export const MySurveyCard = ({ data }: Props) => {
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
const editSurvey = () => { const editSurvey = () => {
navigate(`/surveys/edit/${data._id}`, { navigate(`/surveys/${data._id}/edit`, {
replace: true, replace: true,
state: { save: true }, state: { save: true },
}); });
...@@ -29,7 +29,7 @@ export const MySurveyCard = ({ data }: Props) => { ...@@ -29,7 +29,7 @@ export const MySurveyCard = ({ data }: Props) => {
}; };
const copyLink = () => { const copyLink = () => {
navigator.clipboard.writeText(`http://localhost:8080/surveys/${data._id}`); navigator.clipboard.writeText(`http://localhost:8080/survey/${data._id}`);
alert("설문조사의 링크가 클립보드에 저장되었습니다."); alert("설문조사의 링크가 클립보드에 저장되었습니다.");
}; };
......
...@@ -17,7 +17,7 @@ export const EditResultButton = () => { ...@@ -17,7 +17,7 @@ export const EditResultButton = () => {
<div> <div>
<div className="flex place-content-center mt-6"> <div className="flex place-content-center mt-6">
<NavLink <NavLink
to={`/surveys/edit/${surveyId}`} to={`/surveys/${surveyId}/edit`}
style={({ isActive }) => style={({ isActive }) =>
isActive isActive
? { ? {
...@@ -33,7 +33,7 @@ export const EditResultButton = () => { ...@@ -33,7 +33,7 @@ export const EditResultButton = () => {
<div className="text-xl m-3 ">설문지 수정</div> <div className="text-xl m-3 ">설문지 수정</div>
</NavLink> </NavLink>
<NavLink <NavLink
to={`/surveys/edit/${surveyId}/result`} to={`/surveys/${surveyId}/result`}
style={({ isActive }) => style={({ isActive }) =>
isActive isActive
? { ? {
......
import React from "react"; import React, { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import { surveyApi } from "../apis";
import { catchErrors } from "../helpers";
import { AnswerType, SurveyType } from "../types";
import Accordion from "./Accordion"; import Accordion from "./Accordion";
export const ResultSurvey = () => { export const ResultSurvey = () => {
let { surveyId } = useParams<{ surveyId: string }>();
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const [survey, setSurvey] = useState<SurveyType>({
_id: surveyId || "",
user: {},
title: "",
comment: "",
questions: [],
});
useEffect(() => {
ansSurvey();
}, [surveyId]);
async function ansSurvey() {
try {
if (surveyId) {
const getSurvey: any = await surveyApi.ansSurvey(surveyId);
console.log("survey가져옴ㅎㅎ", getSurvey);
setSurvey(getSurvey);
} else {
setLoading(true);
}
} catch (error) {
catchErrors(error, setError);
} finally {
setLoading(false);
}
}
const data = [ const data = [
{ {
title: "1번질문", title: "1번질문",
content: content: "1번 답변들",
"1번 답변들asdfadsgsjadhfasld;nvaldkfnbljgnahgvlajnbl janl;nvja; sabv;jnsvjl;asjvh asjfagkfnjf;nvasgn va;sdn va sglanksvl ds af adb adf afg dgafbg dfh jbvlkna lkslbk kjv nbkkdlfn akdl nvjbnkdjf nlkbakdn bkjnakjn n knk",
}, },
{ {
title: "2번질문", title: "2번질문",
...@@ -21,10 +55,10 @@ export const ResultSurvey = () => { ...@@ -21,10 +55,10 @@ export const ResultSurvey = () => {
<div className="flex flex-col place-items-center"> <div className="flex flex-col place-items-center">
<div className="flex flex-col container place-items-center mt-4"> <div className="flex flex-col container place-items-center mt-4">
<div className="font-bold text-4xl text-center m-2 border-b-2"> <div className="font-bold text-4xl text-center m-2 border-b-2">
설문지 제목 {survey.title}
</div> </div>
<div className="font-bold text-1xl text-center m-2 resize-none"> <div className="font-bold text-1xl text-center m-2 resize-none">
설문조사 설명 {survey.comment}
</div> </div>
</div> </div>
......
...@@ -14,6 +14,7 @@ export const createSurvey = asyncWrap( ...@@ -14,6 +14,7 @@ export const createSurvey = asyncWrap(
let survey = req.body; let survey = req.body;
survey.user = userId; survey.user = userId;
console.log("survey body", survey); console.log("survey body", survey);
delete survey._id;
const newSurvey = await surveyDb.createSurvey(survey); const newSurvey = await surveyDb.createSurvey(survey);
return res.json(newSurvey); return res.json(newSurvey);
} }
......
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