fix(vendor): correct contact field inheritance UI logic
Fixed the inheritance UI to be based on formData content rather than stale server state (vendor._inherited flags): - "(from company)" shows when formData field is empty - "Reset" shows when formData field has a value - Purple border shows when formData field is empty - formData initialization: empty for inherited, actual value for overrides This ensures each field's UI is independent and reactive to user input. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -65,15 +65,18 @@ function adminVendorEdit() {
|
||||
this.vendor = response;
|
||||
|
||||
// Initialize form data
|
||||
// For contact fields: empty if inherited (shows placeholder), actual value if override
|
||||
this.formData = {
|
||||
name: response.name || '',
|
||||
subdomain: response.subdomain || '',
|
||||
description: response.description || '',
|
||||
contact_email: response.contact_email || '',
|
||||
contact_phone: response.contact_phone || '',
|
||||
website: response.website || '',
|
||||
business_address: response.business_address || '',
|
||||
tax_number: response.tax_number || '',
|
||||
// Contact fields: empty string for inherited (will show company value as placeholder)
|
||||
contact_email: response.contact_email_inherited ? '' : (response.contact_email || ''),
|
||||
contact_phone: response.contact_phone_inherited ? '' : (response.contact_phone || ''),
|
||||
website: response.website_inherited ? '' : (response.website || ''),
|
||||
business_address: response.business_address_inherited ? '' : (response.business_address || ''),
|
||||
tax_number: response.tax_number_inherited ? '' : (response.tax_number || ''),
|
||||
// Marketplace URLs (no inheritance)
|
||||
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 || ''
|
||||
@@ -272,11 +275,6 @@ function adminVendorEdit() {
|
||||
|
||||
editLog.info(`Resetting ${fieldName} to inherit from company`);
|
||||
this.formData[fieldName] = '';
|
||||
|
||||
// Update the vendor object to reflect inheritance (UI indicator)
|
||||
if (this.vendor) {
|
||||
this.vendor[`${fieldName}_inherited`] = true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -288,23 +286,18 @@ function adminVendorEdit() {
|
||||
const contactFields = ['contact_email', 'contact_phone', 'website', 'business_address', 'tax_number'];
|
||||
contactFields.forEach(field => {
|
||||
this.formData[field] = '';
|
||||
if (this.vendor) {
|
||||
this.vendor[`${field}_inherited`] = true;
|
||||
}
|
||||
});
|
||||
|
||||
Utils.showToast('All contact fields reset to company defaults', 'info');
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if any contact field has a vendor-level override (not inherited).
|
||||
* @returns {boolean} True if at least one contact field is overridden
|
||||
* Check if any contact field has a value (not empty = has override).
|
||||
* @returns {boolean} True if at least one contact field has a value
|
||||
*/
|
||||
hasAnyContactOverride() {
|
||||
if (!this.vendor) return false;
|
||||
|
||||
const contactFields = ['contact_email', 'contact_phone', 'website', 'business_address', 'tax_number'];
|
||||
return contactFields.some(field => !this.vendor[`${field}_inherited`]);
|
||||
return contactFields.some(field => this.formData[field]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user