diff --git a/portal/index.html b/portal/index.html index ffa52d7..d950ef3 100644 --- a/portal/index.html +++ b/portal/index.html @@ -105,6 +105,18 @@
Online
+ + + + + Switch Business + + + + + + Add New Business + diff --git a/portal/login.html b/portal/login.html index 2b458ac..cd0f531 100644 --- a/portal/login.html +++ b/portal/login.html @@ -242,13 +242,23 @@ // Check if already logged in const savedToken = localStorage.getItem('payfrit_portal_token'); const savedBusiness = localStorage.getItem('payfrit_portal_business'); + const savedUserId = localStorage.getItem('payfrit_portal_userid'); if (savedToken && savedBusiness) { - // Verify token is still valid + // Already logged in with a business - redirect to portal this.verifyAndRedirect(savedToken, savedBusiness); return; } + if (savedToken && savedUserId) { + // Has token but no business selected (switching businesses) + // Skip login form, go directly to business selection + this.userToken = savedToken; + this.userId = parseInt(savedUserId); + this.loadBusinessesAndShow(); + return; + } + // Setup form handlers document.getElementById('loginForm').addEventListener('submit', (e) => { e.preventDefault(); @@ -256,6 +266,22 @@ }); }, + // Load businesses and show selection (for switching businesses) + async loadBusinessesAndShow() { + await this.loadBusinesses(); + + if (this.businesses.length === 0) { + // No businesses - go directly to wizard + this.startNewRestaurant(); + } else if (this.businesses.length === 1) { + // Single business - auto-login to it + this.selectBusinessById(this.businesses[0].BusinessID); + } else { + // Multiple businesses - show selection + this.showStep('business'); + } + }, + async verifyAndRedirect(token, businessId) { // Save business ID to localStorage and redirect localStorage.setItem('payfrit_portal_business', businessId); @@ -308,8 +334,11 @@ if (this.businesses.length === 0) { // No businesses - go directly to wizard this.startNewRestaurant(); + } else if (this.businesses.length === 1) { + // Single business - auto-login to it + this.selectBusinessById(this.businesses[0].BusinessID); } else { - // Show business selection (even if just one, so they can access wizard) + // Multiple businesses - show selection this.showStep('business'); } } else { diff --git a/portal/portal.js b/portal/portal.js index cec20b3..e256b01 100644 --- a/portal/portal.js +++ b/portal/portal.js @@ -136,6 +136,18 @@ const Portal = { window.location.href = BASE_PATH + '/portal/login.html'; }, + // Switch to a different business (go back to login to select) + switchBusiness() { + // Clear current business selection but keep token + localStorage.removeItem('payfrit_portal_business'); + window.location.href = BASE_PATH + '/portal/login.html'; + }, + + // Add a new business (go to setup wizard) + addNewBusiness() { + window.location.href = BASE_PATH + '/portal/setup-wizard.html'; + }, + // Setup navigation setupNavigation() { document.querySelectorAll('.nav-item[data-page]').forEach(item => {