import React, { useState, useEffect } from 'react';
import { Formik, Field, ErrorMessage, FieldArray } from 'formik';
import Menu from '../Components/Menu';
import axios from 'axios';
import * as Yup from 'yup';
import { Redirect } from 'react-router-dom';
import { Col, Container, Row } from 'react-bootstrap';
function Apply(props) {
const [state, setState] = useState({ok:""});
const [user, setUser] = useState({ name: "" });
useEffect(() => {
getUser();
}, [])
if (state.ok==="no") return ;
if (state.ok==="ok") {
return ;
}
function time(starttime) {
if (starttime == 21) {
return (
)
}
if (starttime == 20) {
return (
)
}
return (
)
}
function getUser() {
axios.get(`/users/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
localStorage.clear();
setState({ok:"no"});
}
console.log(res.data);
setUser(res.data);
})
.catch(err => {
alert(err.error)
});
}
return (
{
console.log(values)
axios({
method: 'post',
url: '/reserves',
data: values
}).then(res => {
if (res.status === 404) {
alert(res.data.error)
return window.location.reload();
}
alert("신청이 완료되었습니다!");
setState({ok:"ok"});
console.log("res.data", res.data)
})
.catch(err => {
alert(err.error)
});
setTimeout(() => {
setSubmitting(false);
}, 400); // finish the cycle in handler
}}
>
{({
errors,
touched,
values,
handleSubmit,
getFieldProps,
isSubmitting,
}) => (
)}
)
}
export default Apply