-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathEventPriority.js
More file actions
57 lines (50 loc) · 1.8 KB
/
EventPriority.js
File metadata and controls
57 lines (50 loc) · 1.8 KB
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
import React, { useCallback, useState, useEffect } from 'react'
import { useSelector } from 'react-redux'
import { Grid2 as Grid, Box, Typography, IconButton } from '@mui/material'
import AddCircle from '@mui/icons-material/AddCircle'
import RemoveCircleIcon from '@mui/icons-material/RemoveCircle'
import { useTranslation } from 'react-i18next'
import EventService from 'services/events'
import * as AuthSelectors from 'reducers/auth/selectors'
export default ({ data = [] }) => {
const { t } = useTranslation()
const idToken = useSelector(AuthSelectors.getIdToken)
const [events, setEvents] = useState(data)
//TODO add state for counter component
useEffect(() => {
EventService.getPublicEvents().then(e => {
if (e) setEvents(e)
})
}, [])
const handleClick = useCallback(
(event, i) => {
EventService.setFrontpagePriority(
idToken,
event.slug,
event.frontPagePriority + i,
)
},
[idToken],
)
return (
<Box mt={3}>
<Typography variant="h6" gutterBottom>
{t('event_priority_')}
</Typography>
<Grid container spacing={3} sx={{ p: 2 }}>
{events.map(event => (
<Grid key={event.slug}>
{event.slug}
<IconButton onClick={() => handleClick(event, 1)}>
<AddCircle />
</IconButton>
{event.frontPagePriority}
<IconButton onClick={() => handleClick(event, -1)}>
<RemoveCircleIcon />
</IconButton>
</Grid>
))}
</Grid>
</Box>
)
}