From 34aceed38fe37dc3b681f1bfce687acfbe3b309c Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Sun, 14 Jul 2024 22:57:55 +0300 Subject: [PATCH] comment av repetition logic for locked dates --- components/availability/AvailabilityForm.js | 49 ++++++++++++--------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/components/availability/AvailabilityForm.js b/components/availability/AvailabilityForm.js index 6034d9c..93a451d 100644 --- a/components/availability/AvailabilityForm.js +++ b/components/availability/AvailabilityForm.js @@ -31,8 +31,8 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o }; const id = parseInt(router.query.id); - //coalsce existingItems to empty array - existingItems = existingItems || []; + + const originalAvailabilities = existingItems || []; const [editMode, setEditMode] = useState(existingItems.length > 0); const [publisher, setPublisher] = useState({ id: publisherId }); @@ -144,25 +144,34 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o setAvailabilities(avs); } + // Handle repetition logic - avs.forEach(async av => { - if (av.repeatWeekly && av.startTime < lockedBeforeDate) { - const newDate = availability.startTime; - while (newDate < lockedBeforeDate) { - const newAvailability = { - ...updatedAvailability, - startTime: newDate, - parentAvailabilityId: id, - dateOfEntry: new Date(), - type: "OneTime" - }; - await axiosInstance.post(urls.apiUrl, newAvailability); - newDate.setDate(newDate.getDate() + 7); // Repeat weekly - } - } - console.log("Updated availability: ", av) - } - ); + // const parentAvailabilityId = avs[0].id; + // originalAvailabilities.forEach(async av => { + // if (av.repeatWeekly && av.startTime < lockedBeforeDate) { + // const newDate = av.startTime; + // while (newDate < lockedBeforeDate) { + // const newAvailability = { + // ...av, + // startTime: newDate, + // parentAvailability: { connect: { id: parentAvailabilityId } }, + // publisher: { connect: { id: publisher.id } }, + // dateOfEntry: new Date(), + // type: "OneTime" + // }; + + // delete newAvailability.id; + // delete newAvailability.title; + // delete newAvailability.date; + // delete newAvailability.publisherId + + // await axiosInstance.post(urls.apiUrl, newAvailability); + // newDate.setDate(newDate.getDate() + 7); // Repeat weekly + // } + // } + // console.log("Updated availability: ", av) + // } + // ); handleCompletion({ updated: true }); } catch (error) {