| 3462 |
stevensc |
1 |
import React, { useState } from 'react';
|
|
|
2 |
import { useSelector } from 'react-redux';
|
|
|
3 |
import { IconButton, Menu, MenuItem, styled, Typography } from '@mui/material';
|
|
|
4 |
import { MoreVert } from '@mui/icons-material';
|
|
|
5 |
|
|
|
6 |
import { parse } from '@app/utils';
|
|
|
7 |
|
|
|
8 |
import { Card, CardContent, CardMedia } from '@shared/components';
|
|
|
9 |
|
|
|
10 |
const OptionsButton = styled(IconButton)(({ theme }) => ({
|
|
|
11 |
position: 'absolute',
|
|
|
12 |
top: theme.spacing(1),
|
|
|
13 |
right: theme.spacing(1),
|
|
|
14 |
zIndex: 1
|
|
|
15 |
}));
|
|
|
16 |
|
|
|
17 |
export function KnowledgeCard({
|
|
|
18 |
knowledge: { link_delete, link_edit, category, description, image, title },
|
|
|
19 |
onEdit,
|
|
|
20 |
onDelete
|
|
|
21 |
}) {
|
|
|
22 |
const labels = useSelector(({ intl }) => intl.labels);
|
|
|
23 |
const [anchorEl, setAnchorEl] = useState();
|
|
|
24 |
const open = Boolean(anchorEl);
|
|
|
25 |
|
|
|
26 |
const handleClick = (event) => {
|
|
|
27 |
setAnchorEl(event.currentTarget);
|
|
|
28 |
};
|
|
|
29 |
|
|
|
30 |
const handleClose = () => {
|
|
|
31 |
setAnchorEl(null);
|
|
|
32 |
};
|
|
|
33 |
|
|
|
34 |
const handleMenuItemClick = (onClick) => {
|
|
|
35 |
handleClose();
|
|
|
36 |
onClick();
|
|
|
37 |
};
|
|
|
38 |
|
|
|
39 |
return (
|
|
|
40 |
<Card>
|
|
|
41 |
<OptionsButton onClick={handleClick}>
|
|
|
42 |
<MoreVert />
|
|
|
43 |
</OptionsButton>
|
|
|
44 |
<Menu
|
|
|
45 |
anchorEl={anchorEl}
|
|
|
46 |
open={open}
|
|
|
47 |
onClose={handleClose}
|
|
|
48 |
anchorOrigin={{
|
|
|
49 |
vertical: 'top',
|
|
|
50 |
horizontal: 'right'
|
|
|
51 |
}}
|
|
|
52 |
transformOrigin={{
|
|
|
53 |
vertical: 'top',
|
|
|
54 |
horizontal: 'right'
|
|
|
55 |
}}
|
|
|
56 |
>
|
|
|
57 |
<MenuItem onClick={() => handleMenuItemClick(() => onEdit(link_edit))}>
|
|
|
58 |
{labels.edit}
|
|
|
59 |
</MenuItem>
|
|
|
60 |
<MenuItem onClick={() => handleMenuItemClick(() => onDelete(link_delete))}>
|
|
|
61 |
{labels.delete}
|
|
|
62 |
</MenuItem>
|
|
|
63 |
</Menu>
|
|
|
64 |
|
|
|
65 |
<CardMedia height={200} src={image} alt={`${title} image`} />
|
|
|
66 |
|
|
|
67 |
<CardContent>
|
|
|
68 |
<Typography variant='h2'>{title}</Typography>
|
|
|
69 |
<Typography variant='overline'>{category}</Typography>
|
|
|
70 |
<Typography>{parse(description)}</Typography>
|
|
|
71 |
</CardContent>
|
|
|
72 |
</Card>
|
|
|
73 |
);
|
|
|
74 |
}
|