|
1
|
import { useQuery } from "@tanstack/react-query"; |
|
2
|
import { useAuth } from "./useAuth"; |
|
3
|
|
|
4
|
export function useAdmin() { |
|
5
|
const { user, isAuthenticated } = useAuth(); |
|
6
|
|
|
7
|
const { data: adminData, isLoading } = useQuery({ |
|
8
|
queryKey: ["/api/admin/users"], |
|
9
|
enabled: isAuthenticated && user?.role === "admin", |
|
10
|
retry: false, |
|
11
|
}); |
|
12
|
|
|
13
|
return { |
|
14
|
isAdmin: user?.role === "admin", |
|
15
|
adminData, |
|
16
|
isLoading, |
|
17
|
}; |
|
18
|
} |
|
19
|
|
|
20
|
export function useAdminStats() { |
|
21
|
const { isAdmin } = useAdmin(); |
|
22
|
|
|
23
|
const { data: stats, isLoading } = useQuery({ |
|
24
|
queryKey: ["/api/admin/stats"], |
|
25
|
enabled: isAdmin, |
|
26
|
retry: false, |
|
27
|
}); |
|
28
|
|
|
29
|
return { |
|
30
|
stats, |
|
31
|
isLoading, |
|
32
|
}; |
|
33
|
} |