From fff721dd185f5b97f7ae7a6e64189e55887ff590 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 05 Jul 2026 18:36:57 +0000
Subject: [PATCH] =Cleaning up the Square integration (still a bit more to do yet). Also majorly overhauled /rest/ files to ignore a rest request 'user' paramater, and rely on get_current_user_id() instead.

---
 assets/js/concise/Login.js |   78 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/assets/js/concise/Login.js b/assets/js/concise/Login.js
index 88528e8..1d51b30 100644
--- a/assets/js/concise/Login.js
+++ b/assets/js/concise/Login.js
@@ -14,10 +14,84 @@
 		for (let [id, form] of Object.entries(this.ui)) {
 			if (form) {
 				this.forms[id] =  window.jvbForm.registerForm(form, {
-					cache: false,
-					useQueue: false,
+					cache: 		false,
+					showStatus: false,
+					useQueue: 	false,
 				});
 
+				if (id === 'magic') {
+					window.jvbForm.subscribe((event, data) => {
+
+						if (data.config === this.forms[id]) {
+							if (event === 'form-submit') {
+								form.hidden = true;
+								this.spinner = window.jvbTemplates.create('spinner', {});
+								form.parentElement.append(this.spinner);
+
+							} else if (event === 'form-success') {
+								form.hidden = true;
+								let el = window.jvbTemplates.create('formSummary', {config: form, changes: {}});
+								Array.from(el.children).forEach(ch => {
+									if (ch.tagName === 'H2') {
+										ch.textContent = 'Check your email!';
+									} else if (ch.classList.contains('message')) {
+										let children = Array.from(ch.children);
+										children[0].textContent = 'You\'ll find a magic link to log in in your email';
+										children[1].textContent = 'If you can\'t find it - check your spam folder.';
+										children[2].textContent = 'The link will expire in 15 minutes.';
+										children[3].remove();
+									} else if (ch.classList.contains('summary')) {
+										ch.remove();
+									}
+								});
+								if (this.spinner) {
+									this.spinner.remove();
+								}
+								form.parentElement.append(el);
+							} else if (event === 'form-error' ) {
+								if (this.spinner) {
+									this.spinner.remove();
+								}
+								if (Object.hasOwn(data.data, 'code') && data.data.code === 'rate_limit_exceeded') {
+
+									let el = window.jvbTemplates.create('formSummary', {config: form, changes: {}});
+									Array.from(el.children).forEach(ch => {
+										if (ch.tagName === 'H2') {
+											ch.textContent = 'Slow down there!';
+										} else if (ch.classList.contains('message')) {
+											let children = Array.from(ch.children);
+											children[0].textContent = 'You tried submitting a few too many times in a short window.';
+											children[1].textContent = 'Try again in an hour or so.';
+											children[2].remove();
+											children[3].remove();
+										} else if (ch.classList.contains('summary')) {
+											ch.remove();
+										}
+									});
+									form.parentElement.append(el);
+								} else {
+									let el = window.jvbTemplates.create('formSummary', {config: form, changes: {}});
+									Array.from(el.children).forEach(ch => {
+										if (ch.tagName === 'H2') {
+											ch.textContent = 'Something went wrong.';
+										} else if (ch.classList.contains('message')) {
+											let children = Array.from(ch.children);
+											children[0].textContent = 'We aren\'t exactly sure what.';
+											children[1].textContent = 'Try clearing your cookies and trying again. If the problem persists, let us know!';
+											children[2].remove();
+											children[3].remove();
+										} else if (ch.classList.contains('summary')) {
+											ch.remove();
+										}
+									});
+									form.parentElement.append(el);
+								}
+							}
+						}
+
+					});
+				}
+
 			}
 		}
 	}

--
Gitblit v1.10.0