Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1456 | Rev 2076 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1456 Rev 1929
Línea 11... Línea 11...
11
 
11
 
12
import { axios, debounce } from 'utils/index'
12
import { axios, debounce } from 'utils/index'
Línea 13... Línea 13...
13
import { addNotification } from '../../redux/notification/notification.actions'
13
import { addNotification } from '../../redux/notification/notification.actions'
14
 
-
 
15
import Modal from 'components/UI/modal/Modal'
14
 
Línea 16... Línea 15...
16
import Spinner from 'components/UI/Spinner'
15
import Modal from 'components/UI/modal/Modal'
17
import TextInput from 'components/UI/inputs/TextInput'
16
import TextInput from 'components/UI/inputs/TextInput'
18
 
-
 
19
const ContactsModal = ({ show, onClose, onComplete }) => {
17
 
Línea 20... Línea 18...
20
  const [contacts, setContacts] = useState([])
18
const ContactsModal = ({ show, onClose, onComplete }) => {
21
  const [loading, setLoading] = useState(false)
19
  const [contacts, setContacts] = useState([])
22
  const dispatch = useDispatch()
20
  const dispatch = useDispatch()
23
 
21
 
Línea 24... Línea 22...
24
  const closeModal = () => {
22
  const closeModal = () => {
Línea 25... Línea 23...
25
    setContacts([])
23
    setContacts([])
26
    onClose()
-
 
-
 
24
    onClose()
27
  }
25
  }
28
 
26
 
29
  const handleSearch = debounce((value) => getContacts(value), 500)
27
  const handleSearch = debounce((value) => getContacts(value), 500)
30
 
28
 
31
  const getContacts = (searchValue = '') => {
29
  const getContacts = (searchValue = '') => {
32
    setLoading(true)
30
 
33
    axios
31
    axios
34
      .get(`/chat/users?search=${searchValue.toLowerCase()}`)
32
      .get(`/chat/users?search=${searchValue.toLowerCase()}`)
35
      .then(({ data: response }) => {
33
      .then(({ data: response }) => {
36
        if (!response.success) {
34
        if (!response.success) {
37
          return dispatch(
-
 
38
            addNotification({ style: 'danger', msg: 'Ha ocurrido un error' })
35
          return dispatch(
Línea 39... Línea 36...
39
          )
36
            addNotification({ style: 'danger', msg: 'Ha ocurrido un error' })
40
        }
-
 
-
 
37
          )
41
        setContacts(response.data)
38
        }
42
      })
39
        setContacts(response.data)
43
      .finally(() => setLoading(false))
40
      })
44
  }
41
  }
45
 
42
 
46
  const startConversation = ({ link_open_or_create, link_send }) => {
43
  const startConversation = ({ link_open_or_create, link_send }) => {
47
    setLoading(true)
44
    
48
    axios
45
    axios
49
      .post(link_open_or_create)
-
 
50
      .then(({ data: response }) => {
46
      .post(link_open_or_create)
Línea 51... Línea 47...
51
        if (response.success) {
47
      .then(({ data: response }) => {
52
          closeModal()
48
        if (response.success) {
53
          onComplete(link_send)
49
          closeModal()
Línea 69... Línea 65...
69
        type='text'
65
        type='text'
70
        placeholder='Escribe el nombre de la persona'
66
        placeholder='Escribe el nombre de la persona'
71
        onChange={(e) => handleSearch(e.target.value)}
67
        onChange={(e) => handleSearch(e.target.value)}
72
      />
68
      />
Línea 73... Línea -...
73
 
-
 
74
      {loading ? (
-
 
75
        <Spinner />
-
 
76
      ) : (
69
 
77
        <List sx={{ width: '100%' }}>
70
      <List sx={{ width: '100%' }}>
78
          {contacts.map((user) => {
71
          {contacts.map((user) => {
Línea 79... Línea 72...
79
            const { image, name } = user
72
            const { image, name } = user
80
 
73
 
Línea 92... Línea 85...
92
                </ListItemButton>
85
                </ListItemButton>
93
              </ListItem>
86
              </ListItem>
94
            )
87
            )
95
          })}
88
          })}
96
        </List>
89
        </List>
97
      )}
-
 
98
    </Modal>
90
    </Modal>
99
  )
91
  )
100
}
92
}
Línea 101... Línea 93...
101
 
93