fix modal add/remove
This commit is contained in:
@ -145,4 +145,41 @@ function getColorForShift(shift) {
|
||||
}
|
||||
}
|
||||
|
||||
//ToDo: DRY - move to common
|
||||
const addAssignment = async (publisher, shiftId) => {
|
||||
try {
|
||||
console.log(`calendar.idx: new assignment for publisher ${publisher.id} - ${publisher.firstName} ${publisher.lastName}`);
|
||||
const newAssignment = {
|
||||
publisher: { connect: { id: publisher.id } },
|
||||
shift: { connect: { id: shiftId } },
|
||||
isConfirmed: true
|
||||
};
|
||||
const { data } = await axiosInstance.post("/api/data/assignments", newAssignment);
|
||||
if (selectedShiftId == shiftId) {
|
||||
handleShiftSelection(shifts.find(shift => shift.id === shiftId));
|
||||
}
|
||||
|
||||
// Update the 'publisher' property of the returned data with the full publisher object
|
||||
data.publisher = publisher;
|
||||
data.shift = shifts.find(shift => shift.id === shiftId);
|
||||
publisher.assignments = [...publisher.assignments, data];
|
||||
handleAssignmentChange(publisher.id, 'add');
|
||||
} catch (error) {
|
||||
console.error("Error adding assignment:", error);
|
||||
}
|
||||
};
|
||||
const removeAssignment = async (publisher, shiftId) => {
|
||||
try {
|
||||
const assignment = publisher.assignments.find(ass => ass.shift.id === shiftId);
|
||||
console.log(`calendar.idx: remove assignment for shift ${shiftId}`);
|
||||
const { data } = await axiosInstance.delete(`/api/data/assignments/${assignment.id}`);
|
||||
//remove from local assignments:
|
||||
publisher.assignments = publisher.assignments.filter(a => a.id !== assignment.id)
|
||||
//
|
||||
handleAssignmentChange(publisher.id, 'remove')
|
||||
} catch (error) {
|
||||
console.error("Error removing assignment:", error);
|
||||
}
|
||||
}
|
||||
|
||||
export default PublisherShiftsModal;
|
Reference in New Issue
Block a user