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

제출 시localstorage정보저장

parent eaf39470
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";
...@@ -11,6 +12,7 @@ export const SurveyForm = () => { ...@@ -11,6 +12,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: {},
...@@ -25,6 +27,13 @@ export const SurveyForm = () => { ...@@ -25,6 +27,13 @@ export const SurveyForm = () => {
answers: [], answers: [],
}); });
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)) {
setFiles([...files, oneFile]); setFiles([...files, oneFile]);
...@@ -79,6 +88,9 @@ export const SurveyForm = () => { ...@@ -79,6 +88,9 @@ export const SurveyForm = () => {
formData.append("files", f.file); formData.append("files", f.file);
}); });
const newAnswer: AnswerType = await answerApi.saveAnswers(formData); const newAnswer: AnswerType = await answerApi.saveAnswers(formData);
localStorage.setItem(`survey_${surveyId}`, surveyId ?? "");
alert("제출되었습니다");
navigate(`/`);
// console.log(newAnswer); // console.log(newAnswer);
setSuccess(true); setSuccess(true);
setError(""); setError("");
......
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