Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5796 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { axios } from '../../../../utils'
3
import { useDispatch } from 'react-redux'
4
import { addNotification } from '../../../../redux/notification/notification.actions'
5
 
6
const GroupInfo = ({
7
  groupId,
8
  image,
9
  name,
10
  totalMembers,
11
  linkInmail,
12
  accessibility,
13
}) => {
14
  const [actionLinks, setActionLinks] = useState({})
15
  const dispatch = useDispatch()
16
 
17
  const load = () => {
18
    axios
19
      .get('')
20
      .then(({ data }) => {
21
        if (!data.success) {
22
          dispatch(addNotification({ style: 'error', msg: data.data }))
23
          return
24
        }
25
        setActionLinks(data.data)
26
      })
27
      .catch((err) => console.log('>>: err > ', err))
28
  }
29
 
30
  const handleActionLink = (url) => {
31
    axios
32
      .post(url)
33
      .then(({ data }) => {
34
        if (!data.success) {
35
          dispatch(addNotification({ style: 'error', msg: data.data }))
36
          return
37
        }
38
        dispatch(addNotification({ style: 'success', msg: data.data }))
39
        window.location.reload()
40
      })
41
      .catch((err) => console.log('>>: err > ', err))
42
  }
43
 
44
  useEffect(() => load(), [])
45
 
46
  return (
47
    <div className="group-info">
48
      <img
49
        src={`/storage/type/group/code/${groupId}/${
50
          image ? `filename/${image}` : ''
51
        }`}
52
        alt="profile-image"
53
      />
54
 
55
      <h2>{name}</h2>
56
      <span>
57
        <b>{totalMembers}</b>
58
        <br />
59
        Miembros
60
      </span>
61
      <div className="row ">
62
        {linkInmail && (
63
          <a href={linkInmail} className="btn btn-primary">
64
            Contactar con el Administrador
65
          </a>
66
        )}
67
        {actionLinks.link_accept && (
68
          <button
69
            onClick={() => handleActionLink(actionLinks.link_accept)}
70
            className="btn btn-primary"
71
          >
72
            Aceptar invitacion
73
          </button>
74
        )}
75
        {actionLinks.link_cancel && (
76
          <button
77
            onClick={() => handleActionLink(actionLinks.link_cancel)}
78
            className="btn btn-primary"
79
          >
80
            Cancelar invitacion
81
          </button>
82
        )}
83
        {actionLinks.link_leave && (
84
          <button
85
            onClick={() => handleActionLink(actionLinks.link_leave)}
86
            className="btn btn-primary"
87
          >
88
            Abandonar grupo
89
          </button>
90
        )}
91
        {actionLinks.link_request && (
92
          <button
93
            onClick={() => handleActionLink(actionLinks.link_request)}
94
            className="btn btn-primary"
95
          >
96
            {accessibility === 'Auto unirse' ? 'Unirse' : 'Solicitar membresia'}
97
          </button>
98
        )}
99
      </div>
100
    </div>
101
  )
102
}
103
 
104
export default GroupInfo