This commit is contained in:
NotII
2025-04-08 01:54:20 +01:00
parent c85af30518
commit 2011a33c4d
6 changed files with 121 additions and 72 deletions

View File

@@ -49,7 +49,7 @@ export async function fetchServer<T = unknown>(
}
// Get auth token from cookies
const cookieStore = await cookiesModule.cookies();
const cookieStore = await cookiesModule.cookies();
const authToken = cookieStore.get('Authorization')?.value;
// Redirect to login if not authenticated
@@ -116,7 +116,27 @@ export const getCustomerDetailsServer = async (userId: string): Promise<Customer
// Server-side platform stats function
export async function getPlatformStatsServer(): Promise<any> {
try {
return fetchServer('/stats/platform');
// Try to fetch from server first
const serverData = await fetchServer('/stats/platform')
.catch(e => {
console.warn('Could not fetch real stats from API:', e);
return null;
});
// If we have real data, use it
if (serverData && Object.keys(serverData).length > 0) {
return serverData;
}
// If API call failed or returned empty data, use sample data
console.info('Using sample stats data for demo');
return {
totalProducts: 243,
totalVendors: 15,
totalOrders: 1289,
totalCustomers: 756,
gmv: 38450
};
} catch (error) {
console.error('Error fetching platform stats (server):', error);
// Return default stats to prevent UI breakage