improvement: redirect to ticketId after new ticket

This commit is contained in:
canove
2020-08-04 15:29:14 -03:00
parent f7e8fed7d8
commit 87dc0c0625
3 changed files with 9 additions and 4 deletions

View File

@@ -61,7 +61,7 @@ exports.index = async (req, res, next) => {
});
if (!ticket) {
return res.status(400).json({ error: "No ticket found with this ID" });
return res.status(404).json({ error: "No ticket found with this ID" });
}
await setMessagesAsRead(ticketId);

View File

@@ -1,6 +1,7 @@
import React, { useState, useEffect, useRef } from "react";
import { useParams, useHistory } from "react-router-dom";
import { toast } from "react-toastify";
import { isSameDay, parseISO, format } from "date-fns";
import openSocket from "socket.io-client";
import InfiniteScrollReverse from "react-infinite-scroll-reverse";
@@ -263,13 +264,14 @@ const MessagesList = () => {
}
} catch (err) {
console.log(err);
alert(err);
toast.error("Ticket não encontrado");
history.push("/chat");
}
};
fetchMessages();
}, 1000);
return () => clearTimeout(delayDebounceFn);
}, [searchParam, pageNumber, ticketId, token]);
}, [searchParam, pageNumber, ticketId, token, history]);
useEffect(() => {
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);

View File

@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import { useHistory } from "react-router-dom";
import Button from "@material-ui/core/Button";
import TextField from "@material-ui/core/TextField";
@@ -37,6 +38,7 @@ const useStyles = makeStyles(theme => ({
}));
const NewTicketModal = ({ modalOpen, onClose, contactId }) => {
const history = useHistory();
const classes = useStyles();
const userId = +localStorage.getItem("userId");
@@ -77,11 +79,12 @@ const NewTicketModal = ({ modalOpen, onClose, contactId }) => {
if (!selectedContact) return;
setLoading(true);
try {
await api.post("/tickets", {
const { data: ticket } = await api.post("/tickets", {
contactId: selectedContact.id,
userId: userId,
status: "open",
});
history.push(`/chat/${ticket.id}`);
} catch (err) {
alert(err);
}