/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ import { useParams } from "next/navigation"; import useSWR, { mutate } from "swr"; import { TOAST_TYPE, setToast } from "@plane/propel/toast"; import type { IWorkspaceIntegration } from "@plane/types"; // assets import GithubLogo from "@/app/assets/logos/github-square.png?url"; import SlackLogo from "@/app/assets/services/slack.png?url"; // components import { SelectChannel } from "@/components/integration/slack/select-channel"; import { SelectRepository } from "@/components/integration/github/select-repository"; // constants import { PROJECT_GITHUB_REPOSITORY } from "@plane/constants"; // services import { ProjectService } from "@/services/project"; type Props = { integration: IWorkspaceIntegration; }; const integrationDetails: { [key: string]: any } = { github: { logo: GithubLogo, description: "Select GitHub repository to enable sync.", }, slack: { logo: SlackLogo, description: "Get regular updates and control which notification you want to receive.", }, }; // services const projectService = new ProjectService(); export function IntegrationCard({ integration }: Props) { const { workspaceSlug, projectId } = useParams(); const { data: syncedGithubRepository } = useSWR(projectId ? PROJECT_GITHUB_REPOSITORY(projectId) : null, () => workspaceSlug && projectId && integration ? projectService.getProjectGithubRepository(workspaceSlug, projectId, integration.id) : null ); const handleChange = (repo: any) => { if (!workspaceSlug || !projectId || !integration) return; const { html_url, owner: { login }, id, name, } = repo; projectService .syncGithubRepository(workspaceSlug, projectId, integration.id, { name, owner: login, repository_id: id, url: html_url, }) .then(() => { mutate(PROJECT_GITHUB_REPOSITORY(projectId)); setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: `${login}/${name} repository synced with the project successfully.`, }); }) .catch((err) => { console.error(err); setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Repository could not be synced with the project. Please try again.", }); }); }; return ( <> {integration && (
{integrationDetails[integration.integration_detail.provider].description}