Commit dc16c4a2 authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

컨텍스트 루트로 로직 변경

parent 44530f9a
import React from "react"; import React from "react";
import { surveyApi } from "../apis"; import { surveyApi } from "../apis";
import { useSurveys } from "../layouts";
import { ISurvey } from "../types"; import { ISurvey } from "../types";
import { ModifySurvey } from "./ModifySurvey"; import { ModifySurvey } from "./ModifySurvey";
export const CreateSurvey = () => { export const CreateSurvey = () => {
const { error, loading, create } = useSurveys();
const surveyData = { const surveyData = {
_id: "", _id: "",
user: "", user: "",
...@@ -12,10 +15,10 @@ export const CreateSurvey = () => { ...@@ -12,10 +15,10 @@ export const CreateSurvey = () => {
questions: [], questions: [],
}; };
const create = async (surveyData: ISurvey) => { // const create = async (surveyData: ISurvey) => {
const result = await surveyApi.createSurvey(surveyData); // const result = await surveyApi.createSurvey(surveyData);
return result; // return result;
}; // };
return <ModifySurvey surveyData={surveyData} callApi={create} />; return <ModifySurvey surveyData={surveyData} callApi={create} />;
}; };
import React from "react"; import React, { useState } from "react";
import { useLocation } from "react-router-dom"; import { Navigate, useLocation, useParams } from "react-router-dom";
import { surveyApi } from "../apis"; import { surveyApi } from "../apis";
import { ISurvey } from "../types"; import { ISurvey } from "../types";
import { ModifySurvey } from "./ModifySurvey"; import { ModifySurvey } from "./ModifySurvey";
import { useSurvey } from "../layouts/SurveyLayout";
export const EditSurvey = () => { export const EditSurvey = () => {
const location = useLocation(); const { survey, update } = useSurvey();
const surveyState = location.state as ISurvey; // const [survey, setSurvey] = useState(surveyData);
console.log("edit survey:", surveyState);
const update = async (surveyData: ISurvey) => { console.log("survey", survey);
const result = await surveyApi.updateSurvey(surveyData); // const location = useLocation();
return result; // const surveyState = location.state as ISurvey;
}; // console.log("edit survey:", surveyState);
return <ModifySurvey surveyData={surveyState} callApi={update} />; // 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} />;
}; };
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