mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
fix(webpush): only prompt user to allow notifications if enabled in user settings (#1552)
This commit is contained in:
@@ -81,10 +81,16 @@ router.get('/status/appdata', (_req, res) => {
|
||||
});
|
||||
|
||||
router.use('/user', isAuthenticated(), user);
|
||||
router.get('/settings/public', async (_req, res) => {
|
||||
router.get('/settings/public', async (req, res) => {
|
||||
const settings = getSettings();
|
||||
|
||||
return res.status(200).json(settings.fullPublicSettings);
|
||||
if (!req.user?.settings?.notificationTypes.webpush) {
|
||||
return res
|
||||
.status(200)
|
||||
.json({ ...settings.fullPublicSettings, enablePushRegistration: false });
|
||||
} else {
|
||||
return res.status(200).json(settings.fullPublicSettings);
|
||||
}
|
||||
});
|
||||
router.use(
|
||||
'/settings',
|
||||
|
@@ -3,7 +3,7 @@ import { Field, Form, Formik } from 'formik';
|
||||
import React, { useState } from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import { useToasts } from 'react-toast-notifications';
|
||||
import useSWR from 'swr';
|
||||
import useSWR, { mutate } from 'swr';
|
||||
import globalMessages from '../../../../i18n/globalMessages';
|
||||
import Button from '../../../Common/Button';
|
||||
import LoadingSpinner from '../../../Common/LoadingSpinner';
|
||||
@@ -44,6 +44,7 @@ const NotificationsWebPush: React.FC = () => {
|
||||
types: values.types,
|
||||
options: {},
|
||||
});
|
||||
mutate('/api/v1/settings/public');
|
||||
addToast(intl.formatMessage(messages.webpushsettingssaved), {
|
||||
appearance: 'success',
|
||||
autoDismiss: true,
|
||||
|
@@ -4,7 +4,7 @@ import { useRouter } from 'next/router';
|
||||
import React from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import { useToasts } from 'react-toast-notifications';
|
||||
import useSWR from 'swr';
|
||||
import useSWR, { mutate } from 'swr';
|
||||
import { UserSettingsNotificationsResponse } from '../../../../../server/interfaces/api/userSettingsInterfaces';
|
||||
import { useUser } from '../../../../hooks/useUser';
|
||||
import globalMessages from '../../../../i18n/globalMessages';
|
||||
@@ -48,6 +48,7 @@ const UserWebPushSettings: React.FC = () => {
|
||||
webpush: values.enableWebPush ? ALL_NOTIFICATIONS : 0,
|
||||
},
|
||||
});
|
||||
mutate('/api/v1/settings/public');
|
||||
addToast(intl.formatMessage(messages.webpushsettingssaved), {
|
||||
appearance: 'success',
|
||||
autoDismiss: true,
|
||||
|
Reference in New Issue
Block a user