From 2ba80fcdb657ba8dbe0b9e62c54ac79396f3e293 Mon Sep 17 00:00:00 2001 From: lenhanphung Date: Thu, 9 Oct 2025 13:28:21 +0700 Subject: [PATCH] fix: handle converting recurring events to non-recurring events in edit all mode --- src/features/Events/EventDisplay.tsx | 2 +- src/features/Events/EventUpdateModal.tsx | 38 ++++++++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/features/Events/EventDisplay.tsx b/src/features/Events/EventDisplay.tsx index 475dd2c..b94a79f 100644 --- a/src/features/Events/EventDisplay.tsx +++ b/src/features/Events/EventDisplay.tsx @@ -46,7 +46,7 @@ import { import { Calendars } from "../Calendars/CalendarTypes"; import { userAttendee } from "../User/userDataTypes"; import { getEvent } from "./EventApi"; -import { formatLocalDateTime } from "../../components/Event/EventFormFields"; +import { formatLocalDateTime } from "./EventModal"; import { CalendarEvent, RepetitionObject } from "./EventsTypes"; export default function EventDisplayModal({ diff --git a/src/features/Events/EventUpdateModal.tsx b/src/features/Events/EventUpdateModal.tsx index ab71e14..a406034 100644 --- a/src/features/Events/EventUpdateModal.tsx +++ b/src/features/Events/EventUpdateModal.tsx @@ -361,12 +361,38 @@ function EventUpdateModal({ ); } else if (typeOfAction === "all") { // Update all instances - dispatch( - updateSeriesAsync({ - cal: targetCalendar, - event: { ...newEvent, recurrenceId }, - }) - ); + + // Special case: When converting recurring event to non-recurring + if (event.repetition?.freq && !repetition.freq) { + // For repeat -> no-repeat, create a new non-repeating event + dispatch( + putEventAsync({ + cal: targetCalendar, + newEvent: { + ...newEvent, + uid: crypto.randomUUID(), // Generate new ID for the single event + URL: `/calendars/${newCalId || calId}/${crypto.randomUUID()}.ics`, + }, + }) + ); + + // Delete the old repeating series + const baseUID = event.uid.split("/")[0]; + Object.keys(targetCalendar.events).forEach((eventId) => { + if (eventId.split("/")[0] === baseUID) { + dispatch(removeEvent({ calendarUid: calId, eventUid: eventId })); + } + }); + } else { + // Normal update for recurring events + dispatch( + updateSeriesAsync({ + cal: targetCalendar, + event: { ...newEvent, recurrenceId }, + }) + ); + } + // Refresh calendars to ensure all instances are updated const calendarRange = getCalendarRange(new Date(start)); await refreshCalendars(dispatch, Object.values(calendarsList), calendarRange);