Skip to content

[Maintenance] - Allow Deletion of Future Events #4516

Description

@Santiordon

Description

Currently you can either delete a single instance of a recurring schedule slot or all instances of the recurring schedule slot (aka, delete the entire event). The request is to add a third option to delete all future scheduled slots of that event.

Image

Acceptance Criteria

  • Add a third option: "All future occurrences (X slots)"
  • Create the API endpoint that deletes any future schedule slots
  • BONUS: CalendarWeekView.tsx and CalendarDayView.tsx both have this function (also EventClickPopup.tsx):
const handleSeriesDeleteConfirm = async (deleteEntireEvent: boolean) => {
    try {
      setShowSeriesDeleteModal(false);
      setLockedTooltipEventId(null);
      if (deleteEntireEvent) {
        await deleteEvent();
        toast.success('Event deleted successfully!');
      } else {
        await deleteScheduleSlot();
        toast.success('Event occurrence deleted successfully!');
      }
    } catch (err) {
      if (err instanceof Error) toast.error(err.message);
    }
  };
  • If possible, please merge these all into one shared function from a helper file

Proposed Solution

  • Start by removing the logic that is currently in place. As it stands right now, there is a boolean: either all events, or one event. You must turn this into an Enum instead where it is either all events, future events, or the one event. For this you must reformat setDeleteEntireEvent within DeleteSeriesConfirmationModal.tsx with a new name and for it must take that Enum as its state.
  • Add the new FormControlLabel below the other options
  • Create the mutation similar to the one below: (name it useDeleteFutureScheduleSlots
export const useDeleteScheduleSlot = (eventId: string, scheduleSlotId: string) => {
  const queryClient = useQueryClient();
  return useMutation<Event, Error>(
    ['events', 'delete-schedule-slot', eventId, scheduleSlotId],
    async () => {
      const { data } = await postDeleteScheduleSlot(eventId, scheduleSlotId);
      return data;
    },
    {
      onSuccess: () => {
        queryClient.invalidateQueries(['filter-events']);
        queryClient.invalidateQueries(EVENT_KEY);
        queryClient.invalidateQueries(['events', eventId]);
      }
    }
  );
};
  • Create the axios post similar to: (name it postDeleteFutureScheduleSlots)
export const postDeleteScheduleSlot = async (eventId: string, scheduleSlotId: string) => {
  return axios.post<Event>(
    apiUrls.calendarDeleteScheduleSlot(eventId, scheduleSlotId),
    {},
    {
      transformResponse: (data) => eventTransformer(JSON.parse(data))
    }
  );
};
  • Make a new route in calendar.routes.ts similar to this:
calendarRouter.post('/event/:eventId/schedule-slot/:scheduleSlotId/delete', CalendarController.deleteScheduleSlot);
  • Make a new function in CalendarController.ts named deleteFutureScheduleSlots
  • Make a function in CalendarService.ts also named deleteFutureScheduleSlots
  • It may be very helpful to follow deleteScheduleSlot in calendar.service.ts
  • Do a prisma call to find all schedule slots after a "selectedDate" (gte stands for Greater Than or Equal to ensure that you also delete the current one seleted as well)
const scheduleSlots = await prisma.schedule_Slot.findMany({
  where: {
    startTime: {
      gte: selectedDate
    }
  }
});
  • Follow the rest of the logic that happens in deleteScheduleSlot within calendar.service.ts.

Mocks

Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions