reload availabilities from DB in case of delete error

This commit is contained in:
Dobromir Popov
2024-03-05 16:21:28 +02:00
parent a9f726519f
commit c15da32fd2

View File

@ -56,16 +56,12 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
}, []);
// Define the minimum and maximum times
const minTime = new Date();
minTime.setHours(8, 0, 0, 0); // 8:00 AM
const maxTime = new Date();
maxTime.setHours(20, 0, 0, 0); // 8:00 PM
useEffect(() => {
const fetchItemFromDB = async () => {
const id = parseInt(router.query.id);
if (existingItems.length == 0 && id) {
@ -80,6 +76,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
}
};
useEffect(() => {
fetchItemFromDB();
}, [router.query.id]);
@ -212,10 +209,6 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
return availability;
}
const handleDelete = async (e) => {
e.preventDefault();
try {
@ -236,6 +229,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
alert("Нещо се обърка при изтриването. Моля, опитайте отново или се свържете с нас");
console.log(JSON.stringify(error));
toast.error(error.response?.data?.message || "An error occurred");
fetchItemFromDB();
}
};