comment av repetition logic for locked dates
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user