mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
feat: PWA Support (#1488)
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
import axios from 'axios';
|
||||
import { Field, Form, Formik } from 'formik';
|
||||
import { useRouter } from 'next/router';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
import { useToasts } from 'react-toast-notifications';
|
||||
import useSWR from 'swr';
|
||||
import * as Yup from 'yup';
|
||||
import { UserSettingsNotificationsResponse } from '../../../../../server/interfaces/api/userSettingsInterfaces';
|
||||
import {
|
||||
hasNotificationAgentEnabled,
|
||||
NotificationAgentType,
|
||||
} from '../../../../../server/lib/notifications/agenttypes';
|
||||
import { useUser } from '../../../../hooks/useUser';
|
||||
import globalMessages from '../../../../i18n/globalMessages';
|
||||
import Button from '../../../Common/Button';
|
||||
import LoadingSpinner from '../../../Common/LoadingSpinner';
|
||||
import { ALL_NOTIFICATIONS } from '../../../NotificationTypeSelector';
|
||||
|
||||
const messages = defineMessages({
|
||||
discordsettingssaved: 'Discord notification settings saved successfully!',
|
||||
@@ -30,18 +27,11 @@ const UserNotificationsDiscord: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
const { addToast } = useToasts();
|
||||
const router = useRouter();
|
||||
const [notificationAgents, setNotificationAgents] = useState(0);
|
||||
const { user } = useUser({ id: Number(router.query.userId) });
|
||||
const { data, error, revalidate } = useSWR<UserSettingsNotificationsResponse>(
|
||||
user ? `/api/v1/user/${user?.id}/settings/notifications` : null
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setNotificationAgents(
|
||||
data?.notificationAgents ?? NotificationAgentType.EMAIL
|
||||
);
|
||||
}, [data]);
|
||||
|
||||
const UserNotificationsDiscordSchema = Yup.object().shape({
|
||||
discordId: Yup.string()
|
||||
.when('enableDiscord', {
|
||||
@@ -61,10 +51,7 @@ const UserNotificationsDiscord: React.FC = () => {
|
||||
return (
|
||||
<Formik
|
||||
initialValues={{
|
||||
enableDiscord: hasNotificationAgentEnabled(
|
||||
NotificationAgentType.DISCORD,
|
||||
data?.notificationAgents ?? NotificationAgentType.EMAIL
|
||||
),
|
||||
enableDiscord: !!data?.notificationTypes.discord,
|
||||
discordId: data?.discordId,
|
||||
}}
|
||||
validationSchema={UserNotificationsDiscordSchema}
|
||||
@@ -72,11 +59,13 @@ const UserNotificationsDiscord: React.FC = () => {
|
||||
onSubmit={async (values) => {
|
||||
try {
|
||||
await axios.post(`/api/v1/user/${user?.id}/settings/notifications`, {
|
||||
notificationAgents,
|
||||
pgpKey: data?.pgpKey,
|
||||
discordId: values.discordId,
|
||||
telegramChatId: data?.telegramChatId,
|
||||
telegramSendSilently: data?.telegramSendSilently,
|
||||
notificationTypes: {
|
||||
discord: values.enableDiscord ? ALL_NOTIFICATIONS : 0,
|
||||
},
|
||||
});
|
||||
addToast(intl.formatMessage(messages.discordsettingssaved), {
|
||||
appearance: 'success',
|
||||
@@ -92,7 +81,7 @@ const UserNotificationsDiscord: React.FC = () => {
|
||||
}
|
||||
}}
|
||||
>
|
||||
{({ errors, touched, isSubmitting, isValid, values, setFieldValue }) => {
|
||||
{({ errors, touched, isSubmitting, isValid }) => {
|
||||
return (
|
||||
<Form className="section">
|
||||
{data?.discordEnabled && (
|
||||
@@ -105,21 +94,6 @@ const UserNotificationsDiscord: React.FC = () => {
|
||||
type="checkbox"
|
||||
id="enableDiscord"
|
||||
name="enableDiscord"
|
||||
checked={hasNotificationAgentEnabled(
|
||||
NotificationAgentType.DISCORD,
|
||||
notificationAgents
|
||||
)}
|
||||
onChange={() => {
|
||||
setNotificationAgents(
|
||||
hasNotificationAgentEnabled(
|
||||
NotificationAgentType.DISCORD,
|
||||
notificationAgents
|
||||
)
|
||||
? notificationAgents - NotificationAgentType.DISCORD
|
||||
: notificationAgents + NotificationAgentType.DISCORD
|
||||
);
|
||||
setFieldValue('enableDiscord', !values.enableDiscord);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user