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) => {
console.log(answerQuestion);
};
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
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}
>
{element.content.choices.map((choice) => (
......
import React, { FormEvent, useEffect, useRef, useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import { useParams } from "react-router-dom";
import { surveyApi, answerApi } from "../apis";
import { catchErrors } from "../helpers";
......@@ -13,6 +14,7 @@ export const SurveyForm = () => {
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const navigate = useNavigate();
const [survey, setSurvey] = useState<SurveyType>({
_id: surveyId,
user: {},
......@@ -32,6 +34,12 @@ export const SurveyForm = () => {
useEffect(() => {
ansSurvey();
}, [surveyId]);
const isSurvey = localStorage.getItem(`survey_${surveyId}`);
if (isSurvey) {
console.log("object", isSurvey);
alert("제출한 설문조사입니다");
navigate("/");
}
const addFiles = (oneFile: { questionId: string; file: File }) => {
if (!files.find((a) => a.questionId === oneFile.questionId)) {
......@@ -82,6 +90,9 @@ export const SurveyForm = () => {
});
const newAnswer: AnswerType = await answerApi.saveAnswers(formData);
console.log(newAnswer);
localStorage.setItem(`survey_${surveyId}`, surveyId ?? "");
alert("제출되었습니다");
setSuccess(true);
setError("");
} catch (error) {
......
......@@ -16,7 +16,7 @@ export const MySurveyCard = ({ data }: Props) => {
const [success, setSuccess] = useState(false);
const editSurvey = () => {
navigate(`/surveys/${data._id}/edit`, {
navigate(`/surveys/edit/${data._id}`, {
replace: true,
state: { save: true },
});
......
......@@ -17,7 +17,7 @@ export const EditResultButton = () => {
<div>
<div className="flex place-content-center mt-6">
<NavLink
to={`/surveys/${surveyId}/edit`}
to={`/surveys/edit/${surveyId}`}
style={({ isActive }) =>
isActive
? {
......@@ -33,7 +33,7 @@ export const EditResultButton = () => {
<div className="text-xl m-3 ">설문지 수정</div>
</NavLink>
<NavLink
to={`/surveys/${surveyId}/result`}
to={`/surveys/edit/${surveyId}/result`}
style={({ isActive }) =>
isActive
? {
......
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 { SpinnerIcon } from "../icons";
import { Question } from "../questions";
......@@ -20,6 +20,7 @@ export const EditSurvey = () => {
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const navigate = useNavigate();
const [survey, setSurvey] = useState<SurveyType>({
_id: surveyId,
user: {},
......@@ -60,6 +61,8 @@ export const EditSurvey = () => {
const newSurvey: SurveyType = await surveyApi.editSurvey(survey);
console.log(newSurvey);
setSuccess(true);
alert("저장되었습니다");
navigate("/profile");
setError("");
} catch (error) {
catchErrors(error, setError);
......
import { NextFunction, Request, Response } from "express";
import { surveyDb } from "../db";
import { asyncWrap } from "../helpers/asyncWrap";
// import jwt, { JwtPayload } from "jsonwebtoken";
// import { cookieConfig, envConfig, jwtCofig } from "../config";
export interface TypedRequestAuth<T> extends Request {
auth: T;
......@@ -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