Skip to content

Commit

Permalink
Add Ícone para permitir notificações
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed Dec 11, 2024
1 parent db4d438 commit ed9bf77
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
40 changes: 30 additions & 10 deletions frontend/src/components/NotificationsPopOver/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import {
Badge,
Button,
IconButton,
List,
ListItem,
ListItemText,
Popover,
Tooltip
} from "@material-ui/core";
import { makeStyles } from "@material-ui/core/styles";
import ChatIcon from "@material-ui/icons/Chat";
import HelpOutlineIcon from "@material-ui/icons/HelpOutline";
import VolumeOffIcon from "@material-ui/icons/VolumeOff";
import VolumeUpIcon from "@material-ui/icons/VolumeUp";
import { format } from "date-fns";
import React, { useCallback, useContext, useEffect, useRef, useState } from "react";
import { useHistory } from "react-router-dom";
import { toast } from "react-toastify";
import useSound from "use-sound";
import alertSound from "../../assets/sound.mp3";
import { AuthContext } from "../../context/Auth/AuthContext";
Expand Down Expand Up @@ -68,13 +70,29 @@ const NotificationsPopOver = () => {
}, [tickets]);

const requestNotificationPermission = () => {
Notification.requestPermission().then((permission) => {
if (permission === "granted") {
setNotificationsAllowed(true);
}
});
// Verifica se o navegador suporta notificações
if (!("Notification" in window)) {
alert(i18n.t("notifications.unsupported")); // Notificações não suportadas
return;
}

// Solicita permissão
Notification.requestPermission()
.then((permission) => {
if (permission === "granted") {
setNotificationsAllowed(true);
toast.success(i18n.t("notifications.permissionGranted"));
} else if (permission === "denied") {
toast.error(i18n.t("notifications.permissionDenied"));
}
})
.catch((error) => {
console.error("Erro ao solicitar permissão para notificações:", error);
toast.error(i18n.t("notifications.error"));
});
};


const handleNotifications = useCallback(
(data) => {
if (!notificationsAllowed) return;
Expand Down Expand Up @@ -175,13 +193,15 @@ const NotificationsPopOver = () => {
{isAudioEnabled ? <VolumeUpIcon /> : <VolumeOffIcon />}
</IconButton>
{!notificationsAllowed && (
<Button
<IconButton
onClick={requestNotificationPermission}
color="primary"
color="inherit"
variant="contained"
>
{i18n.t("notifications.allow")}
</Button>
<Tooltip title={i18n.t("notifications.allow")} arrow>
<HelpOutlineIcon />
</Tooltip>
</IconButton>
)}
<IconButton
onClick={handleClick}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,10 @@ const messages = {
},
},
notifications: {
allow: "Permitir as notificações no navegador?",
noTickets: "Nenhuma notificação.",
permissionGranted: "Permissão concedida.",
permissionDenied: "Permissão negada.",
},
queues: {
title: "Setores",
Expand Down

0 comments on commit ed9bf77

Please sign in to comment.