Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3284 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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