Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b523c74d

Přidáno uživatelem Michal Schwob před asi 2 roky(ů)

Creation of administration page and user registration
re #9627

Zobrazit rozdíly:

frontend/src/features/Home/Home.tsx
1
import {Button, Paper} from '@mui/material'
1
import {Button, Container, Paper} from '@mui/material'
2 2
import {Fragment, useEffect, useState} from 'react'
3 3
import { useDispatch, useSelector } from 'react-redux'
4 4
import { logout } from '../Auth/userSlice'
......
28 28
        navigate(path)
29 29
    }
30 30

  
31
    const roles = useSelector(
32
        (state: RootState) => state.user.roles
31
    const isAdmin = useSelector(
32
        (state: RootState) => state.user.roles.includes("ROLE_ADMIN")
33 33
    )
34

  
35
    const isAdmin = roles.includes("ROLE_ADMIN")
36

  
37 34
    // Fetch the item from the api after mounting the component
38 35
    useEffect(() => {
39 36
        // Function to fetch the item from the api
40
        console.log("useEffect called")
41 37
        const fetchItem = async () => {
42 38
            try {
43 39
                const { data, status } = await axiosInstance.get(
......
55 51
            }
56 52
        }
57 53
        fetchItem()
58
    }, [roles])
54
    }, [])
59 55

  
60 56
    return (
61 57
        <Fragment>
62
            <Paper style={{ minHeight: '100vh' }} variant="outlined">
58
            <Paper style={{ minHeight: '80vh', display:'flex', justifyContent: 'space-between', flexDirection:'column'}} variant="outlined">
63 59
                {isContentLoading && !err ? <ContentLoading /> : null}
64 60
                {!isContentLoading && content ? (
65
                    <div>
61
                    <Container>
66 62
                        <h1>Home</h1>
67 63
                        {formatHtmlStringToReactDom(content["content"] as string)}
68
                    </div>
64
                    </Container>
69 65
                ) : null}
70
                {isAdmin ? (
71
                        <Button
72
                            startIcon={<EditIcon />}
73
                            variant="contained"
74
                            component={RouterLink}
75
                            to="/editHome"
76
                            color="primary"
77
                            sx={{ mb: 2 }}
78
                        >
79
                            Edit
80
                        </Button>
81 66

  
67
                {isAdmin ? (
68
                    <Container sx={{ mb: 3 }} >
69
                            <Button
70
                                startIcon={<EditIcon />}
71
                                variant="contained"
72
                                component={RouterLink}
73
                                to="/editHome"
74
                                color="primary"
75
                                sx={{ mb: 2 }}
76
                            >
77
                                Edit
78
                            </Button>
79
                    </Container>
82 80
                ) : null}
83 81
            </Paper>
84 82
        </Fragment>

Také k dispozici: Unified diff