Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3284 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React, { useState } from 'react';
2
import { useNavigate } from 'react-router-dom';
3
import { useDispatch, useSelector } from 'react-redux';
4
 
5
import { addNotification } from '@app/redux/notification/notification.actions';
6
import { showReportModal } from '@app/redux/report/report.actions';
7
import { deleteFeed, fetchFeeds } from '@app/redux/feed/feed.actions';
8
 
9
import Widget from '@components/UI/Widget';
10
import Options from '@components/UI/Option';
11
import ConfirmModal from '@components/modals/ConfirmModal';
12
 
13
export default function FeedHeader({ id }) {
14
  const [showConfirmModal, setShowConfirmModal] = useState(false);
15
  const navigate = useNavigate();
16
  const dispatch = useDispatch();
17
 
18
  const { timelineUrl, currentPage } = useSelector(({ feed }) => feed);
19
 
20
  const {
21
    feed_delete_url: deleteUrl,
22
    feed_abuse_report_url: reportUrl,
23
    owner_image: image,
24
    owner_name: name,
25
    owner_time_elapse: timeElapse,
26
    owner_url: profileUrl
27
  } = useSelector(({ feed }) => feed.feeds.byId[id]);
28
 
29
  const removeFeed = async () => {
30
    try {
31
      const response = await dispatch(deleteFeed(deleteUrl, id));
32
      dispatch(addNotification({ style: 'success', msg: response }));
33
      toggleConfirm();
34
    } catch (error) {
35
      dispatch(addNotification({ style: 'danger', msg: error.message }));
36
    }
37
  };
38
 
39
  const reportFeed = () =>
40
    dispatch(
41
      showReportModal({
42
        type: 'publicación',
43
        reportUrl,
44
        onComplete: () => dispatch(fetchFeeds(timelineUrl, currentPage))
45
      })
46
    );
47
 
48
  const toggleConfirm = () => setShowConfirmModal(!showConfirmModal);
49
 
50
  return (
51
    <>
52
      <Widget.Header
53
        avatar={image}
54
        title={name}
55
        onClick={() => navigate(profileUrl)}
56
        subheader={timeElapse}
57
        renderAction={() => (
58
          <Options>
59
            {reportUrl ? <Options.Item onClick={reportFeed}>Reportar</Options.Item> : null}
60
 
61
            {deleteUrl ? <Options.Item onClick={toggleConfirm}>Borrar</Options.Item> : null}
62
          </Options>
63
        )}
64
      />
65
      <ConfirmModal show={showConfirmModal} onClose={toggleConfirm} onAccept={removeFeed} />
66
    </>
67
  );
68
}