mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
improvement: redirect to ticketId after new ticket
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user