fix finalize and unsubscribe pages by making them use new api module
This commit is contained in:
parent
15ae483fad
commit
3e9a17abb9
@ -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,30 @@ 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 subToken = urlParams.get('subToken');
|
||||
|
||||
if (!subToken) {
|
||||
setErr("No subscription token provided");
|
||||
return;
|
||||
}
|
||||
if (!subToken) throw "No subscription token provided";
|
||||
|
||||
const finalizeForm = new FormData();
|
||||
finalizeForm.append('subToken', subToken);
|
||||
const api = await import("/assets/api.js");
|
||||
|
||||
const finalizeReq = new Request('/api/mailinglist/finalize', {
|
||||
method: 'POST',
|
||||
body: finalizeForm,
|
||||
await api.call('POST', '/api/mailinglist/finalize', {
|
||||
body: { subToken },
|
||||
});
|
||||
|
||||
const res = await fetch(finalizeReq)
|
||||
.then(response => response.json());
|
||||
|
||||
if (res.error) {
|
||||
setErr(res.error);
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
@ -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');
|
||||
|
||||
if (!unsubToken) {
|
||||
setErr("No unsubscribe token provided");
|
||||
return;
|
||||
}
|
||||
if (!unsubToken) throw "No unsubscribe token provided";
|
||||
|
||||
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());
|
||||
|
||||
if (res.error) {
|
||||
setErr(res.error);
|
||||
return;
|
||||
}
|
||||
|
||||
resultSpan.className = "success";
|
||||
resultSpan.innerHTML = "You have been unsubscribed! Please go on about your day.";
|
||||
|
||||
} catch (e) {
|
||||
resultSpan.className = "fail";
|
||||
resultSpan.innerHTML = e;
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user