mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 03:58:39 +02:00
updated return of success message, handling success and error messages on members table
This commit is contained in:
parent
159180c3ac
commit
aa8faab8aa
3 changed files with 46 additions and 16 deletions
|
@ -2252,22 +2252,22 @@ class MembersTable extends LoadTableBase {
|
||||||
body: formData
|
body: formData
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 204) {
|
if (response.status === 200) {
|
||||||
// TODO: Add success alert with "You've removed member.email from the organization." text
|
// TODO: Add success alert with "You've removed member.email from the organization." text
|
||||||
console.log('Member successfully deleted');
|
response.json().then(data => {
|
||||||
// Update data and UI
|
if (data.success) {
|
||||||
this.loadTable(pageToDisplay, this.currentSortBy, this.currentOrder, this.scrollToTable, this.currentSearchTerm);
|
this.addAlert("success", data.success);
|
||||||
|
}
|
||||||
|
this.loadTable(pageToDisplay, this.currentSortBy, this.currentOrder, this.scrollToTable, this.currentSearchTerm);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// If the response isn't 204, handle the error response
|
// If the response isn't 204, handle the error response
|
||||||
return response.json().then(data => {
|
response.json().then(data => {
|
||||||
console.log("Member response not 204");
|
console.log("Member response not 200");
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
// TODO: We maybe don't need the consts above and have those
|
|
||||||
// responses in the portfolios.py JSON response. Formatting though?
|
|
||||||
|
|
||||||
// This should display the error given from backend for
|
// This should display the error given from backend for
|
||||||
// either only admin OR in progress requests
|
// either only admin OR in progress requests
|
||||||
this.displayErrorMessage(data.error);
|
this.addAlert("error", data.error);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unexpected status: ${response.status}`);
|
throw new Error(`Unexpected status: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
@ -2276,13 +2276,36 @@ class MembersTable extends LoadTableBase {
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error deleting member:', error);
|
console.error('Error deleting member:', error);
|
||||||
this.displayErrorMessage(error.message);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
displayErrorMessage(errorMessage) {
|
|
||||||
alert(errorMessage); // Just debugging for now
|
/**
|
||||||
}
|
* Adds an alert message to the page with an alert class.
|
||||||
|
*
|
||||||
|
* @param {string} alertClass - {error, warning, info, success}
|
||||||
|
* @param {string} alertMessage - The text that will be displayed
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
addAlert(alertClass, alertMessage) {
|
||||||
|
let toggleableAlertDiv = document.getElementById("toggleable-alert");
|
||||||
|
this.resetAlert();
|
||||||
|
toggleableAlertDiv.classList.add(`usa-alert--${alertClass}`);
|
||||||
|
let alertParagraph = toggleableAlertDiv.querySelector(".usa-alert__text");
|
||||||
|
alertParagraph.innerHTML = alertMessage
|
||||||
|
showElement(toggleableAlertDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the reusable alert message
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
resetAlert() {
|
||||||
|
let toggleableAlertDiv = document.getElementById("toggleable-alert");
|
||||||
|
toggleableAlertDiv.classList.remove('usa-alert--error');
|
||||||
|
toggleableAlertDiv.classList.remove('usa-alert--success');
|
||||||
|
hideElement(toggleableAlertDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,6 +14,13 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<div id="main-content">
|
<div id="main-content">
|
||||||
|
<div id="toggleable-alert" class="usa-alert usa-alert--slim margin-bottom-2 display-none">
|
||||||
|
<div class="usa-alert__body">
|
||||||
|
<p class="usa-alert__text ">
|
||||||
|
<!-- alert message will be conditionally populated by javascript -->
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="grid-row grid-gap">
|
<div class="grid-row grid-gap">
|
||||||
<div class="mobile:grid-col-12 tablet:grid-col-6">
|
<div class="mobile:grid-col-12 tablet:grid-col-6">
|
||||||
<h1 id="members-header">Members</h1>
|
<h1 id="members-header">Members</h1>
|
||||||
|
|
|
@ -122,7 +122,7 @@ class PortfolioMemberDeleteView(PortfolioMemberPermission, View):
|
||||||
|
|
||||||
portfolio_member_permission.delete()
|
portfolio_member_permission.delete()
|
||||||
|
|
||||||
return HttpResponse(status=204)
|
return JsonResponse({"success": f"You've removed {member.email} from the organization."}, status=200)
|
||||||
|
|
||||||
|
|
||||||
class PortfolioMemberEditView(PortfolioMemberEditPermissionView, View):
|
class PortfolioMemberEditView(PortfolioMemberEditPermissionView, View):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue