File size: 8,167 Bytes
f5071ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
import React from "react";
import { useState, useContext } from "react";
import { Link, useNavigate } from "react-router-dom";
import { Fade } from "react-reveal";
import {
getAuth,
createUserWithEmailAndPassword,
onAuthStateChanged,
} from "firebase/auth";
import { setDoc, doc } from "firebase/firestore";
import { db } from "../Firebase/FirebaseConfig";
import { AuthContext } from "../Context/UserContext";
import { ClipLoader } from "react-spinners";
import WelcomePageBanner from "../images/WelcomePageBanner.jpg";
function SignUp() {
const { User, setUser } = useContext(AuthContext);
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [ErrorMessage, setErrorMessage] = useState("");
const [loader, setLoader] = useState(false);
const navigate = useNavigate();
const handleSubmit = (e) => {
e.preventDefault();
setLoader(true);
const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
onAuthStateChanged(auth, (user) => {
const EmptyArray = [];
setDoc(doc(db, "Users", user.uid), {
email: email,
Uid: user.uid,
}).then(() => {
setDoc(
doc(db, "MyList", user.uid),
{
movies: EmptyArray,
},
{ merge: true }
).then(() => {
setDoc(
doc(db, "WatchedMovies", user.uid),
{
movies: EmptyArray,
},
{ merge: true }
);
setDoc(
doc(db, "LikedMovies", user.uid),
{
movies: EmptyArray,
},
{ merge: true }
);
});
});
});
const user = userCredential.user;
if (user != null) {
navigate("/");
}
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
setLoader(false);
setErrorMessage(errorMessage);
console.log(errorCode);
console.log(errorMessage);
});
};
return (
<section
className="h-[100vh] bg-gray-500"
style={{
background: `linear-gradient(0deg, hsl(0deg 0% 0% / 73%) 0%, hsl(0deg 0% 0% / 73%) 35%),url(${WelcomePageBanner})`,
}}
>
<div className="h-[100vh] flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0">
<div className="w-full bg-[#000000a2] rounded-lg shadow sm:my-0 md:mt-0 sm:max-w-lg xl:p-0 border-2 border-stone-800 lg:border-0">
<Fade>
<div>
<div className="p-6 space-y-4 md:space-y-6 sm:p-12">
<h1 className="text-xl font-bold leading-tight tracking-tight text-white md:text-2xl dark:text-white">
Create a new account
</h1>
<h1 className="text-white text-2xl p-3 text-center border-2 border-red-700 rounded-sm">
Not Real Netflix
</h1>
<form
onSubmit={handleSubmit}
className="space-y-4 md:space-y-6"
action="#"
>
<div>
<label
for="email"
className="block mb-2 text-sm font-medium text-white dark:text-white"
>
Your email
</label>
<input
onChange={(e) => setEmail(e.target.value)}
type="email"
name="email"
id="email"
className={
ErrorMessage
? "bg-stone-700 text-white sm:text-sm rounded-sm border-2 border-red-700 focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:text-white "
: "bg-stone-700 text-white sm:text-sm rounded-sm focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:text-white "
}
placeholder="name@emil.com"
required=""
></input>
</div>
<div>
<label
for="password"
className="block mb-2 text-sm font-medium text-white dark:text-white"
>
Password
</label>
<input
onChange={(e) => setPassword(e.target.value)}
type="password"
name="password"
id="password"
placeholder="••••••••"
className={
ErrorMessage
? "bg-stone-700 text-white sm:text-sm rounded-sm border-2 border-red-700 focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5"
: "bg-stone-700 text-white sm:text-sm rounded-sm focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:text-white"
}
required=""
></input>
</div>
<div>
{ErrorMessage && (
<h1 className="flex text-white font-bold p-4 bg-red-700 rounded text-center">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className="w-6 h-6 mr-1"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
/>
</svg>
{ErrorMessage}
</h1>
)}
</div>
<div className="flex items-center justify-between">
<div className="flex items-start">
<div className="flex items-center h-5">
<input
id="remember"
aria-describedby="remember"
type="checkbox"
className="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 "
required=""
></input>
</div>
<div className="ml-3 text-sm">
<label for="remember" className="text-gray-500">
Remember me
</label>
</div>
</div>
</div>
<button
type="submit"
className={`w-full text-white ${
loader
? `bg-stone-700`
: `bg-red-800 focus:ring-4 focus:outline-none focus:ring-primary-300`
} font-medium rounded-sm text-sm px-5 py-2.5 text-center`}
>
{loader ? <ClipLoader color="#ff0000" /> : "Create now"}
</button>
<p className="text-sm font-light text-gray-500">
Already have one?{" "}
<Link
className="font-medium text-white hover:underline"
to={"/signin"}
>
Sign in
</Link>
</p>
</form>
</div>
</div>
</Fade>
</div>
</div>
</section>
);
}
export default SignUp;
|