Some checks failed
Logo URL is required by Google Wallet API for LoyaltyClass creation. Added validation across all three program edit screens (admin, merchant, store) with a helpful hint explaining the requirement. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
97 lines
3.4 KiB
JavaScript
97 lines
3.4 KiB
JavaScript
// app/modules/loyalty/static/merchant/js/loyalty-settings.js
|
|
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
|
|
|
const loyaltySettingsLog = window.LogConfig.loggers.loyaltySettings || window.LogConfig.createLogger('loyaltySettings');
|
|
|
|
function merchantLoyaltySettings() {
|
|
return {
|
|
...data(),
|
|
...createProgramFormMixin(),
|
|
currentPage: 'loyalty-program',
|
|
|
|
loading: false,
|
|
error: null,
|
|
|
|
async init() {
|
|
loyaltySettingsLog.info('=== MERCHANT LOYALTY SETTINGS PAGE INITIALIZING ===');
|
|
if (window._merchantLoyaltySettingsInitialized) return;
|
|
window._merchantLoyaltySettingsInitialized = true;
|
|
|
|
// Load sidebar menu (from base data())
|
|
this.loadMenuConfig();
|
|
|
|
await this.loadSettings();
|
|
loyaltySettingsLog.info('=== MERCHANT LOYALTY SETTINGS PAGE INITIALIZATION COMPLETE ===');
|
|
},
|
|
|
|
async loadSettings() {
|
|
this.loading = true;
|
|
this.error = null;
|
|
|
|
try {
|
|
const response = await apiClient.get('/merchants/loyalty/program');
|
|
if (response) {
|
|
this.populateSettings(response);
|
|
this.isNewProgram = false;
|
|
loyaltySettingsLog.info('Settings loaded');
|
|
}
|
|
} catch (error) {
|
|
if (error.status === 404) {
|
|
loyaltySettingsLog.info('No program found, creating new');
|
|
this.isNewProgram = true;
|
|
} else {
|
|
throw error;
|
|
}
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
|
|
async saveSettings() {
|
|
this.saving = true;
|
|
|
|
try {
|
|
const payload = this.buildPayload();
|
|
if (!payload) { this.saving = false; return; }
|
|
|
|
if (this.isNewProgram) {
|
|
await apiClient.post('/merchants/loyalty/program', payload);
|
|
this.isNewProgram = false;
|
|
} else {
|
|
await apiClient.patch('/merchants/loyalty/program', payload);
|
|
}
|
|
|
|
Utils.showToast('Settings saved successfully', 'success');
|
|
loyaltySettingsLog.info('Settings saved');
|
|
} catch (error) {
|
|
Utils.showToast(`Failed to save: ${error.message}`, 'error');
|
|
loyaltySettingsLog.error('Save failed:', error);
|
|
} finally {
|
|
this.saving = false;
|
|
}
|
|
},
|
|
|
|
async deleteProgram() {
|
|
this.deleting = true;
|
|
|
|
try {
|
|
await apiClient.delete('/merchants/loyalty/program');
|
|
Utils.showToast('Loyalty program deleted', 'success');
|
|
loyaltySettingsLog.info('Program deleted');
|
|
window.location.href = '/merchants/loyalty/program';
|
|
} catch (error) {
|
|
Utils.showToast(`Failed to delete: ${error.message}`, 'error');
|
|
loyaltySettingsLog.error('Delete failed:', error);
|
|
} finally {
|
|
this.deleting = false;
|
|
this.showDeleteModal = false;
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
if (!window.LogConfig.loggers.loyaltySettings) {
|
|
window.LogConfig.loggers.loyaltySettings = window.LogConfig.createLogger('loyaltySettings');
|
|
}
|
|
loyaltySettingsLog.info('Merchant loyalty settings module loaded');
|