Fix onboarding calendar connection (#3036)
parent
a2bb210ebd
commit
2faf7e6806
|
@ -1,6 +1,7 @@
|
||||||
import { Fragment } from "react";
|
import { Fragment } from "react";
|
||||||
import { useMutation } from "react-query";
|
import { useMutation } from "react-query";
|
||||||
|
|
||||||
|
import { InstallAppButton } from "@calcom/app-store/components";
|
||||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||||
import showToast from "@calcom/lib/notification";
|
import showToast from "@calcom/lib/notification";
|
||||||
import { Alert } from "@calcom/ui/Alert";
|
import { Alert } from "@calcom/ui/Alert";
|
||||||
|
@ -22,6 +23,7 @@ import SubHeadingTitleWithConnections from "./SubHeadingTitleWithConnections";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onChanged: () => unknown | Promise<unknown>;
|
onChanged: () => unknown | Promise<unknown>;
|
||||||
|
fromOnboarding?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function CalendarSwitch(props: {
|
function CalendarSwitch(props: {
|
||||||
|
@ -93,10 +95,44 @@ function CalendarSwitch(props: {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CalendarList(props: Props) {
|
||||||
|
const { t } = useLocale();
|
||||||
|
const query = trpc.useQuery(["viewer.integrations", { variant: "calendar", onlyInstalled: false }]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<QueryCell
|
||||||
|
query={query}
|
||||||
|
success={({ data }) => (
|
||||||
|
<List>
|
||||||
|
{data.items.map((item) => (
|
||||||
|
<IntegrationListItem
|
||||||
|
key={item.title}
|
||||||
|
title={item.title}
|
||||||
|
imageSrc={item.imageSrc}
|
||||||
|
description={item.description}
|
||||||
|
actions={
|
||||||
|
<InstallAppButton
|
||||||
|
type={item.type}
|
||||||
|
render={(buttonProps) => (
|
||||||
|
<Button color="secondary" {...buttonProps}>
|
||||||
|
{t("connect")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
onChanged={() => props.onChanged()}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function ConnectedCalendarsList(props: Props) {
|
function ConnectedCalendarsList(props: Props) {
|
||||||
const { t } = useLocale();
|
const { t } = useLocale();
|
||||||
const query = trpc.useQuery(["viewer.connectedCalendars"], { suspense: true });
|
const query = trpc.useQuery(["viewer.connectedCalendars"], { suspense: true });
|
||||||
|
const { fromOnboarding } = props;
|
||||||
return (
|
return (
|
||||||
<QueryCell
|
<QueryCell
|
||||||
query={query}
|
query={query}
|
||||||
|
@ -125,6 +161,8 @@ function ConnectedCalendarsList(props: Props) {
|
||||||
onOpenChange={props.onChanged}
|
onOpenChange={props.onChanged}
|
||||||
/>
|
/>
|
||||||
}>
|
}>
|
||||||
|
{!fromOnboarding && (
|
||||||
|
<>
|
||||||
<p className="px-4 pt-4 text-sm text-neutral-500">
|
<p className="px-4 pt-4 text-sm text-neutral-500">
|
||||||
Toggle the calendar(s) you want to check for conflicts to prevent double bookings.
|
Toggle the calendar(s) you want to check for conflicts to prevent double bookings.
|
||||||
</p>
|
</p>
|
||||||
|
@ -139,6 +177,8 @@ function ConnectedCalendarsList(props: Props) {
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</IntegrationListItem>
|
</IntegrationListItem>
|
||||||
) : (
|
) : (
|
||||||
<Alert
|
<Alert
|
||||||
|
@ -167,9 +207,9 @@ function ConnectedCalendarsList(props: Props) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CalendarListContainer(props: { heading?: false }) {
|
export function CalendarListContainer(props: { heading?: boolean; fromOnboarding?: boolean }) {
|
||||||
const { t } = useLocale();
|
const { t } = useLocale();
|
||||||
const { heading = true } = props;
|
const { heading = true, fromOnboarding } = props;
|
||||||
const utils = trpc.useContext();
|
const utils = trpc.useContext();
|
||||||
const onChanged = () =>
|
const onChanged = () =>
|
||||||
Promise.allSettled([
|
Promise.allSettled([
|
||||||
|
@ -210,6 +250,7 @@ export function CalendarListContainer(props: { heading?: false }) {
|
||||||
value={data.destinationCalendar?.externalId}
|
value={data.destinationCalendar?.externalId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!!data.connectedCalendars.length && (
|
{!!data.connectedCalendars.length && (
|
||||||
<div className="sm:min-w-80 inline max-w-full">
|
<div className="sm:min-w-80 inline max-w-full">
|
||||||
<AdditionalCalendarSelector isLoading={mutation.isLoading} />
|
<AdditionalCalendarSelector isLoading={mutation.isLoading} />
|
||||||
|
@ -219,7 +260,18 @@ export function CalendarListContainer(props: { heading?: false }) {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<ConnectedCalendarsList onChanged={onChanged} />
|
<ConnectedCalendarsList onChanged={onChanged} fromOnboarding />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{fromOnboarding && (
|
||||||
|
<>
|
||||||
|
{!!query.data?.connectedCalendars.length && (
|
||||||
|
<ShellSubHeading
|
||||||
|
className="mt-4"
|
||||||
|
title={<SubHeadingTitleWithConnections title={t("connect_additional_calendar")} />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<CalendarList onChanged={onChanged} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -429,7 +429,7 @@ export default function Onboarding(props: inferSSRProps<typeof getServerSideProp
|
||||||
description: t("connect_your_calendar_instructions"),
|
description: t("connect_your_calendar_instructions"),
|
||||||
Component: (
|
Component: (
|
||||||
<ClientSuspense fallback={<Loader />}>
|
<ClientSuspense fallback={<Loader />}>
|
||||||
<CalendarListContainer heading={false} />
|
<CalendarListContainer heading={false} fromOnboarding={true} />
|
||||||
</ClientSuspense>
|
</ClientSuspense>
|
||||||
),
|
),
|
||||||
hideConfirm: true,
|
hideConfirm: true,
|
||||||
|
|
Loading…
Reference in New Issue