fix: redirect to chat when ticket deleted by other

This commit is contained in:
canove
2020-07-31 08:45:17 -03:00
parent 32ab7fe505
commit 9fa9bfb560
2 changed files with 6 additions and 9 deletions

View File

@@ -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

View File

@@ -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 => {