Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3432 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React, { useMemo, useState } from 'react';
2
import { Tab, Tabs, styled } from '@mui/material';
3
 
4
import { useFetch } from '@hooks';
5
import { REACTIONS } from '@constants/feed';
6
 
7
import Modal from '@components/UI/modal/Modal';
8
import Spinner from '@components/UI/Spinner';
9
import UsersList from '@components/UI/UsersList';
10
 
11
const ReactionTab = styled(Tab)(() => ({
12
  minWidth: 'auto',
13
  minHeight: 'auto',
14
  padding: '0.5rem 1rem'
15
}));
16
 
17
export default function ReactionsModal({
18
  reactionsUsersUrl = '',
19
  reactions = [],
20
  show = false,
21
  onClose
22
}) {
23
  const { data: users, isLoading } = useFetch(show ? reactionsUsersUrl : '', []);
24
  const [reaction, setReaction] = useState('');
25
 
26
  const availableReactions = useMemo(
27
    () => REACTIONS.filter(({ type }) => reactions.some(({ reaction }) => type === reaction)),
28
    [reactions]
29
  );
30
 
31
  const filteredUsers = useMemo(
32
    () => (reaction ? users.filter((u) => u.reaction === reaction) : users),
33
    [reaction, users]
34
  );
35
 
36
  return (
37
    <Modal show={show} title='Personas que reaccionaron' onClose={onClose} showFooter={false}>
38
      <Tabs
39
        value={reaction}
40
        onChange={(e, newValue) => setReaction(newValue)}
41
        sx={{
42
          width: '100%',
43
          minHeight: 'auto',
44
          '& .MuiTabs-indicator': {
45
            backgroundColor: 'var(--font-color)'
46
          }
47
        }}
48
      >
49
        <ReactionTab value='' label='Todas' disableRipple />
50
 
51
        {availableReactions.map(({ name, icon: Icon, type, color }) => (
52
          <ReactionTab
53
            key={type}
54
            value={type}
55
            label={name}
56
            icon={<Icon style={{ color }} />}
57
            disableRipple
58
          />
59
        ))}
60
      </Tabs>
61
 
62
      {isLoading ? <Spinner /> : <UsersList users={filteredUsers} />}
63
    </Modal>
64
  );
65
}