|
1 | | -import { useContext } from 'react' |
2 | | -import { Link } from 'react-router-dom' |
| 1 | +import { useContext, useState } from 'react' |
| 2 | +import { Link, useNavigate } from 'react-router-dom' |
3 | 3 | import loginimg from '../assets/forgot.png' |
4 | 4 | import '../css/login.css' |
5 | 5 | import { AppContext } from '../App' |
| 6 | +import toast, { Toaster } from 'react-hot-toast'; |
| 7 | +import axios from 'axios' |
| 8 | +import { url } from '../baseurl' |
| 9 | + |
6 | 10 |
|
7 | 11 | export const Reset = () => { |
8 | 12 | const context = useContext(AppContext) |
| 13 | + const navigate = useNavigate() |
| 14 | + const [otp, setOpt] = useState('') |
| 15 | + const [email, setEmail] = useState('') |
| 16 | + const [pass, setPass] = useState('') |
| 17 | + |
9 | 18 |
|
| 19 | + async function sendOtp() { |
| 20 | + if (!email) |
| 21 | + toast.error("Email required", { |
| 22 | + style: { |
| 23 | + fontSize: '12px' |
| 24 | + } |
| 25 | + }) |
| 26 | + const resp = await axios.put(`${url}/user/password/otp`, { |
| 27 | + email |
| 28 | + }) |
| 29 | + if (resp.data.status) { |
| 30 | + toast.success("OTP sent", { |
| 31 | + style: { |
| 32 | + fontSize: '12px' |
| 33 | + } |
| 34 | + }) |
| 35 | + } |
| 36 | + } |
| 37 | + async function changePass() { |
| 38 | + if (!email) |
| 39 | + toast.error("Email required", { |
| 40 | + style: { |
| 41 | + fontSize: '12px' |
| 42 | + } |
| 43 | + }) |
| 44 | + if (!pass) |
| 45 | + toast.error("Password required", { |
| 46 | + style: { |
| 47 | + fontSize: '12px' |
| 48 | + } |
| 49 | + }) |
| 50 | + if (!otp) |
| 51 | + toast.error("OTP required", { |
| 52 | + style: { |
| 53 | + fontSize: '12px' |
| 54 | + } |
| 55 | + }) |
| 56 | + await axios.put(`${url}/user/verifyotp`, { |
| 57 | + email, password: pass, otp |
| 58 | + }).then(() => navigate('/login')) |
| 59 | + } |
10 | 60 | return ( |
11 | 61 | <div className="containerlogin"> |
| 62 | + <Toaster /> |
12 | 63 | <div className="leftlogin"> |
13 | | - <img style={{ marginTop: '-40px', minWidth: '400px', zIndex: '-99',width:'85%' }} src={loginimg} alt="" /> |
| 64 | + <img style={{ marginTop: '-40px', minWidth: '400px', zIndex: '-99', width: '85%' }} src={loginimg} alt="" /> |
14 | 65 | </div> |
15 | 66 | <div className="rightlogin"> |
16 | 67 | <div className="headerlogin"> |
17 | 68 | <h1 className='hrespreset'> |
18 | 69 | Reset Password |
19 | 70 | </h1> |
20 | | - <p style={{ marginTop: '-10px', marginBottom: '5px' ,fontSize:'14px',marginLeft:'5px',minWidth:'320px'}}>Remember your password <Link to="/login" style={{ color: 'rgb(109 109 109)', textDecoration: 'none', marginBottom: '-2.5px', marginLeft: '3px' }}> Login here</Link></p> |
| 71 | + <p style={{ marginTop: '-10px', marginBottom: '5px', fontSize: '14px', marginLeft: '5px', minWidth: '320px' }}>Remember your password <Link to="/login" style={{ color: 'rgb(109 109 109)', textDecoration: 'none', marginBottom: '-2.5px', marginLeft: '3px' }}> Login here</Link></p> |
| 72 | + </div> |
| 73 | + <div className="same-line" style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', width: '325px', marginTop: '20px', }}> |
| 74 | + <input value={email} onChange={e => setEmail(e.target.value)} type="email" placeholder='Enter email' style={{ background: context.dark ? 'rgb(66 66 66)' : 'rgb(248 248 248)', height: '47px', outline: 'none', border: 'none', borderRadius: '5px', color: 'inherit', paddingLeft: '14px', width: '78%' }} /> |
| 75 | + <button onClick={() => sendOtp()} style={{ fontFamily: 'Poppins', color: context.dark ? 'black' : 'white', border: 'none', outline: 'none', background: context.dark ? 'white' : 'rgb(66 66 66)', cursor: 'pointer', fontWeight: 'bold', borderRadius: '5px', height: '45px', width: '21%', marginLeft: '8px' }}>OTP</button> |
21 | 76 | </div> |
22 | | - <input type="email" placeholder='Enter email' style={{ background: context.dark ? 'rgb(66 66 66)' : 'rgb(248 248 248)', height: '47px', outline: 'none', border: 'none', borderRadius: '5px', color: 'inherit', width: '325px', marginTop: '20px', paddingLeft: '14px' }} /> |
23 | | - <input type="password" placeholder='Enter new password' style={{ background: context.dark ? 'rgb(66 66 66)' : 'rgb(248 248 248)', height: '47px', outline: 'none', border: 'none', borderRadius: '5px', color: 'inherit', width: '325px', marginTop: '20px', paddingLeft: '14px' }} /> |
24 | | - <button style={{ fontFamily: 'Poppins', width: '320px', color: context.dark ? 'black' : 'white', border: 'none', outline: 'none', background: context.dark ? 'white' : 'rgb(66 66 66)', height: '44px', borderRadius: '5px', cursor: 'pointer', marginTop: '20px', fontWeight: 'bold' }} variant="outlined">Done</button> |
| 77 | + <input value={otp} onChange={e => setOpt(e.target.value)} type="text" placeholder='Enter OTP' style={{ background: context.dark ? 'rgb(66 66 66)' : 'rgb(248 248 248)', height: '47px', outline: 'none', border: 'none', borderRadius: '5px', color: 'inherit', width: '325px', marginTop: '20px', paddingLeft: '14px' }} /> |
| 78 | + <input value={pass} onChange={e => setPass(e.target.value)} type="password" placeholder='Enter new password' style={{ background: context.dark ? 'rgb(66 66 66)' : 'rgb(248 248 248)', height: '47px', outline: 'none', border: 'none', borderRadius: '5px', color: 'inherit', width: '325px', marginTop: '20px', paddingLeft: '14px' }} /> |
| 79 | + <button onClick={() => changePass()} style={{ fontFamily: 'Poppins', width: '320px', color: context.dark ? 'black' : 'white', border: 'none', outline: 'none', background: context.dark ? 'white' : 'rgb(66 66 66)', height: '44px', borderRadius: '5px', cursor: 'pointer', marginTop: '20px', fontWeight: 'bold' }} variant="outlined">Done</button> |
25 | 80 | </div> |
26 | 81 | </div> |
27 | 82 | ) |
|
0 commit comments