Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3416 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
2899 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
    () =>
28
      REACTIONS.filter(({ type }) =>
29
        reactions.some(({ reaction }) => type === reaction)
30
      ),
31
    [reactions]
32
  )
33
 
34
  const filteredUsers = useMemo(
35
    () => (reaction ? users.filter((u) => u.reaction === reaction) : users),
36
    [reaction, users]
37
  )
38
 
39
  return (
40
    <Modal
41
      show={show}
42
      title='Personas que reaccionaron'
43
      onClose={onClose}
44
      showFooter={false}
45
    >
46
      <Tabs
47
        value={reaction}
48
        onChange={(e, newValue) => setReaction(newValue)}
49
        sx={{
50
          width: '100%',
51
          minHeight: 'auto',
52
          '& .MuiTabs-indicator': {
53
            backgroundColor: 'var(--font-color)'
54
          }
55
        }}
56
      >
57
        <ReactionTab value='' label='Todas' disableRipple />
58
 
59
        {availableReactions.map(({ name, icon: Icon, type, color }) => (
60
          <ReactionTab
61
            key={type}
62
            value={type}
63
            label={name}
64
            icon={<Icon style={{ color }} />}
65
            disableRipple
66
          />
67
        ))}
68
      </Tabs>
69
 
70
      {isLoading ? <Spinner /> : <UsersList users={filteredUsers} />}
71
    </Modal>
72
  )
73
}