feat(loyalty): align program view, edit, and analytics pages across all frontends
Some checks failed
CI / ruff (push) Successful in 11s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / pytest (push) Has been cancelled

Standardize naming (Program for view/edit, Analytics for stats), create shared
read-only program-view partial, fix admin edit field population bug (14 missing
fields), add store Program menu item, and rename merchant Overview→Program,
Settings→Analytics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 22:51:26 +01:00
parent aefca3115e
commit eee33d6a1b
20 changed files with 674 additions and 665 deletions

View File

@@ -6,26 +6,11 @@ const loyaltySettingsLog = window.LogConfig.loggers.loyaltySettings || window.Lo
function merchantLoyaltySettings() {
return {
...data(),
currentPage: 'loyalty-settings',
settings: {
loyalty_type: 'points',
points_per_euro: 1,
welcome_bonus_points: 0,
minimum_redemption_points: 100,
points_expiration_days: null,
points_rewards: [],
card_name: '',
card_color: '#4F46E5',
is_active: true
},
...createProgramFormMixin(),
currentPage: 'loyalty-program',
loading: false,
saving: false,
deleting: false,
error: null,
isNewProgram: false,
showDeleteModal: false,
async init() {
loyaltySettingsLog.info('=== MERCHANT LOYALTY SETTINGS PAGE INITIALIZING ===');
@@ -46,17 +31,7 @@ function merchantLoyaltySettings() {
try {
const response = await apiClient.get('/merchants/loyalty/program');
if (response) {
this.settings = {
loyalty_type: response.loyalty_type || 'points',
points_per_euro: response.points_per_euro || 1,
welcome_bonus_points: response.welcome_bonus_points || 0,
minimum_redemption_points: response.minimum_redemption_points || 100,
points_expiration_days: response.points_expiration_days || null,
points_rewards: response.points_rewards || [],
card_name: response.card_name || '',
card_color: response.card_color || '#4F46E5',
is_active: response.is_active !== false
};
this.populateSettings(response);
this.isNewProgram = false;
loyaltySettingsLog.info('Settings loaded');
}
@@ -76,19 +51,13 @@ function merchantLoyaltySettings() {
this.saving = true;
try {
// Ensure rewards have IDs
this.settings.points_rewards = this.settings.points_rewards.map((r, i) => ({
...r,
id: r.id || `reward_${i + 1}`,
is_active: r.is_active !== false
}));
const payload = this.buildPayload();
let response;
if (this.isNewProgram) {
response = await apiClient.post('/merchants/loyalty/program', this.settings);
await apiClient.post('/merchants/loyalty/program', payload);
this.isNewProgram = false;
} else {
response = await apiClient.patch('/merchants/loyalty/program', this.settings);
await apiClient.patch('/merchants/loyalty/program', payload);
}
Utils.showToast('Settings saved successfully', 'success');
@@ -101,10 +70,6 @@ function merchantLoyaltySettings() {
}
},
confirmDelete() {
this.showDeleteModal = true;
},
async deleteProgram() {
this.deleting = true;
@@ -112,8 +77,7 @@ function merchantLoyaltySettings() {
await apiClient.delete('/merchants/loyalty/program');
Utils.showToast('Loyalty program deleted', 'success');
loyaltySettingsLog.info('Program deleted');
// Redirect to overview
window.location.href = '/merchants/loyalty/overview';
window.location.href = '/merchants/loyalty/program';
} catch (error) {
Utils.showToast(`Failed to delete: ${error.message}`, 'error');
loyaltySettingsLog.error('Delete failed:', error);
@@ -122,20 +86,6 @@ function merchantLoyaltySettings() {
this.showDeleteModal = false;
}
},
addReward() {
this.settings.points_rewards.push({
id: `reward_${Date.now()}`,
name: '',
points_required: 100,
description: '',
is_active: true
});
},
removeReward(index) {
this.settings.points_rewards.splice(index, 1);
}
};
}