-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathHackerpackList.js
More file actions
78 lines (71 loc) · 2.7 KB
/
HackerpackList.js
File metadata and controls
78 lines (71 loc) · 2.7 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React, { useCallback, useState, useEffect } from 'react'
import { useSelector } from 'react-redux'
import { Grid2 as Grid, Box, Typography } from '@mui/material'
import CompanySection from 'components/hackerpack/CompanySection'
import { useTranslation } from 'react-i18next'
import { IconButton } from '@mui/material'
import DeleteIcon from '@mui/icons-material/Delete'
import EditIcon from '@mui/icons-material/Edit'
import HackerpackService from 'services/hackerpack'
import * as AuthSelectors from 'reducers/auth/selectors'
import { useNavigate } from 'react-router-dom'
export default ({ data = [] }) => {
const navigate = useNavigate()
const { t } = useTranslation()
const idToken = useSelector(AuthSelectors.getIdToken)
const [hackerpack, setHackerpack] = useState(data)
useEffect(() => {
HackerpackService.getFullHackerpack().then(pack => {
if (pack) setHackerpack(pack)
})
}, [])
const handleRemove = useCallback(
slug => {
console.log(hackerpack)
HackerpackService.deleteHackerpack(idToken, slug)
setHackerpack(
hackerpack.filter(function (obj) {
return obj.slug !== slug
}),
)
},
[hackerpack, idToken],
)
return (
<Box mt={3}>
<Typography variant="h6" gutterBottom>
{t('Your_hackerpack_')}
</Typography>
<Grid container spacing={3}>
{hackerpack.map(company => (
<>
<Box p={2}>
<IconButton
edge="end"
aria-label="delete"
onClick={() => handleRemove(company.slug)}
>
<DeleteIcon />
</IconButton>
<IconButton
edge="end"
aria-label="edit"
onClick={() =>
navigate(`admin/hackerpack/${company.slug}`)
}
>
<EditIcon />
</IconButton>
<CompanySection
name={company.name}
description={company.description}
icon={company.icon}
link={company.link}
/>
</Box>
</>
))}
</Grid>
</Box>
)
}