2024-08-12 23:08:57 -05:00
|
|
|
import { useQuery } from "@tanstack/react-query";
|
2024-08-14 15:44:07 -05:00
|
|
|
import { useSession } from "next-auth/react";
|
2024-08-12 23:08:57 -05:00
|
|
|
|
|
|
|
const useDashboardData = () => {
|
2024-08-14 15:44:07 -05:00
|
|
|
const { status } = useSession();
|
|
|
|
|
2024-08-12 23:08:57 -05:00
|
|
|
return useQuery({
|
|
|
|
queryKey: ["dashboardData"],
|
2024-09-09 23:09:33 -05:00
|
|
|
queryFn: async () => {
|
|
|
|
const response = await fetch("/api/v2/dashboard");
|
2024-08-12 23:08:57 -05:00
|
|
|
const data = await response.json();
|
|
|
|
|
2024-09-09 23:09:33 -05:00
|
|
|
return data.data;
|
2024-08-12 23:08:57 -05:00
|
|
|
},
|
2024-08-14 15:44:07 -05:00
|
|
|
enabled: status === "authenticated",
|
2024-08-12 23:08:57 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export { useDashboardData };
|