From a359672ebafffef742858814f0faa918e0341aa3 Mon Sep 17 00:00:00 2001 From: sct Date: Tue, 24 Nov 2020 15:51:56 +0000 Subject: [PATCH] feat: add application url config to main settings ui --- overseerr-api.yml | 6 +- server/routes/settings.ts | 3 +- src/components/Settings/SettingsMain.tsx | 140 +++++++++++++----- .../Settings/SettingsNotifications.tsx | 9 ++ 4 files changed, 120 insertions(+), 38 deletions(-) diff --git a/overseerr-api.yml b/overseerr-api.yml index 9921e09f..667f4508 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -54,8 +54,10 @@ components: apiKey: type: string example: 'anapikey' - required: - - apiKey + readOnly: true + applicationUrl: + type: string + example: https://os.example.com PlexLibrary: type: object properties: diff --git a/server/routes/settings.ts b/server/routes/settings.ts index fe082600..424bb4dc 100644 --- a/server/routes/settings.ts +++ b/server/routes/settings.ts @@ -15,6 +15,7 @@ import logger from '../logger'; import { scheduledJobs } from '../job/schedule'; import { Permission } from '../lib/permissions'; import { isAuthenticated } from '../middleware/auth'; +import { merge } from 'lodash'; const settingsRoutes = Router(); @@ -27,7 +28,7 @@ settingsRoutes.get('/main', (_req, res) => { settingsRoutes.post('/main', (req, res) => { const settings = getSettings(); - settings.main = req.body; + settings.main = merge(settings.main, req.body); settings.save(); return res.status(200).json(settings.main); diff --git a/src/components/Settings/SettingsMain.tsx b/src/components/Settings/SettingsMain.tsx index 6eeb19da..cf009798 100644 --- a/src/components/Settings/SettingsMain.tsx +++ b/src/components/Settings/SettingsMain.tsx @@ -3,9 +3,21 @@ import useSWR from 'swr'; import LoadingSpinner from '../Common/LoadingSpinner'; import type { MainSettings } from '../../../server/lib/settings'; import CopyButton from './CopyButton'; +import { Form, Formik, Field } from 'formik'; +import axios from 'axios'; +import Button from '../Common/Button'; +import { defineMessages, useIntl } from 'react-intl'; + +const messages = defineMessages({ + save: 'Save Changes', + saving: 'Saving...', +}); const SettingsMain: React.FC = () => { - const { data, error } = useSWR('/api/v1/settings/main'); + const intl = useIntl(); + const { data, error, revalidate } = useSWR( + '/api/v1/settings/main' + ); if (!data && !error) { return ; @@ -22,40 +34,98 @@ const SettingsMain: React.FC = () => {

-
- -
-
- - - -
-
-
+ { + try { + await axios.post('/api/v1/settings/main', { + applicationUrl: values.applicationUrl, + }); + } catch (e) { + // TODO show error + } finally { + revalidate(); + } + }} + > + {({ errors, touched, isSubmitting }) => { + return ( +
+
+ +
+
+ + + +
+
+
+
+ +
+
+ +
+
+
+
+
+ + + +
+
+
+ ); + }} +
); diff --git a/src/components/Settings/SettingsNotifications.tsx b/src/components/Settings/SettingsNotifications.tsx index 7b06772f..9c54d4f6 100644 --- a/src/components/Settings/SettingsNotifications.tsx +++ b/src/components/Settings/SettingsNotifications.tsx @@ -53,6 +53,15 @@ const SettingsNotifications: React.FC = ({ children }) => { return ( <> +
+

+ Notification Settings +

+

+ Here you can pick and choose what types of notifications to send and + through what types of services. +

+