Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
2268 stevensc 1
import React, { useState } from 'react'
691 stevensc 2
import { useDispatch } from 'react-redux'
3330 stevensc 3
import { Typography } from '@mui/material'
5 stevensc 4
 
3330 stevensc 5
import { axios } from '@utils'
2780 stevensc 6
import { useFetch } from '@hooks'
3330 stevensc 7
import { addNotification } from '@store/notification/notification.actions'
5 stevensc 8
 
3330 stevensc 9
import Widget from '@components/UI/Widget'
10
import EmojiSelector from '@components/common/emoji-selector'
11
import LoadingWrapper from '@components/common/loading-wrapper'
2268 stevensc 12
 
3330 stevensc 13
const DailyPulse = ({ dailyPulseUrl = '' }) => {
14
  const [isSubmitting, setIsSubmitting] = useState(false)
15
  const dispatch = useDispatch()
41 stevensc 16
 
3332 stevensc 17
  const { data, isLoading, refetch } = useFetch(dailyPulseUrl, {
3331 stevensc 18
    emojis_how_are_you_feel: [],
19
    emojis_climate_on_your_organization: []
3330 stevensc 20
  })
5 stevensc 21
 
3332 stevensc 22
  /*  const updateEmojis = (id) => {
23
    const isClimate = data.emojis_climate_on_your_organization.some(
24
      (emoji) => emoji.id === id
25
    )
26
 
27
    if (isClimate) {
28
      data.emojis_climate_on_your_organization.filter(
29
        (emoji) => emoji.id === id
30
      )
31
    }
32
  } */
33
 
34
  const saveEmoji = async ({ link_save = '', id = '' }) => {
3330 stevensc 35
    try {
36
      setIsSubmitting(true)
3332 stevensc 37
      const response = await axios.post(link_save)
3330 stevensc 38
      const { data, success } = response.data
691 stevensc 39
 
3330 stevensc 40
      if (!success) {
41
        const errMsg = typeof data === 'string' ? data : 'Ha ocurrido un error'
42
        throw new Error(errMsg)
43
      }
44
 
3332 stevensc 45
      refetch()
3330 stevensc 46
    } catch (error) {
47
      dispatch(addNotification({ style: 'danger', msg: error.message }))
48
    } finally {
49
      setIsSubmitting(false)
50
    }
2281 stevensc 51
  }
52
 
2268 stevensc 53
  return (
2281 stevensc 54
    <Widget>
2276 stevensc 55
      <Widget.Header title='Pulso Diario' />
5 stevensc 56
 
3330 stevensc 57
      <Widget.Body>
58
        <LoadingWrapper
59
          loading={isLoading || isSubmitting}
60
          displayChildren={isSubmitting}
61
        >
3331 stevensc 62
          <Typography variant='h4' textAlign='center'>
63
            ¿Como te sientes hoy?
64
          </Typography>
3330 stevensc 65
          <EmojiSelector
66
            options={data.emojis_how_are_you_feel}
67
            onSelect={saveEmoji}
68
          />
69
 
3331 stevensc 70
          <Typography variant='h4' textAlign='center'>
3330 stevensc 71
            ¿Como esta el clima en la organización?
72
          </Typography>
73
          <EmojiSelector
74
            options={data.emojis_climate_on_your_organization}
75
            onSelect={saveEmoji}
76
          />
77
        </LoadingWrapper>
2268 stevensc 78
      </Widget.Body>
79
    </Widget>
691 stevensc 80
  )
81
}
5 stevensc 82
 
691 stevensc 83
export default DailyPulse