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

컨텍스트 루트로 로직 변경

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