Platform Email Settings (Admin): - Add GET/PUT/DELETE /admin/settings/email/* endpoints - Settings stored in admin_settings table override .env values - Support all providers: SMTP, SendGrid, Mailgun, Amazon SES - Edit mode UI with provider-specific configuration forms - Reset to .env defaults functionality - Test email to verify configuration Vendor Email Settings: - Add VendorEmailSettings model with one-to-one vendor relationship - Migration: v0a1b2c3d4e5_add_vendor_email_settings.py - Service: vendor_email_settings_service.py with tier validation - API endpoints: /vendor/email-settings/* (CRUD, status, verify) - Email tab in vendor settings page with full configuration - Warning banner until email is configured (like billing warnings) - Premium providers (SendGrid, Mailgun, SES) tier-gated to Business+ Email Service Updates: - get_platform_email_config(db) checks DB first, then .env - Configurable provider classes accept config dict - EmailService uses database-aware providers - Vendor emails use vendor's own SMTP (Wizamart doesn't pay) - "Powered by Wizamart" footer for Essential/Professional tiers - White-label (no footer) for Business/Enterprise tiers Other: - Add scripts/install.py for first-time platform setup - Add make install target - Update init-prod to include email template seeding 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
129 lines
4.4 KiB
JavaScript
129 lines
4.4 KiB
JavaScript
// app/static/vendor/js/dashboard.js
|
|
/**
|
|
* Vendor dashboard page logic
|
|
*/
|
|
|
|
// ✅ Use centralized logger (with safe fallback)
|
|
const vendorDashLog = window.LogConfig.loggers.dashboard ||
|
|
window.LogConfig.createLogger('dashboard', false);
|
|
|
|
vendorDashLog.info('Loading...');
|
|
vendorDashLog.info('[VENDOR DASHBOARD] data function exists?', typeof data);
|
|
|
|
function vendorDashboard() {
|
|
vendorDashLog.info('[VENDOR DASHBOARD] vendorDashboard() called');
|
|
vendorDashLog.info('[VENDOR DASHBOARD] data function exists inside?', typeof data);
|
|
|
|
return {
|
|
// ✅ Inherit base layout state (includes vendorCode, dark mode, menu states)
|
|
...data(),
|
|
|
|
// ✅ Set page identifier
|
|
currentPage: 'dashboard',
|
|
|
|
loading: false,
|
|
error: '',
|
|
stats: {
|
|
products_count: 0,
|
|
orders_count: 0,
|
|
customers_count: 0,
|
|
revenue: 0
|
|
},
|
|
recentOrders: [],
|
|
recentProducts: [],
|
|
|
|
async init() {
|
|
// Guard against multiple initialization
|
|
if (window._vendorDashboardInitialized) {
|
|
return;
|
|
}
|
|
window._vendorDashboardInitialized = true;
|
|
|
|
try {
|
|
// IMPORTANT: Call parent init first to set vendorCode from URL
|
|
const parentInit = data().init;
|
|
if (parentInit) {
|
|
await parentInit.call(this);
|
|
}
|
|
|
|
await this.loadDashboardData();
|
|
} catch (error) {
|
|
vendorDashLog.error('Failed to initialize dashboard:', error);
|
|
}
|
|
},
|
|
|
|
async loadDashboardData() {
|
|
this.loading = true;
|
|
this.error = '';
|
|
|
|
try {
|
|
// Load stats
|
|
// NOTE: apiClient prepends /api/v1, and vendor context middleware handles vendor detection
|
|
// So we just call /vendor/dashboard/stats → becomes /api/v1/vendor/dashboard/stats
|
|
const statsResponse = await apiClient.get(
|
|
`/vendor/dashboard/stats`
|
|
);
|
|
|
|
// Map API response to stats (similar to admin dashboard pattern)
|
|
this.stats = {
|
|
products_count: statsResponse.products?.total || 0,
|
|
orders_count: statsResponse.orders?.total || 0,
|
|
customers_count: statsResponse.customers?.total || 0,
|
|
revenue: statsResponse.revenue?.total || 0
|
|
};
|
|
|
|
// Load recent orders
|
|
const ordersResponse = await apiClient.get(
|
|
`/vendor/orders?limit=5&sort=created_at:desc`
|
|
);
|
|
this.recentOrders = ordersResponse.items || [];
|
|
|
|
// Load recent products
|
|
const productsResponse = await apiClient.get(
|
|
`/vendor/products?limit=5&sort=created_at:desc`
|
|
);
|
|
this.recentProducts = productsResponse.items || [];
|
|
|
|
vendorDashLog.info('Dashboard data loaded', {
|
|
stats: this.stats,
|
|
orders: this.recentOrders.length,
|
|
products: this.recentProducts.length
|
|
});
|
|
|
|
} catch (error) {
|
|
vendorDashLog.error('Failed to load dashboard data', error);
|
|
this.error = 'Failed to load dashboard data. Please try refreshing the page.';
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
|
|
async refresh() {
|
|
try {
|
|
await this.loadDashboardData();
|
|
} catch (error) {
|
|
vendorDashLog.error('Failed to refresh dashboard:', error);
|
|
}
|
|
},
|
|
|
|
formatCurrency(amount) {
|
|
const locale = window.VENDOR_CONFIG?.locale || 'en-GB';
|
|
const currency = window.VENDOR_CONFIG?.currency || 'EUR';
|
|
return new Intl.NumberFormat(locale, {
|
|
style: 'currency',
|
|
currency: currency
|
|
}).format(amount || 0);
|
|
},
|
|
|
|
formatDate(dateString) {
|
|
if (!dateString) return '';
|
|
const date = new Date(dateString);
|
|
const locale = window.VENDOR_CONFIG?.locale || 'en-GB';
|
|
return date.toLocaleDateString(locale, {
|
|
year: 'numeric',
|
|
month: 'short',
|
|
day: 'numeric'
|
|
});
|
|
}
|
|
};
|
|
} |