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