mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-23 23:28:12 +02:00
5 files changed
+227
-26
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import { Loader2, Calendar, BookOpen, Search, ChevronRight, Eye } from 'lucide-react';
|
||||
import { Loader2, Calendar, BookOpen, Search, ChevronRight, Eye, Trash2 } from 'lucide-react';
|
||||
import axios from 'axios';
|
||||
import { useAuth } from '../hooks/use-auth';
|
||||
|
||||
const API_BASE = '/api/catalogues';
|
||||
|
||||
@@ -14,6 +15,7 @@ export default function Catalogues() {
|
||||
const [selectedCatalogue, setSelectedCatalogue] = useState(null);
|
||||
const [cataloguePages, setCataloguePages] = useState([]);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const { user, getAuthHeaders } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
loadEnseignes();
|
||||
@@ -104,6 +106,26 @@ export default function Catalogues() {
|
||||
return now >= debut && now <= fin;
|
||||
};
|
||||
|
||||
const deleteCatalogue = async (catalogueId, event) => {
|
||||
event.stopPropagation(); // Prevent opening the catalogue
|
||||
|
||||
if (!confirm('Êtes-vous sûr de vouloir supprimer ce catalogue ?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await axios.delete(`${API_BASE}/admin/${catalogueId}`, {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
|
||||
toast.success('Catalogue supprimé');
|
||||
loadCatalogues(); // Reload the list
|
||||
} catch (error) {
|
||||
console.error('Error deleting catalogue:', error);
|
||||
toast.error('Erreur lors de la suppression');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-7xl mx-auto">
|
||||
{/* Header */}
|
||||
@@ -244,9 +266,20 @@ export default function Catalogues() {
|
||||
</div>
|
||||
|
||||
{/* Pages */}
|
||||
<div className="flex items-center gap-1 text-sm text-muted-foreground">
|
||||
<BookOpen className="h-4 w-4" />
|
||||
<span>{catalogue.nombre_pages} pages</span>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-1 text-sm text-muted-foreground">
|
||||
<BookOpen className="h-4 w-4" />
|
||||
<span>{catalogue.nombre_pages} pages</span>
|
||||
</div>
|
||||
{user?.is_admin && (
|
||||
<button
|
||||
onClick={(e) => deleteCatalogue(catalogue.id, e)}
|
||||
className="p-2 text-red-500 hover:bg-red-50 rounded-lg transition-colors"
|
||||
title="Supprimer le catalogue"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user