Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 2781 Rev 3432
Línea 1... Línea 1...
1
import React, { useState } from 'react'
1
import React, { useState } from "react";
2
import { connect } from 'react-redux'
2
import { connect } from "react-redux";
Línea 3... Línea 3...
3
 
3
 
4
import { axios } from 'utils'
4
import { axios } from "utils";
Línea 5... Línea 5...
5
import { addNotification } from '@app/redux/notification/notification.actions'
5
import { addNotification } from "@app/redux/notification/notification.actions";
6
 
6
 
7
import Widget from '@components/UI/Widget'
7
import Widget from "@components/UI/Widget";
Línea 8... Línea 8...
8
import Spinner from '@components/UI/Spinner'
8
import Spinner from "@components/UI/Spinner";
9
import SwitchInput from '@components/UI/SwitchInput'
9
import SwitchInput from "@components/UI/SwitchInput";
10
 
10
 
11
const SocialNetworks = ({
11
const SocialNetworks = ({
12
  facebook,
12
  facebook,
13
  google,
13
  google,
14
  twitter,
14
  twitter,
Línea 15... Línea 15...
15
  addNotification // Redux action
15
  addNotification, // Redux action
16
}) => {
16
}) => {
Línea 17... Línea 17...
17
  const [loading, setLoading] = useState(false)
17
  const [loading, setLoading] = useState(false);
18
 
18
 
19
  const addSocialNetwork = (network) => {
19
  const addSocialNetwork = (network) => {
20
    setLoading(true)
20
    setLoading(true);
21
 
21
 
22
    axios
22
    axios
23
      .get(`/account-settings/add-${network.toLowerCase()}`)
23
      .get(`/account-settings/add-${network.toLowerCase()}`)
24
      .then((response) => {
24
      .then((response) => {
25
        const resData = response.data
25
        const resData = response.data;
26
        if (!resData.success) {
26
        if (!resData.success) {
27
          return addNotification({
27
          return addNotification({
28
            style: 'danger',
28
            style: "danger",
29
            msg: 'Ha ocurrido un error, Por favor intente más tarde'
29
            msg: "Ha ocurrido un error, Por favor intente más tarde",
30
          })
30
          });
Línea 31... Línea 31...
31
        }
31
        }
32
        const OauthLink = resData.data
32
        const OauthLink = resData.data;
Línea 33... Línea 33...
33
        window.location.replace(OauthLink)
33
        window.location.replace(OauthLink);
34
      })
34
      });
35
  }
35
  };
36
 
36
 
Línea 37... Línea 37...
37
  const removeSocialNetwork = (network) => {
37
  const removeSocialNetwork = (network) => {
38
    setLoading(true)
38
    setLoading(true);
39
 
39
 
Línea 40... Línea 40...
40
    axios
40
    axios
41
      .post(`/account-settings/add-${network.toLowerCase()}`)
41
      .post(`/account-settings/add-${network.toLowerCase()}`)
42
      .then(({ data: responseData }) => {
42
      .then((response) => {
43
        const { success, data } = responseData
43
        const { success, data } = response.data;
44
 
44
 
Línea 45... Línea 45...
45
        if (!success) {
45
        if (!success) {
46
          throw new Error(data)
46
          throw new Error(data);
47
        }
47
        }
48
 
48
 
49
        addNotification({ style: 'success', msg: data })
49
        addNotification({ style: "success", msg: data });
50
      })
50
      })
51
      .catch((err) => addNotification({ style: 'danger', msg: err.message }))
51
      .catch((err) => addNotification({ style: "danger", msg: err.message }))
52
      .finally(() => setLoading(false))
52
      .finally(() => setLoading(false));
53
  }
53
  };
54
 
54
 
55
  const socialNetworks = [
55
  const socialNetworks = [
56
    {
56
    {
57
      name: 'Facebook',
57
      name: "Facebook",
58
      status: facebook
58
      status: facebook,
Línea 59... Línea 59...
59
    },
59
    },
60
    {
60
    {
61
      name: 'Google',
61
      name: "Google",
Línea 62... Línea 62...
62
      status: google
62
      status: google,
63
    },
63
    },
64
    {
64
    {
65
      name: 'Twitter',
65
      name: "Twitter",
66
      status: twitter
66
      status: twitter,
67
    }
67
    },
68
  ]
68
  ];
69
 
69
 
70
  return (
70
  return (
Línea 71... Línea 71...
71
    <Widget>
71
    <Widget>
72
      <Widget.Header title='Cambiar Configuración de las redes sociales' />
72
      <Widget.Header title="Cambiar Configuración de las redes sociales" />
73
 
73
 
74
      <Widget.Body>
74
      <Widget.Body>
75
        {loading && <Spinner />}
75
        {loading && <Spinner />}
76
        {!!socialNetworks.length &&
76
        {!!socialNetworks.length &&
77
          socialNetworks.map(({ name, status }) => (
77
          socialNetworks.map(({ name, status }) => (
78
            <div
78
            <div
79
              key={name}
79
              key={name}
80
              className='d-flex align-items-center justify-content-between'
80
              className="d-flex align-items-center justify-content-between"
Línea 98... Línea 98...
98
              </div>
98
              </div>
99
            </div>
99
            </div>
100
          ))}
100
          ))}
101
      </Widget.Body>
101
      </Widget.Body>
102
    </Widget>
102
    </Widget>
103
  )
103
  );
104
}
104
};
Línea 105... Línea 105...
105
 
105
 
106
const mapDispatchToProps = {
106
const mapDispatchToProps = {
107
  addNotification: (notification) => addNotification(notification)
107
  addNotification: (notification) => addNotification(notification),
Línea 108... Línea 108...
108
}
108
};