Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use-primary-by-default-overlay #11935

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from "next/link";
import { useRouter } from "next/navigation";
import { Fragment } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { Fragment, useEffect, useState } from "react";

import { classNames } from "@calcom/lib";
import { useLocale } from "@calcom/lib/hooks/useLocale";
Expand Down Expand Up @@ -43,17 +43,35 @@ const SkeletonLoader = () => {

export function OverlayCalendarSettingsModal(props: IOverlayCalendarContinueModalProps) {
const utils = trpc.useContext();
const [initalised, setInitalised] = useState(false);
const searchParams = useSearchParams();
const setOverlayBusyDates = useOverlayCalendarStore((state) => state.setOverlayBusyDates);
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;
externalId: string;
}>("toggledConnectedCalendars", []);

const router = useRouter();
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]);
Comment on lines +61 to +73
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to use initialised here to ensure this only runs ONCE after the primary has been selected - allowing users to deselect the calendar if they wish


return (
<>
<Dialog open={props.open} onOpenChange={props.onClose}>
Expand Down