From 0c4fb6446be425905a120df5be9a28b052e884c0 Mon Sep 17 00:00:00 2001
From: TheCatLady <52870424+TheCatLady@users.noreply.github.com>
Date: Sat, 8 May 2021 00:01:02 -0400
Subject: [PATCH] feat(webpush): add warning to web push settings re: HTTPS
requirement (#1599)
---
.../NotificationsWebPush/index.tsx | 16 +++++++++++++-
.../Settings/SettingsNotifications.tsx | 22 +++++++++----------
src/i18n/locale/en.json | 1 +
3 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/components/Settings/Notifications/NotificationsWebPush/index.tsx b/src/components/Settings/Notifications/NotificationsWebPush/index.tsx
index aa4f98bf..f3e0c6d7 100644
--- a/src/components/Settings/Notifications/NotificationsWebPush/index.tsx
+++ b/src/components/Settings/Notifications/NotificationsWebPush/index.tsx
@@ -1,10 +1,11 @@
import axios from 'axios';
import { Field, Form, Formik } from 'formik';
-import React, { useState } from 'react';
+import React, { useEffect, useState } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { useToasts } from 'react-toast-notifications';
import useSWR, { mutate } from 'swr';
import globalMessages from '../../../../i18n/globalMessages';
+import Alert from '../../../Common/Alert';
import Button from '../../../Common/Button';
import LoadingSpinner from '../../../Common/LoadingSpinner';
import NotificationTypeSelector from '../../../NotificationTypeSelector';
@@ -16,22 +17,35 @@ const messages = defineMessages({
toastWebPushTestSending: 'Sending web push test notification…',
toastWebPushTestSuccess: 'Web push test notification sent!',
toastWebPushTestFailed: 'Web push test notification failed to send.',
+ httpsRequirement:
+ 'In order to receive web push notifications, Overseerr must be served over HTTPS.',
});
const NotificationsWebPush: React.FC = () => {
const intl = useIntl();
const { addToast, removeToast } = useToasts();
const [isTesting, setIsTesting] = useState(false);
+ const [isHttps, setIsHttps] = useState(false);
const { data, error, revalidate } = useSWR(
'/api/v1/settings/notifications/webpush'
);
+ useEffect(() => {
+ setIsHttps(window.location.protocol.startsWith('https'));
+ }, []);
+
if (!data && !error) {
return ;
}
return (
<>
+ {!isHttps && (
+
+ )}
{
route: '/settings/notifications/email',
regex: /^\/settings\/notifications\/email/,
},
+ {
+ text: intl.formatMessage(messages.webpush),
+ content: (
+
+
+ {intl.formatMessage(messages.webpush)}
+
+ ),
+ route: '/settings/notifications/webpush',
+ regex: /^\/settings\/notifications\/webpush/,
+ },
{
text: 'Discord',
content: (
@@ -103,17 +114,6 @@ const SettingsNotifications: React.FC = ({ children }) => {
route: '/settings/notifications/telegram',
regex: /^\/settings\/notifications\/telegram/,
},
- {
- text: intl.formatMessage(messages.webpush),
- content: (
-
-
- {intl.formatMessage(messages.webpush)}
-
- ),
- route: '/settings/notifications/webpush',
- regex: /^\/settings\/notifications\/webpush/,
- },
{
text: intl.formatMessage(messages.webhook),
content: (
diff --git a/src/i18n/locale/en.json b/src/i18n/locale/en.json
index e6961f51..855f3c9c 100644
--- a/src/i18n/locale/en.json
+++ b/src/i18n/locale/en.json
@@ -290,6 +290,7 @@
"components.Settings.Notifications.NotificationsSlack.webhookUrl": "Webhook URL",
"components.Settings.Notifications.NotificationsSlack.webhookUrlTip": "Create an Incoming Webhook integration",
"components.Settings.Notifications.NotificationsWebPush.agentenabled": "Enable Agent",
+ "components.Settings.Notifications.NotificationsWebPush.httpsRequirement": "In order to receive web push notifications, Overseerr must be served over HTTPS.",
"components.Settings.Notifications.NotificationsWebPush.toastWebPushTestFailed": "Web push test notification failed to send.",
"components.Settings.Notifications.NotificationsWebPush.toastWebPushTestSending": "Sending web push test notification…",
"components.Settings.Notifications.NotificationsWebPush.toastWebPushTestSuccess": "Web push test notification sent!",