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