summaryrefslogtreecommitdiff
path: root/static/src/mailinglist/unsubscribe.md
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2021-08-30 10:58:12 -0600
committerBrian Picciano <mediocregopher@gmail.com>2021-08-30 10:58:12 -0600
commit3e9a17abb9a9d63af3c260fba9dc404dd9c59ade (patch)
tree48065b5b454176634b1e03beaa580d8c06e68320 /static/src/mailinglist/unsubscribe.md
parent15ae483fadbd136acefcd602b2f2ac5a83165c73 (diff)
fix finalize and unsubscribe pages by making them use new api module
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>