Projekt

Obecné

Profil

Stáhnout (1.03 KB) Statistiky
| Větev: | Tag: | Revize:
1 b523c74d Schwobik
import { Fragment, useEffect } from 'react'
2 627f4d82 Schwobik
import {useDispatch, useSelector} from 'react-redux'
3 b523c74d Schwobik
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 627f4d82 Schwobik
import {resetIsRegistered} from "./userSlice"
9 2da5627e Vaclav Honzik
10 b523c74d Schwobik
11
const Register = () => {
12
    const isAdmin = useSelector(
13
        (state: RootState) => state.user.roles.includes("ROLE_ADMIN")
14
    )
15 627f4d82 Schwobik
    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 b523c74d Schwobik
30
    return (
31
        <Fragment>
32
            {isAdmin ? (<RegisterDialog />) : <NotAuthorized />}
33
        </Fragment>
34
    )
35
}
36
37
export default Register