2023-02-22 14:10:57 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
2023-02-23 12:42:07 +00:00
|
|
|
|
2023-02-22 14:10:57 +00:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import workspaceService from "services/workspace.service";
|
2023-04-05 19:21:15 +00:00
|
|
|
import IntegrationService from "services/integration";
|
2023-02-23 12:42:07 +00:00
|
|
|
// lib
|
|
|
|
import { requiredWorkspaceAdmin } from "lib/auth";
|
2023-02-22 14:10:57 +00:00
|
|
|
// layouts
|
|
|
|
import AppLayout from "layouts/app-layout";
|
2023-02-23 12:42:07 +00:00
|
|
|
// componentss
|
|
|
|
import OAuthPopUp from "components/popup";
|
2023-02-22 14:10:57 +00:00
|
|
|
// ui
|
2023-02-23 17:04:36 +00:00
|
|
|
import { Loader } from "components/ui";
|
2023-02-22 14:10:57 +00:00
|
|
|
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
2023-02-23 12:42:07 +00:00
|
|
|
// types
|
|
|
|
import type { NextPage, GetServerSideProps } from "next";
|
|
|
|
import { UserAuth } from "types";
|
|
|
|
// fetch-keys
|
2023-02-22 14:10:57 +00:00
|
|
|
import { WORKSPACE_DETAILS, APP_INTEGRATIONS } from "constants/fetch-keys";
|
|
|
|
|
2023-02-23 12:42:07 +00:00
|
|
|
const WorkspaceIntegrations: NextPage<UserAuth> = (props) => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
2023-02-22 14:10:57 +00:00
|
|
|
|
|
|
|
const { data: activeWorkspace } = useSWR(
|
|
|
|
workspaceSlug ? WORKSPACE_DETAILS(workspaceSlug as string) : null,
|
|
|
|
() => (workspaceSlug ? workspaceService.getWorkspace(workspaceSlug as string) : null)
|
|
|
|
);
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
const { data: appIntegrations } = useSWR(workspaceSlug ? APP_INTEGRATIONS : null, () =>
|
|
|
|
workspaceSlug ? IntegrationService.getAppIntegrationsList() : null
|
2023-02-22 14:10:57 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<AppLayout
|
|
|
|
memberType={props}
|
|
|
|
breadcrumbs={
|
|
|
|
<Breadcrumbs>
|
|
|
|
<BreadcrumbItem
|
|
|
|
title={`${activeWorkspace?.name ?? "Workspace"}`}
|
|
|
|
link={`/${workspaceSlug}`}
|
|
|
|
/>
|
|
|
|
<BreadcrumbItem title="Integrations" />
|
|
|
|
</Breadcrumbs>
|
|
|
|
}
|
2023-03-07 19:37:00 +00:00
|
|
|
settingsLayout
|
2023-02-22 14:10:57 +00:00
|
|
|
>
|
|
|
|
<section className="space-y-8">
|
2023-03-07 19:37:00 +00:00
|
|
|
<h3 className="text-2xl font-semibold">Integrations</h3>
|
|
|
|
<div className="space-y-5">
|
2023-04-05 19:21:15 +00:00
|
|
|
{appIntegrations ? (
|
|
|
|
appIntegrations.map((integration) => (
|
2023-02-23 17:04:36 +00:00
|
|
|
<OAuthPopUp
|
|
|
|
key={integration.id}
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
integration={integration}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
) : (
|
|
|
|
<Loader className="space-y-5">
|
|
|
|
<Loader.Item height="60px" />
|
|
|
|
<Loader.Item height="60px" />
|
|
|
|
</Loader>
|
|
|
|
)}
|
2023-02-23 12:42:07 +00:00
|
|
|
</div>
|
2023-02-22 14:10:57 +00:00
|
|
|
</section>
|
|
|
|
</AppLayout>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|
|
|
const workspaceSlug = ctx.params?.workspaceSlug as string;
|
|
|
|
|
|
|
|
const memberDetail = await requiredWorkspaceAdmin(workspaceSlug, ctx.req.headers.cookie);
|
|
|
|
|
|
|
|
if (memberDetail === null) {
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
destination: "/",
|
|
|
|
permanent: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
isOwner: memberDetail?.role === 20,
|
|
|
|
isMember: memberDetail?.role === 15,
|
|
|
|
isViewer: memberDetail?.role === 10,
|
|
|
|
isGuest: memberDetail?.role === 5,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WorkspaceIntegrations;
|