mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-21 21:29:25 +00:00
improvement: focus app when clicking desktop notification
This commit is contained in:
@@ -338,7 +338,7 @@ const MessagesList = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.action === "delete") {
|
if (data.action === "delete") {
|
||||||
toast.success("The deleted sucessfully.");
|
toast.success("Ticket deleted sucessfully.");
|
||||||
history.push("/tickets");
|
history.push("/tickets");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -108,39 +108,40 @@ const NotificationsPopOver = () => {
|
|||||||
(data.ticket.userId !== userId && data.ticket.userId)
|
(data.ticket.userId !== userId && data.ticket.userId)
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
showDesktopNotification(data);
|
else {
|
||||||
|
// show desktop notification
|
||||||
|
const { message, contact, ticket } = data;
|
||||||
|
const options = {
|
||||||
|
body: `${message.body} - ${format(new Date(), "HH:mm")}`,
|
||||||
|
icon: contact.profilePicUrl,
|
||||||
|
tag: ticket.id,
|
||||||
|
};
|
||||||
|
let notification = new Notification(
|
||||||
|
`${i18n.t("tickets.notification.message")} ${contact.name}`,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
|
notification.onclick = function (event) {
|
||||||
|
event.preventDefault(); //
|
||||||
|
window.focus();
|
||||||
|
history.push(`/tickets/${ticket.id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("visibilitychange", () => {
|
||||||
|
if (document.visibilityState === "visible") {
|
||||||
|
notification.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
soundAlert.current.play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
};
|
};
|
||||||
}, [userId]);
|
}, [history, userId]);
|
||||||
|
|
||||||
const showDesktopNotification = ({ message, contact, ticket }) => {
|
|
||||||
const options = {
|
|
||||||
body: `${message.body} - ${format(new Date(), "HH:mm")}`,
|
|
||||||
icon: contact.profilePicUrl,
|
|
||||||
tag: ticket.id,
|
|
||||||
};
|
|
||||||
let notification = new Notification(
|
|
||||||
`${i18n.t("tickets.notification.message")} ${contact.name}`,
|
|
||||||
options
|
|
||||||
);
|
|
||||||
|
|
||||||
notification.onclick = function (event) {
|
|
||||||
event.preventDefault(); //
|
|
||||||
history.push(`/tickets/${ticket.id}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener("visibilitychange", () => {
|
|
||||||
if (document.visibilityState === "visible") {
|
|
||||||
notification.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
soundAlert.current.play();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClick = useCallback(() => {
|
const handleClick = useCallback(() => {
|
||||||
setIsOpen(!isOpen);
|
setIsOpen(!isOpen);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useHistory } from "react-router-dom";
|
|
||||||
|
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
@@ -12,7 +11,6 @@ import ConfirmationModal from "../ConfirmationModal";
|
|||||||
|
|
||||||
const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
||||||
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
||||||
const history = useHistory();
|
|
||||||
|
|
||||||
const handleDeleteTicket = async () => {
|
const handleDeleteTicket = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user