import React, {useState} from "react"; import titleShape from "../../../../assets/images/shape/title_shape_3.svg"; import AuthLayout from "../../AuthLayout"; import Otp from "./Otp"; import { useNavigate } from 'react-router-dom'; import usersService from "../../../../services/UsersService"; export default function VerifyYou() { const navigate = useNavigate(); const verifyOTP = new usersService(); const [loading, setLoading] = useState(false) // For loading spinner const [errorMessage, setErrorMessage] = useState({ // For Displaying success or error message success: false, message: '' }) // state for user inputed values const [verificationCode, setVerificationCode] = useState({ value_one: '', value_two: '', value_three: '', value_four: '', value_five: '', value_six: '', }) const handleVerificationInput = ({target:{name, value}}) => { // function that listens to input change setVerificationCode(prev => { return {...prev, [name]:value} }) } const handleUserOTPVerify = async () => { // handles input validation and submits to api call setErrorMessage({ // resets the error message to empty string success: false, message: '' }) setLoading(true) // Sets loading spinner let otpCode = ''; for(let values in verificationCode){ otpCode+=verificationCode[values] } if(!otpCode){ // checks if code is empty setLoading(false) setErrorMessage({ success: false, message: 'Please input the code sent to you' }) return } if(otpCode.length < 6){ // checks if verifiedCode is empty setLoading(false) setErrorMessage({ success: false, message: 'Code must be 6 characters' }) return } let apiInput = { username: localStorage.getItem('username'), pend_uid: localStorage.getItem('uuid'), random_text: otpCode, mode: 'VERIFY', } try { const res = await verifyOTP.signupUser(apiInput) if(res.status != 200){ setLoading(false) setErrorMessage({ success: false, message: 'Could not verify code' }) return } if(res.status == 200){ if(res.data.status < 0) { // when resquest is successful but status is not 100 setLoading(false) setErrorMessage({ success: false, message: res.data.error_msg }) return } // if request is successful and status is 100 proceed setErrorMessage({ success: true, message: 'verification successfully' }) //clears the temporary uuid and email in tge local storage localStorage.removeItem('uuid') localStorage.removeItem('username') setTimeout(()=>{ setLoading(false) navigate('/complete-signup', { replace: true }) }, 1000) } } catch (error) { setLoading(false) setErrorMessage({ success: false, message: 'Opps! something went wrong, Try agian later' }) } } return ( <>

SignUp Verification

shape
{errorMessage.message != '' &&

{errorMessage.message}

}

Dont’t have an aceount ? Please resend

); }