feat: comprehensive vendor settings overhaul with Company inheritance
- Add structured API response with business_info, localization, letzshop, invoice_settings, theme_settings, domains, and stripe_info sections - Add PUT /vendor/settings/business-info with reset_to_company capability - Add PUT /vendor/settings/letzshop with validation for tax rates, delivery - Add 9 settings sections: General, Business Info, Localization, Marketplace, Invoices, Branding, Domains, API & Payments, Notifications - Business Info shows "Inherited" badges and Reset buttons for company fields - Marketplace section includes Letzshop CSV URLs and feed options - Read-only sections for Invoices, Branding, Domains, API with contact support - Add globe-alt icon for Domains section - Document email templates architecture for future implementation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -93,6 +93,7 @@ const Icons = {
|
||||
'chat': `<svg class="{{classes}}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/></svg>`,
|
||||
'bell': `<svg class="{{classes}}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"/></svg>`,
|
||||
'inbox': `<svg class="{{classes}}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"/></svg>`,
|
||||
'paper-airplane': `<svg class="{{classes}}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"/></svg>`,
|
||||
|
||||
// Files & Documents
|
||||
'document': `<svg class="{{classes}}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>`,
|
||||
@@ -119,6 +120,7 @@ const Icons = {
|
||||
// Location
|
||||
'location-marker': `<svg class="{{classes}}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"/></svg>`,
|
||||
'globe': `<svg class="{{classes}}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>`,
|
||||
'globe-alt': `<svg class="{{classes}}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"/></svg>`,
|
||||
|
||||
// Status & Indicators
|
||||
'exclamation': `<svg class="{{classes}}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>`,
|
||||
|
||||
228
static/vendor/js/settings.js
vendored
228
static/vendor/js/settings.js
vendored
@@ -24,7 +24,7 @@ function vendorSettings() {
|
||||
error: '',
|
||||
saving: false,
|
||||
|
||||
// Settings data
|
||||
// Settings data from API
|
||||
settings: null,
|
||||
|
||||
// Active section
|
||||
@@ -33,7 +33,13 @@ function vendorSettings() {
|
||||
// Sections for navigation
|
||||
sections: [
|
||||
{ id: 'general', label: 'General', icon: 'cog' },
|
||||
{ id: 'business', label: 'Business Info', icon: 'office-building' },
|
||||
{ id: 'localization', label: 'Localization', icon: 'globe' },
|
||||
{ id: 'marketplace', label: 'Marketplace', icon: 'shopping-cart' },
|
||||
{ id: 'invoices', label: 'Invoices', icon: 'document-text' },
|
||||
{ id: 'branding', label: 'Branding', icon: 'color-swatch' },
|
||||
{ id: 'domains', label: 'Domains', icon: 'globe-alt' },
|
||||
{ id: 'api', label: 'API & Payments', icon: 'key' },
|
||||
{ id: 'notifications', label: 'Notifications', icon: 'bell' }
|
||||
],
|
||||
|
||||
@@ -43,10 +49,36 @@ function vendorSettings() {
|
||||
is_active: true
|
||||
},
|
||||
|
||||
businessForm: {
|
||||
name: '',
|
||||
description: '',
|
||||
contact_email: '',
|
||||
contact_phone: '',
|
||||
website: '',
|
||||
business_address: '',
|
||||
tax_number: ''
|
||||
},
|
||||
|
||||
// Track which fields are inherited from company
|
||||
businessInherited: {
|
||||
contact_email: false,
|
||||
contact_phone: false,
|
||||
website: false,
|
||||
business_address: false,
|
||||
tax_number: false
|
||||
},
|
||||
|
||||
// Company name for display
|
||||
companyName: '',
|
||||
|
||||
marketplaceForm: {
|
||||
letzshop_csv_url_fr: '',
|
||||
letzshop_csv_url_en: '',
|
||||
letzshop_csv_url_de: ''
|
||||
letzshop_csv_url_de: '',
|
||||
letzshop_default_tax_rate: null,
|
||||
letzshop_boost_sort: '',
|
||||
letzshop_delivery_method: '',
|
||||
letzshop_preorder_days: null
|
||||
},
|
||||
|
||||
notificationForm: {
|
||||
@@ -55,8 +87,19 @@ function vendorSettings() {
|
||||
marketing_emails: false
|
||||
},
|
||||
|
||||
// Track changes
|
||||
localizationForm: {
|
||||
default_language: 'fr',
|
||||
dashboard_language: 'fr',
|
||||
storefront_language: 'fr',
|
||||
storefront_languages: ['fr', 'de', 'en'],
|
||||
storefront_locale: ''
|
||||
},
|
||||
|
||||
// Track changes per section
|
||||
hasChanges: false,
|
||||
hasBusinessChanges: false,
|
||||
hasLocalizationChanges: false,
|
||||
hasMarketplaceChanges: false,
|
||||
|
||||
async init() {
|
||||
vendorSettingsLog.info('Settings init() called');
|
||||
@@ -96,19 +139,60 @@ function vendorSettings() {
|
||||
|
||||
this.settings = response;
|
||||
|
||||
// Populate forms
|
||||
// Populate general form
|
||||
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 || ''
|
||||
// Populate business info form with inheritance tracking
|
||||
const biz = response.business_info || {};
|
||||
this.businessForm = {
|
||||
name: response.name || '',
|
||||
description: response.description || '',
|
||||
contact_email: biz.contact_email_override || '',
|
||||
contact_phone: biz.contact_phone_override || '',
|
||||
website: biz.website_override || '',
|
||||
business_address: biz.business_address_override || '',
|
||||
tax_number: biz.tax_number_override || ''
|
||||
};
|
||||
this.businessInherited = {
|
||||
contact_email: biz.contact_email_inherited || false,
|
||||
contact_phone: biz.contact_phone_inherited || false,
|
||||
website: biz.website_inherited || false,
|
||||
business_address: biz.business_address_inherited || false,
|
||||
tax_number: biz.tax_number_inherited || false
|
||||
};
|
||||
this.companyName = biz.company_name || '';
|
||||
|
||||
// Populate localization form from nested structure
|
||||
const loc = response.localization || {};
|
||||
this.localizationForm = {
|
||||
default_language: loc.default_language || 'fr',
|
||||
dashboard_language: loc.dashboard_language || 'fr',
|
||||
storefront_language: loc.storefront_language || 'fr',
|
||||
storefront_languages: loc.storefront_languages || ['fr', 'de', 'en'],
|
||||
storefront_locale: loc.storefront_locale || ''
|
||||
};
|
||||
|
||||
// Populate marketplace form from nested structure
|
||||
const lz = response.letzshop || {};
|
||||
this.marketplaceForm = {
|
||||
letzshop_csv_url_fr: lz.csv_url_fr || '',
|
||||
letzshop_csv_url_en: lz.csv_url_en || '',
|
||||
letzshop_csv_url_de: lz.csv_url_de || '',
|
||||
letzshop_default_tax_rate: lz.default_tax_rate,
|
||||
letzshop_boost_sort: lz.boost_sort || '',
|
||||
letzshop_delivery_method: lz.delivery_method || '',
|
||||
letzshop_preorder_days: lz.preorder_days
|
||||
};
|
||||
|
||||
// Reset all change flags
|
||||
this.hasChanges = false;
|
||||
this.hasBusinessChanges = false;
|
||||
this.hasLocalizationChanges = false;
|
||||
this.hasMarketplaceChanges = false;
|
||||
|
||||
vendorSettingsLog.info('Loaded settings');
|
||||
} catch (error) {
|
||||
vendorSettingsLog.error('Failed to load settings:', error);
|
||||
@@ -119,24 +203,111 @@ function vendorSettings() {
|
||||
},
|
||||
|
||||
/**
|
||||
* Mark form as changed
|
||||
* Mark general form as changed
|
||||
*/
|
||||
markChanged() {
|
||||
this.hasChanges = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Save marketplace settings
|
||||
* Mark business form as changed
|
||||
*/
|
||||
markBusinessChanged() {
|
||||
this.hasBusinessChanges = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Mark localization form as changed
|
||||
*/
|
||||
markLocalizationChanged() {
|
||||
this.hasLocalizationChanges = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Mark marketplace form as changed
|
||||
*/
|
||||
markMarketplaceChanged() {
|
||||
this.hasMarketplaceChanges = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get effective value for a business field (override or inherited)
|
||||
*/
|
||||
getEffectiveBusinessValue(field) {
|
||||
const override = this.businessForm[field];
|
||||
if (override) return override;
|
||||
// Return the effective value from settings (includes company inheritance)
|
||||
return this.settings?.business_info?.[field] || '';
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if field is using inherited value
|
||||
*/
|
||||
isFieldInherited(field) {
|
||||
return this.businessInherited[field] && !this.businessForm[field];
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset a business field to inherit from company
|
||||
*/
|
||||
resetToCompany(field) {
|
||||
this.businessForm[field] = '';
|
||||
this.hasBusinessChanges = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Save business info
|
||||
*/
|
||||
async saveBusinessInfo() {
|
||||
this.saving = true;
|
||||
try {
|
||||
// Determine which fields should be reset to company values
|
||||
const resetFields = [];
|
||||
for (const field of ['contact_email', 'contact_phone', 'website', 'business_address', 'tax_number']) {
|
||||
if (!this.businessForm[field] && this.settings?.business_info?.[field]) {
|
||||
resetFields.push(field);
|
||||
}
|
||||
}
|
||||
|
||||
const payload = {
|
||||
name: this.businessForm.name,
|
||||
description: this.businessForm.description,
|
||||
contact_email: this.businessForm.contact_email || null,
|
||||
contact_phone: this.businessForm.contact_phone || null,
|
||||
website: this.businessForm.website || null,
|
||||
business_address: this.businessForm.business_address || null,
|
||||
tax_number: this.businessForm.tax_number || null,
|
||||
reset_to_company: resetFields
|
||||
};
|
||||
|
||||
await apiClient.put(`/vendor/settings/business-info`, payload);
|
||||
|
||||
Utils.showToast('Business info saved', 'success');
|
||||
vendorSettingsLog.info('Business info updated');
|
||||
|
||||
// Reload to get updated inheritance flags
|
||||
await this.loadSettings();
|
||||
this.hasBusinessChanges = false;
|
||||
} catch (error) {
|
||||
vendorSettingsLog.error('Failed to save business info:', error);
|
||||
Utils.showToast(error.message || 'Failed to save business info', 'error');
|
||||
} finally {
|
||||
this.saving = false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Save marketplace settings (Letzshop)
|
||||
*/
|
||||
async saveMarketplaceSettings() {
|
||||
this.saving = true;
|
||||
try {
|
||||
await apiClient.put(`/vendor/settings/marketplace`, this.marketplaceForm);
|
||||
await apiClient.put(`/vendor/settings/letzshop`, this.marketplaceForm);
|
||||
|
||||
Utils.showToast('Marketplace settings saved', 'success');
|
||||
vendorSettingsLog.info('Marketplace settings updated');
|
||||
|
||||
this.hasChanges = false;
|
||||
this.hasMarketplaceChanges = false;
|
||||
} catch (error) {
|
||||
vendorSettingsLog.error('Failed to save marketplace settings:', error);
|
||||
Utils.showToast(error.message || 'Failed to save settings', 'error');
|
||||
@@ -179,6 +350,39 @@ function vendorSettings() {
|
||||
*/
|
||||
setSection(sectionId) {
|
||||
this.activeSection = sectionId;
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle a storefront language
|
||||
*/
|
||||
toggleStorefrontLanguage(langCode) {
|
||||
const index = this.localizationForm.storefront_languages.indexOf(langCode);
|
||||
if (index === -1) {
|
||||
this.localizationForm.storefront_languages.push(langCode);
|
||||
} else {
|
||||
this.localizationForm.storefront_languages.splice(index, 1);
|
||||
}
|
||||
this.hasLocalizationChanges = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Save localization settings
|
||||
*/
|
||||
async saveLocalizationSettings() {
|
||||
this.saving = true;
|
||||
try {
|
||||
await apiClient.put(`/vendor/settings/localization`, this.localizationForm);
|
||||
|
||||
Utils.showToast('Localization settings saved', 'success');
|
||||
vendorSettingsLog.info('Localization settings updated');
|
||||
|
||||
this.hasLocalizationChanges = false;
|
||||
} catch (error) {
|
||||
vendorSettingsLog.error('Failed to save localization settings:', error);
|
||||
Utils.showToast(error.message || 'Failed to save settings', 'error');
|
||||
} finally {
|
||||
this.saving = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user