Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3432 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React, { useEffect, useState } from 'react';
2
import { Navigate, useParams } from 'react-router-dom';
3
import { useDispatch } from 'react-redux';
4
 
5
import { axios } from '@utils/index.js';
6
import { addNotification } from '../../redux/notification/notification.actions';
7
 
8
const ActiveAccount = () => {
9
  const [isValidated, setIsValidated] = useState(false);
10
  const dispatch = useDispatch();
11
  const { uuid } = useParams();
12
 
13
  useEffect(() => {
14
    const activeAccount = async () => {
15
      try {
16
        const response = await axios.get(`/activate-account/${uuid}`);
17
        const { data, success } = response.data;
18
 
19
        if (!success) {
20
          throw new Error(data);
21
        }
22
 
23
        dispatch(addNotification({ style: 'success', msg: data }));
24
      } catch (error) {
25
        console.log(error);
26
        dispatch(addNotification({ style: 'danger', msg: error.message }));
27
      } finally {
28
        setIsValidated(true);
29
      }
30
    };
31
 
32
    activeAccount();
33
  }, [uuid]);
34
 
35
  if (!isValidated) {
36
    return null;
37
  }
38
 
39
  return <Navigate to='/signin' />;
40
};
41
 
42
export default ActiveAccount;