2021-03-24 15:03:04 +00:00
|
|
|
import Head from 'next/head';
|
2021-04-10 12:02:35 +00:00
|
|
|
import Link from 'next/link';
|
|
|
|
import prisma from '../../lib/prisma';
|
|
|
|
import Shell from '../../components/Shell';
|
2021-03-24 15:03:04 +00:00
|
|
|
import { useState } from 'react';
|
|
|
|
import { useSession, getSession } from 'next-auth/client';
|
2021-04-21 10:10:27 +00:00
|
|
|
import { CheckCircleIcon, XCircleIcon, ChevronRightIcon, PlusIcon } from '@heroicons/react/solid';
|
|
|
|
import { InformationCircleIcon } from '@heroicons/react/outline';
|
2021-03-24 15:03:04 +00:00
|
|
|
|
2021-03-30 13:23:51 +00:00
|
|
|
export default function Home(props) {
|
2021-03-26 15:51:19 +00:00
|
|
|
const [session, loading] = useSession();
|
|
|
|
const [showAddModal, setShowAddModal] = useState(false);
|
2021-03-24 15:03:04 +00:00
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return <p className="text-gray-400">Loading...</p>;
|
|
|
|
} else {
|
|
|
|
if (!session) {
|
2021-03-26 15:51:19 +00:00
|
|
|
window.location.href = "/";
|
2021-03-24 15:03:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-26 15:51:19 +00:00
|
|
|
function toggleAddModal() {
|
|
|
|
setShowAddModal(!showAddModal);
|
|
|
|
}
|
|
|
|
|
|
|
|
function googleCalendarHandler() {
|
|
|
|
fetch('/api/integrations/googlecalendar/add')
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => window.location.href = data.url);
|
|
|
|
}
|
|
|
|
|
2021-03-24 15:03:04 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Head>
|
|
|
|
<title>Integrations | Calendso</title>
|
|
|
|
<link rel="icon" href="/favicon.ico" />
|
|
|
|
</Head>
|
|
|
|
|
|
|
|
<Shell heading="Integrations">
|
|
|
|
<div className="bg-white shadow overflow-hidden sm:rounded-lg">
|
|
|
|
<ul className="divide-y divide-gray-200">
|
2021-03-30 13:23:51 +00:00
|
|
|
{props.credentials.map((integration) =>
|
2021-03-24 15:03:04 +00:00
|
|
|
<li>
|
2021-04-10 12:02:35 +00:00
|
|
|
<Link href={"/integrations/" + integration.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">
|
|
|
|
{integration.type == 'google_calendar' && <img className="h-10 w-10 mr-2" src="integrations/google-calendar.png" alt="Google Calendar" />}
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
2021-04-10 12:02:35 +00:00
|
|
|
<div className="min-w-0 flex-1 px-4 md:grid md:grid-cols-2 md:gap-4">
|
2021-03-24 15:03:04 +00:00
|
|
|
<div>
|
2021-04-10 12:02:35 +00:00
|
|
|
{integration.type == 'google_calendar' && <p className="text-sm font-medium text-blue-600 truncate">Google Calendar</p>}
|
|
|
|
<p className="mt-2 flex items-center text-sm text-gray-500">
|
|
|
|
{integration.type == 'google_calendar' && <span className="truncate">Calendar Integration</span>}
|
2021-03-24 15:03:04 +00:00
|
|
|
</p>
|
2021-04-10 12:02:35 +00:00
|
|
|
</div>
|
|
|
|
<div className="hidden md:block">
|
|
|
|
<div>
|
|
|
|
{integration.key &&
|
|
|
|
<p className="mt-3 flex items-center text text-gray-500">
|
2021-04-21 10:10:27 +00:00
|
|
|
<CheckCircleIcon className="flex-shrink-0 mr-1.5 h-5 w-5 text-green-400" />
|
2021-04-10 12:02:35 +00:00
|
|
|
Connected
|
|
|
|
</p>
|
|
|
|
}
|
|
|
|
{!integration.key &&
|
|
|
|
<p className="mt-3 flex items-center text text-gray-500">
|
2021-04-21 10:10:27 +00:00
|
|
|
<XCircleIcon className="flex-shrink-0 mr-1.5 h-5 w-5 text-yellow-400" />
|
2021-04-10 12:02:35 +00:00
|
|
|
Not connected
|
|
|
|
</p>
|
|
|
|
}
|
|
|
|
</div>
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-10 12:02:35 +00:00
|
|
|
<div>
|
2021-04-21 10:10:27 +00:00
|
|
|
<ChevronRightIcon className="h-5 w-5 text-gray-400" />
|
2021-04-10 12:02:35 +00:00
|
|
|
</div>
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
2021-04-10 12:02:35 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
2021-03-24 15:03:04 +00:00
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</ul>
|
2021-03-30 13:23:51 +00:00
|
|
|
{props.credentials.length == 0 &&
|
2021-03-26 15:51:19 +00:00
|
|
|
<div className="bg-white shadow sm:rounded-lg">
|
|
|
|
<div className="flex">
|
|
|
|
<div className="py-9 pl-8">
|
2021-04-21 10:10:27 +00:00
|
|
|
<InformationCircleIcon className="text-blue-600 w-16" />
|
2021-03-26 15:51:19 +00:00
|
|
|
</div>
|
|
|
|
<div className="py-5 sm:p-6">
|
|
|
|
<h3 className="text-lg leading-6 font-medium text-gray-900">
|
|
|
|
You don't have any integrations added.
|
|
|
|
</h3>
|
|
|
|
<div className="mt-2 text-sm text-gray-500">
|
|
|
|
<p>
|
|
|
|
You currently do not have any integrations set up. Add your first integration to get started.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="mt-3 text-sm">
|
|
|
|
<button onClick={toggleAddModal} className="font-medium text-blue-600 hover:text-blue-500"> Add your first integration <span aria-hidden="true">→</span></button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
{showAddModal &&
|
|
|
|
<div className="fixed z-10 inset-0 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true">
|
|
|
|
<div className="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
|
|
|
|
{/* <!--
|
|
|
|
Background overlay, show/hide based on modal state.
|
|
|
|
|
|
|
|
Entering: "ease-out duration-300"
|
|
|
|
From: "opacity-0"
|
|
|
|
To: "opacity-100"
|
|
|
|
Leaving: "ease-in duration-200"
|
|
|
|
From: "opacity-100"
|
|
|
|
To: "opacity-0"
|
|
|
|
--> */}
|
|
|
|
<div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" aria-hidden="true"></div>
|
|
|
|
<span className="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">​</span>
|
|
|
|
{/* <!--
|
|
|
|
Modal panel, show/hide based on modal state.
|
|
|
|
|
|
|
|
Entering: "ease-out duration-300"
|
|
|
|
From: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
|
|
To: "opacity-100 translate-y-0 sm:scale-100"
|
|
|
|
Leaving: "ease-in duration-200"
|
|
|
|
From: "opacity-100 translate-y-0 sm:scale-100"
|
|
|
|
To: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
|
|
--> */}
|
|
|
|
<div className="inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6">
|
|
|
|
<div className="sm:flex sm:items-start">
|
|
|
|
<div className="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-blue-100 sm:mx-0 sm:h-10 sm:w-10">
|
2021-04-21 10:10:27 +00:00
|
|
|
<PlusIcon className="h-6 w-6 text-blue-600" />
|
2021-03-26 15:51:19 +00:00
|
|
|
</div>
|
|
|
|
<div className="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
|
|
|
|
<h3 className="text-lg leading-6 font-medium text-gray-900" id="modal-title">
|
|
|
|
Add a new integration
|
|
|
|
</h3>
|
|
|
|
<div>
|
|
|
|
<p className="text-sm text-gray-400">
|
|
|
|
Link a new integration to your account.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="my-4">
|
|
|
|
<ul className="divide-y divide-gray-200">
|
|
|
|
<li className="flex py-4">
|
|
|
|
<div className="w-1/12 mr-4 pt-2">
|
|
|
|
<img className="h-8 w-8 mr-2" src="integrations/google-calendar.png" alt="Google Calendar" />
|
|
|
|
</div>
|
|
|
|
<div className="w-10/12">
|
|
|
|
<h2 className="text-gray-800 font-medium">Google Calendar</h2>
|
|
|
|
<p className="text-gray-400 text-sm">For personal and business accounts</p>
|
|
|
|
</div>
|
|
|
|
<div className="w-2/12 text-right pt-2">
|
|
|
|
<button onClick={googleCalendarHandler} className="font-medium text-blue-600 hover:text-blue-500">Add</button>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
|
|
|
<button onClick={toggleAddModal} type="button" className="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:w-auto sm:text-sm">
|
|
|
|
Close
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
2021-03-26 15:51:19 +00:00
|
|
|
}
|
2021-03-24 15:03:04 +00:00
|
|
|
</Shell>
|
|
|
|
</div>
|
|
|
|
);
|
2021-03-30 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getServerSideProps(context) {
|
|
|
|
const session = await getSession(context);
|
|
|
|
|
|
|
|
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: {
|
2021-04-10 12:02:35 +00:00
|
|
|
id: true,
|
2021-03-30 13:23:51 +00:00
|
|
|
type: true,
|
|
|
|
key: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
props: {credentials}, // will be passed to the page component as props
|
|
|
|
}
|
2021-03-24 15:03:04 +00:00
|
|
|
}
|