diff --git a/app/dashboard/templates/dashboard/alias_contact_manager.html b/app/dashboard/templates/dashboard/alias_contact_manager.html index a359e397..386a8989 100644 --- a/app/dashboard/templates/dashboard/alias_contact_manager.html +++ b/app/dashboard/templates/dashboard/alias_contact_manager.html @@ -98,11 +98,32 @@ {% set contact = contact_info.contact %}
-
- {{ contact.website_email }} - {% if contact.pgp_finger_print %} - 🗝 - {% endif %} +
+
+ {{ contact.website_email }} + {% if contact.pgp_finger_print %} + 🗝 + {% endif %} +
+ +
+ +
@@ -216,8 +237,45 @@ } } }) - - }); + + $(".enable-disable-contact").change(async function () { + let contactID = $(this).data("contact"); + let contactEmail = $(this).data("contact-email"); + + await blockContact(contactID, contactEmail); + }) + + async function blockContact(contactID, contactEmail) { + let oldValue; + try { + let res = await fetch(`/api/contacts/${contactID}/toggle`, { + method: "POST", + headers: { + "Content-Type": "application/json", + } + }); + + if (res.ok) { + let json = await res.json(); + + if (json.block_forward) { + toastr.success(`${contactEmail} is blocked`); + } else { + toastr.success(`${contactEmail} is unblocked`); + } + } else { + toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error"); + // reset to the original value + oldValue = !$(this).prop("checked"); + $(this).prop("checked", oldValue); + } + } catch (e) { + toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error"); + // reset to the original value + oldValue = !$(this).prop("checked"); + $(this).prop("checked", oldValue); + } + } {% endblock %} \ No newline at end of file