Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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