| 3719 |
stevensc |
1 |
import React, { useMemo, useState } from 'react';
|
|
|
2 |
import { Link } from 'react-router-dom';
|
|
|
3 |
import { useSelector } from 'react-redux';
|
|
|
4 |
import {
|
|
|
5 |
Accordion,
|
|
|
6 |
AccordionDetails,
|
|
|
7 |
AccordionSummary,
|
|
|
8 |
Avatar,
|
|
|
9 |
List,
|
|
|
10 |
ListItem,
|
|
|
11 |
ListItemAvatar,
|
|
|
12 |
ListItemButton,
|
|
|
13 |
ListItemText,
|
|
|
14 |
Typography
|
|
|
15 |
} from '@mui/material';
|
|
|
16 |
import ExpandMore from '@mui/icons-material/ExpandMore';
|
|
|
17 |
|
|
|
18 |
import { useFetch } from '@hooks';
|
|
|
19 |
|
|
|
20 |
import Widget from '@components/UI/Widget';
|
|
|
21 |
|
|
|
22 |
const GroupsWidget = () => {
|
|
|
23 |
const labels = useSelector(({ intl }) => intl.labels);
|
|
|
24 |
|
|
|
25 |
return (
|
|
|
26 |
<Widget>
|
|
|
27 |
<Widget.Body>
|
|
|
28 |
<GroupsWidget.Item url='/helpers/my-groups' title={labels.my_groups} />
|
|
|
29 |
<GroupsWidget.Item url='/helpers/groups-suggestion' title={labels.suggest_groups} />
|
|
|
30 |
</Widget.Body>
|
|
|
31 |
</Widget>
|
|
|
32 |
);
|
|
|
33 |
};
|
|
|
34 |
|
|
|
35 |
const Item = ({ url = '/helpers/my-groups', title = 'Mis grupos' }) => {
|
|
|
36 |
const labels = useSelector(({ intl }) => intl.labels);
|
|
|
37 |
const [lookMore, setLookMore] = useState(false);
|
|
|
38 |
|
|
|
39 |
const { data } = useFetch(url, []);
|
|
|
40 |
|
|
|
41 |
const items = useMemo(() => (lookMore ? data : data.slice(0, 3)), [lookMore, data]);
|
|
|
42 |
|
|
|
43 |
const toggleList = () => setLookMore(!lookMore);
|
|
|
44 |
|
|
|
45 |
return (
|
|
|
46 |
<Accordion>
|
|
|
47 |
<AccordionSummary expandIcon={<ExpandMore />}>
|
|
|
48 |
<Typography variant='overline'>{title}</Typography>
|
|
|
49 |
</AccordionSummary>
|
|
|
50 |
<AccordionDetails>
|
|
|
51 |
<List sx={{ maxHeight: 225, overflow: 'auto' }}>
|
|
|
52 |
{items.map(({ id, name, profile, image }) => (
|
|
|
53 |
<ListItem key={id}>
|
|
|
54 |
<ListItemButton to={profile} LinkComponent={Link}>
|
|
|
55 |
<ListItemAvatar>
|
|
|
56 |
<Avatar src={image} />
|
|
|
57 |
</ListItemAvatar>
|
|
|
58 |
|
|
|
59 |
<ListItemText primary={name} />
|
|
|
60 |
</ListItemButton>
|
|
|
61 |
</ListItem>
|
|
|
62 |
))}
|
|
|
63 |
|
|
|
64 |
{data.length > 3 && (
|
|
|
65 |
<ListItem>
|
|
|
66 |
<ListItemButton onClick={toggleList}>
|
|
|
67 |
<ListItemText
|
|
|
68 |
sx={{ textAlign: 'center' }}
|
|
|
69 |
primary={lookMore ? labels.view_less : labels.view_more}
|
|
|
70 |
/>
|
|
|
71 |
</ListItemButton>
|
|
|
72 |
</ListItem>
|
|
|
73 |
)}
|
|
|
74 |
</List>
|
|
|
75 |
</AccordionDetails>
|
|
|
76 |
</Accordion>
|
|
|
77 |
);
|
|
|
78 |
};
|
|
|
79 |
|
|
|
80 |
GroupsWidget.Item = Item;
|
|
|
81 |
|
|
|
82 |
export default GroupsWidget;
|