import Head from 'next/head'; import Link from 'next/link'; import prisma from '../../lib/prisma'; import Shell from '../../components/Shell'; import {useState} from 'react'; import {getSession, useSession} from 'next-auth/client'; import {CheckCircleIcon, ChevronRightIcon, PlusIcon, XCircleIcon} from '@heroicons/react/solid'; import {InformationCircleIcon} from '@heroicons/react/outline'; export default function Home({ integrations }) { const [session, loading] = useSession(); const [showAddModal, setShowAddModal] = useState(false); if (loading) { return

Loading...

; } function toggleAddModal() { setShowAddModal(!showAddModal); } function integrationHandler(type) { fetch('/api/integrations/' + type.replace('_', '') + '/add') .then((response) => response.json()) .then((data) => window.location.href = data.url); } return (
Integrations | Calendso
{integrations.filter( (ig) => ig.credential ).length !== 0 ? :

You don't have any integrations added.

You currently do not have any integrations set up. Add your first integration to get started.

}
{showAddModal &&
{/* */} {/* */}

Link a new integration to your account.

    {integrations.filter( (integration) => integration.installed ).map( (integration) => (
  • {integration.title}

    { integration.title }

    { integration.description }

  • ))}
}
); } const validJson = (jsonString: string) => { try { const o = JSON.parse(jsonString); if (o && typeof o === "object") { return o; } } catch (e) {} return false; } export async function getServerSideProps(context) { 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 } }); const credentials = await prisma.credential.findMany({ where: { userId: user.id, }, select: { id: true, type: true, key: true } }); 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", imageSrc: "integrations/google-calendar.png", description: "For personal and business accounts", }, { 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", imageSrc: "integrations/office-365.png", description: "For personal and business accounts", }, { 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", imageSrc: "integrations/zoom.png", description: "For personal and business accounts", } ]; return { props: {integrations}, } }