cal.pub0.org/pages/integrations/[integration].tsx

104 lines
3.6 KiB
TypeScript
Raw Normal View History

import { useSession } from "next-auth/client";
import { useRouter } from "next/router";
import { getSession } from "@lib/auth";
import { getIntegrationName, getIntegrationType } from "@lib/integrations";
import prisma from "@lib/prisma";
import Loader from "@components/Loader";
import Shell from "@components/Shell";
2021-04-10 12:02:35 +00:00
export default function Integration(props) {
2021-07-30 23:05:38 +00:00
const router = useRouter();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2021-07-30 23:05:38 +00:00
const [session, loading] = useSession();
2021-08-06 13:09:44 +00:00
2021-07-30 23:05:38 +00:00
if (loading) {
return <Loader />;
2021-07-30 23:05:38 +00:00
}
2021-04-10 12:02:35 +00:00
2021-07-30 23:05:38 +00:00
async function deleteIntegrationHandler(event) {
event.preventDefault();
2021-04-10 12:02:35 +00:00
/*eslint-disable */
2021-07-30 23:05:38 +00:00
const response = await fetch("/api/integrations", {
method: "DELETE",
body: JSON.stringify({ id: props.integration.id }),
headers: {
"Content-Type": "application/json",
},
});
/*eslint-enable */
2021-04-10 12:02:35 +00:00
2021-07-30 23:05:38 +00:00
router.push("/integrations");
}
2021-04-10 12:02:35 +00:00
2021-07-30 23:05:38 +00:00
return (
<div>
<Shell
heading={`${getIntegrationName(props.integration.type)} App`}
subtitle="Manage and delete this app.">
2021-08-06 13:09:44 +00:00
<div className="block sm:grid grid-cols-3 gap-4">
<div className="col-span-2 bg-white border border-gray-200 mb-6 overflow-hidden rounded-sm">
2021-07-30 23:05:38 +00:00
<div className="px-4 py-5 sm:px-6">
<h3 className="text-lg leading-6 font-medium text-gray-900">Integration Details</h3>
<p className="mt-1 max-w-2xl text-sm text-gray-500">
2021-08-06 13:09:44 +00:00
Information about your {getIntegrationName(props.integration.type)} App.
2021-07-30 23:05:38 +00:00
</p>
</div>
<div className="border-t border-gray-200 px-4 py-5 sm:px-6">
<dl className="grid gap-y-8">
<div>
2021-08-06 13:09:44 +00:00
<dt className="text-sm font-medium text-gray-500">App name</dt>
2021-07-30 23:05:38 +00:00
<dd className="mt-1 text-sm text-gray-900">{getIntegrationName(props.integration.type)}</dd>
</div>
<div>
2021-08-06 13:09:44 +00:00
<dt className="text-sm font-medium text-gray-500">App Category</dt>
2021-07-30 23:05:38 +00:00
<dd className="mt-1 text-sm text-gray-900">{getIntegrationType(props.integration.type)}</dd>
</div>
</dl>
</div>
</div>
<div>
2021-08-06 13:09:44 +00:00
<div className="bg-white border border-gray-200 mb-6 rounded-sm">
2021-07-30 23:05:38 +00:00
<div className="px-4 py-5 sm:p-6">
2021-08-06 13:09:44 +00:00
<h3 className="text-lg leading-6 font-medium text-gray-900">Delete this app</h3>
2021-07-30 23:05:38 +00:00
<div className="mt-2 max-w-xl text-sm text-gray-500">
2021-08-06 13:09:44 +00:00
<p>Once you delete this app, it will be permanently removed.</p>
2021-04-10 12:02:35 +00:00
</div>
2021-07-30 23:05:38 +00:00
<div className="mt-5">
<button
onClick={deleteIntegrationHandler}
type="button"
className="inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-sm text-red-700 bg-red-100 hover:bg-red-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:text-sm">
2021-08-06 13:09:44 +00:00
Delete App
2021-07-30 23:05:38 +00:00
</button>
</div>
</div>
</div>
</div>
2021-04-10 12:02:35 +00:00
</div>
2021-07-30 23:05:38 +00:00
</Shell>
</div>
);
2021-04-10 12:02:35 +00:00
}
export async function getServerSideProps(context) {
2021-08-06 13:09:44 +00:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2021-07-30 23:05:38 +00:00
const session = await getSession(context);
2021-04-10 12:02:35 +00:00
2021-07-30 23:05:38 +00:00
const integration = await prisma.credential.findFirst({
where: {
id: parseInt(context.query.integration),
},
select: {
id: true,
type: true,
key: true,
},
});
return {
props: { integration }, // will be passed to the page component as props
};
}