mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-17 19:37:02 +00:00
94 lines
2.3 KiB
JavaScript
94 lines
2.3 KiB
JavaScript
import React, { useEffect, useRef, useState } from "react";
|
|
|
|
import MenuItem from "@material-ui/core/MenuItem";
|
|
import Menu from "@material-ui/core/Menu";
|
|
|
|
import { i18n } from "../../translate/i18n";
|
|
import api from "../../services/api";
|
|
import ConfirmationModal from "../ConfirmationModal";
|
|
import TransferTicketModal from "../TransferTicketModal";
|
|
import toastError from "../../errors/toastError";
|
|
|
|
const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
|
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
|
const [transferTicketModalOpen, setTransferTicketModalOpen] = useState(false);
|
|
const isMounted = useRef(true);
|
|
|
|
useEffect(() => {
|
|
return () => {
|
|
isMounted.current = false;
|
|
};
|
|
}, []);
|
|
|
|
const handleDeleteTicket = async () => {
|
|
try {
|
|
await api.delete(`/tickets/${ticket.id}`);
|
|
} catch (err) {
|
|
toastError(err);
|
|
}
|
|
};
|
|
|
|
const handleOpenConfirmationModal = e => {
|
|
setConfirmationOpen(true);
|
|
handleClose();
|
|
};
|
|
|
|
const handleOpenTransferModal = e => {
|
|
setTransferTicketModalOpen(true);
|
|
handleClose();
|
|
};
|
|
|
|
const handleCloseTransferTicketModal = () => {
|
|
if (isMounted.current) {
|
|
setTransferTicketModalOpen(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Menu
|
|
id="menu-appbar"
|
|
anchorEl={anchorEl}
|
|
getContentAnchorEl={null}
|
|
anchorOrigin={{
|
|
vertical: "bottom",
|
|
horizontal: "right",
|
|
}}
|
|
keepMounted
|
|
transformOrigin={{
|
|
vertical: "top",
|
|
horizontal: "right",
|
|
}}
|
|
open={menuOpen}
|
|
onClose={handleClose}
|
|
>
|
|
<MenuItem onClick={handleOpenConfirmationModal}>
|
|
{i18n.t("ticketOptionsMenu.delete")}
|
|
</MenuItem>
|
|
<MenuItem onClick={handleOpenTransferModal}>
|
|
{i18n.t("ticketOptionsMenu.transfer")}
|
|
</MenuItem>
|
|
</Menu>
|
|
<ConfirmationModal
|
|
title={`${i18n.t("ticketOptionsMenu.confirmationModal.title")}${
|
|
ticket.id
|
|
} ${i18n.t("ticketOptionsMenu.confirmationModal.titleFrom")} ${
|
|
ticket.contact.name
|
|
}?`}
|
|
open={confirmationOpen}
|
|
setOpen={setConfirmationOpen}
|
|
onConfirm={handleDeleteTicket}
|
|
>
|
|
{i18n.t("ticketOptionsMenu.confirmationModal.message")}
|
|
</ConfirmationModal>
|
|
<TransferTicketModal
|
|
modalOpen={transferTicketModalOpen}
|
|
onClose={handleCloseTransferTicketModal}
|
|
ticketid={ticket.id}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default TicketOptionsMenu;
|