diff --git a/lib/integrations.ts b/lib/integrations.ts new file mode 100644 index 00000000..940ea153 --- /dev/null +++ b/lib/integrations.ts @@ -0,0 +1,17 @@ +export function getIntegrationName(name: String) { + switch(name) { + case "google_calendar": + return "Google Calendar"; + default: + return "Unknown"; + } +} + +export function getIntegrationType(name: String) { + switch(name) { + case "google_calendar": + return "Calendar"; + default: + return "Unknown"; + } +} \ No newline at end of file diff --git a/pages/api/integrations.ts b/pages/api/integrations.ts index 7401a98d..df39f691 100644 --- a/pages/api/integrations.ts +++ b/pages/api/integrations.ts @@ -30,4 +30,32 @@ export default async function handler(req, res) { res.status(200).json(credentials); } + + if (req.method == "DELETE") { + const session = await getSession({req: req}); + + if (!session) { res.status(401).json({message: 'You must be logged in to do this'}); return; } + + // TODO: Add user ID to user session object + const user = await prisma.user.findFirst({ + where: { + email: session.user.email, + }, + select: { + id: true + } + }); + + if (!user) { res.status(404).json({message: 'User not found'}); return; } + + const id = req.body.id; + + const deleteIntegration = await prisma.credential.delete({ + where: { + id: id, + }, + }); + + res.status(200).json({message: 'Integration deleted successfully'}); + } } \ No newline at end of file diff --git a/pages/integrations/[integration].tsx b/pages/integrations/[integration].tsx new file mode 100644 index 00000000..6366122a --- /dev/null +++ b/pages/integrations/[integration].tsx @@ -0,0 +1,134 @@ +import Head from 'next/head'; +import prisma from '../../lib/prisma'; +import { getIntegrationName, getIntegrationType } from '../../lib/integrations'; +import Shell from '../../components/Shell'; +import { useState } from 'react'; +import { useRouter } from 'next/router'; +import { useSession, getSession } from 'next-auth/client'; + +export default function integration(props) { + const router = useRouter(); + const [session, loading] = useSession(); + const [showAPIKey, setShowAPIKey] = useState(false); + + if (loading) { + return
Loading...
; + } else { + if (!session) { + window.location.href = "/"; + } + } + + function toggleShowAPIKey() { + setShowAPIKey(!showAPIKey); + } + + async function deleteIntegrationHandler(event) { + event.preventDefault(); + + const response = await fetch('/api/integrations', { + method: 'DELETE', + body: JSON.stringify({id: props.integration.id}), + headers: { + 'Content-Type': 'application/json' + } + }); + + router.push('/integrations'); + } + + return( ++ Information about your {getIntegrationName(props.integration.type)} integration. +
++ Once you delete this integration, it will be permanently removed. +
+Google Calendar
} -- {integration.type == 'google_calendar' && Calendar Integration} -
+ + +- - Connected -
- } - {!integration.key && -- - Not connected + {integration.type == 'google_calendar' &&
Google Calendar
} ++ {integration.type == 'google_calendar' && Calendar Integration}
- } ++ + Connected +
+ } + {!integration.key && ++ + Not connected +
+ } +