diff --git a/client/src/pages/History.tsx b/client/src/pages/History.tsx index a050289..5c80c7f 100644 --- a/client/src/pages/History.tsx +++ b/client/src/pages/History.tsx @@ -10,17 +10,77 @@ import { } from "@/components/ui/table"; import { Badge } from "@/components/ui/badge"; import { trpc } from "@/lib/trpc"; -import { History as HistoryIcon, FileText } from "lucide-react"; +import { History as HistoryIcon, FileText, Trash2 } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { toast } from "sonner"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "@/components/ui/alert-dialog"; export default function History() { const { data: logs, isLoading } = trpc.importLogs.getByUser.useQuery(); + const deleteAllMutation = trpc.importLogs.deleteAll.useMutation(); + const utils = trpc.useUtils(); + + const handleDeleteAll = async () => { + try { + await deleteAllMutation.mutateAsync(); + await utils.importLogs.getByUser.invalidate(); + toast.success("Logs supprimés", { + description: "Tous les logs d'import ont été supprimés avec succès.", + }); + } catch (error) { + toast.error("Erreur", { + description: "Impossible de supprimer les logs d'import.", + }); + } + }; return (
-
-

Historique des imports

-

Consultez l'historique de tous vos imports de factures

+
+
+

Historique des imports

+

Consultez l'historique de tous vos imports de factures

+
+ + {logs && logs.length > 0 && ( + + + + + + + Êtes-vous sûr ? + + Cette action supprimera définitivement tous les logs d'import. Cette opération est irréversible. + + + + Annuler + + {deleteAllMutation.isPending ? "Suppression..." : "Supprimer"} + + + + + )}
diff --git a/server/db.ts b/server/db.ts index dca3085..1a227b3 100644 --- a/server/db.ts +++ b/server/db.ts @@ -413,6 +413,12 @@ export async function getImportLogsByUser(userId: number): Promise return db.select().from(importLogs).where(eq(importLogs.userId, userId)).orderBy(desc(importLogs.importedAt)); } +export async function deleteAllImportLogs(userId: number): Promise { + const db = await getDb(); + if (!db) throw new Error("Database not available"); + await db.delete(importLogs).where(eq(importLogs.userId, userId)); +} + // ============= LLM LOG OPERATIONS ============= export async function createLlmLog(data: InsertLlmLog): Promise { diff --git a/server/routers.ts b/server/routers.ts index af8d4f3..57e6bfe 100644 --- a/server/routers.ts +++ b/server/routers.ts @@ -24,6 +24,7 @@ import { findDuplicateInvoice, createImportLog, getImportLogsByUser, + deleteAllImportLogs, getLlmLogsBySourceFile, getLlmLogsByInvoice, getImportSettingsByUser, @@ -560,6 +561,11 @@ export const appRouter = router({ getByUser: protectedProcedure.query(async ({ ctx }) => { return getImportLogsByUser(ctx.user.id); }), + + deleteAll: protectedProcedure.mutation(async ({ ctx }) => { + await deleteAllImportLogs(ctx.user.id); + return { success: true }; + }), }), // ============= LLM LOGS ROUTES ============= diff --git a/todo.md b/todo.md index 07adad2..7fb85d7 100644 --- a/todo.md +++ b/todo.md @@ -176,3 +176,10 @@ - [x] Implémenter l'envoi de notifications après import automatique dossier - [x] Inclure le résumé : nombre de factures importées, doublons ignorés, erreurs - [ ] Tester les fonctionnalités avec des données réelles + +## Bouton effacer les logs d'import +- [x] Ajouter fonction deleteAllImportLogs dans db.ts +- [x] Ajouter route tRPC importLogs.deleteAll +- [x] Ajouter bouton "Effacer les logs" dans la page History +- [x] Ajouter confirmation avant suppression (AlertDialog) +- [x] Tester la fonctionnalité