import axios from "axios"; import { useEffect, useState } from "react"; import { Redirect } from "react-router-dom"; import userApi from "../apis/user.api"; import catchErrors from "../context/catchError"; const INIT_USER = { name: "", email: "", password: "", checkpw: "", phone: "", }; const Signup = () => { const [user, setUser] = useState(INIT_USER); const [error, setError] = useState(""); const [disabled, setDisabled] = useState(false); const [success, setSuccess] = useState(false); const [loading, setLoading] = useState(false); useEffect(() => { setDisabled( !( user.name && user.email && user.password && user.checkpw ) ); }, [user]); function handleChange(event) { const { name, value } = event.target; setUser({ ...user, [name]: value }); // console.log(user); } async function handleSubmit() { console.log('회원가입') try { const data = await userApi.signup(user) setLoading(true); setError(""); // const success = await login(user.email, user.password); console.log(data); setSuccess(true); } catch (error) { catchErrors(error, setError); } finally { setLoading(false); } } if (success) { alert('회원가입 되었습니다.') return ; } const { name, id, password, checkpw, phone } = user; return (
{error &&
{error}
}
회원가입
{console.log(disabled)}
); }; export default Signup;