2021-07-20 18:18:26 +00:00
|
|
|
import Head from "next/head";
|
|
|
|
import Link from "next/link";
|
|
|
|
import prisma from "../../lib/prisma";
|
|
|
|
import Shell from "../../components/Shell";
|
2021-08-15 14:22:05 +00:00
|
|
|
import { useEffect, useState, useRef, useCallback } from "react";
|
2021-07-20 18:18:26 +00:00
|
|
|
import { getSession, useSession } from "next-auth/client";
|
2021-08-06 12:32:08 +00:00
|
|
|
import { CheckCircleIcon, ChevronRightIcon, PlusIcon, XCircleIcon } from "@heroicons/react/solid";
|
2021-07-20 18:18:26 +00:00
|
|
|
import { InformationCircleIcon } from "@heroicons/react/outline";
|
2021-08-08 19:21:33 +00:00
|
|
|
import { Dialog, DialogClose, DialogContent, DialogHeader, DialogTrigger } from "@components/Dialog";
|
2021-08-09 22:43:57 +00:00
|
|
|
import Switch from "@components/ui/Switch";
|
|
|
|
import Loader from "@components/Loader";
|
2021-08-15 14:22:05 +00:00
|
|
|
import AddCalDavIntegration, {
|
|
|
|
ADD_CALDAV_INTEGRATION_FORM_TITLE,
|
|
|
|
} from "@lib/integrations/CalDav/components/AddCalDavIntegration";
|
2021-08-15 01:53:59 +00:00
|
|
|
|
|
|
|
type Integration = {
|
|
|
|
installed: boolean;
|
|
|
|
credential: unknown;
|
|
|
|
type: string;
|
|
|
|
title: string;
|
|
|
|
imageSrc: string;
|
|
|
|
description: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
integrations: Integration[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function Home({ integrations }: Props) {
|
|
|
|
const [, loading] = useSession();
|
2021-03-24 15:03:04 +00:00
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
const [selectableCalendars, setSelectableCalendars] = useState([]);
|
2021-08-15 01:53:59 +00:00
|
|
|
const addCalDavIntegrationRef = useRef<HTMLFormElement>(null);
|
|
|
|
const [isAddCalDavIntegrationDialogOpen, setIsAddCalDavIntegrationDialogOpen] = useState(false);
|
2021-08-15 14:22:05 +00:00
|
|
|
const [addCalDavError, setAddCalDavError] = useState<{ message: string } | null>(null);
|
2021-08-15 01:53:59 +00:00
|
|
|
|
|
|
|
useEffect(loadCalendars, [integrations]);
|
2021-03-24 15:03:04 +00:00
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
function loadCalendars() {
|
|
|
|
fetch("api/availability/calendar")
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
|
|
|
setSelectableCalendars(data);
|
|
|
|
});
|
|
|
|
}
|
2021-06-14 17:45:24 +00:00
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
function integrationHandler(type) {
|
2021-08-15 01:53:59 +00:00
|
|
|
if (type === "caldav_calendar") {
|
2021-08-15 14:22:05 +00:00
|
|
|
setAddCalDavError(null);
|
2021-08-15 01:53:59 +00:00
|
|
|
setIsAddCalDavIntegrationDialogOpen(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
fetch("/api/integrations/" + type.replace("_", "") + "/add")
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => (window.location.href = data.url));
|
|
|
|
}
|
2021-03-26 15:51:19 +00:00
|
|
|
|
2021-08-15 01:53:59 +00:00
|
|
|
const handleAddCalDavIntegration = async ({ url, username, password }) => {
|
|
|
|
const requestBody = JSON.stringify({
|
|
|
|
url,
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
});
|
|
|
|
|
2021-08-15 14:22:05 +00:00
|
|
|
return await fetch("/api/integrations/caldav/add", {
|
2021-08-15 01:53:59 +00:00
|
|
|
method: "POST",
|
|
|
|
body: requestBody,
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
function calendarSelectionHandler(calendar) {
|
|
|
|
return (selected) => {
|
2021-08-09 22:43:57 +00:00
|
|
|
const i = selectableCalendars.findIndex((c) => c.externalId === calendar.externalId);
|
|
|
|
selectableCalendars[i].selected = selected;
|
2021-07-20 18:18:26 +00:00
|
|
|
if (selected) {
|
|
|
|
fetch("api/availability/calendar", {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
2021-08-09 22:43:57 +00:00
|
|
|
body: JSON.stringify(selectableCalendars[i]),
|
2021-07-20 18:18:26 +00:00
|
|
|
}).then((response) => response.json());
|
|
|
|
} else {
|
|
|
|
fetch("api/availability/calendar", {
|
|
|
|
method: "DELETE",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
2021-08-09 22:43:57 +00:00
|
|
|
body: JSON.stringify(selectableCalendars[i]),
|
2021-07-20 18:18:26 +00:00
|
|
|
}).then((response) => response.json());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-06-14 17:45:24 +00:00
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
function getCalendarIntegrationImage(integrationType: string) {
|
|
|
|
switch (integrationType) {
|
|
|
|
case "google_calendar":
|
2021-08-02 14:10:24 +00:00
|
|
|
return "integrations/google-calendar.svg";
|
2021-07-20 18:18:26 +00:00
|
|
|
case "office365_calendar":
|
2021-08-02 14:10:24 +00:00
|
|
|
return "integrations/outlook.svg";
|
2021-08-15 01:53:59 +00:00
|
|
|
case "caldav_calendar":
|
2021-08-15 16:37:50 +00:00
|
|
|
return "integrations/caldav.svg";
|
2021-07-20 18:18:26 +00:00
|
|
|
default:
|
|
|
|
return "";
|
2021-06-14 17:45:24 +00:00
|
|
|
}
|
2021-07-20 18:18:26 +00:00
|
|
|
}
|
2021-06-14 17:45:24 +00:00
|
|
|
|
2021-08-09 22:43:57 +00:00
|
|
|
function onCloseSelectCalendar() {
|
|
|
|
setSelectableCalendars([...selectableCalendars]);
|
|
|
|
}
|
|
|
|
|
2021-08-06 12:32:08 +00:00
|
|
|
const ConnectNewAppDialog = () => (
|
|
|
|
<Dialog>
|
|
|
|
<DialogTrigger className="py-2 px-4 mt-6 border border-transparent rounded-sm shadow-sm text-sm font-medium text-white bg-neutral-900 hover:bg-neutral-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-neutral-900">
|
|
|
|
<PlusIcon className="w-5 h-5 mr-1 inline" />
|
|
|
|
Connect a new App
|
|
|
|
</DialogTrigger>
|
|
|
|
|
|
|
|
<DialogContent>
|
|
|
|
<DialogHeader title="Connect a new App" subtitle="Connect a new app to your account." />
|
|
|
|
<div className="my-4">
|
|
|
|
<ul className="divide-y divide-gray-200">
|
|
|
|
{integrations
|
|
|
|
.filter((integration) => integration.installed)
|
2021-08-15 01:53:59 +00:00
|
|
|
.map((integration) => {
|
|
|
|
return (
|
|
|
|
<li key={integration.type} className="flex py-4">
|
|
|
|
<div className="w-1/12 mr-4 pt-2">
|
|
|
|
<img className="h-8 w-8 mr-2" src={integration.imageSrc} alt={integration.title} />
|
|
|
|
</div>
|
|
|
|
<div className="w-10/12">
|
|
|
|
<h2 className="text-gray-800 font-medium">{integration.title}</h2>
|
|
|
|
<p className="text-gray-400 text-sm">{integration.description}</p>
|
|
|
|
</div>
|
|
|
|
<div className="w-2/12 text-right pt-2">
|
2021-08-15 14:22:05 +00:00
|
|
|
<button
|
|
|
|
onClick={() => integrationHandler(integration.type)}
|
|
|
|
className="font-medium text-neutral-900 hover:text-neutral-500">
|
|
|
|
Add
|
|
|
|
</button>
|
2021-08-15 01:53:59 +00:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})}
|
2021-08-06 12:32:08 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
|
|
|
<DialogClose as="button" className="btn btn-white mx-2">
|
|
|
|
Cancel
|
|
|
|
</DialogClose>
|
|
|
|
</div>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
|
|
|
|
const SelectCalendarDialog = () => (
|
2021-08-09 22:43:57 +00:00
|
|
|
<Dialog onOpenChange={(open) => !open && onCloseSelectCalendar()}>
|
2021-08-06 12:32:08 +00:00
|
|
|
<DialogTrigger className="py-2 px-4 mt-6 border border-transparent rounded-sm shadow-sm text-sm font-medium text-white bg-neutral-900 hover:bg-neutral-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-neutral-900">
|
|
|
|
Select calendars
|
|
|
|
</DialogTrigger>
|
|
|
|
|
|
|
|
<DialogContent>
|
|
|
|
<DialogHeader
|
|
|
|
title="Select calendars"
|
|
|
|
subtitle="If no entry is selected, all calendars will be checked"
|
|
|
|
/>
|
|
|
|
<div className="my-4">
|
|
|
|
<ul className="divide-y divide-gray-200">
|
|
|
|
{selectableCalendars.map((calendar) => (
|
|
|
|
<li key={calendar.name} className="flex py-4">
|
|
|
|
<div className="w-1/12 mr-4 pt-2">
|
|
|
|
<img
|
|
|
|
className="h-8 w-8 mr-2"
|
|
|
|
src={getCalendarIntegrationImage(calendar.integration)}
|
|
|
|
alt={calendar.integration}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="w-10/12 pt-3">
|
|
|
|
<h2 className="text-gray-800 font-medium">{calendar.name}</h2>
|
|
|
|
</div>
|
|
|
|
<div className="w-2/12 text-right pt-3">
|
|
|
|
<Switch
|
2021-08-09 22:43:57 +00:00
|
|
|
defaultChecked={calendar.selected}
|
|
|
|
onCheckedChange={calendarSelectionHandler(calendar)}
|
|
|
|
/>
|
2021-08-06 12:32:08 +00:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
|
|
|
<DialogClose as="button" className="btn btn-white mx-2">
|
|
|
|
Cancel
|
|
|
|
</DialogClose>
|
|
|
|
</div>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
|
2021-08-15 14:22:05 +00:00
|
|
|
const handleAddCalDavIntegrationSaveButtonPress = async () => {
|
2021-08-15 01:53:59 +00:00
|
|
|
const form = addCalDavIntegrationRef.current.elements;
|
|
|
|
const url = form.url.value;
|
|
|
|
const password = form.password.value;
|
|
|
|
const username = form.username.value;
|
|
|
|
|
2021-08-15 14:22:05 +00:00
|
|
|
try {
|
|
|
|
setAddCalDavError(null);
|
|
|
|
const addCalDavIntegrationResponse = await handleAddCalDavIntegration({ username, password, url });
|
|
|
|
if (addCalDavIntegrationResponse.ok) {
|
|
|
|
setIsAddCalDavIntegrationDialogOpen(false);
|
2021-08-15 01:53:59 +00:00
|
|
|
} else {
|
2021-08-15 14:22:05 +00:00
|
|
|
const j = await addCalDavIntegrationResponse.json();
|
|
|
|
setAddCalDavError({ message: j.message });
|
2021-08-15 01:53:59 +00:00
|
|
|
}
|
2021-08-15 14:22:05 +00:00
|
|
|
} catch (reason) {
|
|
|
|
console.error(reason);
|
2021-08-15 01:53:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-15 14:22:05 +00:00
|
|
|
const ConnectCalDavServerDialog = useCallback(() => {
|
2021-08-15 01:53:59 +00:00
|
|
|
return (
|
2021-08-15 14:22:05 +00:00
|
|
|
<Dialog
|
|
|
|
open={isAddCalDavIntegrationDialogOpen}
|
|
|
|
onOpenChange={(isOpen) => setIsAddCalDavIntegrationDialogOpen(isOpen)}>
|
2021-08-15 01:53:59 +00:00
|
|
|
<DialogContent>
|
2021-08-15 11:10:01 +00:00
|
|
|
<DialogHeader
|
|
|
|
title="Connect to CalDav Server"
|
|
|
|
subtitle="Your credentials will be stored and encrypted."
|
|
|
|
/>
|
|
|
|
<div className="my-4">
|
2021-08-15 14:22:05 +00:00
|
|
|
{addCalDavError && (
|
|
|
|
<p className="text-red-700 text-sm">
|
|
|
|
<span className="font-bold">Error: </span>
|
|
|
|
{addCalDavError.message}
|
|
|
|
</p>
|
|
|
|
)}
|
2021-08-15 11:10:01 +00:00
|
|
|
<AddCalDavIntegration
|
|
|
|
ref={addCalDavIntegrationRef}
|
|
|
|
onSubmit={handleAddCalDavIntegrationSaveButtonPress}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
|
|
|
<button
|
2021-08-15 14:22:05 +00:00
|
|
|
type="submit"
|
|
|
|
form={ADD_CALDAV_INTEGRATION_FORM_TITLE}
|
2021-08-15 11:10:01 +00:00
|
|
|
className="flex justify-center py-2 px-4 border border-transparent rounded-sm shadow-sm text-sm font-medium text-white bg-neutral-900 hover:bg-neutral-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-neutral-900">
|
|
|
|
Save
|
|
|
|
</button>
|
2021-08-15 13:49:30 +00:00
|
|
|
<DialogClose
|
|
|
|
onClick={() => {
|
|
|
|
setIsAddCalDavIntegrationDialogOpen(false);
|
|
|
|
}}
|
|
|
|
as="button"
|
|
|
|
className="btn btn-white mx-2">
|
2021-08-15 11:10:01 +00:00
|
|
|
Cancel
|
|
|
|
</DialogClose>
|
2021-08-15 01:53:59 +00:00
|
|
|
</div>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
);
|
2021-08-15 14:22:05 +00:00
|
|
|
}, [isAddCalDavIntegrationDialogOpen, addCalDavError]);
|
2021-08-15 01:53:59 +00:00
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return <Loader />;
|
|
|
|
}
|
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Head>
|
2021-08-05 12:02:59 +00:00
|
|
|
<title>App Store | Calendso</title>
|
2021-07-20 18:18:26 +00:00
|
|
|
<link rel="icon" href="/favicon.ico" />
|
|
|
|
</Head>
|
2021-03-24 15:03:04 +00:00
|
|
|
|
2021-08-06 12:32:08 +00:00
|
|
|
<Shell heading="App Store" subtitle="Connect your favourite apps." CTA={<ConnectNewAppDialog />}>
|
2021-08-05 12:13:34 +00:00
|
|
|
<div className="bg-white border border-gray-200 overflow-hidden rounded-sm mb-8">
|
2021-07-20 18:18:26 +00:00
|
|
|
{integrations.filter((ig) => ig.credential).length !== 0 ? (
|
|
|
|
<ul className="divide-y divide-gray-200">
|
|
|
|
{integrations
|
|
|
|
.filter((ig) => ig.credential)
|
|
|
|
.map((ig) => (
|
2021-08-09 22:43:57 +00:00
|
|
|
<li key={ig.credential.id}>
|
2021-07-20 18:18:26 +00:00
|
|
|
<Link href={"/integrations/" + ig.credential.id}>
|
|
|
|
<a className="block hover:bg-gray-50">
|
|
|
|
<div className="flex items-center px-4 py-4 sm:px-6">
|
|
|
|
<div className="min-w-0 flex-1 flex items-center">
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
<img className="h-10 w-10 mr-2" src={ig.imageSrc} alt={ig.title} />
|
2021-05-04 20:31:15 +00:00
|
|
|
</div>
|
2021-07-20 18:18:26 +00:00
|
|
|
<div className="min-w-0 flex-1 px-4 md:grid md:grid-cols-2 md:gap-4">
|
|
|
|
<div>
|
2021-07-30 23:05:38 +00:00
|
|
|
<p className="text-sm font-medium text-neutral-900 truncate">{ig.title}</p>
|
2021-07-20 18:18:26 +00:00
|
|
|
<p className="flex items-center text-sm text-gray-500">
|
|
|
|
{ig.type.endsWith("_calendar") && (
|
|
|
|
<span className="truncate">Calendar Integration</span>
|
|
|
|
)}
|
|
|
|
{ig.type.endsWith("_video") && (
|
|
|
|
<span className="truncate">Video Conferencing</span>
|
|
|
|
)}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="hidden md:block">
|
|
|
|
{ig.credential.key && (
|
|
|
|
<p className="mt-2 flex items-center text text-gray-500">
|
|
|
|
<CheckCircleIcon className="flex-shrink-0 mr-1.5 h-5 w-5 text-green-400" />
|
|
|
|
Connected
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
{!ig.credential.key && (
|
|
|
|
<p className="mt-3 flex items-center text text-gray-500">
|
|
|
|
<XCircleIcon className="flex-shrink-0 mr-1.5 h-5 w-5 text-yellow-400" />
|
|
|
|
Not connected
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-03-26 15:51:19 +00:00
|
|
|
</div>
|
2021-07-20 18:18:26 +00:00
|
|
|
<div>
|
|
|
|
<ChevronRightIcon className="h-5 w-5 text-gray-400" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-26 15:51:19 +00:00
|
|
|
</div>
|
2021-07-20 18:18:26 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
) : (
|
2021-07-30 23:05:38 +00:00
|
|
|
<div className="bg-white shadow rounded-sm">
|
2021-07-20 18:18:26 +00:00
|
|
|
<div className="flex">
|
|
|
|
<div className="py-9 pl-8">
|
2021-07-30 23:05:38 +00:00
|
|
|
<InformationCircleIcon className="text-neutral-900 w-16" />
|
2021-03-26 15:51:19 +00:00
|
|
|
</div>
|
2021-07-20 18:18:26 +00:00
|
|
|
<div className="py-5 sm:p-6">
|
|
|
|
<h3 className="text-lg leading-6 font-medium text-gray-900">
|
2021-08-05 12:13:34 +00:00
|
|
|
You don't have any apps connected.
|
2021-07-20 18:18:26 +00:00
|
|
|
</h3>
|
|
|
|
<div className="mt-2 text-sm text-gray-500">
|
|
|
|
<p>
|
2021-08-05 12:13:34 +00:00
|
|
|
You currently do not have any apps connected. Connect your first app to get started.
|
2021-07-20 18:18:26 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2021-08-06 12:32:08 +00:00
|
|
|
<ConnectNewAppDialog />
|
2021-07-20 18:18:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-08-05 12:13:34 +00:00
|
|
|
<div className="bg-white border border-gray-200 rounded-sm mb-8">
|
2021-07-20 18:18:26 +00:00
|
|
|
<div className="px-4 py-5 sm:p-6">
|
|
|
|
<h3 className="text-lg leading-6 font-medium text-gray-900">Select calendars</h3>
|
|
|
|
<div className="mt-2 max-w-xl text-sm text-gray-500">
|
|
|
|
<p>Select which calendars are checked for availability to prevent double bookings.</p>
|
|
|
|
</div>
|
2021-08-06 12:32:08 +00:00
|
|
|
<SelectCalendarDialog />
|
2021-07-20 18:18:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-05 12:13:34 +00:00
|
|
|
<div className="border border-gray-200 rounded-sm">
|
|
|
|
<div className="px-4 py-5 sm:p-6">
|
|
|
|
<h3 className="text-lg leading-6 font-medium text-gray-900">Launch your own App</h3>
|
|
|
|
<div className="mt-2 max-w-xl text-sm text-gray-500">
|
|
|
|
<p>If you want to add your own App here, get in touch with us.</p>
|
|
|
|
</div>
|
|
|
|
<div className="mt-5">
|
2021-08-06 23:08:55 +00:00
|
|
|
<a href="mailto:apps@calendso.com" className="btn btn-white">
|
2021-08-05 12:13:34 +00:00
|
|
|
Contact us
|
|
|
|
</a>
|
2021-07-20 18:18:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-05 12:13:34 +00:00
|
|
|
</div>
|
2021-08-15 14:22:05 +00:00
|
|
|
<ConnectCalDavServerDialog />
|
2021-07-20 18:18:26 +00:00
|
|
|
</Shell>
|
|
|
|
</div>
|
|
|
|
);
|
2021-03-30 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 20:31:15 +00:00
|
|
|
const validJson = (jsonString: string) => {
|
2021-07-20 18:18:26 +00:00
|
|
|
try {
|
|
|
|
const o = JSON.parse(jsonString);
|
|
|
|
if (o && typeof o === "object") {
|
|
|
|
return o;
|
2021-05-04 20:31:15 +00:00
|
|
|
}
|
2021-07-20 18:18:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2021-05-04 20:31:15 +00:00
|
|
|
|
2021-03-30 13:23:51 +00:00
|
|
|
export async function getServerSideProps(context) {
|
2021-07-20 18:18:26 +00:00
|
|
|
const session = await getSession(context);
|
|
|
|
if (!session) {
|
|
|
|
return { redirect: { permanent: false, destination: "/auth/login" } };
|
|
|
|
}
|
|
|
|
const user = await prisma.user.findFirst({
|
|
|
|
where: {
|
|
|
|
email: session.user.email,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
},
|
|
|
|
});
|
2021-03-30 13:23:51 +00:00
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
const credentials = await prisma.credential.findMany({
|
|
|
|
where: {
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
type: true,
|
|
|
|
key: true,
|
|
|
|
},
|
|
|
|
});
|
2021-05-04 20:31:15 +00:00
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
const integrations = [
|
|
|
|
{
|
|
|
|
installed: !!(process.env.GOOGLE_API_CREDENTIALS && validJson(process.env.GOOGLE_API_CREDENTIALS)),
|
|
|
|
credential: credentials.find((integration) => integration.type === "google_calendar") || null,
|
|
|
|
type: "google_calendar",
|
|
|
|
title: "Google Calendar",
|
2021-08-02 14:10:24 +00:00
|
|
|
imageSrc: "integrations/google-calendar.svg",
|
2021-07-20 18:18:26 +00:00
|
|
|
description: "For personal and business calendars",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
installed: !!(process.env.MS_GRAPH_CLIENT_ID && process.env.MS_GRAPH_CLIENT_SECRET),
|
|
|
|
type: "office365_calendar",
|
|
|
|
credential: credentials.find((integration) => integration.type === "office365_calendar") || null,
|
|
|
|
title: "Office 365 / Outlook.com Calendar",
|
2021-08-02 14:10:24 +00:00
|
|
|
imageSrc: "integrations/outlook.svg",
|
2021-07-20 18:18:26 +00:00
|
|
|
description: "For personal and business calendars",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
installed: !!(process.env.ZOOM_CLIENT_ID && process.env.ZOOM_CLIENT_SECRET),
|
|
|
|
type: "zoom_video",
|
|
|
|
credential: credentials.find((integration) => integration.type === "zoom_video") || null,
|
|
|
|
title: "Zoom",
|
2021-08-02 14:10:24 +00:00
|
|
|
imageSrc: "integrations/zoom.svg",
|
2021-07-20 18:18:26 +00:00
|
|
|
description: "Video Conferencing",
|
|
|
|
},
|
2021-08-15 01:53:59 +00:00
|
|
|
{
|
|
|
|
installed: true,
|
|
|
|
type: "caldav_calendar",
|
|
|
|
credential: credentials.find((integration) => integration.type === "caldav_calendar") || null,
|
|
|
|
title: "CalDav Server",
|
2021-08-15 16:37:50 +00:00
|
|
|
imageSrc: "integrations/caldav.svg",
|
2021-08-15 01:53:59 +00:00
|
|
|
description: "For personal and business calendars",
|
|
|
|
},
|
2021-07-20 18:18:26 +00:00
|
|
|
];
|
2021-05-04 20:31:15 +00:00
|
|
|
|
2021-07-20 18:18:26 +00:00
|
|
|
return {
|
|
|
|
props: { integrations },
|
|
|
|
};
|
2021-06-17 16:06:32 +00:00
|
|
|
}
|