Skip to content

Commit

Permalink
Fix stacked alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
therealslimhsiehdy committed Oct 29, 2024
1 parent c0e740f commit 9459fa9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/registrar/assets/js/get-gov.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function deleteMember(member_delete_url, pageToDisplay) {
*/
function addAlert(alertClass, alertMessage) {
let toggleableAlertDiv = document.getElementById("toggleable-alert");
this.resetAlert();
this.resetAlerts();
toggleableAlertDiv.classList.add(`usa-alert--${alertClass}`);
let alertParagraph = toggleableAlertDiv.querySelector(".usa-alert__text");
alertParagraph.innerHTML = alertMessage
Expand All @@ -290,7 +290,11 @@ function addAlert(alertClass, alertMessage) {
* Resets the reusable alert message
*
*/
function resetAlert() {
function resetAlerts() {
// Create a list of any alert that's leftover and remove
document.querySelectorAll(".usa-alert:not(#toggleable-alert)").forEach(alert => {
alert.remove();
});
let toggleableAlertDiv = document.getElementById("toggleable-alert");
toggleableAlertDiv.classList.remove('usa-alert--error');
toggleableAlertDiv.classList.remove('usa-alert--success');
Expand Down
3 changes: 0 additions & 3 deletions src/registrar/templates/portfolio_members.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
{% endblock %}

{% block portfolio_content %}
{% block messages %}
{% include "includes/form_messages.html" %}
{% endblock %}

<div id="main-content">
<div id="toggleable-alert" class="usa-alert usa-alert--slim margin-bottom-2 display-none">
Expand Down
10 changes: 4 additions & 6 deletions src/registrar/views/portfolios.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def post(self, request, pk):

support_url = "https://get.gov/contact/"

error_message = ''
error_message = ""

if active_requests_count > 0:
# If they have any in progress requests
Expand All @@ -133,14 +133,12 @@ def post(self, request, pk):
if error_message:
if request.headers.get("X-Requested-With") == "XMLHttpRequest":
return JsonResponse(
{
"error": error_message
},
{"error": error_message},
status=400,
)
else:
messages.error(request, error_message)
return redirect(reverse('member', kwargs={'pk': pk}))
return redirect(reverse("member", kwargs={"pk": pk}))

# passed all error conditions
portfolio_member_permission.delete()
Expand All @@ -150,7 +148,7 @@ def post(self, request, pk):
return JsonResponse({"success": success_message}, status=200)
else:
messages.success(request, success_message)
return redirect(reverse('members'))
return redirect(reverse("members"))


class PortfolioMemberEditView(PortfolioMemberEditPermissionView, View):
Expand Down

0 comments on commit 9459fa9

Please sign in to comment.