2023-04-05 19:21:15 +00:00
|
|
|
import React from "react";
|
2023-02-22 14:10:57 +00:00
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-02-23 12:42:07 +00:00
|
|
|
import useSWR from "swr";
|
2023-02-22 14:10:57 +00:00
|
|
|
|
|
|
|
// layouts
|
2023-04-08 08:16:46 +00:00
|
|
|
import { ProjectAuthorizationWrapper } from "layouts/auth-layout";
|
2023-02-22 14:10:57 +00:00
|
|
|
// services
|
2023-04-05 19:21:15 +00:00
|
|
|
import IntegrationService from "services/integration";
|
2023-02-22 14:10:57 +00:00
|
|
|
import projectService from "services/project.service";
|
2023-04-05 19:21:15 +00:00
|
|
|
// components
|
2023-09-13 17:39:55 +00:00
|
|
|
import { SettingsSidebar, SingleIntegration } from "components/project";
|
2023-02-23 12:42:07 +00:00
|
|
|
// ui
|
2023-07-12 06:15:45 +00:00
|
|
|
import { EmptyState, IntegrationAndImportExportBanner, 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
|
|
|
// icons
|
|
|
|
import { PlusIcon, PuzzlePieceIcon } from "@heroicons/react/24/outline";
|
2023-07-12 06:15:45 +00:00
|
|
|
// images
|
|
|
|
import emptyIntegration from "public/empty-state/integration.svg";
|
2023-02-22 14:10:57 +00:00
|
|
|
// types
|
2023-04-08 08:16:46 +00:00
|
|
|
import { IProject } from "types";
|
|
|
|
import type { NextPage } from "next";
|
2023-02-22 14:10:57 +00:00
|
|
|
// fetch-keys
|
2023-10-04 13:54:13 +00:00
|
|
|
import { PROJECT_DETAILS, USER_PROJECT_VIEW, WORKSPACE_INTEGRATIONS } from "constants/fetch-keys";
|
2023-07-31 11:52:48 +00:00
|
|
|
// helper
|
|
|
|
import { truncateText } from "helpers/string.helper";
|
2023-02-22 14:10:57 +00:00
|
|
|
|
2023-04-08 08:16:46 +00:00
|
|
|
const ProjectIntegrations: NextPage = () => {
|
2023-02-23 12:42:07 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
2023-02-22 14:10:57 +00:00
|
|
|
|
|
|
|
const { data: projectDetails } = useSWR<IProject>(
|
|
|
|
workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.getProject(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-02-23 12:42:07 +00:00
|
|
|
const { data: workspaceIntegrations } = useSWR(
|
2023-02-22 14:10:57 +00:00
|
|
|
workspaceSlug ? WORKSPACE_INTEGRATIONS(workspaceSlug as string) : null,
|
|
|
|
() =>
|
2023-04-05 19:21:15 +00:00
|
|
|
workspaceSlug
|
|
|
|
? IntegrationService.getWorkspaceIntegrationsList(workspaceSlug as string)
|
|
|
|
: null
|
2023-02-22 14:10:57 +00:00
|
|
|
);
|
|
|
|
|
2023-10-04 13:54:13 +00:00
|
|
|
const { data: memberDetails } = useSWR(
|
|
|
|
workspaceSlug && projectId ? USER_PROJECT_VIEW(projectId.toString()) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.projectMemberMe(workspaceSlug.toString(), projectId.toString())
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const isAdmin = memberDetails?.role === 20;
|
|
|
|
|
2023-02-22 14:10:57 +00:00
|
|
|
return (
|
2023-04-08 08:16:46 +00:00
|
|
|
<ProjectAuthorizationWrapper
|
2023-02-22 14:10:57 +00:00
|
|
|
breadcrumbs={
|
|
|
|
<Breadcrumbs>
|
|
|
|
<BreadcrumbItem
|
2023-07-31 11:52:48 +00:00
|
|
|
title={`${truncateText(projectDetails?.name ?? "Project", 32)}`}
|
2023-02-22 14:10:57 +00:00
|
|
|
link={`/${workspaceSlug}/projects/${projectId}/issues`}
|
2023-07-31 11:52:48 +00:00
|
|
|
linkTruncate
|
2023-02-22 14:10:57 +00:00
|
|
|
/>
|
2023-09-15 14:00:53 +00:00
|
|
|
<BreadcrumbItem title="Integrations Settings" unshrinkTitle />
|
2023-02-22 14:10:57 +00:00
|
|
|
</Breadcrumbs>
|
|
|
|
}
|
|
|
|
>
|
2023-09-15 14:00:53 +00:00
|
|
|
<div className="flex flex-row gap-2 h-full">
|
|
|
|
<div className="w-80 pt-8 overflow-y-hidden flex-shrink-0">
|
2023-09-13 17:39:55 +00:00
|
|
|
<SettingsSidebar />
|
|
|
|
</div>
|
2023-10-04 13:54:13 +00:00
|
|
|
<div className={`pr-9 py-8 gap-10 w-full overflow-y-auto ${isAdmin ? "" : "opacity-60"}`}>
|
2023-09-15 14:00:53 +00:00
|
|
|
<div className="flex items-center py-3.5 border-b border-custom-border-200">
|
|
|
|
<h3 className="text-xl font-medium">Integrations</h3>
|
|
|
|
</div>
|
|
|
|
{workspaceIntegrations ? (
|
|
|
|
workspaceIntegrations.length > 0 ? (
|
2023-09-13 17:39:55 +00:00
|
|
|
<div>
|
2023-05-05 11:37:29 +00:00
|
|
|
{workspaceIntegrations.map((integration) => (
|
|
|
|
<SingleIntegration
|
|
|
|
key={integration.integration_detail.id}
|
|
|
|
integration={integration}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-09-15 14:00:53 +00:00
|
|
|
) : (
|
|
|
|
<EmptyState
|
|
|
|
title="You haven't configured integrations"
|
|
|
|
description="Configure GitHub and other integrations to sync your project issues."
|
|
|
|
image={emptyIntegration}
|
|
|
|
primaryButton={{
|
|
|
|
text: "Configure now",
|
|
|
|
onClick: () => router.push(`/${workspaceSlug}/settings/integrations`),
|
|
|
|
}}
|
2023-10-04 13:54:13 +00:00
|
|
|
disabled={!isAdmin}
|
2023-09-15 14:00:53 +00:00
|
|
|
/>
|
|
|
|
)
|
2023-05-05 11:37:29 +00:00
|
|
|
) : (
|
2023-09-15 14:00:53 +00:00
|
|
|
<Loader className="space-y-5">
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
<Loader.Item height="40px" />
|
|
|
|
</Loader>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-05-05 11:37:29 +00:00
|
|
|
</div>
|
2023-04-08 08:16:46 +00:00
|
|
|
</ProjectAuthorizationWrapper>
|
2023-02-22 14:10:57 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProjectIntegrations;
|