summaryrefslogtreecommitdiff
path: root/static/src/mailinglist/finalize.md
diff options
context:
space:
mode:
Diffstat (limited to 'static/src/mailinglist/finalize.md')
-rw-r--r--static/src/mailinglist/finalize.md42
1 files changed, 17 insertions, 25 deletions
diff --git a/static/src/mailinglist/finalize.md b/static/src/mailinglist/finalize.md
index fe8f741..56878b9 100644
--- a/static/src/mailinglist/finalize.md
+++ b/static/src/mailinglist/finalize.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,39 +16,29 @@ nofollow: true
<script>
(async () => {
+
const resultSpan = document.getElementById("result");
-
- function setErr(errStr) {
- resultSpan.className = "fail";
- resultSpan.innerHTML = errStr;
- }
- const urlParams = new URLSearchParams(window.location.search);
- const subToken = urlParams.get('subToken');
+ try {
- if (!subToken) {
- setErr("No subscription token provided");
- return;
- }
+ const urlParams = new URLSearchParams(window.location.search);
+ const subToken = urlParams.get('subToken');
- const finalizeForm = new FormData();
- finalizeForm.append('subToken', subToken);
+ if (!subToken) throw "No subscription token provided";
- const finalizeReq = new Request('/api/mailinglist/finalize', {
- method: 'POST',
- body: finalizeForm,
- });
+ const api = await import("/assets/api.js");
- const res = await fetch(finalizeReq)
- .then(response => response.json());
+ await api.call('POST', '/api/mailinglist/finalize', {
+ body: { subToken },
+ });
- if (res.error) {
- setErr(res.error);
- return;
- }
+ resultSpan.className = "success";
+ resultSpan.innerHTML = "Your email subscription has been finalized! Please go on about your day.";
- resultSpan.className = "success";
- resultSpan.innerHTML = "Your email subscription has been finalized! Please go on about your day.";
+ } catch (e) {
+ resultSpan.className = "fail";
+ resultSpan.innerHTML = e;
+ }
})();