EditSurvey.tsx 864 Bytes
Newer Older
1
2
import React, { useState } from "react";
import { Navigate, useLocation, useParams } from "react-router-dom";
Yoon, Daeki's avatar
Yoon, Daeki committed
3
4
5
import { surveyApi } from "../apis";
import { ISurvey } from "../types";
import { ModifySurvey } from "./ModifySurvey";
6
import { useSurvey } from "../layouts/SurveyLayout";
Yoon, Daeki's avatar
Yoon, Daeki committed
7
8

export const EditSurvey = () => {
9
10
  const { survey, update } = useSurvey();
  // const [survey, setSurvey] = useState(surveyData);
Yoon, Daeki's avatar
Yoon, Daeki committed
11

12
13
14
15
  console.log("survey", survey);
  // const location = useLocation();
  // const surveyState = location.state as ISurvey;
  // console.log("edit survey:", surveyState);
Yoon, Daeki's avatar
Yoon, Daeki committed
16

17
18
19
20
21
22
23
24
25
26
  // const update = async (surveyData: ISurvey) => {
  //   const result = await surveyApi.updateSurvey(surveyData);
  //   return result;
  // };

  if (!survey) {
    return <Navigate to={"/surveys"} />;
  }

  return <ModifySurvey surveyData={survey} callApi={update} />;
Yoon, Daeki's avatar
Yoon, Daeki committed
27
};