[a26f6a1] | 1 | import React, {useEffect, useState} from 'react'
|
---|
| 2 | import {Header} from "../Header";
|
---|
| 3 | import {Modal, notification, Spin} from "antd";
|
---|
| 4 | import {useLocation} from "react-router";
|
---|
| 5 | import {useNavigate, useSearchParams} from "react-router-dom";
|
---|
| 6 | import axios from "axios";
|
---|
| 7 | import env from "../env";
|
---|
| 8 |
|
---|
| 9 | const Confirm = ({setUser, user}) => {
|
---|
| 10 |
|
---|
| 11 | const history = useNavigate()
|
---|
| 12 | const [result, setResult] = useState("")
|
---|
| 13 | const [searchParams, setSearchParams] = useSearchParams();
|
---|
| 14 |
|
---|
| 15 | useEffect(()=>{
|
---|
| 16 | const param = searchParams.get("id");
|
---|
| 17 | if(param==null){
|
---|
| 18 | setResult("Invalid key");
|
---|
| 19 | return;
|
---|
| 20 | }
|
---|
| 21 | axios.post(env.api+"Users/confirmed?validityString="+param,{},{headers:{Authorization:localStorage.getItem('Auth')}}).then(el => {
|
---|
| 22 | setResult("Успешно потврдена емаил адреса. Ќе бидете редиректирани за 3 секунди")
|
---|
| 23 | setUser(user => {return {...user,isConfirmed: true}})
|
---|
| 24 | setTimeout(()=>{
|
---|
| 25 | history('/login')
|
---|
| 26 | },3000)
|
---|
| 27 | }).catch(er=>{
|
---|
| 28 | if(er.response.data.includes("Invalid check")){
|
---|
| 29 | setResult("Невалиден линк")
|
---|
| 30 | }
|
---|
| 31 | if(er.response.data.includes("Link expired")){
|
---|
| 32 | setResult("Линкот е стар. Ве молиме обновете го.")
|
---|
| 33 | }
|
---|
| 34 | });
|
---|
| 35 |
|
---|
| 36 | },[])
|
---|
| 37 |
|
---|
| 38 | return (
|
---|
| 39 | <div>
|
---|
| 40 | <Header/>
|
---|
| 41 | <div style={{textAlign:'center',margin:'50px'}}>
|
---|
| 42 | {result == "" ? <Spin/> : <h2>{result}</h2>}
|
---|
| 43 | </div>
|
---|
| 44 | </div>
|
---|
| 45 | )
|
---|
| 46 | }
|
---|
| 47 | export default Confirm; |
---|