import { React, useState } from "react";
import "./signin.css";
import Logo from "../imgs/logo2.png";
import BG1 from "../imgs/login-BG.png";
import BG2 from "../imgs/login-BG2.png";
import google from "../imgs/google.png";
import { app } from "../Firebase";
import { Link, useNavigate } from "react-router-dom";
import {
getAuth,
createUserWithEmailAndPassword,
GoogleAuthProvider,
signInWithPopup,
updateProfile,
} from "firebase/auth";
import swal from "sweetalert";
import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
const auth = getAuth(app);
const provider = new GoogleAuthProvider();
function Signup() {
const [email, setEmail] = useState("");
const [name, setName] = useState("");
const [password, setPassword] = useState("");
const [emailError, setEmailError] = useState("");
const [bgLoaded, setBgLoaded] = useState(false);
const [PasswordError, setPasswordError] = useState("");
const [NameError, setNameError] = useState("");
document.title = "Amazon"
const notify1 = () =>
toast.error("Please fill-up all the credentials properly!", {
position: "top-center",
autoClose: 1200,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "colored",
});
const navigate = useNavigate();
const handleEmailChange = (event) => {
setEmail(event.target.value);
};
const handleNameChange = (event) => {
setName(event.target.value);
};
const handlePasswordChange = (event) => {
setPassword(event.target.value);
};
const handleEmailBlur = (event) => {
if (
event.target.value === "" ||
!event.target.value.includes("@") ||
!event.target.value.includes(".com")
) {
setEmailError("Please enter a valid email address.");
} else {
setEmailError("");
}
};
const handleNameBlur = (event) => {
if (event.target.value === "") {
setNameError("Please enter your name.");
} else {
setNameError("");
}
};
const handlePasswordBlur = (event) => {
if (event.target.value === "") {
setPasswordError("Please enter your password.");
} else if (event.target.value.length < 4) {
setPasswordError("Password is too small.");
} else {
setPasswordError("");
}
};
const CreateUser = async () => {
try {
const { user } = await createUserWithEmailAndPassword(
auth,
email,
password
);
await updateProfile(user, {
displayName: name,
});
navigate("/home");
} catch (error) {
swal({
title: "Error!",
text: error.message,
icon: "error",
buttons: "Ok",
});
}
};
const GoogleAuth = async () => {
signInWithPopup(auth, provider)
.then((result) => {
navigate("/home");
})
.catch((error) => {
swal({
title: "Error!",
text: error.message,
icon: "error",
buttons: "Ok",
});
});
};
const handleBgLoad = () => {
setBgLoaded(true);
};
return (
<>
User Registration
Hey, Enter your details to create a new account
― Or ―