From 255da585887edd83222b733a44297d28ba539f9f Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Wed, 17 Jan 2024 19:49:17 +0100 Subject: [PATCH] added new layout for verify link page --- .../AuthPages/VerifyLink/index2.jsx | 245 ++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 src/components/AuthPages/VerifyLink/index2.jsx diff --git a/src/components/AuthPages/VerifyLink/index2.jsx b/src/components/AuthPages/VerifyLink/index2.jsx new file mode 100644 index 0000000..2349513 --- /dev/null +++ b/src/components/AuthPages/VerifyLink/index2.jsx @@ -0,0 +1,245 @@ +import { useCallback, useEffect, useState } from "react"; +import { Link, useLocation, useNavigate } from "react-router-dom"; +import WrenchBoard from "../../../assets/images/wrenchboard-logo-text.png"; +import debounce from "../../../hooks/debounce"; +import usersService from "../../../services/UsersService"; +import InputCom from "../../Helpers/Inputs/InputCom"; +import AuthLayout from "../AuthLayout"; + +export default function VerifyLink() { + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [msgError, setMsgError] = useState(""); + const [linkLoader, setLinkLoader] = useState(false); + const [pageLoader, setPageLoader] = useState(true); + const [linkSuccess, setLinkSuccess] = useState(true); + const navigate = useNavigate(); + const location = useLocation(); + const queryParams = new URLSearchParams(location?.search); + const token = queryParams.get("vlnk"); + const userApi = new usersService(); + + // email + const handleEmail = (e) => { + setEmail(e.target.value); + }; + // password + const handlePassword = (e) => { + setPassword(e.target.value); + }; + + // if verification is okay. set a complete signup form + const completeSignup = async () => { + try { + if (email !== "" && password !== "") { + setLinkLoader(true); + var postData = { + username: email, + password: password, + login_mode: 100, + sessionid: "STARTER-NOTREAL", + verify_link: token, + action: 11012, + }; + const res = await userApi?.CompleteSignUp(postData); + + if (res.status === 200) { + const { data } = res; + if ( + data?.status > 0 && + data?.internal_return == 100 && + data?.session != "" + ) { + localStorage.setItem("email", `${data?.email}`); + localStorage.setItem("member_id", `${data?.member_id}`); + localStorage.setItem("session_token", `${data?.session}`); + localStorage.setItem("session", `${data?.session}`); + localStorage.setItem("uid", data?.uid) + + + navigate("/", { replace: true }); + setLinkLoader(false); + } else { + setLinkLoader(false); + setMsgError("Invalid Link or Password Combination"); + } + } else { + setLinkLoader(false); + setLinkSuccess(false); + setMsgError("An error occurred"); + } + } else { + setMsgError("Please fill in fields"); + } + } catch (error) { + setLinkLoader(false); + setLinkSuccess(false); + throw new Error(error); + } finally { + setTimeout(() => { + setMsgError(null); + }, process.env.REACT_APP_SIGNUP_ERROR_TIMEOUT); + } + }; + + // for verifying the incoming verification link and render the correct component + const verifyEmail = useCallback(async (code) => { + try { + const verifyRes = await userApi.verifyEmail(code); + if (verifyRes.status === 200) { + let { data } = verifyRes; + console.log('TESTING VERIFY',data) + if ( + data && + data.internal_return >= 0 && + data.status == 0 && + data.pending_id != '' && + data.pending_uid != '' && + data.username != '' && + data.status_text === "Link Verified" + ) { + setPageLoader(false); + } else { + setPageLoader(false); + setLinkSuccess(false); + } + } + } catch (error) { + setPageLoader(false); + setLinkSuccess(false); + throw new Error(error); + } + }, []); + + // delay verify requests by 10000ms + const debouncedEmail = debounce(verifyEmail, 1000); + + useEffect(() => { + debouncedEmail(token); + }, []); + + return ( + <> + + {pageLoader ? ( + wrenchboard + ) : ( +
+
+ + wrenchboard + +
+
+
+
+

+ {linkSuccess + ? "Sign In to WrenchBoard" + : "Invalid verification link"} +

+
+ {/* If the verification was a success */} + {linkSuccess ? ( + + ) : ( + navigate("/login")} /> + )} +
+
+
+ )} +
+ + ); +} + +const SuccessfulComponent = ({ + onSubmit, + password, + handlePassword, + email, + handleEmail, + msgErr, + loader, +}) => ( +
+ {/* INPUT */} +
+ +
+
+ +
+ {msgErr && ( +
+ {msgErr} +
+ )} +
+ +
+
+); + +const ErrorComponent = ({ onClick }) => ( +
+
+

+ This error occurs because you have already verified this link or the + link has expired. Try login or reset password. If none worked, try to + create the account from the start. +

+
+ +
+ +
+
+);