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

제출 시localstorage정보저장

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