migrating vendor frontend to new architecture
This commit is contained in:
@@ -1,14 +1,8 @@
|
||||
// static/admin/js/vendor-edit.js
|
||||
|
||||
// Log levels: 0 = None, 1 = Error, 2 = Warning, 3 = Info, 4 = Debug
|
||||
const VENDOR_EDIT_LOG_LEVEL = 3;
|
||||
|
||||
const editLog = {
|
||||
error: (...args) => VENDOR_EDIT_LOG_LEVEL >= 1 && console.error('❌ [VENDOR_EDIT ERROR]', ...args),
|
||||
warn: (...args) => VENDOR_EDIT_LOG_LEVEL >= 2 && console.warn('⚠️ [VENDOR_EDIT WARN]', ...args),
|
||||
info: (...args) => VENDOR_EDIT_LOG_LEVEL >= 3 && console.info('ℹ️ [VENDOR_EDIT INFO]', ...args),
|
||||
debug: (...args) => VENDOR_EDIT_LOG_LEVEL >= 4 && console.log('🔍 [VENDOR_EDIT DEBUG]', ...args)
|
||||
};
|
||||
// ✅ Use centralized logger - ONE LINE!
|
||||
// Create custom logger for vendor edit
|
||||
const editLog = window.LogConfig.createLogger('VENDOR-EDIT');
|
||||
|
||||
function adminVendorEdit() {
|
||||
return {
|
||||
@@ -58,9 +52,15 @@ function adminVendorEdit() {
|
||||
this.loadingVendor = true;
|
||||
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
const response = await apiClient.get(`/admin/vendors/${this.vendorCode}`);
|
||||
const duration = Date.now() - startTime;
|
||||
const url = `/admin/vendors/${this.vendorCode}`;
|
||||
window.LogConfig.logApiCall('GET', url, null, 'request');
|
||||
|
||||
const startTime = performance.now();
|
||||
const response = await apiClient.get(url);
|
||||
const duration = performance.now() - startTime;
|
||||
|
||||
window.LogConfig.logApiCall('GET', url, response, 'response');
|
||||
window.LogConfig.logPerformance('Load Vendor', duration);
|
||||
|
||||
this.vendor = response;
|
||||
|
||||
@@ -83,7 +83,7 @@ function adminVendorEdit() {
|
||||
editLog.debug('Form data initialized:', this.formData);
|
||||
|
||||
} catch (error) {
|
||||
editLog.error('Failed to load vendor:', error);
|
||||
window.LogConfig.logError(error, 'Load Vendor');
|
||||
Utils.showToast('Failed to load vendor', 'error');
|
||||
setTimeout(() => window.location.href = '/admin/vendors', 2000);
|
||||
} finally {
|
||||
@@ -108,12 +108,15 @@ function adminVendorEdit() {
|
||||
this.saving = true;
|
||||
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
const response = await apiClient.put(
|
||||
`/admin/vendors/${this.vendorCode}`,
|
||||
this.formData
|
||||
);
|
||||
const duration = Date.now() - startTime;
|
||||
const url = `/admin/vendors/${this.vendorCode}`;
|
||||
window.LogConfig.logApiCall('PUT', url, this.formData, 'request');
|
||||
|
||||
const startTime = performance.now();
|
||||
const response = await apiClient.put(url, this.formData);
|
||||
const duration = performance.now() - startTime;
|
||||
|
||||
window.LogConfig.logApiCall('PUT', url, response, 'response');
|
||||
window.LogConfig.logPerformance('Update Vendor', duration);
|
||||
|
||||
this.vendor = response;
|
||||
Utils.showToast('Vendor updated successfully', 'success');
|
||||
@@ -123,7 +126,7 @@ function adminVendorEdit() {
|
||||
// setTimeout(() => window.location.href = '/admin/vendors', 1500);
|
||||
|
||||
} catch (error) {
|
||||
editLog.error('Failed to update vendor:', error);
|
||||
window.LogConfig.logError(error, 'Update Vendor');
|
||||
|
||||
// Handle validation errors
|
||||
if (error.details && error.details.validation_errors) {
|
||||
@@ -155,17 +158,21 @@ function adminVendorEdit() {
|
||||
|
||||
this.saving = true;
|
||||
try {
|
||||
const response = await apiClient.put(
|
||||
`/admin/vendors/${this.vendorCode}/verification`,
|
||||
{ is_verified: !this.vendor.is_verified }
|
||||
);
|
||||
const url = `/admin/vendors/${this.vendorCode}/verification`;
|
||||
const payload = { is_verified: !this.vendor.is_verified };
|
||||
|
||||
window.LogConfig.logApiCall('PUT', url, payload, 'request');
|
||||
|
||||
const response = await apiClient.put(url, payload);
|
||||
|
||||
window.LogConfig.logApiCall('PUT', url, response, 'response');
|
||||
|
||||
this.vendor = response;
|
||||
Utils.showToast(`Vendor ${action}ed successfully`, 'success');
|
||||
editLog.info(`Vendor ${action}ed successfully`);
|
||||
|
||||
} catch (error) {
|
||||
editLog.error(`Failed to ${action} vendor:`, error);
|
||||
window.LogConfig.logError(error, `Toggle Verification (${action})`);
|
||||
Utils.showToast(`Failed to ${action} vendor`, 'error');
|
||||
} finally {
|
||||
this.saving = false;
|
||||
@@ -184,17 +191,21 @@ function adminVendorEdit() {
|
||||
|
||||
this.saving = true;
|
||||
try {
|
||||
const response = await apiClient.put(
|
||||
`/admin/vendors/${this.vendorCode}/status`,
|
||||
{ is_active: !this.vendor.is_active }
|
||||
);
|
||||
const url = `/admin/vendors/${this.vendorCode}/status`;
|
||||
const payload = { is_active: !this.vendor.is_active };
|
||||
|
||||
window.LogConfig.logApiCall('PUT', url, payload, 'request');
|
||||
|
||||
const response = await apiClient.put(url, payload);
|
||||
|
||||
window.LogConfig.logApiCall('PUT', url, response, 'response');
|
||||
|
||||
this.vendor = response;
|
||||
Utils.showToast(`Vendor ${action}d successfully`, 'success');
|
||||
editLog.info(`Vendor ${action}d successfully`);
|
||||
|
||||
} catch (error) {
|
||||
editLog.error(`Failed to ${action} vendor:`, error);
|
||||
window.LogConfig.logError(error, `Toggle Active Status (${action})`);
|
||||
Utils.showToast(`Failed to ${action} vendor`, 'error');
|
||||
} finally {
|
||||
this.saving = false;
|
||||
|
||||
Reference in New Issue
Block a user