feat: Add bulk AI analyzer component to process product data and generate insights.

This commit is contained in:
Michael committed 2026-02-23 00:40:49 +01:00
1 parent 8c02771e46
commit 17498dcc10
4 files changed
+47 -8

No files matched your search

@@ -12,15 +12,18 @@ interface AiInsightBlockProps {
}
export function AiInsightBlock({ row }: AiInsightBlockProps) {
const { insights, analyzeProduct } = useAiCopilotStore();
const setDraftGamme = useGridStore(state => state.setDraftGamme);
const insight = insights[row.codein];
const insight = useAiCopilotStore((s) => s.insights[row.codein]);
const analyzeProduct = useAiCopilotStore((s) => s.analyzeProduct);
const setLoading = useAiCopilotStore((s) => s.setLoading);
const setDraftGamme = useGridStore((s) => s.setDraftGamme);
const status = insight?.status ?? "idle";
const handleAnalyze = () => {
if (status === "loading") return;
// Vider la recommandation actuelle avant de relancer l'IA
// Reset Visuel Immédiat
setLoading(row.codein);
setDraftGamme(row.codein, "Aucune");
const regScore = Object.values(row.sales12m || {}).filter(v => v > 0).length;
@@ -14,6 +14,7 @@ interface AiCopilotState {
insights: Record<string, AiInsight>;
setInsight: (codein: string, insight: string, isDuplicate?: boolean) => void;
setLoading: (codein: string) => void;
batchSetLoading: (codeins: string[]) => void;
setError: (codein: string, error: string) => void;
analyzeProduct: (payload: {
codein: string;
@@ -56,6 +57,16 @@ export const useAiCopilotStore = create<AiCopilotState>()(
}));
},
batchSetLoading: (codeins) => {
set((s) => {
const nextInsights = { ...s.insights };
codeins.forEach(codein => {
nextInsights[codein] = { codein, insight: "", status: "loading" };
});
return { insights: nextInsights };
});
},
setError: (codein, error) => {
set((s) => ({
insights: {