mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
fix: redirect to chat when ticket deleted by other
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import React, { useState } from "react";
|
||||
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
import MenuItem from "@material-ui/core/MenuItem";
|
||||
@@ -10,21 +9,15 @@ import api from "../../services/api";
|
||||
import ConfirmationModal from "../ConfirmationModal";
|
||||
|
||||
const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
||||
const history = useHistory();
|
||||
|
||||
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
||||
|
||||
const handleDeleteTicket = async () => {
|
||||
try {
|
||||
await api.delete(`/tickets/${ticket.id}`);
|
||||
toast.success("Ticket deletado com sucesso.");
|
||||
history.push("/chat");
|
||||
} catch (err) {
|
||||
toast.error("Erro ao deletar o ticket");
|
||||
}
|
||||
|
||||
console.log("deleted");
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const handleTransferTicket = e => {
|
||||
@@ -37,7 +30,6 @@ const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
||||
handleClose();
|
||||
};
|
||||
|
||||
console.log(ticket);
|
||||
return (
|
||||
<>
|
||||
<Menu
|
||||
|
||||
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
|
||||
import { useHistory, useParams } from "react-router-dom";
|
||||
import openSocket from "socket.io-client";
|
||||
import { parseISO, format } from "date-fns";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import { green } from "@material-ui/core/colors";
|
||||
@@ -258,6 +259,10 @@ const TicketsList = () => {
|
||||
}
|
||||
if (data.action === "delete") {
|
||||
deleteTicket(data);
|
||||
if (ticketId && data.ticketId === +ticketId) {
|
||||
toast.warn("O ticket que você estava foi deletado.");
|
||||
history.push("/chat");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -278,7 +283,7 @@ const TicketsList = () => {
|
||||
return () => {
|
||||
socket.disconnect();
|
||||
};
|
||||
}, [ticketId, userId]);
|
||||
}, [ticketId, userId, history]);
|
||||
|
||||
const updateUnreadMessagesCount = ({ message, ticket }) => {
|
||||
setTickets(prevState => {
|
||||
|
||||
Reference in New Issue
Block a user