import { useState } from "react";
import { Redirect } from "react-router-dom";
import { useAuth } from "../../context/auth_context.js";
import catchErrors from "../../utils/catchErrors";
import styles from "./login.module.scss";
const Login = () => {
const { login, loading } = useAuth();
const [state, setState] = useState(true);
const [user, setUser] = useState({
id: '',
password: ''
});
const [error, setError] = useState("");
const [success, setSuccess] = useState(false);
const [guest, setGuset] = useState({
guestName: '',
gusetBirthday: '',
gusetMbnum: '',
guestPassword: ''
})
const handleLoginOnChange = (e) => {
setUser({
...user,
[e.target.name]: e.target.value
})
};
const handleGuestOnChange = (e) => {
setGuset({
...guest,
[e.target.name]: e.target.value
})
}
const requestServer = async (data) => {
if (data === user) {
const success = await login(data);
if (success) {
setSuccess(true);
alert('로그인이 완료되었습니다.')
}
}
}
const handleOnSummit = async (e) => {
e.preventDefault();
try {
setError("");
if (e.target.name === "login") {
requestServer(user);
}
else {
requestServer(guest);
alert('로그인이 완료되었습니다.')
}
} catch (error) {
catchErrors(error, setError);
}
}
if (success) {
return