Files
orion/static/vendor/js/dashboard.js

81 lines
2.4 KiB
JavaScript

// app/static/vendor/js/dashboard.js
/**
* Vendor dashboard page logic
*/
function vendorDashboard() {
return {
loading: false,
error: '',
stats: {
products_count: 0,
orders_count: 0,
customers_count: 0,
revenue: 0
},
recentOrders: [],
recentProducts: [],
async init() {
await this.loadDashboardData();
},
async loadDashboardData() {
this.loading = true;
this.error = '';
try {
// Load stats
const statsResponse = await apiClient.get(
`/api/v1/vendors/${this.vendorCode}/stats`
);
this.stats = statsResponse;
// Load recent orders
const ordersResponse = await apiClient.get(
`/api/v1/vendors/${this.vendorCode}/orders?limit=5&sort=created_at:desc`
);
this.recentOrders = ordersResponse.items || [];
// Load recent products
const productsResponse = await apiClient.get(
`/api/v1/vendors/${this.vendorCode}/products?limit=5&sort=created_at:desc`
);
this.recentProducts = productsResponse.items || [];
logInfo('Dashboard data loaded', {
stats: this.stats,
orders: this.recentOrders.length,
products: this.recentProducts.length
});
} catch (error) {
logError('Failed to load dashboard data', error);
this.error = 'Failed to load dashboard data. Please try refreshing the page.';
} finally {
this.loading = false;
}
},
async refresh() {
await this.loadDashboardData();
},
formatCurrency(amount) {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'EUR'
}).format(amount || 0);
},
formatDate(dateString) {
if (!dateString) return '';
const date = new Date(dateString);
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric'
});
}
};
}