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>
102 lines
3.4 KiB
JavaScript
102 lines
3.4 KiB
JavaScript
// app/modules/loyalty/static/vendor/js/loyalty-enroll.js
|
|
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
|
|
|
const loyaltyEnrollLog = window.LogConfig.loggers.loyaltyEnroll || window.LogConfig.createLogger('loyaltyEnroll');
|
|
|
|
function vendorLoyaltyEnroll() {
|
|
return {
|
|
...data(),
|
|
currentPage: 'loyalty-enroll',
|
|
|
|
program: null,
|
|
form: {
|
|
first_name: '',
|
|
last_name: '',
|
|
email: '',
|
|
phone: '',
|
|
birthday: '',
|
|
marketing_email: false,
|
|
marketing_sms: false
|
|
},
|
|
|
|
enrolling: false,
|
|
enrolledCard: null,
|
|
loading: false,
|
|
error: null,
|
|
|
|
async init() {
|
|
loyaltyEnrollLog.info('=== LOYALTY ENROLL PAGE INITIALIZING ===');
|
|
if (window._loyaltyEnrollInitialized) return;
|
|
window._loyaltyEnrollInitialized = true;
|
|
|
|
await this.loadProgram();
|
|
loyaltyEnrollLog.info('=== LOYALTY ENROLL PAGE INITIALIZATION COMPLETE ===');
|
|
},
|
|
|
|
async loadProgram() {
|
|
this.loading = true;
|
|
try {
|
|
const response = await apiClient.get('/vendor/loyalty/program');
|
|
if (response) {
|
|
this.program = response;
|
|
loyaltyEnrollLog.info('Program loaded:', this.program.display_name);
|
|
}
|
|
} catch (error) {
|
|
if (error.status === 404) {
|
|
loyaltyEnrollLog.warn('No program configured');
|
|
} else {
|
|
this.error = error.message;
|
|
}
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
|
|
async enrollCustomer() {
|
|
if (!this.form.first_name || !this.form.email) return;
|
|
|
|
this.enrolling = true;
|
|
|
|
try {
|
|
loyaltyEnrollLog.info('Enrolling customer:', this.form.email);
|
|
|
|
const response = await apiClient.post('/vendor/loyalty/cards/enroll', {
|
|
customer_email: this.form.email,
|
|
customer_phone: this.form.phone || null,
|
|
customer_name: [this.form.first_name, this.form.last_name].filter(Boolean).join(' '),
|
|
customer_birthday: this.form.birthday || null,
|
|
marketing_email_consent: this.form.marketing_email,
|
|
marketing_sms_consent: this.form.marketing_sms
|
|
});
|
|
|
|
if (response) {
|
|
this.enrolledCard = response;
|
|
loyaltyEnrollLog.info('Customer enrolled successfully:', response.card_number);
|
|
}
|
|
} catch (error) {
|
|
Utils.showToast(`Enrollment failed: ${error.message}`, 'error');
|
|
loyaltyEnrollLog.error('Enrollment failed:', error);
|
|
} finally {
|
|
this.enrolling = false;
|
|
}
|
|
},
|
|
|
|
resetForm() {
|
|
this.form = {
|
|
first_name: '',
|
|
last_name: '',
|
|
email: '',
|
|
phone: '',
|
|
birthday: '',
|
|
marketing_email: false,
|
|
marketing_sms: false
|
|
};
|
|
}
|
|
};
|
|
}
|
|
|
|
if (!window.LogConfig.loggers.loyaltyEnroll) {
|
|
window.LogConfig.loggers.loyaltyEnroll = window.LogConfig.createLogger('loyaltyEnroll');
|
|
}
|
|
loyaltyEnrollLog.info('Loyalty enroll module loaded');
|