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: "" }); const [room_Num, setRoom_Num] = useState({ "9-116": 5, "7-234": 7, "25-101": 10 }); 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"}); } setUser(res.data); }) .catch(err => { alert(err.error) }); } function addRoomInfo(values) { for (let room in room_Num) { if (room === values.room) { values.roomInfo = room_Num[room] } }; } return (
{ addRoomInfo(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"}); }) .catch(err => { alert(err.error) }); setTimeout(() => { setSubmitting(false); }, 400); // finish the cycle in handler }} > {({ errors, touched, values, handleSubmit, getFieldProps, isSubmitting, }) => (

{user.name}

신청날짜
{time(values.starttime)}
강의실
대관 목적
{({ remove, push }) => (
이용자
{values.students.map((student, index) => (
))}
)}
)}
) } export default Apply