Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4800 | Rev 4802 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4309 stevensc 1
/* eslint-disable react/display-name */
2
import React, { useState } from "react"
3
import { useDispatch } from "react-redux"
4
import { EmailIcon, EmailShareButton, FacebookIcon, FacebookShareButton, RedditIcon, RedditShareButton, TelegramIcon, TelegramShareButton, TwitterIcon, TwitterShareButton, WhatsappIcon, WhatsappShareButton } from "react-share"
5
import { addNotification } from "../../../../redux/notification/notification.actions"
6
import { axios } from "../../../../utils"
7
 
8
export default function withExternalShare(Component, url, params) {
9
    return function () {
10
        const dispatch = useDispatch()
11
        const [shareOptions, setShareOptions] = useState(false)
12
        const [shareUrl, setShareUrl] = useState('');
13
 
14
        const handleDisplayReactionList = () => setShareOptions(!shareOptions)
15
 
4798 stevensc 16
        async function getShareUrl() {
17
            await axios.get(url)
18
                .then(({ data }) => {
19
                    if (!data.success) {
20
                        dispatch(addNotification({ style: 'danger', msg: data.data }))
21
                        setShareOptions(false)
22
                        return
23
                    }
4792 stevensc 24
 
4798 stevensc 25
                    setShareUrl(data.data)
26
                })
27
                .catch((err) => console.log(err))
28
        }
4309 stevensc 29
 
4801 stevensc 30
        const promise = getShareUrl()
31
 
4798 stevensc 32
        const handleClose = () => alert('Counter: 1')
4792 stevensc 33
 
4309 stevensc 34
        return (
4626 stevensc 35
            <div className="position-relative d-inline-flex" onClick={handleDisplayReactionList} style={{ flexGrow: 1 }}>
4309 stevensc 36
                <Component {...params} />
37
                {shareOptions &&
38
                    <div className="external__share" >
4801 stevensc 39
                        <FacebookShareButton beforeOnClick={()=> promise} url={shareUrl} onShareWindowClose={handleClose}>
4309 stevensc 40
                            <FacebookIcon size={32} round />
41
                        </FacebookShareButton>
4798 stevensc 42
                        <TwitterShareButton beforeOnClick={getShareUrl} url={shareUrl}>
4309 stevensc 43
                            <TwitterIcon size={32} round />
44
                        </TwitterShareButton>
4798 stevensc 45
                        <TelegramShareButton beforeOnClick={getShareUrl} url={shareUrl}>
4309 stevensc 46
                            <TelegramIcon size={32} round />
47
                        </TelegramShareButton>
4798 stevensc 48
                        <WhatsappShareButton beforeOnClick={getShareUrl} url={shareUrl}>
4309 stevensc 49
                            <WhatsappIcon size={32} round />
50
                        </WhatsappShareButton>
4798 stevensc 51
                        <RedditShareButton beforeOnClick={getShareUrl} url={shareUrl}>
4309 stevensc 52
                            <RedditIcon size={32} round />
53
                        </RedditShareButton>
4798 stevensc 54
                        <EmailShareButton beforeOnClick={getShareUrl} url={shareUrl}>
4309 stevensc 55
                            <EmailIcon size={32} round />
56
                        </EmailShareButton>
57
                    </div>
58
                }
59
            </div>
60
        )
61
    }
62
}