added other stages
This commit is contained in:
@@ -1,17 +1,87 @@
|
||||
import React, { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import titleShape from "../../../assets/images/shape/title-shape-two.svg";
|
||||
import InputCom from "../../Helpers/Inputs/InputCom";
|
||||
import AuthLayout from "../AuthLayout";
|
||||
import ThankYou from "../ThankYou";
|
||||
import usersService from "../../../services/UsersService";
|
||||
|
||||
export default function UpdatePassword() {
|
||||
const [updated, setValue] = useState(false);
|
||||
const [values, setValues] = useState({
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
})
|
||||
const [message, setMessage] = useState(false);
|
||||
const updatePassword = () => {
|
||||
setValue(!updated);
|
||||
setTimeout(() => {
|
||||
setMessage(!message);
|
||||
}, 100);
|
||||
const [validation, setValidation] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const updatePass = new usersService()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const onChange = (e) => {
|
||||
setValues((prev) => ({ ...prev, [e.target.name]: e.target.value }));
|
||||
};
|
||||
|
||||
const updatePassword = async (e) => {
|
||||
const {username} = JSON.parse(localStorage.getItem('reset_raw'))
|
||||
const otpCode = localStorage.getItem('otp')
|
||||
|
||||
setLoading(true)
|
||||
|
||||
if(!values.password || !values.confirmPassword){
|
||||
setLoading(false)
|
||||
setValidation("Please Fill empty inputs")
|
||||
return
|
||||
}
|
||||
|
||||
const regex = /^[A-Za-z]\w{7,14}$/
|
||||
if(regex.test(values.password) == false) {
|
||||
setLoading(false)
|
||||
setValidation("it must be a least 7 alphanumeric characters")
|
||||
return
|
||||
}
|
||||
|
||||
if (values.password != values.confirmPassword){
|
||||
setLoading(false)
|
||||
setValidation("Password does not match")
|
||||
return
|
||||
}
|
||||
|
||||
const newPassword = {
|
||||
username: username,
|
||||
reset_uuid: localStorage.getItem('reset_uuid'),
|
||||
random_text: otpCode,
|
||||
member_uid: localStorage.getItem('member_uid'),
|
||||
new_password: values.password,
|
||||
stage: 300
|
||||
}
|
||||
|
||||
delete values.confirmPassword
|
||||
|
||||
try {
|
||||
const confirm = await updatePass.resetPassword(newPassword)
|
||||
console.log(confirm)
|
||||
|
||||
if(confirm.status != 200){
|
||||
setLoading(false)
|
||||
setValidation("Sorry, could not verify code")
|
||||
return
|
||||
}
|
||||
|
||||
localStorage.removeItem('reset_uuid')
|
||||
localStorage.removeItem('reset_raw')
|
||||
localStorage.removeItem('otp')
|
||||
|
||||
if(confirm.status == 200){
|
||||
setValidation("Password updated")
|
||||
setTimeout(() => {
|
||||
setLoading(false)
|
||||
navigate("/confirm-reset", {replace : true});
|
||||
}, 2000);
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false)
|
||||
setValidation("An error occurred")
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -19,7 +89,6 @@ export default function UpdatePassword() {
|
||||
<AuthLayout
|
||||
slogan="Welcome to myFit"
|
||||
>
|
||||
{updated === false ? (
|
||||
<div className="content-wrapper update-password-section xl:bg-white dark:bg-dark-white w-full 2xl:h-[818px] xl:h-[600px] sm:w-auto sm:px-[70px] px-5 2xl:px-[100px] rounded-xl flex flex-col justify-center">
|
||||
<div>
|
||||
<div className="title-area relative flex flex-col justify-center items-center mb-7">
|
||||
@@ -32,7 +101,7 @@ export default function UpdatePassword() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="input-area">
|
||||
<div className="input-item mb-5">
|
||||
{/* <div className="input-item mb-5">
|
||||
<InputCom
|
||||
placeholder="*********"
|
||||
label="Old Password"
|
||||
@@ -40,7 +109,7 @@ export default function UpdatePassword() {
|
||||
type="password"
|
||||
iconName="password"
|
||||
/>
|
||||
</div>
|
||||
</div> */}
|
||||
<div className="input-item mb-5">
|
||||
<InputCom
|
||||
placeholder="*********"
|
||||
@@ -48,32 +117,35 @@ export default function UpdatePassword() {
|
||||
name="password"
|
||||
type="password"
|
||||
iconName="password"
|
||||
inputHandler={onChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="input-item mb-5">
|
||||
<InputCom
|
||||
placeholder="*********"
|
||||
label="Re-enter Password"
|
||||
name="password"
|
||||
name="confirmPassword"
|
||||
type="password"
|
||||
iconName="password"
|
||||
inputHandler={onChange}
|
||||
/>
|
||||
</div>
|
||||
{validation && <p className={`my-5 text-center font-light italic text-sm subpixel-antialiased tracking-wide ${validation == 'Password updated' ? 'text-green-600' : 'text-red-500'} `}>{validation}</p>}
|
||||
<div className="signin-area mb-3.5">
|
||||
<button
|
||||
onClick={updatePassword}
|
||||
type="button"
|
||||
className="w-full rounded-[50px] mb-5 h-[58px] text-xl text-white font-bold flex justify-center bg-purple items-center"
|
||||
>
|
||||
Continue
|
||||
{loading ? <div className="signup btn-loader"></div> : <span>Continue</span>}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<ThankYou className={`thankyou-section ${message ? "active" : ""}`} />
|
||||
)}
|
||||
</div>
|
||||
{/* // : (
|
||||
// <ThankYou className={`thankyou-section ${message ? "active" : ""}`} />
|
||||
// )} */}
|
||||
</AuthLayout>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user