import React, { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import axios from "axios"; type SignUpProps = {}; export const SignUp = ({}: SignUpProps) => { interface IUSER { name: string; email: string; password: string; password2: string; } const [user, setUser] = useState({ name: "user", email: "user1234@naver.com", password: "1234", password2: "1234", }); const [error, setError] = useState(""); const [disabled, setDisabled] = useState(false); const [success, setSuccess] = useState(false); const navigate = useNavigate(); useEffect(() => { setDisabled(!(user.name && user.email && user.password && user.password2)); }, [user]); function handleChange(event: React.ChangeEvent) { const { id, value } = event.target; setUser({ ...user, [id]: value }); } async function handleSubmit(event: React.MouseEvent) { event.preventDefault(); try { console.log("checkPassword:", passwordmatch()); if (passwordmatch()) { const res = await axios.post("/api/auth/signup", user); console.log("서버연결됬나요", res); console.log("회원가입"); setSuccess(true); setError(""); } } catch (error) { console.log("에러발생"); // catchErrors(error, setError) } finally { // setLoading(false); } } function passwordmatch() { if (user.password !== user.password2) { alert("비밀번호가 일치하지않습니다"); console.log("password fail"); return false; } else { console.log("password match"); return true; } } if (success) { alert("회원가입 되었습니다"); navigate(`../`); } return (
); };