2022-09-06 22:58:16 +00:00
|
|
|
import classNames from "@calcom/lib/classNames";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-05-11 13:20:39 +00:00
|
|
|
import { List } from "@calcom/ui";
|
2023-05-17 12:47:44 +00:00
|
|
|
import { ArrowRight } from "@calcom/ui/components/icon";
|
2022-09-06 22:58:16 +00:00
|
|
|
|
2023-05-11 13:20:39 +00:00
|
|
|
import { AppConnectionItem } from "../components/AppConnectionItem";
|
2022-09-06 22:58:16 +00:00
|
|
|
import { ConnectedCalendarItem } from "../components/ConnectedCalendarItem";
|
|
|
|
import { CreateEventsOnCalendarSelect } from "../components/CreateEventsOnCalendarSelect";
|
2023-05-11 13:20:39 +00:00
|
|
|
import { StepConnectionLoader } from "../components/StepConnectionLoader";
|
2022-09-06 22:58:16 +00:00
|
|
|
|
|
|
|
interface IConnectCalendarsProps {
|
|
|
|
nextStep: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConnectedCalendars = (props: IConnectCalendarsProps) => {
|
|
|
|
const { nextStep } = props;
|
2022-11-10 23:40:01 +00:00
|
|
|
const queryConnectedCalendars = trpc.viewer.connectedCalendars.useQuery();
|
2022-09-06 22:58:16 +00:00
|
|
|
const { t } = useLocale();
|
2022-11-10 23:40:01 +00:00
|
|
|
const queryIntegrations = trpc.viewer.integrations.useQuery({ variant: "calendar", onlyInstalled: false });
|
2022-09-06 22:58:16 +00:00
|
|
|
|
|
|
|
const firstCalendar = queryConnectedCalendars.data?.connectedCalendars.find(
|
|
|
|
(item) => item.calendars && item.calendars?.length > 0
|
|
|
|
);
|
|
|
|
const disabledNextButton = firstCalendar === undefined;
|
|
|
|
const destinationCalendar = queryConnectedCalendars.data?.destinationCalendar;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{/* Already connected calendars */}
|
2022-09-22 04:26:56 +00:00
|
|
|
{!queryConnectedCalendars.isLoading &&
|
|
|
|
firstCalendar &&
|
2022-09-06 22:58:16 +00:00
|
|
|
firstCalendar.integration &&
|
|
|
|
firstCalendar.integration.title &&
|
2023-04-11 11:38:37 +00:00
|
|
|
firstCalendar.integration.logo && (
|
2022-09-06 22:58:16 +00:00
|
|
|
<>
|
2023-05-11 13:20:39 +00:00
|
|
|
<List className="bg-default border-subtle rounded-md border p-0 dark:bg-black ">
|
2022-09-06 22:58:16 +00:00
|
|
|
<ConnectedCalendarItem
|
|
|
|
key={firstCalendar.integration.title}
|
|
|
|
name={firstCalendar.integration.title}
|
2023-04-11 11:38:37 +00:00
|
|
|
logo={firstCalendar.integration.logo}
|
2022-09-06 22:58:16 +00:00
|
|
|
externalId={
|
|
|
|
firstCalendar && firstCalendar.calendars && firstCalendar.calendars.length > 0
|
|
|
|
? firstCalendar.calendars[0].externalId
|
|
|
|
: ""
|
|
|
|
}
|
|
|
|
calendars={firstCalendar.calendars}
|
|
|
|
integrationType={firstCalendar.integration.type}
|
|
|
|
/>
|
|
|
|
</List>
|
|
|
|
{/* Create event on selected calendar */}
|
|
|
|
<CreateEventsOnCalendarSelect calendar={destinationCalendar} />
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="text-subtle mt-4 text-sm">{t("connect_calendars_from_app_store")}</p>
|
2022-09-06 22:58:16 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{/* Connect calendars list */}
|
|
|
|
{firstCalendar === undefined && queryIntegrations.data && queryIntegrations.data.items.length > 0 && (
|
2023-04-05 18:14:46 +00:00
|
|
|
<List className="bg-default divide-subtle border-subtle mx-1 divide-y rounded-md border p-0 dark:bg-black sm:mx-0">
|
2022-09-06 22:58:16 +00:00
|
|
|
{queryIntegrations.data &&
|
|
|
|
queryIntegrations.data.items.map((item) => (
|
|
|
|
<li key={item.title}>
|
2023-04-11 11:38:37 +00:00
|
|
|
{item.title && item.logo && (
|
2023-05-11 13:20:39 +00:00
|
|
|
<AppConnectionItem
|
2022-09-06 22:58:16 +00:00
|
|
|
type={item.type}
|
|
|
|
title={item.title}
|
|
|
|
description={item.description}
|
2023-04-11 11:38:37 +00:00
|
|
|
logo={item.logo}
|
2022-09-06 22:58:16 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
)}
|
|
|
|
|
2023-05-11 13:20:39 +00:00
|
|
|
{queryIntegrations.isLoading && <StepConnectionLoader />}
|
|
|
|
|
2022-09-06 22:58:16 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
data-testid="save-calendar-button"
|
|
|
|
className={classNames(
|
2023-04-05 18:14:46 +00:00
|
|
|
"text-inverted mt-8 flex w-full flex-row justify-center rounded-md border border-black bg-black p-2 text-center text-sm",
|
2022-09-06 22:58:16 +00:00
|
|
|
disabledNextButton ? "cursor-not-allowed opacity-20" : ""
|
|
|
|
)}
|
|
|
|
onClick={() => nextStep()}
|
|
|
|
disabled={disabledNextButton}>
|
|
|
|
{firstCalendar ? `${t("continue")}` : `${t("next_step_text")}`}
|
2023-05-17 12:47:44 +00:00
|
|
|
<ArrowRight className="ml-2 h-4 w-4 self-center" aria-hidden="true" />
|
2022-09-06 22:58:16 +00:00
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export { ConnectedCalendars };
|