role based auth
implemented superadmin -> admin -> traniner
This commit is contained in:
1 parent
16217f46ff
commit
624cdfc45c
16 files changed
+1105
-54
No files matched your search
+32
-14
@@ -14,11 +14,26 @@ import { AnalyticsDashboard } from "@/components/analytics/AnalyticsDashboard";
|
||||
import { useDashboardStats } from "@/hooks/use-api";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useUser } from "@clerk/nextjs";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { GymSelector } from "@/components/gym/GymSelector";
|
||||
|
||||
export default function Home() {
|
||||
const { data: stats, isLoading, refetch, isFetching } = useDashboardStats();
|
||||
const { user } = useUser();
|
||||
const searchParams = useSearchParams();
|
||||
const gymId = searchParams.get("gymId") ?? undefined;
|
||||
|
||||
const {
|
||||
data: stats,
|
||||
isLoading,
|
||||
refetch,
|
||||
isFetching,
|
||||
} = useDashboardStats(gymId);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// Get user role from metadata
|
||||
const userRole = (user?.publicMetadata?.role as string) ?? "client";
|
||||
|
||||
const handleRefresh = () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["dashboard-stats"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["analytics"] });
|
||||
@@ -40,18 +55,21 @@ export default function Home() {
|
||||
title="Dashboard"
|
||||
description="Welcome back! Here's what's happening with your gym today."
|
||||
actions={
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleRefresh}
|
||||
disabled={isFetching}
|
||||
className="gap-2"
|
||||
>
|
||||
<RefreshCw
|
||||
className={`h-4 w-4 ${isFetching ? "animate-spin" : ""}`}
|
||||
/>
|
||||
Refresh
|
||||
</Button>
|
||||
<div className="flex items-center gap-3">
|
||||
<GymSelector userRole={userRole} />
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleRefresh}
|
||||
disabled={isFetching}
|
||||
className="gap-2"
|
||||
>
|
||||
<RefreshCw
|
||||
className={`h-4 w-4 ${isFetching ? "animate-spin" : ""}`}
|
||||
/>
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -125,7 +143,7 @@ export default function Home() {
|
||||
Overview of your gym metrics
|
||||
</p>
|
||||
</div>
|
||||
<AnalyticsDashboard />
|
||||
<AnalyticsDashboard gymId={gymId} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user