3577 |
stevensc |
1 |
import React, { useEffect, useState } from 'react';
|
|
|
2 |
import { useNavigate, useParams } from 'react-router-dom';
|
|
|
3 |
import { useDispatch } from 'react-redux';
|
|
|
4 |
import { ButtonGroup, IconButton, Box } from '@mui/material';
|
|
|
5 |
import { Delete, Block, Reply } from '@mui/icons-material';
|
|
|
6 |
|
|
|
7 |
import { useInmail } from '@hooks';
|
|
|
8 |
import { deleteInmail } from '@app/services/inmail';
|
|
|
9 |
import { showReportModal } from '@app/redux/report/report.actions';
|
|
|
10 |
import { addNotification } from '@app/redux/notification/notification.actions';
|
|
|
11 |
import ComposeButton from './compose-button';
|
|
|
12 |
import ReplyModal from './reply-modal';
|
|
|
13 |
import ConfirmModal from '@components/modals/ConfirmModal';
|
|
|
14 |
import ReportModal from '@components/modals/ReportModal';
|
|
|
15 |
|
|
|
16 |
export default function ActionsRow() {
|
|
|
17 |
const { uuid } = useParams();
|
|
|
18 |
const { selectedMessage, messages, selectMessage, replyMessage } = useInmail();
|
|
|
19 |
const [showConfirmModal, setShowConfirmModal] = useState(false);
|
|
|
20 |
const dispatch = useDispatch();
|
|
|
21 |
const navigate = useNavigate();
|
|
|
22 |
|
|
|
23 |
const navigateToImbox = () => navigate('/inmail');
|
|
|
24 |
|
|
|
25 |
const handleDelete = async () => {
|
|
|
26 |
try {
|
|
|
27 |
const result = await deleteInmail(selectedMessage.delete_link);
|
|
|
28 |
dispatch(addNotification({ style: 'success', msg: result }));
|
|
|
29 |
navigateToImbox();
|
|
|
30 |
} catch (error) {
|
|
|
31 |
dispatch(addNotification({ style: 'danger', msg: error.message }));
|
|
|
32 |
}
|
|
|
33 |
};
|
|
|
34 |
|
|
|
35 |
const handleReport = () => {
|
|
|
36 |
dispatch(
|
|
|
37 |
showReportModal({
|
|
|
38 |
reportUrl: selectedMessage?.block_link,
|
|
|
39 |
type: 'Inmail',
|
|
|
40 |
onComplete: navigateToImbox
|
|
|
41 |
})
|
|
|
42 |
);
|
|
|
43 |
};
|
|
|
44 |
|
|
|
45 |
const toggleConfirmModal = () => setShowConfirmModal(!showConfirmModal);
|
|
|
46 |
|
|
|
47 |
useEffect(() => {
|
|
|
48 |
if (selectedMessage) return;
|
|
|
49 |
const currentMessage = messages.find((message) => message.email_id === uuid);
|
|
|
50 |
selectMessage(currentMessage);
|
|
|
51 |
}, [selectedMessage, messages, uuid]);
|
|
|
52 |
|
|
|
53 |
return (
|
|
|
54 |
<>
|
|
|
55 |
<Box
|
|
|
56 |
sx={{
|
|
|
57 |
display: 'flex',
|
|
|
58 |
alignItems: 'center',
|
|
|
59 |
justifyContent: 'space-between',
|
|
|
60 |
gap: 0.5,
|
|
|
61 |
mb: 1
|
|
|
62 |
}}
|
|
|
63 |
>
|
|
|
64 |
<ComposeButton />
|
|
|
65 |
|
|
|
66 |
{uuid && selectedMessage ? (
|
|
|
67 |
<ButtonGroup>
|
|
|
68 |
<IconButton onClick={() => replyMessage(selectedMessage)}>
|
|
|
69 |
<Reply />
|
|
|
70 |
</IconButton>
|
|
|
71 |
<ReplyModal />
|
|
|
72 |
|
|
|
73 |
<IconButton onClick={toggleConfirmModal}>
|
|
|
74 |
<Delete />
|
|
|
75 |
</IconButton>
|
|
|
76 |
|
|
|
77 |
<IconButton onClick={handleReport}>
|
|
|
78 |
<Block />
|
|
|
79 |
</IconButton>
|
|
|
80 |
</ButtonGroup>
|
|
|
81 |
) : null}
|
|
|
82 |
</Box>
|
|
|
83 |
<ConfirmModal show={showConfirmModal} onAccept={handleDelete} onClose={toggleConfirmModal} />
|
|
|
84 |
<ReportModal />
|
|
|
85 |
</>
|
|
|
86 |
);
|
|
|
87 |
}
|