feat(loyalty): align program view, edit, and analytics pages across all frontends
Some checks failed
Some checks failed
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:
94
app/modules/loyalty/static/store/js/loyalty-analytics.js
Normal file
94
app/modules/loyalty/static/store/js/loyalty-analytics.js
Normal file
@@ -0,0 +1,94 @@
|
||||
// app/modules/loyalty/static/store/js/loyalty-analytics.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
const loyaltyAnalyticsLog = window.LogConfig.loggers.loyaltyAnalytics || window.LogConfig.createLogger('loyaltyAnalytics');
|
||||
|
||||
function storeLoyaltyAnalytics() {
|
||||
return {
|
||||
...data(),
|
||||
currentPage: 'loyalty-analytics',
|
||||
|
||||
program: null,
|
||||
|
||||
stats: {
|
||||
total_cards: 0,
|
||||
active_cards: 0,
|
||||
new_this_month: 0,
|
||||
total_points_issued: 0,
|
||||
total_points_redeemed: 0,
|
||||
total_points_balance: 0,
|
||||
points_issued_30d: 0,
|
||||
points_redeemed_30d: 0,
|
||||
transactions_30d: 0,
|
||||
avg_points_per_member: 0
|
||||
},
|
||||
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
async init() {
|
||||
loyaltyAnalyticsLog.info('=== LOYALTY ANALYTICS PAGE INITIALIZING ===');
|
||||
if (window._loyaltyAnalyticsInitialized) return;
|
||||
window._loyaltyAnalyticsInitialized = true;
|
||||
|
||||
// IMPORTANT: Call parent init first to set storeCode from URL
|
||||
const parentInit = data().init;
|
||||
if (parentInit) {
|
||||
await parentInit.call(this);
|
||||
}
|
||||
|
||||
await this.loadProgram();
|
||||
if (this.program) {
|
||||
await this.loadStats();
|
||||
}
|
||||
loyaltyAnalyticsLog.info('=== LOYALTY ANALYTICS PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
async loadProgram() {
|
||||
try {
|
||||
const response = await apiClient.get('/store/loyalty/program');
|
||||
if (response) this.program = response;
|
||||
} catch (error) {
|
||||
if (error.status !== 404) throw error;
|
||||
}
|
||||
},
|
||||
|
||||
async loadStats() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
const response = await apiClient.get('/store/loyalty/stats');
|
||||
if (response) {
|
||||
this.stats = {
|
||||
total_cards: response.total_cards || 0,
|
||||
active_cards: response.active_cards || 0,
|
||||
new_this_month: response.new_this_month || 0,
|
||||
total_points_issued: response.total_points_issued || 0,
|
||||
total_points_redeemed: response.total_points_redeemed || 0,
|
||||
total_points_balance: response.total_points_balance || 0,
|
||||
points_issued_30d: response.points_issued_30d || 0,
|
||||
points_redeemed_30d: response.points_redeemed_30d || 0,
|
||||
transactions_30d: response.transactions_30d || 0,
|
||||
avg_points_per_member: response.avg_points_per_member || 0
|
||||
};
|
||||
loyaltyAnalyticsLog.info('Stats loaded');
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyAnalyticsLog.error('Failed to load stats:', error);
|
||||
this.error = error.message;
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
formatNumber(num) {
|
||||
return num == null ? '0' : new Intl.NumberFormat('en-US').format(num);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!window.LogConfig.loggers.loyaltyAnalytics) {
|
||||
window.LogConfig.loggers.loyaltyAnalytics = window.LogConfig.createLogger('loyaltyAnalytics');
|
||||
}
|
||||
loyaltyAnalyticsLog.info('Loyalty analytics module loaded');
|
||||
Reference in New Issue
Block a user