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
 
3878 stevensc 10
const GroupMembersHelper = ({ show = false, 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 (
49
    <React.Fragment>
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
      />
61
      <div className={`members-container ${show ? 'd-block' : 'd-none d-md-inline-block'} w-100 overflow-hidden`}>
3546 stevensc 62
        <div className="sd-title">
3878 stevensc 63
          {!!linkInvite &&
64
            <button
65
              onClick={() => setAddModalShow(!addModalShow)}
66
              className="btn btn-primary btn-sm"
67
            >
68
              Añadir miembros
69
            </button>
2254 stevensc 70
          }
3878 stevensc 71
          <button
72
            onClick={() => setShowMembersModal(!showMembersModal)}
73
            className="btn btn-primary btn-sm d-block d-md-none"
74
          >
75
            Ver miembros
76
          </button>
2254 stevensc 77
          <h3 className="pt-2 pb-2">Miembros</h3>
78
        </div>
3878 stevensc 79
        {
80
          members.map((member) =>
81
            <MemberTemplate
82
              key={member.id}
83
              member={member}
84
              handleAction={handleAction}
85
            />
86
          )
87
        }
1 www 88
      </div>
89
    </React.Fragment>
90
  );
91
};
92
 
93
export default GroupMembersHelper;