added other stages
This commit is contained in:
@@ -1,9 +1,90 @@
|
||||
import React from "react";
|
||||
import React,{useState} from "react";
|
||||
import {useNavigate} from "react-router-dom"
|
||||
import titleShape from "../../../assets/images/shape/text-shape-three.svg";
|
||||
import AuthLayout from "../AuthLayout";
|
||||
import Otp from "./Otp";
|
||||
import usersService from "../../../services/UsersService";
|
||||
|
||||
export default function VerifyYou() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [validation, setValidation] = useState("");
|
||||
const verifyOTP = new usersService()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [verificationCode, setVerificationCode] = useState({
|
||||
value_one: '',
|
||||
value_two: ''
|
||||
})
|
||||
|
||||
const handleVerificationInput = ({target:{name, value}}) => {
|
||||
setVerificationCode(prev => {
|
||||
return {...prev, [name]:value}
|
||||
})
|
||||
}
|
||||
|
||||
const handleSubmit = async() => {
|
||||
setValidation("")
|
||||
setLoading(true)
|
||||
|
||||
let otpCode = '';
|
||||
for(let values in verificationCode){
|
||||
otpCode+=verificationCode[values]
|
||||
}
|
||||
|
||||
// Validating otp code
|
||||
if(!otpCode) {
|
||||
setLoading(false)
|
||||
setValidation("Please enter your otp code")
|
||||
return
|
||||
}
|
||||
if(otpCode.length < 6) {
|
||||
setLoading(false)
|
||||
setValidation("OTP code incomplete")
|
||||
return
|
||||
}
|
||||
|
||||
const {username} = JSON.parse(localStorage.getItem('reset_raw'))
|
||||
const verifyEmail = {
|
||||
username: username,
|
||||
stage: 200,
|
||||
reset_uuid: localStorage.getItem('reset_uuid'),
|
||||
random_text: otpCode
|
||||
}
|
||||
|
||||
localStorage.setItem('otp', otpCode)
|
||||
|
||||
try {
|
||||
const verify = await verifyOTP.resetPassword(verifyEmail);
|
||||
console.log(verify)
|
||||
localStorage.setItem('member_uid', verify.data.member_uid);
|
||||
if (verify.status != 200){
|
||||
setValidation("Sorry, could not verify code")
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
if (verify.status == 200){
|
||||
|
||||
if(verify?.data.error_msg == "Unable to continue"){
|
||||
setLoading(false)
|
||||
setValidation("Incorrect otp code")
|
||||
return
|
||||
}
|
||||
|
||||
setValidation("verified successfully")
|
||||
|
||||
setTimeout(() => {
|
||||
setLoading(false)
|
||||
navigate("/update-password", {replace : true});
|
||||
}, 2000);
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false)
|
||||
setValidation('An error occurred')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<AuthLayout
|
||||
@@ -20,20 +101,22 @@ export default function VerifyYou() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="input-area">
|
||||
<Otp />
|
||||
<Otp handleChange={handleVerificationInput} value={verificationCode} />
|
||||
{validation && <p className={`my-5 text-center font-light italic text-sm subpixel-antialiased tracking-wide ${validation == 'verified successfully' ? 'text-green-600' : 'text-red-500'} `}>{validation}</p>}
|
||||
<div className="signin-area mb-3.5">
|
||||
<a
|
||||
href="/update-password"
|
||||
// href="/update-password"
|
||||
className="w-full rounded-[50px] h-[58px] mb-6 text-xl text-white font-bold flex justify-center bg-purple items-center"
|
||||
onClick={handleSubmit}
|
||||
>
|
||||
Continue
|
||||
{loading ? <div className="signup btn-loader"></div> : <span>Continue</span>}
|
||||
</a>
|
||||
</div>
|
||||
<div className="resend-code flex justify-center">
|
||||
<p className="text-lg text-thin-light-gray font-normal">
|
||||
Dont’t have an aceount ?
|
||||
<a href="#" className="ml-2 text-dark-gray dark:text-white font-bold">
|
||||
Please resend
|
||||
<a href="/signup" className="ml-2 text-dark-gray dark:text-white font-bold">
|
||||
Sign Up
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user