Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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