Commit 05ae28b3 authored by jang dong hyeok's avatar jang dong hyeok
Browse files

설문응답완료후 홈페이지로 이동

parent afb55513
import React, { FormEvent, useEffect, useState } from "react"; import React, { FormEvent, useEffect, useState } from "react";
import { useParams } from "react-router-dom"; import { useParams, useNavigate } from "react-router-dom";
import { answerApi, surveyApi } from "../apis"; import { answerApi, surveyApi } from "../apis";
import { catchErrors } from "../helpers"; import { catchErrors } from "../helpers";
import { SpinnerIcon } from "../icons"; import { SpinnerIcon } from "../icons";
...@@ -12,6 +12,7 @@ export const AnswerSurvey = () => { ...@@ -12,6 +12,7 @@ export const AnswerSurvey = () => {
const [survey, setSurvey] = useState<ISurvey>(); const [survey, setSurvey] = useState<ISurvey>();
const [answers, setAnswers] = useState<IAnswer[]>([]); const [answers, setAnswers] = useState<IAnswer[]>([]);
const [error, setError] = useState(""); const [error, setError] = useState("");
const navigate = useNavigate();
useEffect(() => { useEffect(() => {
surveyId && getSurvey(surveyId); surveyId && getSurvey(surveyId);
...@@ -30,6 +31,7 @@ export const AnswerSurvey = () => { ...@@ -30,6 +31,7 @@ export const AnswerSurvey = () => {
if (!survey) { if (!survey) {
return; return;
} }
if (confirm("제출하시겠습니까?")) {
try { try {
const fileAnswers = answers.filter( const fileAnswers = answers.filter(
(answer) => answer.question.type === "file" (answer) => answer.question.type === "file"
...@@ -72,11 +74,15 @@ export const AnswerSurvey = () => { ...@@ -72,11 +74,15 @@ export const AnswerSurvey = () => {
); );
console.log("result:", result); console.log("result:", result);
navigate("/");
} catch (error) { } catch (error) {
catchErrors(error, setError); catchErrors(error, setError);
} finally { } finally {
// setLoading(false); // setLoading(false);
} }
} else {
return;
}
}; };
async function getSurvey(surveyId: string) { async function getSurvey(surveyId: string) {
......
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