forked from aec-coding-club/AEC-Coding-Club-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setpassword.jsx
126 lines (115 loc) · 3.65 KB
/
Setpassword.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React, { useState, useEffect } from "react";
import axios from "axios";
import { Api } from "../backend";
import { useLocation, useNavigate } from "react-router-dom";
import { toast } from "react-toastify";
import resetpassword from "../Assets/rstpassword.svg";
import { AiFillEye, AiFillEyeInvisible } from "react-icons/ai";
const Setpassword = () => {
const [Passworddata, setPassword] = useState({
password: "",
confirmPassword: "",
});
let loation = useLocation();
let navigate = useNavigate();
const handleSubmit = async (e) => {
e.preventDefault();
// console.log("Form Submitted Successfully");
// console.log("Path Name : ", loation.pathname.slice(1));
const data = {
password: Passworddata.password,
confirmPassword: Passworddata.confirmPassword,
};
const dataPosted = await axios.post(
`${Api}${loation.pathname.slice(1)}`,
data,
{
withCredentials: true,
crossorigin: true,
}
);
if (dataPosted.data.success) {
toast.success(dataPosted.data.message, { theme: "dark" });
navigate("/signin");
} else {
toast.error(dataPosted.data.message, {
theme: "dark",
});
setPassword({
password: "",
confirmPassword: "",
});
}
// console.log("Data: ", dataPosted);
};
function handelChange(e) {
const newdata = { ...Passworddata };
newdata[e.target.id] = e.target.value;
setPassword(newdata);
// console.log(newdata);
}
async function tokenCheker() {
const authToken = localStorage.getItem("token");
if (authToken) {
navigate("/");
}
}
const [viewPassword, setViewPassword] = useState(false);
const togglePassword = () => {
setViewPassword(!viewPassword);
};
const [viewPasswordOne, setViewPasswordOne] = useState(false);
const togglePasswordOne = () => {
setViewPasswordOne(!viewPasswordOne);
};
useEffect(() => {
tokenCheker();
}, []);
return (
<>
<div className='user-login '>
<div className='user-img'>
<img
alt=''
src='https://res.cloudinary.com/sahebcloud/image/upload/v1649396488/Reset_password_epyfbh.svg'
></img>
</div>
<form onSubmit={(e) => handleSubmit(e)}>
<h1>Reset Your Password</h1>
<div className='details inline-input-svg'>
<input
className='input__field signin__input__field head-input resetPass-input'
name='password'
id='password'
type={viewPassword ? "text" : "password"}
placeholder='Enter the New Password'
value={Passworddata.password}
onChange={(e) => handelChange(e)}
/>
<span onClick={togglePassword}>
{viewPassword ? <AiFillEyeInvisible /> : <AiFillEye />}
</span>
</div>
<div className='details inline-input-svg'>
<input
className='input__field signin__input__field head-input resetPass-input'
name='confirmPassword'
id='confirmPassword'
type={viewPasswordOne ? "text" : "password"}
placeholder='Confirm the New Password'
value={Passworddata.confirmPassword}
onChange={(e) => handelChange(e)}
/>
<span onClick={togglePasswordOne}>
{viewPasswordOne ? <AiFillEyeInvisible /> : <AiFillEye />}
</span>
</div>
<button type='submit' className='btn login-signup-btn Cpass-btn'>
Change Password
</button>
</form>
</div>
</>
);
};
export default Setpassword;