finshing architecture for project now we have all layers to build profitionl project app,components ,hooks ,lib,services,styel ,types

This commit is contained in:
m7amedez5511
2026-06-08 23:05:19 +03:00
parent 70853958f5
commit 53c03e9867
45 changed files with 1408 additions and 78 deletions

View File

@@ -0,0 +1,49 @@
// hooks/useDashboardSummary.ts
"use client";
import { useEffect, useState } from "react";
import { dashboardService } from "@/services/dashboard.service";
import { getStoredToken } from "@/lib/auth";
import type { DashboardSummary } from "@/types/dashboard";
interface State {
data: DashboardSummary | null;
error: string | null;
loading: boolean;
}
/**
* Fetches the admin dashboard summary.
* Redirects to /login if no token is present (handled by the caller).
*
* @example
* const { data, loading, error } = useDashboardSummary();
*/
export function useDashboardSummary(): State {
const [state, setState] = useState<State>({
data: null, error: null, loading: true,
});
useEffect(() => {
let cancelled = false;
const token = getStoredToken();
if (!token) {
setState({ data: null, error: "Unauthenticated", loading: false });
return;
}
dashboardService
.getSummary(token)
.then(res => {
if (!cancelled) setState({ data: res.data, error: null, loading: false });
})
.catch((err: Error) => {
if (!cancelled) setState({ data: null, error: err.message, loading: false });
});
return () => { cancelled = true; };
}, []);
return state;
}