Files
orion/app/modules/loyalty/static/merchant/js/loyalty-settings.js
Samir Boulahtit 1d90bfe044 fix(loyalty): align menu item IDs with URL segments for sidebar highlight
The store and merchant init-alpine.js derive currentPage from the URL's
last segment (e.g., /loyalty/program -> 'program'). Loyalty menu items
used prefixed IDs like 'loyalty-program' which never matched, so sidebar
items never highlighted.

Fixed by renaming all store/merchant menu item IDs and JS currentPage
values to match URL segments: program, cards, analytics, transactions,
pins, settings — consistent with how every other module works.

Also reverted the init-alpine.js guard that broke storeCode extraction,
and added missing loyalty.common.contact_admin_setup translation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 18:32:50 +01:00

97 lines
3.5 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: '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(I18n.t('loyalty.toasts.settings_saved'), 'success');
loyaltySettingsLog.info('Settings saved');
} catch (error) {
Utils.showToast(I18n.t('loyalty.toasts.save_failed', {message: 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(I18n.t('loyalty.toasts.program_deleted'), 'success');
loyaltySettingsLog.info('Program deleted');
window.location.href = '/merchants/loyalty/program';
} catch (error) {
Utils.showToast(I18n.t('loyalty.toasts.delete_failed', {message: 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');