import React, { useState, useEffect } from 'react'
import { Alert, Col, Container, Form, Row, Button } from "react-bootstrap";
import axios from "axios";
import catchErrors from '../utils/catchErrors';
import { Link, Redirect} from 'react-router-dom';
const INIT_USER = {
name: '',
email: '',
password: ''
}
function Signup() {
const [user, setUser] = useState(INIT_USER)
const [disabled, setDisabled] = useState(true)
const [error, setError] = useState('')
const [success, setSuccess] = useState(false)
useEffect(() => {
const isUser = Object.values(user).every(el => Boolean(el))
isUser ? setDisabled(false) : setDisabled(true)
}, [user])
function handleChange(event) {
const {name, value} = event.target
setUser({...user, [name]: value})
}
async function handleSubmit(event) {
event.preventDefault()
try {
setError('')
const response = await axios.post('/api/users/signup', user)
console.log(response.data)
setUser(INIT_USER)
} catch (error) {
catchErrors(error, setError)
}
}
if (success) {
return
}
return (
회원가입
{error &&
{error}
}
이름
이메일
비밀번호
)
}
export default Signup