Files
orion/app/modules/loyalty/static/storefront/js/loyalty-dashboard.js
Samir Boulahtit a6e6d9be8e
Some checks failed
CI / ruff (push) Successful in 11s
CI / pytest (push) Failing after 46m49s
CI / validate (push) Successful in 23s
CI / dependency-scanning (push) Successful in 30s
CI / docs (push) Has been skipped
CI / deploy (push) Has been skipped
refactor: rename shopLayoutData to storefrontLayoutData
Align Alpine.js base component naming with storefront terminology.
Updated across all storefront JS, templates, and documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 19:06:45 +01:00

92 lines
2.8 KiB
JavaScript

// app/modules/loyalty/static/storefront/js/loyalty-dashboard.js
// Customer loyalty dashboard
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() {
console.log('Customer loyalty dashboard initializing...');
await this.loadData();
},
async loadData() {
this.loading = true;
try {
await Promise.all([
this.loadCard(),
this.loadTransactions()
]);
} catch (error) {
console.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 };
console.log('Loyalty card loaded:', this.card?.card_number);
}
} catch (error) {
if (error.status === 404) {
console.log('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) {
console.warn('Failed to load transactions:', error.message);
}
},
formatNumber(num) {
if (num == null) return '0';
return new Intl.NumberFormat('en-US').format(num);
},
formatDate(dateString) {
if (!dateString) return '-';
try {
return new Date(dateString).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric'
});
} catch (e) {
return dateString;
}
}
};
}