From 0c1fda4979684b40dfd0b374049aabd5e3aaf2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Fri, 1 Sep 2023 13:36:42 +0200 Subject: [PATCH] Fix: Show error message if user settings can't be saved When the http request returned an error the error message was not shown while changing the user settings in the corresponding dialog. It broke while introducing the JS form validation because its validate function isn't a promise in contrast to the onSave handler. --- src/web/pages/usersettings/dialog.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/web/pages/usersettings/dialog.js b/src/web/pages/usersettings/dialog.js index eaaba0ecaa..784a936945 100644 --- a/src/web/pages/usersettings/dialog.js +++ b/src/web/pages/usersettings/dialog.js @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -import React, {useState} from 'react'; +import React, {useCallback, useState} from 'react'; import styled from 'styled-components'; @@ -169,11 +169,17 @@ let UserSettingsDialog = ({ const [error, setError] = useState(); const [formValues, handleValueChange] = useFormValues(settings); + const handleSave = useCallback(values => { + onSave(values).catch(err => { + setError(err.message); + }) + }, [onSave]); + const {hasError, errors, validate} = useFormValidation( userSettingsRules, formValues, { - onValidationSuccess: onSave, + onValidationSuccess: handleSave, onValidationError: setError, fieldsToValidate, },