fix calenar UI bug
This commit is contained in:
@ -87,27 +87,29 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
||||
e.preventDefault();
|
||||
try {
|
||||
const groupedTimeSlots = mergeCheckedTimeSlots(timeSlots);
|
||||
|
||||
let avs = availabilities.filter(av => av.type !== "assignment");
|
||||
// Determine if we need to delete and recreate, or just update
|
||||
const shouldRecreate = availabilities.length !== groupedTimeSlots.length || availabilities.some(av => !av.id);
|
||||
|
||||
let shouldRecreate = avs.length > 0 && avs.length !== groupedTimeSlots.length || avs.some(av => !av.id);
|
||||
shouldRecreate = shouldRecreate || ( avs.length == 0 && availabilities.length > 0);
|
||||
//create availability if we open a form with assignment without availability
|
||||
|
||||
if (shouldRecreate) {
|
||||
// Delete existing availabilities if they have an ID
|
||||
console.log("Recreating availabilities");
|
||||
await Promise.all(availabilities.filter(av => av.id).map(av => axiosInstance.delete(`${urls.apiUrl}${av.id}`)));
|
||||
await Promise.all(avs.filter(av => av.id).map(av => axiosInstance.delete(`${urls.apiUrl}${av.id}`)));
|
||||
|
||||
// Create new availabilities
|
||||
const createdAvailabilities = await Promise.all(groupedTimeSlots.map(async group => {
|
||||
avs = await Promise.all(groupedTimeSlots.map(async group => {
|
||||
const newAvailability = createAvailabilityFromGroup(group, publisher.id);
|
||||
const response = await axiosInstance.post(urls.apiUrl, newAvailability);
|
||||
return response.data; // Assuming the new availability is returned
|
||||
}));
|
||||
|
||||
setAvailabilities(createdAvailabilities);
|
||||
setAvailabilities(avs);
|
||||
} else {
|
||||
// Update existing availabilities
|
||||
console.log("Updating existing availabilities");
|
||||
const updatedAvailabilities = await Promise.all(availabilities.map(async (availability, index) => {
|
||||
avs = await Promise.all(avs.map(async (availability, index) => {
|
||||
const group = groupedTimeSlots[index];
|
||||
const id = availability.id;
|
||||
const updatedAvailability = updateAvailabilityFromGroup(availability, group);
|
||||
@ -121,7 +123,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
||||
return updatedAvailability;
|
||||
}));
|
||||
|
||||
setAvailabilities(updatedAvailabilities);
|
||||
setAvailabilities(avs);
|
||||
}
|
||||
|
||||
handleCompletion({ updated: true });
|
||||
@ -228,7 +230,8 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
||||
const handleDelete = async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
const deletePromises = availabilities.map(async (availability) => {
|
||||
let avs = availabilities.filter(av => av.type !== "assignment");
|
||||
const deletePromises = avs.map(async (availability) => {
|
||||
if (availability.id) {
|
||||
// console.log("deleting publisher id = ", router.query.id, "; url=" + urls.apiUrl + router.query.id);
|
||||
await axiosInstance.delete(urls.apiUrl + availability.id);
|
||||
|
@ -56,7 +56,14 @@ const AvCalendar = ({ publisherId, events, selectedDate }) => {
|
||||
|
||||
// Update internal state when `events` prop changes
|
||||
useEffect(() => {
|
||||
const updatedEvents = events.map(event => ({
|
||||
//if we have isBySystem - set type to assignment
|
||||
let updatedEvents = events.map(event => {
|
||||
if (event.isBySystem) {
|
||||
event.type = "assignment";
|
||||
}
|
||||
return event;
|
||||
});
|
||||
updatedEvents = events.map(event => ({
|
||||
...event,
|
||||
date: new Date(event.startTime).setHours(0, 0, 0, 0),
|
||||
startTime: new Date(event.startTime),
|
||||
|
Reference in New Issue
Block a user