mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* fix: missiing imports * chore: add popover components for atoms * chore: keep openapi spec up to date
22 lines
634 B
TypeScript
22 lines
634 B
TypeScript
import type { Schedule } from "@calcom/lib/schedules/transformers/getScheduleListItemData";
|
|
import { useEffect, useRef } from "react";
|
|
|
|
export function useEnsureDefaultSchedule(
|
|
schedules: Schedule[],
|
|
onUpdateSchedule: (scheduleId: number) => void | Promise<void>
|
|
): void {
|
|
const onUpdateRef = useRef(onUpdateSchedule);
|
|
|
|
useEffect(() => {
|
|
onUpdateRef.current = onUpdateSchedule;
|
|
});
|
|
|
|
useEffect(() => {
|
|
const defaultSchedule = schedules.filter((schedule) => schedule.isDefault);
|
|
|
|
if (defaultSchedule.length === 0 && schedules.length > 0) {
|
|
onUpdateRef.current(schedules[0].id);
|
|
}
|
|
}, [schedules]);
|
|
}
|