new fn: delete all availabilities

This commit is contained in:
Dobromir Popov
2024-03-04 00:20:13 +02:00
parent 4dc336bfa2
commit 6043df6ad1
2 changed files with 29 additions and 8 deletions

View File

@ -46,7 +46,21 @@ function PublishersPage({ publishers = [] }: IProps) {
setIsDeleting(false);
setIsModalOpen(false);
// After all publishers are deleted, you might want to refresh the list or make additional changes
};
const handleDeleteAllAvailabilities = async () => {
setIsDeleting(true);
try {
const today = new Date();
const targetDate = new Date(today.setDate(today.getDate() - 35));
await axiosInstance.post('/api/?action=deleteAllAvailabilities', { date: targetDate });
} catch (error) {
console.error(JSON.stringify(error)); // Log the error
}
setIsDeleting(false);
setIsModalOpen(false);
};
useEffect(() => {
@ -164,6 +178,15 @@ function PublishersPage({ publishers = [] }: IProps) {
onConfirm={handleDeleteAllVisible}
message="Сигурни ли сте, че искате да изтриете всички показани в момента вестители?"
/>
<button className="button m-2 btn btn-danger" onClick={() => setIsModalOpen(true)} disabled={isDeleting} >
{isDeleting ? "Изтриване..." : "Изтрий ВСИЧКИ предпочитания"}
</button>
<ConfirmationModal
isOpen={isModalOpen}
onClose={() => setIsModalOpen(false)}
onConfirm={handleDeleteAllAvailabilities}
message="Сигурни ли сте, че искате да изтриете предпочитанията на ВСИЧКИ вестители?"
/>
<div className="flex justify-center m-4">
<a href="/cart/publishers/import" className="btn"> Import publishers </a>
</div>