Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3244 stevensc 1
/* eslint-disable react/prop-types */
1 www 2
import React from "react";
3
import { useEffect, useState } from "react";
4
import { addNotification } from "../../../redux/notification/notification.actions";
2254 stevensc 5
import { axios } from "../../../utils";
3878 stevensc 6
import AddMemberModal from "./AddMemberModal";
7
import MembersModal from "./MembersModal";
8
import MemberTemplate from "./MemberTemplate";
1 www 9
 
3880 stevensc 10
const GroupMembersHelper = ({ groupId, handleFirstLinkInvite }) => {
1 www 11
 
3878 stevensc 12
  const [members, setMembers] = useState([])
13
  const [addModalShow, setAddModalShow] = useState(false);
14
  const [showMembersModal, setShowMembersModal] = useState(false);
1 www 15
  const [linkInvite, setLinkInvite] = useState('')
3506 stevensc 16
 
1 www 17
  const load = () => {
3878 stevensc 18
    axios.get(`/helpers/group-members/${groupId}`)
19
      .then(({ data }) => {
20
        if (data.success) {
3879 stevensc 21
          setMembers(data.data.items);
22
          setLinkInvite(data.data.link_invite)
23
          handleFirstLinkInvite(data.data.link_invite)
3878 stevensc 24
        }
25
      });
1 www 26
  }
27
 
3506 stevensc 28
  useEffect(() => load(), []);
29
 
1 www 30
  const handleAction = (url) => {
31
    const params = new FormData()
32
    axios.post(url, params)
3878 stevensc 33
      .then(({ data }) => {
34
        if (!data.success) {
35
          return addNotification({ style: 'danger', msg: data.data })
36
        }
37
        addNotification({ style: 'success', msg: 'Accion realizada exitosamente' })
2254 stevensc 38
        load()
1 www 39
      })
3878 stevensc 40
      .catch(err => console.log('>>: err > ', err))
1 www 41
  }
3878 stevensc 42
 
43
  const closeAddModal = () => {
44
    setAddModalShow(false)
1 www 45
    load()
46
  }
3506 stevensc 47
 
1 www 48
  return (
3892 stevensc 49
    <>
3878 stevensc 50
      <AddMemberModal
51
        isShow={addModalShow}
52
        handleClose={closeAddModal}
53
        linkInvite={linkInvite}
54
      />
55
      <MembersModal
56
        isShow={showMembersModal}
57
        handleClose={() => setShowMembersModal(!showMembersModal)}
58
        members={members}
59
        handleAction={handleAction}
60
      />
3880 stevensc 61
      <div className='members-container'>
62
        {!!linkInvite &&
3878 stevensc 63
          <button
3880 stevensc 64
            onClick={() => setAddModalShow(!addModalShow)}
3881 stevensc 65
            className="btn btn-primary btn-sm w-100"
3878 stevensc 66
          >
3880 stevensc 67
            Añadir miembros
3878 stevensc 68
          </button>
3880 stevensc 69
        }
70
        <button
71
          onClick={() => setShowMembersModal(!showMembersModal)}
3881 stevensc 72
          className="btn btn-primary btn-sm w-100 d-md-none"
3880 stevensc 73
        >
74
          Ver miembros
75
        </button>
3884 stevensc 76
        <div className="d-none d-md-block w-100">
3882 stevensc 77
          <div className="sd-title">
78
            <h3>Miembros</h3>
79
          </div>
80
          {
81
            members.map((member) =>
82
              <MemberTemplate
83
                key={member.id}
84
                member={member}
85
                handleAction={handleAction}
86
              />
87
            )
88
          }
2254 stevensc 89
        </div>
1 www 90
      </div>
3892 stevensc 91
    </>
1 www 92
  );
93
};
94
 
95
export default GroupMembersHelper;