mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-21 05:09:18 +00:00
improvement(style): better menus placement
This commit is contained in:
@@ -3,11 +3,11 @@ import React, { useState } from "react";
|
|||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
import MenuItem from "@material-ui/core/MenuItem";
|
import MenuItem from "@material-ui/core/MenuItem";
|
||||||
import Menu from "@material-ui/core/Menu";
|
|
||||||
|
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import ConfirmationModal from "../ConfirmationModal";
|
import ConfirmationModal from "../ConfirmationModal";
|
||||||
|
import { Popover } from "@material-ui/core";
|
||||||
|
|
||||||
const MessageOptionsMenu = ({ messageId, menuOpen, handleClose, anchorEl }) => {
|
const MessageOptionsMenu = ({ messageId, menuOpen, handleClose, anchorEl }) => {
|
||||||
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
||||||
@@ -44,13 +44,12 @@ const MessageOptionsMenu = ({ messageId, menuOpen, handleClose, anchorEl }) => {
|
|||||||
>
|
>
|
||||||
{i18n.t("messageOptionsMenu.confirmationModal.message")}
|
{i18n.t("messageOptionsMenu.confirmationModal.message")}
|
||||||
</ConfirmationModal>
|
</ConfirmationModal>
|
||||||
<Menu
|
<Popover
|
||||||
anchorEl={anchorEl}
|
anchorEl={anchorEl}
|
||||||
anchorOrigin={{
|
anchorOrigin={{
|
||||||
vertical: "top",
|
vertical: "bottom",
|
||||||
horizontal: "right",
|
horizontal: "right",
|
||||||
}}
|
}}
|
||||||
keepMounted
|
|
||||||
transformOrigin={{
|
transformOrigin={{
|
||||||
vertical: "top",
|
vertical: "top",
|
||||||
horizontal: "right",
|
horizontal: "right",
|
||||||
@@ -62,7 +61,7 @@ const MessageOptionsMenu = ({ messageId, menuOpen, handleClose, anchorEl }) => {
|
|||||||
{i18n.t("messageOptionsMenu.delete")}
|
{i18n.t("messageOptionsMenu.delete")}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem disabled> {i18n.t("messageOptionsMenu.reply")}</MenuItem>
|
<MenuItem disabled> {i18n.t("messageOptionsMenu.reply")}</MenuItem>
|
||||||
</Menu>
|
</Popover>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useRef, useCallback, useEffect } from "react";
|
import React, { useState, useRef, useEffect } from "react";
|
||||||
|
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
@@ -100,41 +100,39 @@ const NotificationsPopOver = () => {
|
|||||||
return [data.ticket, ...prevState];
|
return [data.ticket, ...prevState];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
const shouldNotNotificate =
|
||||||
(ticketIdRef.current &&
|
(data.message.ticketId === ticketIdRef.current &&
|
||||||
data.message.ticketId === ticketIdRef.current &&
|
|
||||||
document.visibilityState === "visible") ||
|
document.visibilityState === "visible") ||
|
||||||
(data.ticket.userId && data.ticket.userId !== userId) ||
|
(data.ticket.userId && data.ticket.userId !== userId) ||
|
||||||
data.ticket.isGroup
|
data.ticket.isGroup;
|
||||||
)
|
|
||||||
return;
|
|
||||||
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) {
|
if (shouldNotNotificate) return;
|
||||||
event.preventDefault(); //
|
|
||||||
window.focus();
|
|
||||||
history.push(`/tickets/${ticket.id}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener("visibilitychange", () => {
|
// show desktop notification
|
||||||
if (document.visibilityState === "visible") {
|
const { message, contact, ticket } = data;
|
||||||
notification.close();
|
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
|
||||||
|
);
|
||||||
|
|
||||||
soundAlert.current.play();
|
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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -143,13 +141,13 @@ const NotificationsPopOver = () => {
|
|||||||
};
|
};
|
||||||
}, [history, userId]);
|
}, [history, userId]);
|
||||||
|
|
||||||
const handleClick = useCallback(() => {
|
const handleClick = () => {
|
||||||
setIsOpen(!isOpen);
|
setIsOpen(prevState => !prevState);
|
||||||
}, [isOpen, setIsOpen]);
|
};
|
||||||
|
|
||||||
const handleClickAway = useCallback(() => {
|
const handleClickAway = () => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
}, [setIsOpen]);
|
};
|
||||||
|
|
||||||
const NotificationTicket = ({ children }) => {
|
const NotificationTicket = ({ children }) => {
|
||||||
return <div onClick={handleClickAway}>{children}</div>;
|
return <div onClick={handleClickAway}>{children}</div>;
|
||||||
@@ -173,7 +171,7 @@ const NotificationsPopOver = () => {
|
|||||||
anchorEl={anchorEl.current}
|
anchorEl={anchorEl.current}
|
||||||
anchorOrigin={{
|
anchorOrigin={{
|
||||||
vertical: "bottom",
|
vertical: "bottom",
|
||||||
horizontal: "left",
|
horizontal: "right",
|
||||||
}}
|
}}
|
||||||
transformOrigin={{
|
transformOrigin={{
|
||||||
vertical: "top",
|
vertical: "top",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import UserModal from "../UserModal";
|
|||||||
import { AuthContext } from "../../context/Auth/AuthContext";
|
import { AuthContext } from "../../context/Auth/AuthContext";
|
||||||
import BackdropLoading from "../BackdropLoading";
|
import BackdropLoading from "../BackdropLoading";
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
|
import { Popover } from "@material-ui/core";
|
||||||
|
|
||||||
const drawerWidth = 240;
|
const drawerWidth = 240;
|
||||||
|
|
||||||
@@ -212,14 +213,13 @@ const LoggedInLayout = ({ appTitle, children }) => {
|
|||||||
>
|
>
|
||||||
<AccountCircle />
|
<AccountCircle />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Menu
|
<Popover
|
||||||
id="menu-appbar"
|
id="menu-appbar"
|
||||||
anchorEl={anchorEl}
|
anchorEl={anchorEl}
|
||||||
anchorOrigin={{
|
anchorOrigin={{
|
||||||
vertical: "top",
|
vertical: "bottom",
|
||||||
horizontal: "right",
|
horizontal: "right",
|
||||||
}}
|
}}
|
||||||
keepMounted
|
|
||||||
transformOrigin={{
|
transformOrigin={{
|
||||||
vertical: "top",
|
vertical: "top",
|
||||||
horizontal: "right",
|
horizontal: "right",
|
||||||
@@ -233,7 +233,7 @@ const LoggedInLayout = ({ appTitle, children }) => {
|
|||||||
<MenuItem onClick={handleLogout}>
|
<MenuItem onClick={handleLogout}>
|
||||||
{i18n.t("mainDrawer.appBar.user.logout")}
|
{i18n.t("mainDrawer.appBar.user.logout")}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</Menu>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ const useTickets = ({
|
|||||||
setHasMore(data.hasMore);
|
setHasMore(data.hasMore);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
setLoading(false);
|
||||||
const errorMsg = err.response?.data?.error;
|
const errorMsg = err.response?.data?.error;
|
||||||
if (errorMsg) {
|
if (errorMsg) {
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user