Added few functions to the platform
This commit is contained in:
@@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useNotification } from './NotificationProvider';
|
||||
import useSWR from 'swr';
|
||||
import ConfirmModal from './ConfirmModal';
|
||||
|
||||
interface User {
|
||||
id: string;
|
||||
@@ -49,6 +50,10 @@ export default function ParametresContent() {
|
||||
prescripteur: '',
|
||||
facturation: '',
|
||||
});
|
||||
const [confirmDeleteModal, setConfirmDeleteModal] = useState<{
|
||||
show: boolean;
|
||||
id: string | null;
|
||||
} | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetchOptions();
|
||||
@@ -148,13 +153,18 @@ export default function ParametresContent() {
|
||||
setEditingValue('');
|
||||
};
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
if (!confirm('Êtes-vous sûr de vouloir supprimer cette option ?')) {
|
||||
return;
|
||||
}
|
||||
const handleDelete = (id: string) => {
|
||||
setConfirmDeleteModal({
|
||||
show: true,
|
||||
id,
|
||||
});
|
||||
};
|
||||
|
||||
const confirmDelete = async () => {
|
||||
if (!confirmDeleteModal?.id) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/settings/adherent-options/${id}`, {
|
||||
const response = await fetch(`/api/settings/adherent-options/${confirmDeleteModal.id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
@@ -168,6 +178,8 @@ export default function ParametresContent() {
|
||||
} catch (error) {
|
||||
console.error('Erreur:', error);
|
||||
showNotification('Erreur lors de la suppression', 'error');
|
||||
} finally {
|
||||
setConfirmDeleteModal(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -366,6 +378,20 @@ export default function ParametresContent() {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Modal de confirmation de suppression */}
|
||||
{confirmDeleteModal && (
|
||||
<ConfirmModal
|
||||
isOpen={confirmDeleteModal.show}
|
||||
title="Supprimer l'option"
|
||||
message="Êtes-vous sûr de vouloir supprimer cette option ?"
|
||||
confirmText="Supprimer"
|
||||
cancelText="Annuler"
|
||||
confirmColor="danger"
|
||||
onConfirm={confirmDelete}
|
||||
onCancel={() => setConfirmDeleteModal(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user