Skip to content

Commit

Permalink
administration ui: Reset loading state in finally block
Browse files Browse the repository at this point in the history
* Previously, the loading state was only reset upon successful completion of the user action. If an error occurred, such as a 403, the UI incorrectly remained in a "loading" state, leaving the button disabled and showing a loading indicator indefinitely. This change ensures that the loading state is reset under all circumstances by moving the setState call to a finally block.
* Removed the line resetting the loading state from the try block.
* Added a finally block to reset the loading state whether the promise is resolved or rejected.
  • Loading branch information
Samk13 authored and ntarocco committed May 2, 2024
1 parent a009b13 commit b71d23b
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is part of Invenio.
* Copyright (C) 2022 CERN.
* Copyright (C) 2024 KTH Royal Institute of Technology.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -84,14 +85,15 @@ export class UserActions extends Component {
try {
await this.cancellableAction.promise;
addNotification(successNotification);
this.setState({ loading: false });
successCallback();
} catch (e) {
addNotification({
title: i18next.t("Error"),
content: e.toString(),
type: "error",
});
} finally {
this.setState({ loading: false });
}
}
};
Expand Down

0 comments on commit b71d23b

Please sign in to comment.