Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3432 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React, { useEffect, useState } from 'react'
import { Redirect, useParams } from 'react-router-dom'
import { useDispatch } from 'react-redux'

import { axios } from 'utils/index'
import { addNotification } from '../../redux/notification/notification.actions'

const ActiveAccount = () => {
  const [isValidated, setIsValidated] = useState(false)
  const dispatch = useDispatch()
  const { uuid } = useParams()

  useEffect(() => {
    const activeAccount = async () => {
      try {
        const { data: response } = await axios.get(`/activate-account/${uuid}`)
        const { data, success } = response

        if (!success) {
          throw new Error(data)
        }

        dispatch(addNotification({ style: 'success', msg: data }))
      } catch (error) {
        console.log(error)
        dispatch(addNotification({ style: 'danger', msg: error.message }))
      } finally {
        setIsValidated(true)
      }
    }

    activeAccount()
  }, [uuid])

  if (!isValidated) {
    return null
  }

  return <Redirect to='/signin' />
}

export default ActiveAccount