Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5205 | Rev 5207 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5205 efrain 1
/* eslint-disable camelcase */
2
import React, { useEffect, useState } from 'react'
3
import { useDispatch } from 'react-redux'
4
import { addNotification } from '../../../redux/notification/notification.actions'
5
import { axios } from '../../../utils'
6
 
5206 stevensc 7
const DailyPulse = ({ routeDailyPulse }) => {
5205 efrain 8
  const [points, setPoints] = useState(0)
9
  const [emojisHowAreYouFeel, setEmojisHowAreYouFeel] = useState([])
10
  const [emojisClimateOnYourOrganization, setEmojisClimateOnYourOrganization] = useState([])
11
  const dispatch = useDispatch()
12
 
13
  const handleEmojiSave = (url) => {
5206 stevensc 14
    if (!url) {
15
      return false
16
    }
17
 
5205 efrain 18
    axios.post(url)
19
      .then(({ data }) => {
20
        if (!data.success) {
21
          return dispatch(addNotification({
22
            style: 'danger',
23
            msg: typeof data.data === 'string'
24
              ? data.data
25
              : 'Ha ocurrido un error'
26
          }))
27
        }
28
 
29
        return getData()
30
      })
31
  }
32
 
33
  const getData = async (url = routeDailyPulse) => {
34
    try {
35
      const { data: response } = await axios.get(url)
36
      if (response.success) {
5206 stevensc 37
        setPoints(response.data.points)
38
        setEmojisHowAreYouFeel(response.data.emojis_how_are_you_feel)
39
        setEmojisClimateOnYourOrganization(response.data.emojis_climate_on_your_organization)
40
      }
5205 efrain 41
    } catch (error) {
42
      console.log(error)
43
    }
44
  }
45
 
46
  useEffect(() => {
47
    getData()
48
  }, [])
49
 
50
  return (
51
    <div className='peopleYouMayKnow'>
52
      <div className="sd-title d-flex align-items-center justify-content-between">
53
        <h3>Pulso Diario</h3>
54
      </div>
5206 stevensc 55
      <span>Puntos acumulados: {points}</span>
56
      <h2>¿Como te sientes hoy?</h2>
57
      {emojisHowAreYouFeel.map(({ link_save, id, image }) =>
58
        <a key={id} href={link_save} onClick={() => handleEmojiSave(link_save)}>
59
          <img src={image} style={{ width: '32px', height: '32px' }} />
60
        </a>
61
      )}
62
      <h2>¿Como esta el clima en la organización ?</h2>
63
      {emojisClimateOnYourOrganization.map(({ link_save, id, image }) =>
64
        <a key={id} href={link_save} onClick={() => handleEmojiSave(link_save)}>
65
          <img src={image} style={{ width: '32px', height: '32px' }} />
66
        </a>
67
      )}
5205 efrain 68
    </div>
69
  )
70
}
71
 
72
export default DailyPulse