fix alot of things

This commit is contained in:
NotII
2025-03-14 16:48:08 +00:00
parent c15e8119c7
commit 87a58a6736
17 changed files with 79 additions and 3102 deletions

View File

@@ -1,9 +1,6 @@
'use client';
import { useEffect, useState } from 'react';
import Dashboard from "@/components/dashboard/dashboard";
import Content from "@/components/dashboard/content";
import { fetchClient } from '@/lib/client-service';
import { fetchServer } from '@/lib/server-service';
// ✅ Corrected Vendor Type
interface Vendor {
@@ -25,43 +22,13 @@ interface OrderStats {
cancelledOrders: number;
}
export default function DashboardPage() {
const [vendor, setVendor] = useState<Vendor | null>(null);
const [orderStats, setOrderStats] = useState<OrderStats | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
export default async function DashboardPage() {
const [userResponse, orderStats] = await Promise.all([
fetchServer<User>("/auth/me"),
fetchServer<OrderStats>("/orders/stats"),
]);
useEffect(() => {
async function fetchData() {
try {
setLoading(true);
// Fetch data from API using relative URLs and client-side fetch
const [userResponse, stats] = await Promise.all([
fetchClient<User>("auth/me"),
fetchClient<OrderStats>("orders/stats"),
]);
setVendor(userResponse.vendor);
setOrderStats(stats);
} catch (err) {
console.error('Error fetching dashboard data:', err);
setError('Failed to load dashboard data');
} finally {
setLoading(false);
}
}
fetchData();
}, []);
if (loading) {
return <Dashboard><div>Loading dashboard...</div></Dashboard>;
}
if (error || !vendor || !orderStats) {
return <Dashboard><div>Error: {error || 'Failed to load data'}</div></Dashboard>;
}
const vendor = userResponse.vendor;
return (
<Dashboard>