Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { axios } from '../../utils'
3
import styled from 'styled-components'
4
import Avatar from '@mui/material/Avatar'
5
import IconButton from '@mui/material/IconButton'
6
import GroupRemoveIcon from '@mui/icons-material/GroupRemove'
7
import ArrowBackIosIcon from '@mui/icons-material/ArrowBackIos'
8
 
9
import Spinner from '../UI/Spinner'
10
import WidgetLayout from '../widgets/WidgetLayout'
11
 
12
const ContactContainer = styled(WidgetLayout)`
13
  padding: 1rem;
14
  position: relative;
15
  flex-grow: 1;
16
  ul {
17
    display: flex;
18
    flex-direction: column;
19
    gap: 0.5rem;
20
    max-height: 300px;
21
    overflow: auto;
22
    margin-top: 1rem;
23
  }
24
`
25
 
26
const ContactTemplate = styled.div`
27
  display: flex;
28
  align-items: center;
29
  justify-content: space-between;
30
  gap: 0.5rem;
31
  .info {
32
    display: flex;
33
    align-items: center;
34
    gap: 0.5rem;
35
  }
36
  h3 {
37
    font-size: 1rem;
38
    color: var(--subtitle-color);
39
    font-weight: 600;
40
  }
41
`
42
 
43
const GroupMembers = ({ group, changeTab }) => {
44
  const { url_get_contact_group_list } = group
45
  const [members, setMembers] = useState([])
46
  const [loading, setLoading] = useState(true)
47
 
48
  const getMembers = async () => {
49
    setLoading(true)
50
    const response = await axios.get(url_get_contact_group_list)
51
    const { success, data } = response.data
52
    if (!success) {
53
      return
54
    }
55
    setMembers(data)
56
    setLoading(false)
57
  }
58
 
59
  const handleRemoveMember = async (remove_url) => {
60
    setLoading(true)
61
    const response = await axios.post(remove_url)
62
    const { success } = response.data
63
    if (!success) {
64
      return
65
    }
66
    await getMembers()
67
    setLoading(false)
68
  }
69
 
70
  useEffect(() => {
71
    getMembers()
72
  }, [])
73
 
74
  return (
75
    <ContactContainer>
76
      <IconButton onClick={() => changeTab('DEFAULT')}>
77
        <ArrowBackIosIcon />
78
      </IconButton>
79
      <ul>
80
        {members.map((member, i) => (
81
          <li key={i}>
82
            <GroupMembers.Item
83
              {...member}
84
              onClick={() => handleRemoveMember(member.url_remove_from_group)}
85
            />
86
          </li>
87
        ))}
88
      </ul>
1366 stevensc 89
      {loading && <Spinner />}
5 stevensc 90
    </ContactContainer>
91
  )
92
}
93
 
1366 stevensc 94
const Item = ({ member, onDelete }) => {
95
  const { image, name, url_remove_from_group } = member
96
 
5 stevensc 97
  return (
98
    <ContactTemplate>
1366 stevensc 99
      <div className='info'>
100
        <Avatar src={image} alt='user_image' />
5 stevensc 101
        <span>{name}</span>
102
      </div>
1366 stevensc 103
      {url_remove_from_group ? (
104
        <IconButton onClick={onDelete}>
105
          <GroupRemoveIcon />
106
        </IconButton>
107
      ) : null}
5 stevensc 108
    </ContactTemplate>
109
  )
110
}
111
 
112
GroupMembers.Item = Item
113
 
114
export default GroupMembers