Skip to content

Commit

Permalink
Fix: Show error message if user settings can't be saved
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjoernricks committed Sep 1, 2023
1 parent b752238 commit 0c1fda4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/web/pages/usersettings/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React, {useState} from 'react';
import React, {useCallback, useState} from 'react';

import styled from 'styled-components';

Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit 0c1fda4

Please sign in to comment.