// retoor 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; } }