Projekt

Obecné

Profil

Stáhnout (1.03 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { Fragment, useEffect } from 'react'
2
import {useDispatch, useSelector} from 'react-redux'
3
import { useNavigate } from 'react-router-dom'
4
import { RootState } from '../redux/store'
5
import LoginDialog from './LoginDialog'
6
import NotAuthorized from "../NotAuthorized/NotAuthorized"
7
import RegisterDialog from "./RegisterDialog"
8
import {resetIsRegistered} from "./userSlice"
9

    
10

    
11
const Register = () => {
12
    const isAdmin = useSelector(
13
        (state: RootState) => state.user.roles.includes("ROLE_ADMIN")
14
    )
15
    const isRegistered = useSelector(
16
        (state: RootState) => state.user.isRegistered
17
    )
18

    
19
    const dispatch = useDispatch()
20

    
21
    // Redirect to home if the user is logged in
22
    const navigate = useNavigate()
23
    useEffect(() => {
24
        if (isRegistered) {
25
            dispatch(resetIsRegistered())
26
            navigate('/administration')
27
        }
28
    }, [isRegistered, navigate])
29

    
30
    return (
31
        <Fragment>
32
            {isAdmin ? (<RegisterDialog />) : <NotAuthorized />}
33
        </Fragment>
34
    )
35
}
36

    
37
export default Register
(4-4/7)