Checkpoint: Ajout du bouton "Effacer les logs" dans la page Historique d'import avec confirmation de suppression.

This commit is contained in:
Manus
2026-02-11 05:24:18 -05:00
parent cd61c75c4c
commit fcf9e8f7b7
4 changed files with 83 additions and 4 deletions

View File

@@ -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 (
<DashboardLayout>
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold">Historique des imports</h1>
<p className="text-gray-500 mt-1">Consultez l'historique de tous vos imports de factures</p>
<div className="flex justify-between items-start">
<div>
<h1 className="text-3xl font-bold">Historique des imports</h1>
<p className="text-gray-500 mt-1">Consultez l'historique de tous vos imports de factures</p>
</div>
{logs && logs.length > 0 && (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="destructive" size="sm">
<Trash2 className="mr-2 h-4 w-4" />
Effacer les logs
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Êtes-vous sûr ?</AlertDialogTitle>
<AlertDialogDescription>
Cette action supprimera définitivement tous les logs d'import. Cette opération est irréversible.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Annuler</AlertDialogCancel>
<AlertDialogAction
onClick={handleDeleteAll}
disabled={deleteAllMutation.isPending}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{deleteAllMutation.isPending ? "Suppression..." : "Supprimer"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)}
</div>
<Card>

View File

@@ -413,6 +413,12 @@ export async function getImportLogsByUser(userId: number): Promise<ImportLog[]>
return db.select().from(importLogs).where(eq(importLogs.userId, userId)).orderBy(desc(importLogs.importedAt));
}
export async function deleteAllImportLogs(userId: number): Promise<void> {
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<LlmLog> {

View File

@@ -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 =============

View File

@@ -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é