Files
orion/app/modules/loyalty/static/merchant/js/loyalty-settings.js
Samir Boulahtit 694a1cd1a5 feat(loyalty): add full i18n support for all loyalty module pages
Replace hardcoded English strings across all 22 templates, 10 JS files,
and 4 locale files (en/fr/de/lb) with ~300 translation keys per language.
Uses server-side _() for Jinja2 templates and I18n.t() for JS toast
messages and dynamic Alpine.js expressions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 19:53:17 +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: '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(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');