const fetchStoreStats = async () => {
try {
const orderResponse = await axios.get(`https://api.citycentermall.com/api/v1/store/${storeId}/dashboard-stats`);
const totalOrders = orderResponse.data.data.totalOrders;
let totalSales = 0;
let totalRevenue = 0;
totalOrders.forEach(order => {
totalSales += 1;
totalRevenue += order.total;
});
setDashboardStats((prevStats) => ({
...prevStats,
total_sales: totalSales,
total_revenue: totalRevenue
}));
} catch (error) {
console.error('Error fetching store stats:', error);
}
};
fetchStore();
fetchProducts();
fetchStats();
fetchStoreStats();
<div className="border border-gray-400 rounded-md p-4">
<p className="text-sm text-gray-500">Total Sales</p>
<h2 className="text-2xl font-bold text-blue-900">
{dashboardStats.total_sales ? dashboardStats.total_sales.toLocaleString() : '0'}
</h2>
<p className="text-sm text-gray-500 mt-3">Revenue</p>
<h2 className="text-2xl font-bold text-blue-900">
$ {dashboardStats.total_revenue ? dashboardStats.total_revenue.toLocaleString() : '0'}
</h2>
</div>