Commit 6442aa99 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

Merge branch '_seoyeon' into develop0722

parents 1b7b0a95 69e77b52
...@@ -21,9 +21,9 @@ export const ADropdownForm = ({ element, answerQuestion }: Props) => { ...@@ -21,9 +21,9 @@ export const ADropdownForm = ({ element, answerQuestion }: Props) => {
console.log(answerQuestion); console.log(answerQuestion);
}; };
return ( return (
<div className="flex flex-col container w-4/5 h-auto items-center m-3 py-3"> <div className="flex flex-col container w-11/12 h-auto m-3 py-3">
<select <select
className="py-2 hover:bg-themeColor bg-gray-200 rounded" className="py-2 w-48 hover:bg-gray-200 border border-black rounded"
onChange={handleChange} onChange={handleChange}
> >
{element.content.choices.map((choice) => ( {element.content.choices.map((choice) => (
......
import React, { FormEvent, useEffect, useRef, useState } from "react"; import React, { FormEvent, useEffect, useRef, useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { surveyApi, answerApi } from "../apis"; import { surveyApi, answerApi } from "../apis";
import { catchErrors } from "../helpers"; import { catchErrors } from "../helpers";
...@@ -13,6 +14,7 @@ export const SurveyForm = () => { ...@@ -13,6 +14,7 @@ export const SurveyForm = () => {
const [error, setError] = useState(""); const [error, setError] = useState("");
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
const navigate = useNavigate();
const [survey, setSurvey] = useState<SurveyType>({ const [survey, setSurvey] = useState<SurveyType>({
_id: surveyId, _id: surveyId,
user: {}, user: {},
...@@ -32,6 +34,12 @@ export const SurveyForm = () => { ...@@ -32,6 +34,12 @@ export const SurveyForm = () => {
useEffect(() => { useEffect(() => {
ansSurvey(); ansSurvey();
}, [surveyId]); }, [surveyId]);
const isSurvey = localStorage.getItem(`survey_${surveyId}`);
if (isSurvey) {
console.log("object", isSurvey);
alert("제출한 설문조사입니다");
navigate("/");
}
const addFiles = (oneFile: { questionId: string; file: File }) => { const addFiles = (oneFile: { questionId: string; file: File }) => {
if (!files.find((a) => a.questionId === oneFile.questionId)) { if (!files.find((a) => a.questionId === oneFile.questionId)) {
...@@ -82,6 +90,9 @@ export const SurveyForm = () => { ...@@ -82,6 +90,9 @@ export const SurveyForm = () => {
}); });
const newAnswer: AnswerType = await answerApi.saveAnswers(formData); const newAnswer: AnswerType = await answerApi.saveAnswers(formData);
console.log(newAnswer); console.log(newAnswer);
localStorage.setItem(`survey_${surveyId}`, surveyId ?? "");
alert("제출되었습니다");
setSuccess(true); setSuccess(true);
setError(""); setError("");
} catch (error) { } catch (error) {
......
...@@ -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/${data._id}/edit`, { navigate(`/surveys/edit/${data._id}`, {
replace: true, replace: true,
state: { save: true }, state: { save: true },
}); });
......
...@@ -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/${surveyId}/edit`} to={`/surveys/edit/${surveyId}`}
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/${surveyId}/result`} to={`/surveys/edit/${surveyId}/result`}
style={({ isActive }) => style={({ isActive }) =>
isActive isActive
? { ? {
......
import React, { FormEvent, useEffect, useState } from "react"; import React, { FormEvent, useEffect, useState } from "react";
import { useParams, useLocation } from "react-router-dom"; import { useParams, useLocation, useNavigate } from "react-router-dom";
import { questionApi, surveyApi } from "../apis"; import { questionApi, surveyApi } from "../apis";
import { SpinnerIcon } from "../icons"; import { SpinnerIcon } from "../icons";
import { Question } from "../questions"; import { Question } from "../questions";
...@@ -20,6 +20,7 @@ export const EditSurvey = () => { ...@@ -20,6 +20,7 @@ export const EditSurvey = () => {
const [error, setError] = useState(""); const [error, setError] = useState("");
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
const navigate = useNavigate();
const [survey, setSurvey] = useState<SurveyType>({ const [survey, setSurvey] = useState<SurveyType>({
_id: surveyId, _id: surveyId,
user: {}, user: {},
...@@ -60,6 +61,8 @@ export const EditSurvey = () => { ...@@ -60,6 +61,8 @@ export const EditSurvey = () => {
const newSurvey: SurveyType = await surveyApi.editSurvey(survey); const newSurvey: SurveyType = await surveyApi.editSurvey(survey);
console.log(newSurvey); console.log(newSurvey);
setSuccess(true); setSuccess(true);
alert("저장되었습니다");
navigate("/profile");
setError(""); setError("");
} catch (error) { } catch (error) {
catchErrors(error, setError); catchErrors(error, setError);
......
import { NextFunction, Request, Response } from "express"; import { NextFunction, Request, Response } from "express";
import { surveyDb } from "../db"; import { surveyDb } from "../db";
import { asyncWrap } from "../helpers/asyncWrap"; import { asyncWrap } from "../helpers/asyncWrap";
// import jwt, { JwtPayload } from "jsonwebtoken";
// import { cookieConfig, envConfig, jwtCofig } from "../config";
export interface TypedRequestAuth<T> extends Request { export interface TypedRequestAuth<T> extends Request {
auth: T; auth: T;
...@@ -70,29 +68,3 @@ export const userBySurveyId = async ( ...@@ -70,29 +68,3 @@ export const userBySurveyId = async (
); );
} }
}; };
\ No newline at end of file
// export const checksurvey = asyncWrap(async(req, res)=> {
// const {_id} = req.body
// const surveyExist = await surveyDb.isSurvey(_id);
// if (surveyExist) {
// return res.status(422).send("이미 제출된 설문조사입니다")
// }
// });
// export const surveynotexist = asyncWrap(async (req, res) => {
// const { _id } = req.body;
// console.log(`surveyId: ${_id}`);
// const checksurveyId = await surveyDb.findUserBySurveyId(_id);
// const surveytoken = jwt.sign({existsurveyId: checksurveyId?.id}, jwtCofig.secret, {
// expiresIn:jwtCofig.expires,
// });
// res.cookie(cookieConfig.name, surveytoken, {
// maxAge:cookieConfig.maxAge,
// path:"/",
// httpOnly: envConfig.mode === "production",
// secure: envConfig.mode === "production",
// })
// res.json({
// surveyId: checksurveyId?._id
// })
// });
\ No newline at end of file
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