mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* 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: [email protected] <[email protected]> * 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: [email protected] <[email protected]> * 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: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
|
import type { ApiResponse, ApiErrorResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
|
|
|
import http from "../../lib/http";
|
|
import type { CreateScheduleHandlerReturn, CreateScheduleInput as CreateScheduleSchema } from "./types";
|
|
import { QUERY_KEY as SchedulesQueryKey } from "./useAtomGetAllSchedules";
|
|
import { QUERY_KEY as ScheduleQueryKey } from "./useAtomSchedule";
|
|
|
|
interface useAtomCreateScheduleOptions {
|
|
onSuccess?: (res: ApiSuccessResponse<CreateScheduleHandlerReturn>) => void;
|
|
onError?: (err: ApiErrorResponse) => void;
|
|
}
|
|
|
|
export const useAtomCreateSchedule = (
|
|
{ onSuccess, onError }: useAtomCreateScheduleOptions = {
|
|
onSuccess: () => {
|
|
return;
|
|
},
|
|
onError: () => {
|
|
return;
|
|
},
|
|
}
|
|
) => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation<ApiResponse<CreateScheduleHandlerReturn>, unknown, CreateScheduleSchema>({
|
|
mutationFn: async (body: CreateScheduleSchema) => {
|
|
const url = `atoms/schedules/create`;
|
|
const response = await http.post<ApiResponse<CreateScheduleHandlerReturn>>(url, body);
|
|
return response.data;
|
|
},
|
|
onSuccess: (data) => {
|
|
if (data.status === SUCCESS_STATUS) {
|
|
onSuccess?.(data);
|
|
queryClient.invalidateQueries({ queryKey: [ScheduleQueryKey] });
|
|
queryClient.invalidateQueries({ queryKey: [SchedulesQueryKey] });
|
|
} else {
|
|
onError?.(data);
|
|
}
|
|
},
|
|
onError: (err) => {
|
|
onError?.(err as ApiErrorResponse);
|
|
},
|
|
});
|
|
};
|