create child availabilities for locked dates if weekly availability is changed for a new future date
This commit is contained in:
@ -144,6 +144,26 @@ 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)
|
||||
}
|
||||
);
|
||||
|
||||
handleCompletion({ updated: true });
|
||||
} catch (error) {
|
||||
alert("Нещо се обърка. Моля, опитайте отново по-късно.");
|
||||
@ -221,9 +241,9 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
||||
availability.dateOfEntry = new Date();
|
||||
}
|
||||
|
||||
function createAvailabilityFromGroup(group) {
|
||||
function createAvailabilityFromGroup(group, publisherId) {
|
||||
let availability = {
|
||||
publisherId: publisher.id,
|
||||
publisherId: publisherId,
|
||||
dayofweek: common.getDayOfWeekNameEnEnumForDate(day),
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user