feat(loyalty): implement Phase 2 - company-wide points system
Complete implementation of loyalty module Phase 2 features: Database & Models: - Add company_id to LoyaltyProgram for chain-wide loyalty - Add company_id to LoyaltyCard for multi-location support - Add CompanyLoyaltySettings model for admin-controlled settings - Add points expiration, welcome bonus, and minimum redemption fields - Add POINTS_EXPIRED, WELCOME_BONUS transaction types Services: - Update program_service for company-based queries - Update card_service with enrollment and welcome bonus - Update points_service with void_points for returns - Update stamp_service for company context - Update pin_service for company-wide operations API Endpoints: - Admin: Program listing with stats, company detail views - Vendor: Terminal operations, card management, settings - Storefront: Customer card/transactions, self-enrollment UI Templates: - Admin: Programs dashboard, company detail, settings - Vendor: Terminal, cards list, card detail, settings, stats, enrollment - Storefront: Dashboard, history, enrollment, success pages Background Tasks: - Point expiration task (daily, based on inactivity) - Wallet sync task (hourly) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
// app/modules/loyalty/static/storefront/js/loyalty-dashboard.js
|
||||
// Customer loyalty dashboard
|
||||
|
||||
function customerLoyaltyDashboard() {
|
||||
return {
|
||||
...data(),
|
||||
|
||||
// Data
|
||||
card: null,
|
||||
program: null,
|
||||
rewards: [],
|
||||
transactions: [],
|
||||
locations: [],
|
||||
|
||||
// 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 || [];
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user