From 09f9c0b0978fea6c63a70bcc33e73c4ad75ab78b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 21 Feb 2026 21:38:27 +0100 Subject: [PATCH] feat(ai): bulk analysis now populates AI insight column with justification and duplicate flag --- .../ai-copilot/components/ai-insight-block.tsx | 17 ++++++++++++----- .../ai-copilot/store/use-ai-copilot-store.ts | 11 +++++++++++ .../grid/components/bulk-ai-analyzer.tsx | 7 ++++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/features/ai-copilot/components/ai-insight-block.tsx b/src/features/ai-copilot/components/ai-insight-block.tsx index 79c2a18..e433edb 100644 --- a/src/features/ai-copilot/components/ai-insight-block.tsx +++ b/src/features/ai-copilot/components/ai-insight-block.tsx @@ -59,11 +59,18 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) { } return ( -
- - - {insight?.insight} - +
+
+ + + {insight?.insight} + +
+ {insight?.isDuplicate && ( + + ⚠️ Doublon probable + + )}
); } diff --git a/src/features/ai-copilot/store/use-ai-copilot-store.ts b/src/features/ai-copilot/store/use-ai-copilot-store.ts index 72ed182..0350193 100644 --- a/src/features/ai-copilot/store/use-ai-copilot-store.ts +++ b/src/features/ai-copilot/store/use-ai-copilot-store.ts @@ -6,10 +6,12 @@ interface AiInsight { codein: string; insight: string; status: "idle" | "loading" | "done" | "error"; + isDuplicate?: boolean; } interface AiCopilotState { insights: Record; + setInsight: (codein: string, insight: string, isDuplicate?: boolean) => void; analyzeProduct: (payload: { codein: string; libelle1: string; @@ -24,6 +26,15 @@ interface AiCopilotState { export const useAiCopilotStore = create((set) => ({ insights: {}, + setInsight: (codein, insight, isDuplicate = false) => { + set((s) => ({ + insights: { + ...s.insights, + [codein]: { codein, insight, status: "done", isDuplicate }, + }, + })); + }, + analyzeProduct: async (payload) => { const { codein } = payload; diff --git a/src/features/grid/components/bulk-ai-analyzer.tsx b/src/features/grid/components/bulk-ai-analyzer.tsx index da04296..8bad250 100644 --- a/src/features/grid/components/bulk-ai-analyzer.tsx +++ b/src/features/grid/components/bulk-ai-analyzer.tsx @@ -2,6 +2,7 @@ import React, { useState } from "react"; import { useGridStore } from "@/features/grid/store/use-grid-store"; +import { useAiCopilotStore } from "@/features/ai-copilot/store/use-ai-copilot-store"; import { Sparkles, Loader2, CheckCircle2 } from "lucide-react"; import { ProductRow } from "@/types/grid"; @@ -9,6 +10,7 @@ export function BulkAiAnalyzer() { const [isAnalyzing, setIsAnalyzing] = useState(false); const [progress, setProgress] = useState({ current: 0, total: 0, message: "" }); const setDraftGamme = useGridStore(state => state.setDraftGamme); + const setInsight = useAiCopilotStore(state => state.setInsight); const handleAnalyze = async () => { const { rows } = useGridStore.getState(); @@ -76,8 +78,11 @@ export function BulkAiAnalyzer() { if (data && Array.isArray(data.results)) { data.results.forEach((reco: any) => { if (reco.codein && reco.recommandationGamme) { - // Add it to the store drafts + // Update the gamme draft setDraftGamme(reco.codein, reco.recommandationGamme); + // Inject the justification into the AI insight column + const justification = reco.justificationCourte || `Recommandation: Gamme ${reco.recommandationGamme}`; + setInsight(reco.codein, justification, reco.isDuplicate ?? false); } }); }