From 3aada9949d51024a92a8b5c6cb70d12f9c3cac16 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 21 Dec 2025 19:59:48 +0000
Subject: [PATCH] =auth refactored via rest, referral system set up for Jane, some javascript consolidation

---
 assets/js/concise/Integrations.js |   27 ++++++++++-----------------
 1 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/assets/js/dash/Integrations.js b/assets/js/concise/Integrations.js
similarity index 95%
rename from assets/js/dash/Integrations.js
rename to assets/js/concise/Integrations.js
index e0d9ed6..0beba0b 100644
--- a/assets/js/dash/Integrations.js
+++ b/assets/js/concise/Integrations.js
@@ -163,7 +163,6 @@
 			return;
 		}
 
-		console.log('Clicked!');
 		if (e.target.tagName === 'BUTTON' || e.target.closest('button')) {
 			e.preventDefault();
 			let target = e.target.tagName === 'BUTTON' ? e.target : e.target.closest('button');
@@ -299,7 +298,7 @@
 			const data = {
 				service: service,
 				action: action,
-				user_id: jvbSettings.currentUser,
+				user_id: window.auth.getUser(),
 				data: {}
 			};
 			if (!isButton) {
@@ -315,15 +314,13 @@
 				}
 			}
 
-			console.log('Sending Data:', data);
-
 			// Make API request
 			const response = await fetch(
 				jvbSettings.api + 'integrations', {
 				method: 'POST',
 				headers: {
 					'Content-Type': 'application/json',
-					'X-WP-Nonce': jvbSettings.nonce
+					'X-WP-Nonce': window.auth.getNonce()
 				},
 				body: JSON.stringify(data)
 			});
@@ -340,7 +337,6 @@
 						this.showNotification('Settings saved successfully', 'success');
 						break;
 				}
-				console.log(result);
 				this.updateUI(form, status);
 
 				if (result.reload) {
@@ -349,7 +345,6 @@
 					}, 50);
 				}
 			} else {
-				console.log (result);
 				this.updateUI(form, 'error', result.message??'');
 				this.showNotification(result.message || 'Operation failed', 'error');
 			}
@@ -366,7 +361,6 @@
 	{
 		let allowed = ['connected', 'disconnected', 'hasChanges', 'syncing', 'error'];
 		if (!allowed.includes(state)) {
-			console.log('Invalid state: ', state);
 			return;
 		}
 		let defaults = {
@@ -391,9 +385,7 @@
 
 		form.classList.remove(...allowed);
 		form.classList.add(state, 'flash');
-		console.log(form);
 		let status = form.querySelector('.setup .text');
-		console.log(status);
 		status.textContent = message;
 		// Enable/disable buttons
 		if (state === 'syncing') {
@@ -415,7 +407,6 @@
 	// Add popup indicator to URL
 	url += (url.indexOf('?') > -1 ? '&' : '?') + 'popup=1';
 
-	console.log('Opening OAuth popup for', service, 'with URL:', url);
 
 	const popup = window.open(
 		url,
@@ -430,8 +421,6 @@
 
 	// Set up listener for OAuth completion
 	window.jvbOAuthComplete = function(completedService, success, message) {
-		console.log('OAuth complete:', completedService, success, message);
-
 		if (completedService === service) {
 			if (success) {
 				// Show success message
@@ -459,7 +448,6 @@
 		try {
 			if (popup.closed) {
 				clearInterval(checkPopup);
-				console.log('OAuth popup closed');
 				// Refresh anyway in case auth completed
 				setTimeout(() => {
 					jvbRefreshIntegration(service);
@@ -475,14 +463,13 @@
 
 // Refresh integration display
 window.jvbRefreshIntegration = function(service) {
-	console.log('Refreshing integration:', service);
 
 	// Use your REST API to check connection status
 	fetch(jvbSettings.api + 'integrations', {
 		method: 'POST',
 		headers: {
 			'Content-Type': 'application/json',
-			'X-WP-Nonce': jvbSettings.nonce
+			'X-WP-Nonce': window.auth.getNonce()
 		},
 		body: JSON.stringify({
 			service: service,
@@ -521,5 +508,11 @@
 			location.reload();
 		});
 };
+document.addEventListener('DOMContentLoaded', async function() {
+	window.auth.subscribe((event) => {
+		if (event === 'auth-loaded') {
+			window.integrations = new IntegrationsManager();
+		}
+	});
+});
 
-window.integrations = new IntegrationsManager();

--
Gitblit v1.10.0