feat: restrict AI analysis to admin role only

- FloatingSummaryBar: hide BulkAiAnalyzer button for non-admins
- AiInsightBlock: hide individual Analyser button for non-admins
- Both use useSession() to check role === "admin"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Sonnet 4.6 committed 2026-04-03 11:43:48 +02:00
1 parent bbb04a4d2a
commit 6ef23de317
2 files changed
+8 -1

No files matched your search

@@ -6,6 +6,7 @@ import { Loader2, AlertCircle, Sparkles, Maximize2 } from "lucide-react";
import { AiExplanationModal } from "./ai-explanation-modal";
import { useAiCopilotStore } from "../store/use-ai-copilot-store";
import { useGridStore } from "@/features/grid/store/use-grid-store";
import { useSession } from "next-auth/react";
import type { ProductRow } from "@/types/grid";
@@ -14,6 +15,8 @@ interface AiInsightBlockProps {
}
export function AiInsightBlock({ row }: AiInsightBlockProps) {
const { data: session } = useSession();
const isAdmin = (session?.user as any)?.role === "admin";
const insight = useAiCopilotStore((s: any) => s.insights[row.codein]);
const analyzeProduct = useAiCopilotStore((s: any) => s.analyzeProduct);
const setLoading = useAiCopilotStore((s: any) => s.setLoading);
@@ -125,6 +128,7 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
};
if (status === "idle") {
if (!isAdmin) return null;
return (
<button
onClick={handleAnalyze}
@@ -1,5 +1,6 @@
import { useGridStore } from "@/features/grid/store/use-grid-store";
import { useAiCopilotStore } from "@/features/ai-copilot/store/use-ai-copilot-store";
import { useSession } from "next-auth/react";
import { BulkAiAnalyzer } from "./bulk-ai-analyzer";
import { useSaveDrafts } from "@/features/grid/hooks/use-save-drafts";
@@ -27,6 +28,8 @@ function Stat({ label, value, sub }: { label: string; value: string; sub?: strin
}
export function FloatingSummaryBar() {
const { data: session } = useSession();
const isAdmin = (session?.user as any)?.role === "admin";
const { summary, resetDrafts, rows, filters, draftChanges } = useGridStore();
const { resetInsights } = useAiCopilotStore();
const [isPending, startTransition] = useTransition();
@@ -175,7 +178,7 @@ export function FloatingSummaryBar() {
</div>
<div className="flex space-x-3 items-center">
<BulkAiAnalyzer />
{isAdmin && <BulkAiAnalyzer />}
<DropdownMenu>
<DropdownMenuTrigger asChild>