source: frontend/src/Auth/Reset.js@ a26f6a1

Last change on this file since a26f6a1 was a26f6a1, checked in by Danilo <danilo.najkov@…>, 23 months ago

full auth flow

  • Property mode set to 100644
File size: 3.1 KB
Line 
1import React, {useEffect, useState} from 'react';
2import {Header} from "../Header";
3import {Button, Form, Input, Modal, notification, Spin} from "antd";
4import axios from "axios";
5import '../App.css'
6import env from "../env";
7import {useNavigate, useSearchParams} from "react-router-dom";
8
9const Reset = () => {
10
11 const [loading, setLoading] = useState(false);
12 const [searchParams, setSearchParams] = useSearchParams();
13
14 const history = useNavigate()
15 const resetPassword = (data) => {
16 setLoading(true)
17 const param = searchParams.get("id");
18 if(param==null){
19 Modal.error({
20 title: 'Невалиден линк',
21 });
22 return;
23 }
24 axios.post(env.api+"Users/reseted",{}, {
25 params: {
26 validityString: param,
27 newPassword: data.password
28 }}).then(el => {
29 setLoading(false)
30 Modal.success({
31 title: 'Успешно потврдена сменета лозинка. Ќе бидете редиректирани за 3 секунди',
32 });
33 setTimeout(()=>{
34 history('/login')
35 },3000)
36 }).catch(er=>{
37 setLoading(false)
38 if(er.response.data.includes("Invalid check")){
39 Modal.error({
40 title: 'Невалиден линк',
41 });
42 }
43 if(er.response.data.includes("Link expired")){
44 Modal.error({
45 title: 'Линкот е стар. Ве молиме обновете го.',
46 });
47 }
48 });
49 }
50
51 return (
52 <div>
53 <div style={{width:'100vw',height:'100vh', textAlign:'center',backgroundColor:'#F2F2F2'}}>
54 <div className='center' style={{backgroundColor:'white',padding:'40px', borderRadius:'20px'}}>
55 <h1 style={{marginBottom:'40px'}}>Ресетирајте ја вашата лозинка</h1>
56 <Form onFinish={resetPassword}
57 onFinishFailed={() => Modal.error({title: "Ве молиме пополнете ги задолжителните полиња"})}>
58 <Form.Item
59 label="Нова лозинка"
60 name="password"
61 rules={[
62 {
63 required: true,
64 message: 'Ве молиме внесете ја новата лозинка!',
65 },
66 ]}
67 >
68 <Input type={'password'}/>
69 </Form.Item>
70 <Form.Item>
71 <Button type="primary" htmlType="submit" loading={loading}>
72 Прати
73 </Button>
74 </Form.Item>
75 </Form>
76 </div>
77 </div>
78 </div>
79 )
80}
81
82export default Reset;
Note: See TracBrowser for help on using the repository browser.