Fixing vendor dashboard area
This commit is contained in:
29
static/vendor/js/init-alpine.js
vendored
29
static/vendor/js/init-alpine.js
vendored
@@ -4,7 +4,13 @@
|
||||
* Provides common data and methods for all vendor pages
|
||||
*/
|
||||
|
||||
// ✅ Use centralized logger
|
||||
const vendorLog = window.LogConfig.log;
|
||||
|
||||
console.log('[VENDOR INIT-ALPINE] Loading...');
|
||||
|
||||
function data() {
|
||||
console.log('[VENDOR INIT-ALPINE] data() function called');
|
||||
return {
|
||||
dark: false,
|
||||
isSideMenuOpen: false,
|
||||
@@ -46,11 +52,12 @@ function data() {
|
||||
if (!this.vendorCode) return;
|
||||
|
||||
try {
|
||||
const response = await apiClient.get(`/api/v1/vendors/${this.vendorCode}`);
|
||||
// apiClient prepends /api/v1, so /vendor/{code} → /api/v1/vendor/{code}
|
||||
const response = await apiClient.get(`/vendor/${this.vendorCode}`);
|
||||
this.vendor = response;
|
||||
logDebug('Vendor info loaded', this.vendor);
|
||||
vendorLog.debug('Vendor info loaded', this.vendor);
|
||||
} catch (error) {
|
||||
logError('Failed to load vendor info', error);
|
||||
vendorLog.error('Failed to load vendor info', error);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -90,13 +97,23 @@ function data() {
|
||||
},
|
||||
|
||||
async handleLogout() {
|
||||
console.log('🚪 Logging out vendor user...');
|
||||
|
||||
try {
|
||||
await apiClient.post('/api/v1/vendor/auth/logout');
|
||||
// Call logout API
|
||||
await apiClient.post('/vendor/auth/logout');
|
||||
console.log('✅ Logout API called successfully');
|
||||
} catch (error) {
|
||||
logError('Logout error', error);
|
||||
console.error('⚠️ Logout API error (continuing anyway):', error);
|
||||
} finally {
|
||||
localStorage.removeItem('accessToken');
|
||||
// Clear all tokens and data
|
||||
console.log('🧹 Clearing tokens...');
|
||||
localStorage.removeItem('vendor_token');
|
||||
localStorage.removeItem('currentUser');
|
||||
localStorage.removeItem('vendorCode');
|
||||
localStorage.clear(); // Clear everything to be safe
|
||||
|
||||
console.log('🔄 Redirecting to login...');
|
||||
window.location.href = `/vendor/${this.vendorCode}/login`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user