feat/use-primary-by-default-overlay (#11935)
parent
9b348adb6a
commit
6b6d3d90e4
|
@ -1,6 +1,6 @@
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
import { Fragment } from "react";
|
import { Fragment, useEffect, useState } from "react";
|
||||||
|
|
||||||
import { classNames } from "@calcom/lib";
|
import { classNames } from "@calcom/lib";
|
||||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||||
|
@ -43,17 +43,35 @@ const SkeletonLoader = () => {
|
||||||
|
|
||||||
export function OverlayCalendarSettingsModal(props: IOverlayCalendarContinueModalProps) {
|
export function OverlayCalendarSettingsModal(props: IOverlayCalendarContinueModalProps) {
|
||||||
const utils = trpc.useContext();
|
const utils = trpc.useContext();
|
||||||
|
const [initalised, setInitalised] = useState(false);
|
||||||
|
const searchParams = useSearchParams();
|
||||||
const setOverlayBusyDates = useOverlayCalendarStore((state) => state.setOverlayBusyDates);
|
const setOverlayBusyDates = useOverlayCalendarStore((state) => state.setOverlayBusyDates);
|
||||||
const { data, isLoading } = trpc.viewer.connectedCalendars.useQuery(undefined, {
|
const { data, isLoading } = trpc.viewer.connectedCalendars.useQuery(undefined, {
|
||||||
enabled: !!props.open,
|
enabled: !!props.open || !!searchParams.get("overlayCalendar"),
|
||||||
});
|
});
|
||||||
const { toggleValue, hasItem } = useLocalSet<{
|
const { toggleValue, hasItem, set } = useLocalSet<{
|
||||||
credentialId: number;
|
credentialId: number;
|
||||||
externalId: string;
|
externalId: string;
|
||||||
}>("toggledConnectedCalendars", []);
|
}>("toggledConnectedCalendars", []);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t } = useLocale();
|
const { t } = useLocale();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data?.connectedCalendars && set.size === 0 && !initalised) {
|
||||||
|
data?.connectedCalendars.forEach((item) => {
|
||||||
|
item.calendars?.forEach((cal) => {
|
||||||
|
const id = { credentialId: item.credentialId, externalId: cal.externalId };
|
||||||
|
if (cal.primary) {
|
||||||
|
toggleValue(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
setInitalised(true);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [data, hasItem, set, initalised]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Dialog open={props.open} onOpenChange={props.onClose}>
|
<Dialog open={props.open} onOpenChange={props.onClose}>
|
||||||
|
|
Loading…
Reference in New Issue