import { Capacitor } from '@capacitor/core'; import { Button, Snackbar, Stack, Typography } from '@mui/joy' import { Preferences } from '@capacitor/preferences'; import { LocalNotifications } from '@capacitor/local-notifications'; import {React, useEffect, useState} from 'react'; const NotificationAccessSnackbar = () => { const [open, setOpen] = useState(false); if (!Capacitor.isNativePlatform()) { return null; } const getNotificationPreferences = async () => { const ret = await Preferences.get({ key: 'notificationPreferences' }); return JSON.parse(ret.value); }; useEffect(() => { getNotificationPreferences().then((data) => { // if optOut is true then don't show the snackbar if(data?.optOut === true || data?.granted === true) { return; } setOpen(true); }); } , []); return ( setOpen(false)} anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} sx={(theme) => ({ background: `linear-gradient(45deg, ${theme.palette.primary[600]} 30%, ${theme.palette.primary[500]} 90%})`, maxWidth: 360, })} >
Need Notification? You need to enable permission to receive notifications, do you want to enable it?
) } export default NotificationAccessSnackbar;