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) {
|
||||
try {
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const subToken = urlParams.get('subToken');
|
||||
|
||||
if (!subToken) throw "No subscription token provided";
|
||||
|
||||
const api = await import("/assets/api.js");
|
||||
|
||||
await api.call('POST', '/api/mailinglist/finalize', {
|
||||
body: { subToken },
|
||||
});
|
||||
|
||||
resultSpan.className = "success";
|
||||
resultSpan.innerHTML = "Your email subscription has been finalized! Please go on about your day.";
|
||||
|
||||
} catch (e) {
|
||||
resultSpan.className = "fail";
|
||||
resultSpan.innerHTML = errStr;
|
||||
resultSpan.innerHTML = e;
|
||||
}
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const subToken = urlParams.get('subToken');
|
||||
|
||||
if (!subToken) {
|
||||
setErr("No subscription token provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const finalizeForm = new FormData();
|
||||
finalizeForm.append('subToken', subToken);
|
||||
|
||||
const finalizeReq = new Request('/api/mailinglist/finalize', {
|
||||
method: 'POST',
|
||||
body: finalizeForm,
|
||||
});
|
||||
|
||||
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.";
|
||||
|
||||
})();
|
||||
|
||||
</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) {
|
||||
try {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const unsubToken = urlParams.get('unsubToken');
|
||||
|
||||
if (!unsubToken) throw "No unsubscribe token provided";
|
||||
|
||||
const api = await import("/assets/api.js");
|
||||
|
||||
await api.call('POST', '/api/mailinglist/unsubscribe', {
|
||||
body: { unsubToken },
|
||||
});
|
||||
|
||||
resultSpan.className = "success";
|
||||
resultSpan.innerHTML = "You have been unsubscribed! Please go on about your day.";
|
||||
|
||||
} catch (e) {
|
||||
resultSpan.className = "fail";
|
||||
resultSpan.innerHTML = errStr;
|
||||
resultSpan.innerHTML = e;
|
||||
}
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const unsubToken = urlParams.get('unsubToken');
|
||||
|
||||
if (!unsubToken) {
|
||||
setErr("No unsubscribe token provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const unsubscribeForm = new FormData();
|
||||
unsubscribeForm.append('unsubToken', unsubToken);
|
||||
|
||||
const unsubscribeReq = new Request('/api/mailinglist/unsubscribe', {
|
||||
method: 'POST',
|
||||
body: unsubscribeForm,
|
||||
});
|
||||
|
||||
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.";
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user