2022-06-01 17:24:41 +00:00
|
|
|
import React from "react";
|
|
|
|
import Select from "react-select";
|
|
|
|
import { OptionProps } from "react-select";
|
|
|
|
|
|
|
|
import { InstallAppButton } from "@calcom/app-store/components";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-06-01 17:24:41 +00:00
|
|
|
import type { App } from "@calcom/types/App";
|
|
|
|
import { Button } from "@calcom/ui";
|
|
|
|
|
|
|
|
import { QueryCell } from "@lib/QueryCell";
|
|
|
|
|
|
|
|
interface AdditionalCalendarSelectorProps {
|
|
|
|
isLoading?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ImageOption = (optionProps: OptionProps<{ [key: string]: string; type: App["type"] }>) => {
|
|
|
|
const { data } = optionProps;
|
|
|
|
return (
|
|
|
|
<InstallAppButton
|
|
|
|
type={data.type}
|
|
|
|
render={(installProps) => {
|
|
|
|
return (
|
|
|
|
<Button {...installProps} className="w-full" color="minimal">
|
|
|
|
{/* eslint-disable @next/next/no-img-element */}
|
|
|
|
{data.image && (
|
|
|
|
<img className="float-left mr-3 inline h-5 w-5" src={data.image} alt={data.label} />
|
|
|
|
)}
|
|
|
|
<p>{data.label}</p>
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const AdditionalCalendarSelector = ({ isLoading }: AdditionalCalendarSelectorProps): JSX.Element | null => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const query = trpc.useQuery(["viewer.integrations", { variant: "calendar", onlyInstalled: true }]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<QueryCell
|
|
|
|
query={query}
|
|
|
|
success={({ data }) => {
|
|
|
|
const options = data.items.map((item) => ({
|
|
|
|
label: item.name,
|
|
|
|
slug: item.slug,
|
2022-08-13 11:04:57 +00:00
|
|
|
image: item.logo,
|
2022-06-01 17:24:41 +00:00
|
|
|
type: item.type,
|
|
|
|
}));
|
|
|
|
return (
|
|
|
|
<Select
|
2022-07-12 17:50:04 +00:00
|
|
|
name="additionalCalendar"
|
2022-06-01 17:24:41 +00:00
|
|
|
placeholder={t("connect_additional_calendar")}
|
|
|
|
options={options}
|
|
|
|
styles={{
|
|
|
|
placeholder: (defaultStyles) => {
|
|
|
|
return {
|
|
|
|
...defaultStyles,
|
|
|
|
color: "#3E3E3E",
|
|
|
|
marginLeft: "3px",
|
|
|
|
};
|
|
|
|
},
|
2022-06-09 20:49:09 +00:00
|
|
|
control: (defaultStyles) => {
|
|
|
|
return {
|
|
|
|
...defaultStyles,
|
|
|
|
borderRadius: "2px",
|
2022-06-20 17:33:07 +00:00
|
|
|
"@media only screen and (min-width: 640px)": {
|
|
|
|
...(defaultStyles["@media only screen and (min-width: 640px)"] as object),
|
|
|
|
maxWidth: "320px",
|
|
|
|
},
|
2022-06-09 20:49:09 +00:00
|
|
|
};
|
|
|
|
},
|
2022-06-01 17:24:41 +00:00
|
|
|
}}
|
|
|
|
isSearchable={false}
|
2022-07-27 02:24:00 +00:00
|
|
|
className="mt-1 mb-2 block w-full min-w-0 flex-1 rounded-none rounded-r-sm border-gray-300 text-sm font-medium text-gray-700"
|
2022-06-01 17:24:41 +00:00
|
|
|
isLoading={isLoading}
|
|
|
|
components={{ Option: ImageOption }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AdditionalCalendarSelector;
|