Files
orion/app/modules/loyalty/static/storefront/js/loyalty-dashboard.js
Samir Boulahtit bb4c400436 fix(loyalty): sweep remaining hardcoded 'en-US' in persona JS files
Follow-up to 06e59f73 which swept non-loyalty modules. The earlier
loyalty fix (dd1f9af8) only touched the shared/ factories; persona-
specific JS files in loyalty's admin/, merchant/, store/, and
storefront/ dirs were missed and still hardcoded 'en-US'.

13 occurrences across 8 files now use I18n.locale:
- admin: loyalty-analytics.js, loyalty-merchant-detail.js,
  loyalty-programs.js
- merchant: loyalty-analytics.js
- store: loyalty-analytics.js, loyalty-terminal.js
- storefront: loyalty-dashboard.js, loyalty-history.js

After this commit grep -rn "'en-US'" --include=*.js across the whole
repo returns nothing. Clearing the deck so the JS-016 rule can ship
at error severity in the next commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 23:51:24 +02:00

93 lines
3.0 KiB
JavaScript

// app/modules/loyalty/static/storefront/js/loyalty-dashboard.js
// Customer loyalty dashboard
const loyaltyDashboardLog = window.LogConfig.loggers.loyaltyDashboard || window.LogConfig.createLogger('loyaltyDashboard');
function customerLoyaltyDashboard() {
return {
...storefrontLayoutData(),
// Data
card: null,
program: null,
rewards: [],
transactions: [],
locations: [],
// Wallet
walletUrls: { google_wallet_url: null, apple_wallet_url: null },
// UI state
loading: false,
showBarcode: false,
async init() {
loyaltyDashboardLog.info('Customer loyalty dashboard initializing...');
await this.loadData();
},
async loadData() {
this.loading = true;
try {
await Promise.all([
this.loadCard(),
this.loadTransactions()
]);
} catch (error) {
loyaltyDashboardLog.error('Failed to load loyalty data:', error);
} finally {
this.loading = false;
}
},
async loadCard() {
try {
const response = await apiClient.get('/storefront/loyalty/card');
if (response) {
this.card = response.card;
this.program = response.program;
this.rewards = response.program?.points_rewards || [];
this.locations = response.locations || [];
this.walletUrls = response.wallet_urls || { google_wallet_url: null, apple_wallet_url: null };
loyaltyDashboardLog.info('Loyalty card loaded:', this.card?.card_number);
}
} catch (error) {
if (error.status === 404) {
loyaltyDashboardLog.info('No loyalty card found');
this.card = null;
} else {
throw error;
}
}
},
async loadTransactions() {
try {
const response = await apiClient.get('/storefront/loyalty/transactions?limit=10');
if (response && response.transactions) {
this.transactions = response.transactions;
}
} catch (error) {
loyaltyDashboardLog.warn('Failed to load transactions:', error.message);
}
},
formatNumber(num) {
if (num == null) return '0';
return new Intl.NumberFormat(I18n.locale).format(num);
},
formatDate(dateString) {
if (!dateString) return '-';
try {
return new Date(dateString).toLocaleDateString(I18n.locale, {
year: 'numeric',
month: 'short',
day: 'numeric'
});
} catch (e) {
return dateString;
}
}
};
}