Vendor API endpoints use JWT authentication, not URL path parameters. The vendorCode should only be used for page URLs (navigation), not API calls. Fixed API paths in 10 vendor JS files: - analytics.js, customers.js, inventory.js, notifications.js - order-detail.js, orders.js, products.js, profile.js - settings.js, team.js Added architecture rule JS-014 to prevent this pattern from recurring. Added validation check _check_vendor_api_paths to validate_architecture.py. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
185 lines
5.3 KiB
JavaScript
185 lines
5.3 KiB
JavaScript
// static/vendor/js/settings.js
|
|
/**
|
|
* Vendor settings management page logic
|
|
* Configure vendor preferences and integrations
|
|
*/
|
|
|
|
const vendorSettingsLog = window.LogConfig.loggers.vendorSettings ||
|
|
window.LogConfig.createLogger('vendorSettings', false);
|
|
|
|
vendorSettingsLog.info('Loading...');
|
|
|
|
function vendorSettings() {
|
|
vendorSettingsLog.info('vendorSettings() called');
|
|
|
|
return {
|
|
// Inherit base layout state
|
|
...data(),
|
|
|
|
// Set page identifier
|
|
currentPage: 'settings',
|
|
|
|
// Loading states
|
|
loading: true,
|
|
error: '',
|
|
saving: false,
|
|
|
|
// Settings data
|
|
settings: null,
|
|
|
|
// Active section
|
|
activeSection: 'general',
|
|
|
|
// Sections for navigation
|
|
sections: [
|
|
{ id: 'general', label: 'General', icon: 'cog' },
|
|
{ id: 'marketplace', label: 'Marketplace', icon: 'shopping-cart' },
|
|
{ id: 'notifications', label: 'Notifications', icon: 'bell' }
|
|
],
|
|
|
|
// Forms for different sections
|
|
generalForm: {
|
|
subdomain: '',
|
|
is_active: true
|
|
},
|
|
|
|
marketplaceForm: {
|
|
letzshop_csv_url_fr: '',
|
|
letzshop_csv_url_en: '',
|
|
letzshop_csv_url_de: ''
|
|
},
|
|
|
|
notificationForm: {
|
|
email_notifications: true,
|
|
order_notifications: true,
|
|
marketing_emails: false
|
|
},
|
|
|
|
// Track changes
|
|
hasChanges: false,
|
|
|
|
async init() {
|
|
vendorSettingsLog.info('Settings init() called');
|
|
|
|
// Guard against multiple initialization
|
|
if (window._vendorSettingsInitialized) {
|
|
vendorSettingsLog.warn('Already initialized, skipping');
|
|
return;
|
|
}
|
|
window._vendorSettingsInitialized = true;
|
|
|
|
// IMPORTANT: Call parent init first to set vendorCode from URL
|
|
const parentInit = data().init;
|
|
if (parentInit) {
|
|
await parentInit.call(this);
|
|
}
|
|
|
|
try {
|
|
await this.loadSettings();
|
|
} catch (error) {
|
|
vendorSettingsLog.error('Init failed:', error);
|
|
this.error = 'Failed to initialize settings page';
|
|
}
|
|
|
|
vendorSettingsLog.info('Settings initialization complete');
|
|
},
|
|
|
|
/**
|
|
* Load vendor settings
|
|
*/
|
|
async loadSettings() {
|
|
this.loading = true;
|
|
this.error = '';
|
|
|
|
try {
|
|
const response = await apiClient.get(`/vendor/settings`);
|
|
|
|
this.settings = response;
|
|
|
|
// Populate forms
|
|
this.generalForm = {
|
|
subdomain: response.subdomain || '',
|
|
is_active: response.is_active !== false
|
|
};
|
|
|
|
this.marketplaceForm = {
|
|
letzshop_csv_url_fr: response.letzshop_csv_url_fr || '',
|
|
letzshop_csv_url_en: response.letzshop_csv_url_en || '',
|
|
letzshop_csv_url_de: response.letzshop_csv_url_de || ''
|
|
};
|
|
|
|
this.hasChanges = false;
|
|
vendorSettingsLog.info('Loaded settings');
|
|
} catch (error) {
|
|
vendorSettingsLog.error('Failed to load settings:', error);
|
|
this.error = error.message || 'Failed to load settings';
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Mark form as changed
|
|
*/
|
|
markChanged() {
|
|
this.hasChanges = true;
|
|
},
|
|
|
|
/**
|
|
* Save marketplace settings
|
|
*/
|
|
async saveMarketplaceSettings() {
|
|
this.saving = true;
|
|
try {
|
|
await apiClient.put(`/vendor/settings/marketplace`, this.marketplaceForm);
|
|
|
|
Utils.showToast('Marketplace settings saved', 'success');
|
|
vendorSettingsLog.info('Marketplace settings updated');
|
|
|
|
this.hasChanges = false;
|
|
} catch (error) {
|
|
vendorSettingsLog.error('Failed to save marketplace settings:', error);
|
|
Utils.showToast(error.message || 'Failed to save settings', 'error');
|
|
} finally {
|
|
this.saving = false;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Test Letzshop CSV URL
|
|
*/
|
|
async testLetzshopUrl(lang) {
|
|
const url = this.marketplaceForm[`letzshop_csv_url_${lang}`];
|
|
if (!url) {
|
|
Utils.showToast('Please enter a URL first', 'error');
|
|
return;
|
|
}
|
|
|
|
this.saving = true;
|
|
try {
|
|
// Try to fetch the URL to validate it
|
|
const response = await fetch(url, { method: 'HEAD', mode: 'no-cors' });
|
|
Utils.showToast(`URL appears to be valid`, 'success');
|
|
} catch (error) {
|
|
Utils.showToast('Could not validate URL - it may still work', 'warning');
|
|
} finally {
|
|
this.saving = false;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Reset settings to saved values
|
|
*/
|
|
resetSettings() {
|
|
this.loadSettings();
|
|
},
|
|
|
|
/**
|
|
* Switch active section
|
|
*/
|
|
setSection(sectionId) {
|
|
this.activeSection = sectionId;
|
|
}
|
|
};
|
|
}
|