From db42d89dd64f83472d7bec25ed6dce2e5f2de5c0 Mon Sep 17 00:00:00 2001 From: bsourisse Date: Fri, 3 Mar 2023 18:47:03 +0100 Subject: [PATCH] feat: init textarea for Apprise URLs --- .../AppriseAlertSettings.js | 98 ++++++++++++++++--- .../UserSettings/UserSettings.module.css | 14 +++ 2 files changed, 98 insertions(+), 14 deletions(-) diff --git a/Containers/UserSettings/AppriseAlertSettings/AppriseAlertSettings.js b/Containers/UserSettings/AppriseAlertSettings/AppriseAlertSettings.js index 76926b1..0cf1e77 100644 --- a/Containers/UserSettings/AppriseAlertSettings/AppriseAlertSettings.js +++ b/Containers/UserSettings/AppriseAlertSettings/AppriseAlertSettings.js @@ -5,6 +5,7 @@ import 'react-toastify/dist/ReactToastify.css'; import classes from '../UserSettings.module.css'; import { useState } from 'react'; import { SpinnerCircularFixed } from 'spinners-react'; +import { useForm } from 'react-hook-form'; //Components import Error from '../../../Components/UI/Error/Error'; @@ -23,10 +24,19 @@ export default function AppriseAlertSettings() { //Callback > re-enabled button after notification. onClose: () => setDisabled(false), }; + let appriseURLs; + + const { + register, + handleSubmit, + formState: { errors, isSubmitting, isValid }, + } = useForm({ mode: 'onBlur' }); ////State - const [isLoading, setIsLoading] = useState(true); + const [checkIsLoading, setCheckIsLoading] = useState(true); const [testIsLoading, setTestIsLoading] = useState(false); + const [formIsLoading, setFormIsLoading] = useState(false); + const [formIsSaved, setFormIsSaved] = useState(false); const [error, setError] = useState(); const [disabled, setDisabled] = useState(false); const [checked, setChecked] = useState(); @@ -44,7 +54,7 @@ export default function AppriseAlertSettings() { }, }); setChecked((await response.json()).appriseAlert); - setIsLoading(false); + setCheckIsLoading(false); } catch (error) { console.log('Fetching Apprise alert setting failed.'); } @@ -53,6 +63,7 @@ export default function AppriseAlertSettings() { }, []); ////Functions + //Switch to enable/disable Apprise notifications const onChangeSwitchHandler = async (data) => { //Remove old error setError(); @@ -84,6 +95,38 @@ export default function AppriseAlertSettings() { } }; + //Form submit handler to modify Apprise services + const formSubmitHandler = async (data) => { + console.log(data); + // //Remove old error + // setError(); + // //Loading button on submit to avoid multiple send. + // setFormIsLoading(true); + // //POST API to update Apprise Services + // const response = await fetch('/api/account/updateAppriseServices', { + // method: 'PUT', + // headers: { + // 'Content-type': 'application/json', + // }, + // body: JSON.stringify(data), + // }); + // const result = await response.json(); + + // if (!response.ok) { + // setFormIsLoading(false); + // setError(result.message); + // setTimeout(() => setError(), 4000); + // } else { + // setFormIsLoading(false); + // setInfo(true); + // toast.success('Email edited !', toastOptions); + // } + + //TEST + setFormIsSaved(true); + setTimeout(() => setFormIsSaved(false), 3000); + }; + return ( <> {/* APPRISE ALERT */} @@ -93,7 +136,7 @@ export default function AppriseAlertSettings() {
- {isLoading ? ( + {checkIsLoading ? ( )} - +
+
+ Apprise URLs +
+
+ {formIsLoading && ( + + )} + {formIsSaved && ( +
+ ✅ Apprise configuration has been saved. +
+ )} +
+
-
- Apprise URLs -
- +