Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3432 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3432 Rev 3719
Línea 1... Línea 1...
1
import React, { useState } from 'react'
1
import React, { useState } from 'react';
2
import { useDispatch } from 'react-redux'
2
import { useDispatch } from 'react-redux';
3
import { Typography } from '@mui/material'
3
import { Typography } from '@mui/material';
4
 
4
 
5
import { axios } from '@utils'
5
import { axios } from '@utils';
6
import { useFetch } from '@hooks'
6
import { useFetch } from '@hooks';
7
import { addNotification } from '@store/notification/notification.actions'
7
import { addNotification } from '@store/notification/notification.actions';
8
 
8
 
9
import Widget from '@components/UI/Widget'
9
import Widget from '@components/UI/Widget';
10
 
10
 
11
import LoadingWrapper from '@components/common/loading-wrapper'
11
import LoadingWrapper from '@components/common/loading-wrapper';
12
import EmojiGroup from '@components/common/emoji-selector'
12
import EmojiGroup from '@components/common/emoji-selector';
13
 
13
 
14
const DailyPulse = ({ dailyPulseUrl = '' }) => {
14
const DailyPulse = ({ dailyPulseUrl = '' }) => {
15
  const [isSubmitting, setIsSubmitting] = useState(false)
15
  const [isSubmitting, setIsSubmitting] = useState(false);
16
  const dispatch = useDispatch()
16
  const dispatch = useDispatch();
17
 
17
 
18
  const { data, isLoading, refetch } = useFetch(dailyPulseUrl, {
18
  const { data, isLoading, refetch } = useFetch(dailyPulseUrl, {
19
    emojis_how_are_you_feel: [],
19
    emojis_how_are_you_feel: [],
20
    emojis_climate_on_your_organization: []
20
    emojis_climate_on_your_organization: []
21
  })
21
  });
22
 
22
 
23
  const saveEmoji = async (link_save = '') => {
23
  const saveEmoji = async (link_save = '') => {
24
    try {
24
    try {
25
      setIsSubmitting(true)
25
      setIsSubmitting(true);
26
      const response = await axios.post(link_save)
26
      const response = await axios.post(link_save);
27
      const { data, success } = response.data
27
      const { data, success } = response.data;
28
 
28
 
29
      if (!success) {
29
      if (!success) {
30
        const errMsg = typeof data === 'string' ? data : 'Error al guardar'
30
        const errMsg = typeof data === 'string' ? data : 'Error al guardar';
31
        throw new Error(errMsg)
31
        throw new Error(errMsg);
32
      }
32
      }
33
 
33
 
34
      refetch()
34
      refetch();
35
    } catch (error) {
35
    } catch (error) {
36
      dispatch(addNotification({ style: 'danger', msg: error.message }))
36
      dispatch(addNotification({ style: 'danger', msg: error.message }));
37
    } finally {
37
    } finally {
38
      setIsSubmitting(false)
38
      setIsSubmitting(false);
39
    }
39
    }
40
  }
40
  };
41
 
41
 
42
  if (
42
  if (
43
    data.emojis_how_are_you_feel.length <= 1 &&
43
    data.emojis_how_are_you_feel.length <= 1 &&
44
    data.emojis_climate_on_your_organization.length <= 1
44
    data.emojis_climate_on_your_organization.length <= 1
45
  ) {
45
  ) {
46
    return null
46
    return null;
47
  }
47
  }
48
 
48
 
49
  return (
49
  return (
50
    <Widget>
50
    <Widget>
51
      <Widget.Header title='Pulso Diario' />
51
      <Widget.Header title='Pulso Diario' />
52
 
52
 
53
      <Widget.Body>
53
      <Widget.Body>
54
        <LoadingWrapper
-
 
55
          loading={isLoading || isSubmitting}
54
        <LoadingWrapper loading={isLoading || isSubmitting} displayChildren={isSubmitting}>
56
          displayChildren={isSubmitting}
-
 
57
        >
-
 
58
          <Typography variant='h4' textAlign='center'>
55
          <Typography variant='h4' textAlign='center'>
59
            ¿Como te sientes hoy?
56
            ¿Como te sientes hoy?
60
          </Typography>
57
          </Typography>
61
 
58
 
62
          <EmojiGroup>
59
          <EmojiGroup>
63
            {data.emojis_how_are_you_feel?.map(
-
 
64
              ({ id, image, link_save }, index) => (
60
            {data.emojis_how_are_you_feel?.map(({ id, image, link_save }, index) => (
65
                <EmojiGroup.Item
61
              <EmojiGroup.Item
66
                  key={id}
62
                key={id}
67
                  image={image}
63
                image={image}
68
                  index={index}
64
                index={index}
69
                  onClick={() => saveEmoji(link_save)}
65
                onClick={() => saveEmoji(link_save)}
70
                />
66
              />
71
              )
-
 
72
            )}
67
            ))}
73
          </EmojiGroup>
68
          </EmojiGroup>
74
 
69
 
75
          <Typography variant='h4' textAlign='center'>
70
          <Typography variant='h4' textAlign='center'>
76
            ¿Como esta el clima en la organización?
71
            ¿Como esta el clima en la organización?
77
          </Typography>
72
          </Typography>
78
 
73
 
79
          <EmojiGroup>
74
          <EmojiGroup>
80
            {data.emojis_climate_on_your_organization?.map(
75
            {data.emojis_climate_on_your_organization?.map(({ id, image, link_save }, index) => (
81
              ({ id, image, link_save }, index) => (
-
 
82
                <EmojiGroup.Item
76
              <EmojiGroup.Item
83
                  key={id}
77
                key={id}
84
                  image={image}
78
                image={image}
85
                  index={index}
79
                index={index}
86
                  onClick={() => saveEmoji(link_save)}
80
                onClick={() => saveEmoji(link_save)}
87
                />
81
              />
88
              )
-
 
89
            )}
82
            ))}
90
          </EmojiGroup>
83
          </EmojiGroup>
91
        </LoadingWrapper>
84
        </LoadingWrapper>
92
      </Widget.Body>
85
      </Widget.Body>
93
    </Widget>
86
    </Widget>
94
  )
87
  );
95
}
88
};
96
 
89
 
97
export default DailyPulse
90
export default DailyPulse;