Auto-login single-business users, add switch/add business links
- Skip business selection for users with only one business - Add Switch Business and Add New Business links in portal sidebar - Handle returning users switching businesses (token + no business)
This commit is contained in:
parent
80aa65d7fa
commit
477cf6b8b5
3 changed files with 55 additions and 2 deletions
|
|
@ -105,6 +105,18 @@
|
|||
<div class="business-status online">Online</div>
|
||||
</div>
|
||||
</div>
|
||||
<a href="#" class="nav-item" onclick="Portal.switchBusiness(); return false;">
|
||||
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M16 3h5v5M8 3H3v5M3 16v5h5M21 16v5h-5M7 12h10"/>
|
||||
</svg>
|
||||
<span>Switch Business</span>
|
||||
</a>
|
||||
<a href="#" class="nav-item" onclick="Portal.addNewBusiness(); return false;">
|
||||
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M12 5v14M5 12h14"/>
|
||||
</svg>
|
||||
<span>Add New Business</span>
|
||||
</a>
|
||||
<a href="#logout" class="nav-item logout" data-page="logout">
|
||||
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M9 21H5a2 2 0 01-2-2V5a2 2 0 012-2h4M16 17l5-5-5-5M21 12H9"/>
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
|
|||
Reference in a new issue