import React, { useState, useEffect } from 'react'; import { Redirect } from 'react-router-dom'; import Menu from '../Components/Menu'; import * as Yup from 'yup'; import axios from 'axios'; import { Container, Row, Col, Button } from 'react-bootstrap'; import { Field, Formik } from 'formik'; function Write() { const [state, setState] = useState(false); const [isadmin, setIsadmin] = useState({ ok: "" }); const [user, setUser] = useState({ name: "" }) useEffect(() => { acheck(); }, []) if (isadmin.ok === "no") return ; if (state) { return ; } function acheck() { axios.get(`/api/users/admin/${localStorage.getItem('_id')}`, { headers: { authorization: localStorage.getItem('token') }, }) .then(res => { if (res.status !== 201) { alert(res.data.error); console.log(res.data) setIsadmin({ ok: "no" }); } setUser({ name: res.data.name }) }).catch(err => { alert(err.error) }); } return (
{ console.log(values) axios({ method: 'post', url: '/api/writes', data: values, }).then(res => { if (res.status === 404) return alert(res.data.error) alert("공지 등록이 완료되었습니다.") setState(true); }) .catch(err => { alert(err.error) }); setTimeout(() => { setSubmitting(false); }, 400); // finish the cycle in handler }} >{({ errors, touched, handleSubmit, getFieldProps, // contain values, handleChange, handleBlur isSubmitting, }) => (
제목
내용
)}
) } export default Write