diff --git a/src/components/AuthPages/VerifyLink/index.jsx b/src/components/AuthPages/VerifyLink/index.jsx new file mode 100644 index 0000000..ed4b7a1 --- /dev/null +++ b/src/components/AuthPages/VerifyLink/index.jsx @@ -0,0 +1,141 @@ +import { useEffect, useState } from "react"; +import { useLocation, Link, useNavigate } from "react-router-dom"; +import AuthLayout from "../AuthLayout"; +import InputCom from "../../Helpers/Inputs/InputCom"; +import usersService from "../../../services/UsersService"; +import WrenchBoard from "../../../assets/images/wrenchboard.png" + +export default function VerifyLink() { + const [pageLoader, setPageLoader] = useState(true) + const [linkSuccess, setLinkSuccess] = useState(false) + const [linkError, setLinkError] = useState(false) + const navigate = useNavigate() + const location = useLocation(); + const queryParams = new URLSearchParams(location?.search) + const token = queryParams.get('vlink') + + const verifyEmail = async (code) => { + const userApi = new usersService() + + try { + const verifyRes = await userApi.verifyEmail(code) + console.log(verifyRes) + if (verifyRes.status === 200) { + let { data } = verifyRes + + if (data && data.internal_return === 0 && data.status_text === 'Link Verfied') { + setPageLoader(false) + setLinkSuccess(true) + } else { + setPageLoader(false) + setLinkError(true) + } + } + } catch (error) { + console.log(error) + setPageLoader(false) + setLinkError(true) + throw new Error(error) + } + } + + useEffect(() => { + verifyEmail(token) + }) + + console.log(token) + + return ( + <> + + {pageLoader ? ( + wrenchboard + ) : ( +
+
+ + wrenchboard + +
+
+
+
+

+ {linkError && 'Invalid verification link'} + {linkSuccess && 'Sign In to WrenchBoard'} +

+
+ {/* If the verification was a success */} + {linkSuccess && } + + {/* If the verification was unsuccessful */} + {linkError && navigate('/login')} />} +
+
+
+ )} +
+ + ) +} + +const SuccessfulComponent = ({ onClick }) => ( +
+ {/* INPUT */} +
+ +
+
+ +
+
+ +
+
+) + +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. +

+
+ +
+ +
+
+) \ No newline at end of file