* mv useTeamMembersWithSegment * remove * fix ts error * remove * remove * remove * biome rule * wip * refactor: remove remaining @calcom/trpc/server imports from atoms - Create local types for schedule handlers (CreateScheduleHandlerReturn, DuplicateScheduleHandlerReturn, GetAvailabilityListHandlerReturn, CreateScheduleInput) - Create local GetAvailableSlotsResponse type for slots hook - Update imports in useAtomCreateSchedule, useAtomDuplicateSchedule, useAtomGetAllSchedules, and useAvailableSlots Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix * fix: add userId to Schedule type and create ScheduleForList type - Schedule type now includes userId for create/duplicate handlers - Created ScheduleForList type for list handler (uses select without userId) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix * fix * fix * fix * fix: correct fromUser/toUser types in GetAvailableSlotsResponse - fromUser: { id, displayName } (matches IFromUser) - toUser: { id, username, displayName } (matches IToUser) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
|
import type {
|
|
GetAvailableSlotsInput_2024_04_15,
|
|
ApiResponse,
|
|
ApiSuccessResponse,
|
|
} from "@calcom/platform-types";
|
|
|
|
import http from "../lib/http";
|
|
import type { GetAvailableSlotsResponse } from "../booker/types";
|
|
|
|
export const QUERY_KEY = "get-available-slots";
|
|
|
|
export const useAvailableSlots = ({
|
|
enabled,
|
|
...rest
|
|
}: GetAvailableSlotsInput_2024_04_15 & { enabled: boolean }) => {
|
|
const availableSlots = useQuery({
|
|
queryKey: [
|
|
QUERY_KEY,
|
|
rest.startTime,
|
|
rest.endTime,
|
|
rest.eventTypeId,
|
|
rest.eventTypeSlug,
|
|
rest.isTeamEvent ?? false,
|
|
rest.teamId ?? false,
|
|
rest.usernameList,
|
|
rest.routedTeamMemberIds,
|
|
rest.skipContactOwner,
|
|
rest.teamMemberEmail,
|
|
rest.rrHostSubsetIds,
|
|
],
|
|
queryFn: () => {
|
|
return http
|
|
.get<ApiResponse<GetAvailableSlotsResponse>>("/slots/available", {
|
|
params: rest,
|
|
})
|
|
.then((res) => {
|
|
if (res.data.status === SUCCESS_STATUS) {
|
|
return (res.data as ApiSuccessResponse<GetAvailableSlotsResponse>).data;
|
|
}
|
|
throw new Error(res.data.error.message);
|
|
});
|
|
},
|
|
enabled: enabled,
|
|
});
|
|
return availableSlots;
|
|
};
|