created specific route files for frontends

This commit is contained in:
2025-11-02 15:26:55 +01:00
parent 9611c03a36
commit 9cc92e5fc4
12 changed files with 76 additions and 235 deletions

View File

@@ -3,9 +3,8 @@
* Vendor login page logic
*/
// ✅ Use centralized logger - ONE LINE!
// Create custom logger for login page
const loginLog = window.LogConfig.createLogger('LOGIN');
// Create custom logger for vendor login page
const vendorLoginLog = window.LogConfig.createLogger('VENDOR-LOGIN');
function vendorLogin() {
return {
@@ -23,29 +22,38 @@ function vendorLogin() {
dark: false,
async init() {
vendorLoginLog.info('=== VENDOR LOGIN PAGE INITIALIZING ===');
// Load theme
const theme = localStorage.getItem('theme');
if (theme === 'dark') {
this.dark = true;
}
vendorLoginLog.debug('Dark mode:', this.dark);
// Get vendor code from URL path
const pathSegments = window.location.pathname.split('/').filter(Boolean);
if (pathSegments[0] === 'vendor' && pathSegments[1]) {
this.vendorCode = pathSegments[1];
vendorLoginLog.debug('Vendor code from URL:', this.vendorCode);
await this.loadVendor();
}
this.checked = true;
vendorLoginLog.info('=== VENDOR LOGIN PAGE INITIALIZATION COMPLETE ===');
},
async loadVendor() {
vendorLoginLog.info('Loading vendor information...');
this.loading = true;
try {
const response = await apiClient.get(`/vendor/${this.vendorCode}`);
this.vendor = response;
logInfo('Vendor loaded', this.vendor);
vendorLoginLog.info('Vendor loaded successfully:', {
code: this.vendor.code,
name: this.vendor.name
});
} catch (error) {
logError('Failed to load vendor', error);
window.LogConfig.logError(error, 'Load Vendor');
this.error = 'Failed to load vendor information';
} finally {
this.loading = false;
@@ -53,6 +61,7 @@ function vendorLogin() {
},
async handleLogin() {
vendorLoginLog.info('=== VENDOR LOGIN ATTEMPT STARTED ===');
this.clearErrors();
this.loading = true;
@@ -65,30 +74,50 @@ function vendorLogin() {
}
if (Object.keys(this.errors).length > 0) {
vendorLoginLog.warn('Validation failed:', this.errors);
this.loading = false;
return;
}
vendorLoginLog.info('Calling vendor login API...');
vendorLoginLog.debug('Username:', this.credentials.username);
vendorLoginLog.debug('Vendor code:', this.vendorCode);
window.LogConfig.logApiCall('POST', '/vendor/auth/login', {
username: this.credentials.username,
vendor_code: this.vendorCode
}, 'request');
const startTime = performance.now();
const response = await apiClient.post('/vendor/auth/login', {
username: this.credentials.username,
password: this.credentials.password,
vendor_code: this.vendorCode
});
const duration = performance.now() - startTime;
logInfo('Login successful', response);
window.LogConfig.logApiCall('POST', '/vendor/auth/login', {
hasToken: !!response.access_token,
user: response.user?.username
}, 'response');
window.LogConfig.logPerformance('Vendor Login', duration);
vendorLoginLog.info('Login successful!');
vendorLoginLog.debug('Storing authentication data...');
localStorage.setItem('accessToken', response.access_token);
localStorage.setItem('currentUser', JSON.stringify(response.user));
localStorage.setItem('vendorCode', this.vendorCode);
this.success = 'Login successful! Redirecting...';
vendorLoginLog.info('Redirecting to vendor dashboard...');
setTimeout(() => {
window.location.href = `/vendor/${this.vendorCode}/dashboard`;
}, 1000);
} catch (error) {
logError('Login failed', error);
window.LogConfig.logError(error, 'Vendor Login');
if (error.status === 401) {
this.error = 'Invalid username or password';
@@ -97,14 +126,26 @@ function vendorLogin() {
} else {
this.error = error.message || 'Login failed. Please try again.';
}
vendorLoginLog.info('Error message displayed to user:', this.error);
} finally {
this.loading = false;
vendorLoginLog.info('=== VENDOR LOGIN ATTEMPT FINISHED ===');
}
},
clearErrors() {
vendorLoginLog.debug('Clearing form errors');
this.error = '';
this.errors = {};
},
toggleDarkMode() {
vendorLoginLog.debug('Toggling dark mode...');
this.dark = !this.dark;
localStorage.setItem('theme', this.dark ? 'dark' : 'light');
vendorLoginLog.info('Dark mode:', this.dark ? 'ON' : 'OFF');
}
};
}
}
vendorLoginLog.info('Vendor login module loaded');