Commit bf1fbd5f authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

questionApi : createQuestion

parent 72abe1cb
...@@ -7,6 +7,7 @@ import React, { ...@@ -7,6 +7,7 @@ import React, {
} from "react"; } from "react";
import axios from "axios"; import axios from "axios";
import { BasicQuestionType } from "../types"; import { BasicQuestionType } from "../types";
import { questionApi } from "../apis";
interface IQuestionContext { interface IQuestionContext {
questionListChange: (e: React.ChangeEvent<HTMLInputElement>) => void; questionListChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
...@@ -38,17 +39,10 @@ export const QuestionProvider: FC<{ children: ReactNode }> = ({ children }) => { ...@@ -38,17 +39,10 @@ export const QuestionProvider: FC<{ children: ReactNode }> = ({ children }) => {
setQuestionList(newList); setQuestionList(newList);
} }
async function addQuestion(e: React.MouseEvent<HTMLButtonElement>) { async function addQuestion() {
try { try {
const res = await axios.post("/api/questions/create", { const newQ: BasicQuestionType = await questionApi.createQuestion();
type: "essay", setQuestionList([...questionList, newQ]);
title: "Question Title",
isRequired: false,
comment: "질문에 대한 설명을 입력해주세요",
content: null,
});
console.log(res.data);
setQuestionList([...questionList, res.data]);
// setSuccess(true); // setSuccess(true);
// setError(""); // setError("");
} catch (error) { } catch (error) {
......
import axios from "axios"; import axios from "axios";
export * as authApi from "./auth.api"; export * as authApi from "./auth.api";
export * as questionApi from "./question.api"
import axios from "axios";
import { } from "../types";
import baseUrl from "./baseUrl";
export const createQuestion = async () => {
const { data } = await axios.post(`${baseUrl}/questions/create`, {
type: "essay",
title: "Question Title",
isRequired: false,
comment: "질문에 대한 설명을 입력해주세요",
content: null,
});
return data;
};
\ No newline at end of file
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