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