Jake Vanderwerf
2025-12-21 3aada9949d51024a92a8b5c6cb70d12f9c3cac16
assets/js/concise/Integrations.js
File was renamed from assets/js/dash/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();
      }
   });
});