-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.tsx
105 lines (99 loc) · 3.9 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { Box, Button, Container, Divider, Stack } from '@mui/material'
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import {
checkUserAccess,
filterInternalReleases,
getFullStudyProgrammeRights,
isDefaultServiceProvider,
} from '@/common'
import { useTitle } from '@/common/hooks'
import { PageTitle } from '@/components/material/PageTitle'
import { useGetAuthorizedUserQuery } from '@/redux/auth'
import { useGetChangelogQuery } from '@/redux/changelog'
import { Release } from '@/shared/types'
import { FeatureItem } from './FeatureItem'
import { MaterialInfoCard } from './MaterialInfoCard'
import { ReleaseItem } from './ReleaseItem'
import { SectionTitle } from './SectionTitle'
export const FrontPage = () => {
useTitle()
const { data: releaseData, isLoading } = useGetChangelogQuery()
const { roles, programmeRights } = useGetAuthorizedUserQuery()
const fullStudyProgrammeRights = getFullStudyProgrammeRights(programmeRights)
const [visibleReleases, setVisibleReleases] = useState<Release[]>([])
// TODO: Add missing features and extract access right checking
const featureItems = [
{
show: true,
title: 'University',
content: 'View tables and diagrams about study progress of different faculties',
},
{
show: checkUserAccess(['admin', 'fullSisuAccess'], roles) || programmeRights.length > 0,
title: 'Programmes',
content: (
<ul>
<li>Class statistics: View details of a specific year of a study programme</li>
<li>Overview: View statistics of a programme across all years</li>
</ul>
),
},
{
show: checkUserAccess(['courseStatistics', 'admin'], roles) || fullStudyProgrammeRights.length > 0,
title: 'Courses',
content: 'View statistics about course attempts, completions and grades',
},
{
show: checkUserAccess(['studyGuidanceGroups', 'admin'], roles) || fullStudyProgrammeRights.length > 0,
title: 'Students',
content: 'View detailed information for a given student',
},
{
show: isDefaultServiceProvider(),
title: 'Feedback',
content: (
<p>
For questions and suggestions, please use the{' '}
<a href="https://oodikone.helsinki.fi/feedback">feedback form</a> or shoot an email to{' '}
<a href="mailto:[email protected]">[email protected]</a>.
</p>
),
},
]
useEffect(() => {
if (!releaseData) {
return
}
setVisibleReleases([...releaseData.filter(filterInternalReleases).slice(0, 2)])
}, [releaseData])
return (
<Container maxWidth="lg">
<PageTitle subtitle="Exploratory Research on Study Data" title="Oodikone" />
<Stack direction={{ sm: 'column', md: 'row' }} divider={<Divider flexItem orientation="vertical" />} gap={3}>
<Stack direction="column" gap={2} sx={{ width: { sm: '100%', md: '50%' } }}>
<SectionTitle title="Features" />
<Stack direction="column" divider={<Divider flexItem orientation="horizontal" />} gap={2}>
{featureItems.map(
item => item.show && <FeatureItem content={item.content} key={item.title} title={item.title} />
)}
</Stack>
</Stack>
<Stack direction="column" gap={2} sx={{ width: { sm: '100%', md: '50%' } }}>
<SectionTitle title="Latest updates" />
<MaterialInfoCard />
<Stack direction="column" divider={<Divider flexItem orientation="horizontal" />} gap={2}>
{visibleReleases.map(release => (
<ReleaseItem isLoading={isLoading} key={release.title} release={release} />
))}
</Stack>
<Box sx={{ justifyContent: 'center', display: 'flex' }}>
<Button component={Link} to="/changelog" variant="contained">
View more
</Button>
</Box>
</Stack>
</Stack>
</Container>
)
}