2023-03-23 17:57:11 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-04-05 19:21:15 +00:00
|
|
|
|
2023-03-23 17:57:11 +00:00
|
|
|
import useSWR from "swr";
|
2023-04-05 19:21:15 +00:00
|
|
|
|
2023-03-23 17:57:11 +00:00
|
|
|
// lib
|
|
|
|
import { requiredWorkspaceAdmin } from "lib/auth";
|
2023-04-05 19:21:15 +00:00
|
|
|
// services
|
|
|
|
import IntegrationService from "services/integration";
|
2023-03-23 17:57:11 +00:00
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// layouts
|
|
|
|
import AppLayout from "layouts/app-layout";
|
|
|
|
import IntegrationGuide from "components/integration/guide";
|
|
|
|
// ui
|
|
|
|
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
|
|
|
// types
|
2023-04-05 19:21:15 +00:00
|
|
|
import { UserAuth } from "types";
|
|
|
|
import type { GetServerSideProps, NextPage } from "next";
|
|
|
|
// fetch-keys
|
|
|
|
import {
|
|
|
|
APP_INTEGRATIONS,
|
|
|
|
IMPORTER_SERVICES_LIST,
|
|
|
|
WORKSPACE_INTEGRATIONS,
|
|
|
|
} from "constants/fetch-keys";
|
2023-03-23 17:57:11 +00:00
|
|
|
|
|
|
|
const ImportExport: NextPage<UserAuth> = (props) => {
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
|
|
|
const router = useRouter();
|
2023-04-05 19:21:15 +00:00
|
|
|
const { workspaceSlug, provider } = router.query;
|
2023-03-23 17:57:11 +00:00
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
const { data: appIntegrations } = useSWR(APP_INTEGRATIONS, () =>
|
|
|
|
IntegrationService.getAppIntegrationsList()
|
2023-03-23 17:57:11 +00:00
|
|
|
);
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
const { data: workspaceIntegrations } = useSWR(
|
|
|
|
workspaceSlug ? WORKSPACE_INTEGRATIONS(workspaceSlug as string) : null,
|
2023-03-23 17:57:11 +00:00
|
|
|
workspaceSlug
|
2023-04-05 19:21:15 +00:00
|
|
|
? () => IntegrationService.getWorkspaceIntegrationsList(workspaceSlug as string)
|
2023-03-23 17:57:11 +00:00
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
const { data: importerServices } = useSWR(
|
|
|
|
workspaceSlug ? IMPORTER_SERVICES_LIST(workspaceSlug as string) : null,
|
|
|
|
workspaceSlug ? () => IntegrationService.getImporterServicesList(workspaceSlug as string) : null
|
2023-03-23 17:57:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2023-04-05 19:21:15 +00:00
|
|
|
<AppLayout
|
|
|
|
memberType={props}
|
|
|
|
breadcrumbs={
|
|
|
|
<Breadcrumbs>
|
|
|
|
<BreadcrumbItem title={`${workspaceSlug ?? "Workspace"}`} link={`/${workspaceSlug}`} />
|
|
|
|
<BreadcrumbItem title="Members Settings" />
|
|
|
|
</Breadcrumbs>
|
|
|
|
}
|
|
|
|
settingsLayout
|
|
|
|
>
|
|
|
|
<IntegrationGuide
|
|
|
|
provider={provider as string}
|
|
|
|
appIntegrations={appIntegrations}
|
|
|
|
workspaceIntegrations={workspaceIntegrations}
|
|
|
|
importerServices={importerServices}
|
|
|
|
/>
|
|
|
|
</AppLayout>
|
2023-03-23 17:57:11 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
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 ImportExport;
|