Checkpoint: Ajout du bouton "Effacer les logs" dans la page Historique d'import avec confirmation de suppression.
This commit is contained in:
@@ -10,17 +10,77 @@ import {
|
|||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { trpc } from "@/lib/trpc";
|
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() {
|
export default function History() {
|
||||||
const { data: logs, isLoading } = trpc.importLogs.getByUser.useQuery();
|
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 (
|
return (
|
||||||
<DashboardLayout>
|
<DashboardLayout>
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div>
|
<div className="flex justify-between items-start">
|
||||||
<h1 className="text-3xl font-bold">Historique des imports</h1>
|
<div>
|
||||||
<p className="text-gray-500 mt-1">Consultez l'historique de tous vos imports de factures</p>
|
<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>
|
</div>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
|
|||||||
@@ -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));
|
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 =============
|
// ============= LLM LOG OPERATIONS =============
|
||||||
|
|
||||||
export async function createLlmLog(data: InsertLlmLog): Promise<LlmLog> {
|
export async function createLlmLog(data: InsertLlmLog): Promise<LlmLog> {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
findDuplicateInvoice,
|
findDuplicateInvoice,
|
||||||
createImportLog,
|
createImportLog,
|
||||||
getImportLogsByUser,
|
getImportLogsByUser,
|
||||||
|
deleteAllImportLogs,
|
||||||
getLlmLogsBySourceFile,
|
getLlmLogsBySourceFile,
|
||||||
getLlmLogsByInvoice,
|
getLlmLogsByInvoice,
|
||||||
getImportSettingsByUser,
|
getImportSettingsByUser,
|
||||||
@@ -560,6 +561,11 @@ export const appRouter = router({
|
|||||||
getByUser: protectedProcedure.query(async ({ ctx }) => {
|
getByUser: protectedProcedure.query(async ({ ctx }) => {
|
||||||
return getImportLogsByUser(ctx.user.id);
|
return getImportLogsByUser(ctx.user.id);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
deleteAll: protectedProcedure.mutation(async ({ ctx }) => {
|
||||||
|
await deleteAllImportLogs(ctx.user.id);
|
||||||
|
return { success: true };
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// ============= LLM LOGS ROUTES =============
|
// ============= LLM LOGS ROUTES =============
|
||||||
|
|||||||
7
todo.md
7
todo.md
@@ -176,3 +176,10 @@
|
|||||||
- [x] Implémenter l'envoi de notifications après import automatique dossier
|
- [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
|
- [x] Inclure le résumé : nombre de factures importées, doublons ignorés, erreurs
|
||||||
- [ ] Tester les fonctionnalités avec des données réelles
|
- [ ] 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é
|
||||||
|
|||||||
Reference in New Issue
Block a user