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();