more responsive calendar UI

This commit is contained in:
Dobromir Popov
2024-05-28 18:21:50 +03:00
parent 59dd7cd7b4
commit d3ade91b80
2 changed files with 39 additions and 7 deletions

View File

@ -9,7 +9,7 @@ const common = require('src/helpers/common');
function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, allPublishersInfo }) {
function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, allPublishersInfo, onAssignmentChange }) {
const [isDeleted, setIsDeleted] = useState(false);
const [assignments, setAssignments] = useState(shift.assignments);
const [isModalOpen, setIsModalOpen] = useState(false);
@ -59,7 +59,11 @@ function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, a
try {
console.log("Removing assignment with id:", id);
await axiosInstance.delete("/api/data/assignments/" + id);
let assingmnt = assignments.find(ass => ass.id == id);
setAssignments(prevAssignments => prevAssignments.filter(ass => ass.id !== id));
if (onAssignmentChange) {
onAssignmentChange(assingmnt.publisherId, 'remove');
}
} catch (error) {
console.error("Error removing assignment:", error);
}
@ -77,6 +81,12 @@ function ShiftComponent({ shift, onShiftSelect, isSelected, onPublisherSelect, a
const { data } = await axiosInstance.post("/api/data/assignments", newAssignment);
// Update the 'publisher' property of the returned data with the full publisher object
data.publisher = publisher;
//ToDo: see if we need to update in state
// publisher.currentWeekAssignments += 1;
// publisher.currentMonthAssignments += 1;
if (onAssignmentChange) {
onAssignmentChange(data.publisher.id, 'add')
}
setAssignments(prevAssignments => [...prevAssignments, data]);
} catch (error) {
console.error("Error adding assignment:", error);