Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 5 | Rev 41 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 5 Rev 40
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React, { useEffect, useState } from "react";
2
import { axios } from '../../../utils'
2
import { axios } from "../../../utils";
3
import { useDispatch } from 'react-redux'
3
import { useDispatch } from "react-redux";
-
 
4
import { addNotification } from "../../../redux/notification/notification.actions";
-
 
5
import { styled } from "styled-components";
-
 
6
import WidgetLayout from "../WidgetLayout";
4
 
7
 
5
import { addNotification } from '../../../redux/notification/notification.actions'
8
const StyledDailyPulseContainer = styled(WidgetLayout)`
-
 
9
  padding: 1rem;
-
 
10
  h3 {
-
 
11
    color: $title-color;
-
 
12
    font-weight: 700;
-
 
13
    font-size: 1.1rem;
-
 
14
  }
-
 
15
  span {
-
 
16
    color: $subtitle-color;
-
 
17
    font-weight: 600;
-
 
18
  }
-
 
19
`;
Línea 6... Línea 20...
6
 
20
 
7
const DailyPulse = ({ dailyPulseUrl = '' }) => {
21
const DailyPulse = ({ dailyPulseUrl = "" }) => {
8
  const [emojisHowAreYouFeel, setEmojisHowAreYouFeel] = useState([])
22
  const [emojisHowAreYouFeel, setEmojisHowAreYouFeel] = useState([]);
9
  const [emojisClimateOnYourOrganization, setEmojisClimateOnYourOrganization] =
23
  const [emojisClimateOnYourOrganization, setEmojisClimateOnYourOrganization] =
Línea 10... Línea 24...
10
    useState([])
24
    useState([]);
11
 
25
 
12
  const getData = (url) => {
26
  const getData = (url) => {
13
    axios
27
    axios
14
      .get(url)
28
      .get(url)
Línea 15... Línea 29...
15
      .then((response) => {
29
      .then((response) => {
16
        const { success, data } = response.data
30
        const { success, data } = response.data;
17
 
31
 
18
        if (success) {
32
        if (success) {
19
          setEmojisHowAreYouFeel(data.emojis_how_are_you_feel)
33
          setEmojisHowAreYouFeel(data.emojis_how_are_you_feel);
20
          setEmojisClimateOnYourOrganization(
34
          setEmojisClimateOnYourOrganization(
21
            data.emojis_climate_on_your_organization
35
            data.emojis_climate_on_your_organization
22
          )
36
          );
23
        }
37
        }
24
      })
38
      })
25
      .catch((error) => {
39
      .catch((error) => {
26
        console.trace(error)
40
        console.trace(error);
Línea 27... Línea 41...
27
        throw new Error(error)
41
        throw new Error(error);
28
      })
42
      });
29
  }
43
  };
Línea 30... Línea 44...
30
 
44
 
31
  useEffect(() => {
45
  useEffect(() => {
32
    getData(dailyPulseUrl)
46
    getData(dailyPulseUrl);
33
  }, [dailyPulseUrl])
47
  }, [dailyPulseUrl]);
34
 
48
 
35
  return (
49
  return (
36
    <div className="daily_pulse-widget">
50
    <StyledDailyPulseContainer>
Línea 43... Línea 57...
43
      <DailyPulse.List
57
      <DailyPulse.List
44
        options={emojisClimateOnYourOrganization}
58
        options={emojisClimateOnYourOrganization}
45
        title="¿Como esta el clima en la organización?"
59
        title="¿Como esta el clima en la organización?"
46
        onComplete={getData}
60
        onComplete={getData}
47
      />
61
      />
48
    </div>
62
    </StyledDailyPulseContainer>
49
  )
63
  );
50
}
64
};
Línea 51... Línea 65...
51
 
65
 
52
const PulseList = ({ options = [], title = '', onComplete = () => null }) => {
66
const PulseList = ({ options = [], title = "", onComplete = () => null }) => {
Línea 53... Línea 67...
53
  const dispatch = useDispatch()
67
  const dispatch = useDispatch();
54
 
68
 
55
  const handleEmojiSave = (url) => {
69
  const handleEmojiSave = (url) => {
56
    if (!url) {
70
    if (!url) {
Línea 57... Línea 71...
57
      return false
71
      return false;
58
    }
72
    }
59
 
73
 
60
    axios.post(url).then(({ data }) => {
74
    axios.post(url).then(({ data }) => {
61
      if (!data.success) {
75
      if (!data.success) {
62
        return dispatch(
76
        return dispatch(
63
          addNotification({
77
          addNotification({
64
            style: 'danger',
78
            style: "danger",
65
            msg:
79
            msg:
66
              typeof data.data === 'string'
80
              typeof data.data === "string"
67
                ? data.data
81
                ? data.data
68
                : 'Ha ocurrido un error',
82
                : "Ha ocurrido un error",
Línea 69... Línea 83...
69
          })
83
          })
70
        )
84
        );
71
      }
85
      }
Línea 72... Línea 86...
72
 
86
 
73
      return onComplete()
87
      return onComplete();
74
    })
88
    });
75
  }
89
  };
76
 
90
 
77
  return (
91
  return (
78
    <div className="daily_pulse-quest">
92
    <div className="daily_pulse-quest">
79
      <h4>{title}</h4>
93
      <h4>{title}</h4>
80
      <ul>
94
      <ul>
81
        {options.map(({ link_save, id, image }, index) => (
95
        {options.map(({ link_save, id, image }, index) => (
82
          <li key={id}>
96
          <li key={id}>
83
            <a
97
            <a
84
              href={link_save}
98
              href={link_save}
85
              onClick={(e) => {
99
              onClick={(e) => {
86
                e.preventDefault()
100
                e.preventDefault();
87
                handleEmojiSave(link_save)
101
                handleEmojiSave(link_save);
Línea 95... Línea 109...
95
            </a>
109
            </a>
96
          </li>
110
          </li>
97
        ))}
111
        ))}
98
      </ul>
112
      </ul>
99
    </div>
113
    </div>
100
  )
114
  );
101
}
115
};
Línea 102... Línea 116...
102
 
116
 
Línea 103... Línea 117...
103
DailyPulse.List = PulseList
117
DailyPulse.List = PulseList;