Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 641 Rev 2157
Línea 1... Línea 1...
1
import React, { useEffect, useState } from "react";
1
import React, { useEffect, useState } from 'react'
2
import { useDispatch } from "react-redux";
2
import { useDispatch } from 'react-redux'
3
import {
3
import {
4
  EmailIcon,
4
  EmailIcon,
5
  EmailShareButton,
5
  EmailShareButton,
6
  FacebookIcon,
6
  FacebookIcon,
7
  FacebookShareButton,
7
  FacebookShareButton,
Línea 10... Línea 10...
10
  TelegramIcon,
10
  TelegramIcon,
11
  TelegramShareButton,
11
  TelegramShareButton,
12
  TwitterIcon,
12
  TwitterIcon,
13
  TwitterShareButton,
13
  TwitterShareButton,
14
  WhatsappIcon,
14
  WhatsappIcon,
15
  WhatsappShareButton,
15
  WhatsappShareButton
16
} from "react-share";
16
} from 'react-share'
17
import { addNotification } from "store/notification/notification.actions";
17
import { addNotification } from 'store/notification/notification.actions'
18
import { axios } from "../../../utils";
18
import { axios } from '../../../utils'
19
import styled from "styled-components";
19
import styled from 'styled-components'
Línea 20... Línea 20...
20
 
20
 
21
const StyledShareContainer = styled.div`
21
const StyledShareContainer = styled.div`
22
  display: flex;
22
  display: flex;
23
  position: absolute;
23
  position: absolute;
Línea 29... Línea 29...
29
  width: 16.5rem;
29
  width: 16.5rem;
30
  border-radius: 10px;
30
  border-radius: 10px;
31
  background-color: #fff;
31
  background-color: #fff;
32
  box-shadow: 0px 4px 4px -2px rgb(0 0 0 / 12%),
32
  box-shadow: 0px 4px 4px -2px rgb(0 0 0 / 12%),
33
    0px -4px 4px -2px rgb(0 0 0 / 12%);
33
    0px -4px 4px -2px rgb(0 0 0 / 12%);
34
`;
34
`
Línea 35... Línea 35...
35
 
35
 
36
export default function withExternalShare(Component, url) {
36
export default function withExternalShare(Component, url) {
37
  return function (props) {
37
  return function ({ children, setValue, shorterUrl }) {
38
    const [shareOptions, setShareOptions] = useState(false);
38
    const [shareOptions, setShareOptions] = useState(false)
39
    const [shareUrl, setShareUrl] = useState("");
39
    const [shareUrl, setShareUrl] = useState('')
Línea 40... Línea 40...
40
    const dispatch = useDispatch();
40
    const dispatch = useDispatch()
41
 
41
 
42
    const toggleShareOptions = () => {
42
    const toggleShareOptions = () => {
Línea 43... Línea 43...
43
      setShareOptions(!shareOptions);
43
      setShareOptions(!shareOptions)
44
    };
44
    }
45
 
45
 
46
    const getShareUrl = async () => {
46
    const getShareUrl = async () => {
47
      await axios
47
      await axios
48
        .get(url)
48
        .get(url)
49
        .then(({ data }) => {
49
        .then(({ data }) => {
50
          if (!data.success) {
50
          if (!data.success) {
51
            dispatch(addNotification({ style: "danger", msg: data.data }));
51
            dispatch(addNotification({ style: 'danger', msg: data.data }))
Línea 52... Línea 52...
52
            setShareOptions(false);
52
            setShareOptions(false)
53
            return;
53
            return
54
          }
54
          }
55
 
55
 
Línea 56... Línea 56...
56
          setShareUrl(data.data);
56
          setShareUrl(data.data)
57
        })
57
        })
58
        .catch((err) => console.log(err));
58
        .catch((err) => console.log(err))
59
    };
59
    }
60
 
60
 
61
    const incrementCount = async () => {
61
    const incrementCount = async () => {
62
      await axios
62
      await axios
63
        .post(props.shareUrl)
63
        .post(shorterUrl)
Línea 64... Línea 64...
64
        .then(({ data }) => {
64
        .then(({ data }) => {
65
          if (!data.success) {
65
          if (!data.success) {
66
            dispatch(addNotification({ style: "danger", msg: data.data }));
66
            dispatch(addNotification({ style: 'danger', msg: data.data }))
67
            return;
67
            return
68
          }
68
          }
Línea 69... Línea 69...
69
 
69
 
70
          setShareOptions(false);
70
          setShareOptions(false)
71
          props.setValue(data.data);
71
          setValue(data.data)
Línea 72... Línea 72...
72
        })
72
        })
73
        .catch((err) => console.log(err));
73
        .catch((err) => console.log(err))
-
 
74
    }
74
    };
75
 
75
 
76
    useEffect(() => {
76
    useEffect(() => {
77
      if (shareOptions && !shareUrl) getShareUrl()
77
      if (shareOptions && !shareUrl) getShareUrl();
78
    }, [shareOptions])
78
    }, [shareOptions]);
79
 
Línea 118... Línea 119...
118
              <EmailIcon size={32} round />
119
              <EmailIcon size={32} round />
119
            </EmailShareButton>
120
            </EmailShareButton>
120
          </StyledShareContainer>
121
          </StyledShareContainer>
121
        )}
122
        )}
122
      </Component>
123
      </Component>
123
    );
124
    )
124
  };
125
  }
125
}
126
}