refactor: Extract schedule determination to seperate fn (#26600)
* refactor: Extract schedule determination to seperate fn * refactor: Extract schedule detection to seperate file and add tests * RouterOutputs should be used in hooks, not direct type imports
This commit is contained in:
1 parent
58798f27d2
commit
312733ce68
4 files changed
+345
-60
No files matched your search
@@ -2,17 +2,23 @@ import { useSession } from "next-auth/react";
|
||||
import { useMemo, useEffect } from "react";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { GetUserAvailabilityResult } from "@calcom/features/availability/lib/getUserAvailability";
|
||||
|
||||
import type { CalendarEvent } from "@calcom/features/calendars/weeklyview/types/events";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
|
||||
type UseOnboardingCalendarEventsProps = {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
};
|
||||
|
||||
const emptyAvailabilityData = {
|
||||
type UseOnboardingCalendarEventsResult = {
|
||||
events: CalendarEvent[];
|
||||
isLoading: boolean;
|
||||
};
|
||||
|
||||
const emptyAvailabilityData: RouterOutputs["viewer"]["availability"]["user"] = {
|
||||
busy: [],
|
||||
timeZone: "",
|
||||
dateRanges: [],
|
||||
@@ -21,9 +27,12 @@ const emptyAvailabilityData = {
|
||||
dateOverrides: [],
|
||||
currentSeats: null,
|
||||
datesOutOfOffice: {},
|
||||
} as GetUserAvailabilityResult;
|
||||
};
|
||||
|
||||
export const useOnboardingCalendarEvents = ({ startDate, endDate }: UseOnboardingCalendarEventsProps) => {
|
||||
export const useOnboardingCalendarEvents = ({
|
||||
startDate,
|
||||
endDate,
|
||||
}: UseOnboardingCalendarEventsProps): UseOnboardingCalendarEventsResult => {
|
||||
const { data: session } = useSession();
|
||||
const utils = trpc.useUtils();
|
||||
|
||||
@@ -65,7 +74,6 @@ export const useOnboardingCalendarEvents = ({ startDate, endDate }: UseOnboardin
|
||||
start: new Date(event.start),
|
||||
end: new Date(event.end),
|
||||
options: {
|
||||
color: event.source ? undefined : undefined,
|
||||
status: BookingStatus.ACCEPTED,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user