Molodetz blogrol volgens DPP-template
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
export class TermsGate {
|
||||
constructor(dialog) {
|
||||
this.dialog = dialog;
|
||||
this.pending = null;
|
||||
}
|
||||
|
||||
async intercept(response) {
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (payload.error?.code !== "terms_required") {
|
||||
return false;
|
||||
}
|
||||
if (!this.pending) {
|
||||
this.pending = this.dialog
|
||||
.confirm(`De voorwaarden zijn gewijzigd (versie ${payload.error.terms_version}). Accepteren en doorgaan?`)
|
||||
.then(async (accepted) => {
|
||||
if (!accepted) {
|
||||
return false;
|
||||
}
|
||||
const result = await fetch("/voorwaarden/accept", {
|
||||
method: "POST",
|
||||
credentials: "same-origin",
|
||||
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
||||
body: "{}",
|
||||
});
|
||||
return result.ok;
|
||||
})
|
||||
.finally(() => {
|
||||
setTimeout(() => { this.pending = null; }, 0);
|
||||
});
|
||||
}
|
||||
return this.pending;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user