[#3] added event deletion to display

This commit is contained in:
Camille Moussu
2025-07-25 15:29:40 +02:00
parent 5f59831be0
commit 2ad41dc4f5
5 changed files with 50 additions and 25 deletions
+9 -7
View File
@@ -308,13 +308,15 @@ export default function CalendarApp() {
open={Boolean(anchorElCal)} open={Boolean(anchorElCal)}
onClose={() => setAnchorElCal(null)} onClose={() => setAnchorElCal(null)}
/> />
<EventDisplayModal {openEventDisplay && eventDisplayedId && eventDisplayedCalId && (
open={openEventDisplay} <EventDisplayModal
onClose={handleCloseEventDisplay} eventId={eventDisplayedId}
anchorEl={anchorElEventDisplay} calId={eventDisplayedCalId}
eventId={eventDisplayedId} anchorEl={anchorElEventDisplay}
calId={eventDisplayedCalId} open={openEventDisplay}
/> onClose={handleCloseEventDisplay}
/>
)}
</div> </div>
</main> </main>
); );
+19 -1
View File
@@ -4,8 +4,9 @@ import { CalendarEvent } from "../Events/EventsTypes";
import { getCalendar, getCalendars } from "./CalendarApi"; import { getCalendar, getCalendars } from "./CalendarApi";
import getOpenPaasUserId from "../User/userAPI"; import getOpenPaasUserId from "../User/userAPI";
import { parseCalendarEvent } from "../Events/eventUtils"; import { parseCalendarEvent } from "../Events/eventUtils";
import { putEvent } from "../Events/EventApi"; import { deleteEvent, putEvent } from "../Events/EventApi";
import { formatDateToYYYYMMDDTHHMMSS } from "../../utils/dateUtils"; import { formatDateToYYYYMMDDTHHMMSS } from "../../utils/dateUtils";
import { responsiveFontSizes } from "@mui/material";
export const getCalendarsListAsync = createAsyncThunk< export const getCalendarsListAsync = createAsyncThunk<
Record<string, Calendars> // Return type Record<string, Calendars> // Return type
@@ -75,6 +76,14 @@ export const putEventAsync = createAsyncThunk<
}; };
}); });
export const deleteEventAsync = createAsyncThunk<
{ calId: string; eventId: string }, // Return type
{ calId: string; eventId: string } // Arg type
>("calendars/delEvent", async ({ calId, eventId }) => {
const response = await deleteEvent(calId, eventId);
return { calId, eventId };
});
const CalendarSlice = createSlice({ const CalendarSlice = createSlice({
name: "calendars", name: "calendars",
initialState: { list: {} as Record<string, Calendars>, pending: false }, initialState: { list: {} as Record<string, Calendars>, pending: false },
@@ -160,9 +169,15 @@ const CalendarSlice = createSlice({
Object.keys(state.list[action.payload.calId].events).forEach((id) => { Object.keys(state.list[action.payload.calId].events).forEach((id) => {
state.list[action.payload.calId].events[id].color = state.list[action.payload.calId].events[id].color =
state.list[action.payload.calId].color; state.list[action.payload.calId].color;
state.list[action.payload.calId].events[id].calId =
action.payload.calId;
}); });
} }
) )
.addCase(deleteEventAsync.fulfilled, (state, action) => {
state.pending = false;
delete state.list[action.payload.calId].events[action.payload.eventId];
})
.addCase(getCalendarDetailAsync.pending, (state) => { .addCase(getCalendarDetailAsync.pending, (state) => {
state.pending = true; state.pending = true;
}) })
@@ -171,6 +186,9 @@ const CalendarSlice = createSlice({
}) })
.addCase(putEventAsync.pending, (state) => { .addCase(putEventAsync.pending, (state) => {
state.pending = true; state.pending = true;
})
.addCase(deleteEventAsync.pending, (state) => {
state.pending = true;
}); });
}, },
}); });
+2 -2
View File
@@ -5,7 +5,7 @@ import { calendarEventToJCal } from "./eventUtils";
export async function putEvent(cal: Calendars, event: CalendarEvent) { export async function putEvent(cal: Calendars, event: CalendarEvent) {
const response = await api( const response = await api(
`dav/calendars/${cal.id}/${event.uid.split(".")[0]}.isc`, `dav/calendars/${cal.id}/${event.uid.split("/")[0]}.isc`,
{ {
method: "PUT", method: "PUT",
body: JSON.stringify(calendarEventToJCal(event)), body: JSON.stringify(calendarEventToJCal(event)),
@@ -19,7 +19,7 @@ export async function putEvent(cal: Calendars, event: CalendarEvent) {
export async function deleteEvent(calId: string, eventId: string) { export async function deleteEvent(calId: string, eventId: string) {
const response = await api( const response = await api(
`dav/calendars/${calId}/${eventId.split(".")[0]}.isc`, `dav/calendars/${calId}/${eventId.split("/")[0]}.isc`,
{ {
method: "DELETE", method: "DELETE",
} }
+19 -14
View File
@@ -1,30 +1,20 @@
import React, { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { addEvent } from "../Calendars/CalendarSlice"; import { deleteEventAsync } from "../Calendars/CalendarSlice";
import { CalendarEvent } from "./EventsTypes";
import { DateSelectArg } from "@fullcalendar/core";
import { useAppDispatch, useAppSelector } from "../../app/hooks"; import { useAppDispatch, useAppSelector } from "../../app/hooks";
import { import {
Popover, Popover,
TextField,
Button, Button,
Box, Box,
Typography, Typography,
Select,
MenuItem,
SelectChangeEvent,
Avatar,
ButtonGroup, ButtonGroup,
Card, Card,
CardContent, CardContent,
Divider, Divider,
IconButton, IconButton,
} from "@mui/material"; } from "@mui/material";
import EventModal from "./EventModal";
import EditIcon from "@mui/icons-material/Edit"; import EditIcon from "@mui/icons-material/Edit";
import DeleteIcon from "@mui/icons-material/Delete"; import DeleteIcon from "@mui/icons-material/Delete";
import MoreVertIcon from "@mui/icons-material/MoreVert";
import CloseIcon from "@mui/icons-material/Close"; import CloseIcon from "@mui/icons-material/Close";
import VisibilityIcon from "@mui/icons-material/Visibility";
import CalendarTodayIcon from "@mui/icons-material/CalendarToday"; import CalendarTodayIcon from "@mui/icons-material/CalendarToday";
import LocationOnIcon from "@mui/icons-material/LocationOn"; import LocationOnIcon from "@mui/icons-material/LocationOn";
import VideocamIcon from "@mui/icons-material/Videocam"; import VideocamIcon from "@mui/icons-material/Videocam";
@@ -45,6 +35,7 @@ function EventDisplayModal({
onClose: (event: {}, reason: "backdropClick" | "escapeKeyDown") => void; onClose: (event: {}, reason: "backdropClick" | "escapeKeyDown") => void;
}) { }) {
if (calId && eventId) { if (calId && eventId) {
const dispatch = useAppDispatch();
const calendar = useAppSelector((state) => state.calendars.list[calId]); const calendar = useAppSelector((state) => state.calendars.list[calId]);
const event = useAppSelector( const event = useAppSelector(
(state) => state.calendars.list[calId].events[eventId] (state) => state.calendars.list[calId].events[eventId]
@@ -53,6 +44,14 @@ function EventDisplayModal({
const [showAllAttendees, setShowAllAttendees] = useState(false); const [showAllAttendees, setShowAllAttendees] = useState(false);
const attendeeDisplayLimit = 3; const attendeeDisplayLimit = 3;
useEffect(() => {
if (!event || !calendar) {
onClose({}, "backdropClick");
}
}, [event, calendar, onClose]);
if (!event || !calendar) return null;
const visibleAttendees = showAllAttendees const visibleAttendees = showAllAttendees
? event.attendee ? event.attendee
: event.attendee.slice(0, attendeeDisplayLimit); : event.attendee.slice(0, attendeeDisplayLimit);
@@ -73,7 +72,13 @@ function EventDisplayModal({
<IconButton size="small"> <IconButton size="small">
<EditIcon fontSize="small" /> <EditIcon fontSize="small" />
</IconButton> </IconButton>
<IconButton size="small"> <IconButton
size="small"
onClick={() => {
onClose({}, "backdropClick");
dispatch(deleteEventAsync({ calId, eventId }));
}}
>
<DeleteIcon fontSize="small" /> <DeleteIcon fontSize="small" />
</IconButton> </IconButton>
<IconButton <IconButton
@@ -187,7 +192,7 @@ function EventDisplayModal({
{/* Attendance options */} {/* Attendance options */}
{event.attendee.find( {event.attendee.find(
(person) => person.cal_address === `mailto:${user.userData.email}` (person) => person.cal_address === user.userData.email
) && ( ) && (
<Box> <Box>
<Typography variant="body2" sx={{ mb: 1 }}> <Typography variant="body2" sx={{ mb: 1 }}>
+1 -1
View File
@@ -70,7 +70,7 @@ function EventPopover({
const handleSave = async () => { const handleSave = async () => {
const newEvent: CalendarEvent = { const newEvent: CalendarEvent = {
calId: calendarid, calId: userPersonnalCalendars[calendarid].id,
title, title,
start: new Date(start), start: new Date(start),
allday, allday,