Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
3630 stevensc 1
/* eslint-disable react/prop-types */
2
import React, { useEffect, useRef, useState } from 'react'
3
import { useDispatch } from 'react-redux';
4
import { deleteFeed } from '../../../redux/feed/feed.actions';
5
import { addNotification } from '../../../redux/notification/notification.actions';
6
import ConfirmModal from '../../../shared/confirm-modal/ConfirmModal';
7
import { axios } from '../../../utils';
8
 
9
const FeedHeader = ({
10
    ownerName,
11
    ownerImage,
12
    ownerTimeElapse,
13
    ownerUrl,
14
    feedDeleteUrl,
15
    feedUnique
16
}) => {
17
 
18
    const [showConfirmModal, setShowConfirmModal] = useState(false);
19
    const [displayOption, setDisplayOption] = useState(false)
20
    const deleteButton = useRef();
21
    const dispatch = useDispatch()
22
 
23
    const handleShowConfirmModal = () => setShowConfirmModal(!showConfirmModal);
24
 
25
    const deleteFeedHandler = () => {
26
        axios.post(feedDeleteUrl)
27
            .then((res) => {
28
                const { data } = res
3820 stevensc 29
                if (!data.success) {
30
                    dispatch(addNotification({ style: "danger", msg: data.data }))
3630 stevensc 31
                    return
32
                }
3818 stevensc 33
                dispatch(addNotification({ style: "success", msg: data.data }))
34
                handleShowConfirmModal()
3630 stevensc 35
                dispatch(deleteFeed(feedUnique));
36
            });
37
    };
38
 
39
    useEffect(() => {
40
        const handleClickOutside = (event) => {
41
            if (deleteButton.current && !deleteButton.current.contains(event.target)) {
42
                setDisplayOption(false)
43
            }
44
        }
45
        document.addEventListener("mousedown", handleClickOutside);
46
 
47
        return () => {
48
            document.removeEventListener("mousedown", handleClickOutside);
49
        };
50
    }, [deleteButton]);
51
 
52
    return (
53
        <>
54
            <div className="post_topbar" >
55
                <div className="usy-dt">
56
                    <a href={ownerUrl}>
57
                        <img
58
                            src={ownerImage}
59
                            alt=""
60
                            style={{ width: "50px", height: "auto", }}
61
                        />
62
                    </a>
63
                    <div className="usy-name">
64
                        <a href={ownerUrl}>
65
                            <h3>{ownerName}</h3>
66
                        </a>
67
                        <span>
68
                            {ownerTimeElapse}
69
                        </span>
70
                    </div>
71
                </div>
72
                {feedDeleteUrl &&
73
                    <div className="cursor-pointer d-flex align-items-center">
4043 stevensc 74
                        <img
4061 stevensc 75
                            src='/images/icons/options.png'
4045 stevensc 76
                            className='cursor-pointer img-icon options'
3630 stevensc 77
                            onClick={() => setDisplayOption(!displayOption)}
78
                        />
79
                        <div className={`feed-options ${displayOption ? 'active' : ''}`}>
80
                            <ul>
81
                                <li>
82
                                    <button
83
                                        className="option-btn"
84
                                        onClick={handleShowConfirmModal}
85
                                        ref={deleteButton}
86
                                    >
4047 stevensc 87
                                        <i className="fa fa-trash-o mr-1" />
3630 stevensc 88
                                        Borrar
89
                                    </button>
90
                                </li>
91
                            </ul>
92
                        </div>
3955 stevensc 93
                        <ConfirmModal
94
                            show={showConfirmModal}
95
                            onClose={() => handleShowConfirmModal(false)}
96
                            onAccept={deleteFeedHandler}
97
                            acceptLabel="Aceptar"
98
                        />
3630 stevensc 99
                    </div>
100
                }
101
            </div >
102
        </>
103
    )
104
}
105
 
106
export default FeedHeader