From d709dd5223aab5d0b0b1dc094b5da4725753c0cd Mon Sep 17 00:00:00 2001 From: VedantGupta-DTU Date: Sat, 28 Mar 2026 19:51:12 +0000 Subject: [PATCH] feat: extract generic useCalendarList hook decoupled from Outlook - Created apps/meteor/client/views/calendar/hooks/useCalendarList.ts with provider-agnostic useCalendarList(date) and useCalendarListForToday() hooks that call /v1/calendar-events.list endpoint directly - Refactored useOutlookCalendarList to delegate to the generic hook - Marked Outlook-specific wrappers as @deprecated - Updated query keys from [outlook, calendar, list] to [calendar, list] so cache invalidation works across all calendar sources - Aligns with GSoC goal of supporting multiple calendar integrations --- .../views/calendar/hooks/useCalendarList.ts | 31 +++++++++++++++++++ .../hooks/useOutlookCalendarList.ts | 28 ++++++++--------- 2 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 apps/meteor/client/views/calendar/hooks/useCalendarList.ts diff --git a/apps/meteor/client/views/calendar/hooks/useCalendarList.ts b/apps/meteor/client/views/calendar/hooks/useCalendarList.ts new file mode 100644 index 0000000000000..9a72d1b436197 --- /dev/null +++ b/apps/meteor/client/views/calendar/hooks/useCalendarList.ts @@ -0,0 +1,31 @@ +import { useEndpoint } from '@rocket.chat/ui-contexts'; +import { useQuery } from '@tanstack/react-query'; + +/** + * Generic hook to fetch calendar events for a given date. + * + * This hook calls the provider-agnostic `/v1/calendar-events.list` endpoint, + * so it works regardless of the calendar source (Outlook, Google, CalDAV, etc.). + * + * @param date - The date for which to fetch calendar events. + * @returns A React Query result containing the list of calendar events. + */ +export const useCalendarList = (date: Date) => { + const calendarData = useEndpoint('GET', '/v1/calendar-events.list'); + + return useQuery({ + queryKey: ['calendar', 'list', date.toISOString()], + + queryFn: async () => { + const { data } = await calendarData({ date: date.toISOString() }); + return data; + }, + }); +}; + +/** + * Convenience wrapper that fetches calendar events for today's date. + */ +export const useCalendarListForToday = () => { + return useCalendarList(new Date()); +}; diff --git a/apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts b/apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts index 372f68352d9d2..bbf644faf7db6 100644 --- a/apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts +++ b/apps/meteor/client/views/outlookCalendar/hooks/useOutlookCalendarList.ts @@ -1,24 +1,24 @@ -import { useToastMessageDispatch, useTranslation, useEndpoint } from '@rocket.chat/ui-contexts'; -import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; +import { useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; import { useOutlookAuthenticationMutation } from './useOutlookAuthentication'; +import { useCalendarList, useCalendarListForToday } from '../../calendar/hooks/useCalendarList'; import { syncOutlookEvents } from '../lib/syncOutlookEvents'; +/** + * @deprecated Use {@link useCalendarListForToday} from `views/calendar/hooks/useCalendarList` directly. + * Kept for backward compatibility with existing Outlook calendar views. + */ export const useOutlookCalendarListForToday = () => { - return useOutlookCalendarList(new Date()); + return useCalendarListForToday(); }; +/** + * @deprecated Use {@link useCalendarList} from `views/calendar/hooks/useCalendarList` directly. + * Kept for backward compatibility with existing Outlook calendar views. + */ export const useOutlookCalendarList = (date: Date) => { - const calendarData = useEndpoint('GET', '/v1/calendar-events.list'); - - return useQuery({ - queryKey: ['outlook', 'calendar', 'list'], - - queryFn: async () => { - const { data } = await calendarData({ date: date.toISOString() }); - return data; - }, - }); + return useCalendarList(date); }; export const useMutationOutlookCalendarSync = () => { @@ -34,7 +34,7 @@ export const useMutationOutlookCalendarSync = () => { await syncOutlookEvents(); await queryClient.invalidateQueries({ - queryKey: ['outlook', 'calendar', 'list'], + queryKey: ['calendar', 'list'], }); await checkOutlookCredentials.mutateAsync();