summaryrefslogtreecommitdiff
path: root/static/src/mailinglist/unsubscribe.md
diff options
context:
space:
mode:
Diffstat (limited to 'static/src/mailinglist/unsubscribe.md')
-rw-r--r--static/src/mailinglist/unsubscribe.md41
1 files changed, 16 insertions, 25 deletions
diff --git a/static/src/mailinglist/unsubscribe.md b/static/src/mailinglist/unsubscribe.md
index 6a118a0..cacd212 100644
--- a/static/src/mailinglist/unsubscribe.md
+++ b/static/src/mailinglist/unsubscribe.md
@@ -4,6 +4,8 @@ title: ""
nofollow: true
---
+<script async type="module" src="/assets/api.js"></script>
+
<style>
#result.success { color: green; }
#result.fail { color: red; }
@@ -14,40 +16,29 @@ nofollow: true
<script>
(async () => {
+
const resultSpan = document.getElementById("result");
- function setErr(errStr) {
- resultSpan.className = "fail";
- resultSpan.innerHTML = errStr;
- }
+ try {
+ const urlParams = new URLSearchParams(window.location.search);
+ const unsubToken = urlParams.get('unsubToken');
- const urlParams = new URLSearchParams(window.location.search);
- const unsubToken = urlParams.get('unsubToken');
+ if (!unsubToken) throw "No unsubscribe token provided";
- if (!unsubToken) {
- setErr("No unsubscribe token provided");
- return;
- }
-
- const unsubscribeForm = new FormData();
- unsubscribeForm.append('unsubToken', unsubToken);
+ const api = await import("/assets/api.js");
- const unsubscribeReq = new Request('/api/mailinglist/unsubscribe', {
- method: 'POST',
- body: unsubscribeForm,
- });
+ await api.call('POST', '/api/mailinglist/unsubscribe', {
+ body: { unsubToken },
+ });
- const res = await fetch(unsubscribeReq)
- .then(response => response.json());
+ resultSpan.className = "success";
+ resultSpan.innerHTML = "You have been unsubscribed! Please go on about your day.";
- if (res.error) {
- setErr(res.error);
- return;
+ } catch (e) {
+ resultSpan.className = "fail";
+ resultSpan.innerHTML = e;
}
- resultSpan.className = "success";
- resultSpan.innerHTML = "You have been unsubscribed! Please go on about your day.";
-
})();
</script>