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";
// import auth from "../context/auth_context"
const INIT_USER = {
name: "",
idNumber1: "",
idNumber2: "",
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.idNumber1 &&
user.idNumber2 &&
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() {
try {
const data = await userApi.signup(user)
// const data = await axios.post("https://localhost:8080/api/room/1/1",user)
setLoading(true);
setError("");
// const success = await login(user.email, user.password);
// const data = await axios.post("/api/room/1/1",user)
console.log(data);
setSuccess(true);
} catch (error) {
// catchErrors(error, setError);
} finally {
setLoading(false);
}
}
if (success) {
alert('회원가입 되었습니다.')
return