import { useCallback } from 'react' import { useParams } from 'common' import { IntegrationConnectionItem } from 'components/interfaces/Integrations/IntegrationConnection' import { IntegrationConnectionHeader, IntegrationInstallation, } from 'components/interfaces/Integrations/IntegrationPanels' import { Markdown } from 'components/interfaces/Markdown' import { ScaffoldContainer, ScaffoldSection, ScaffoldSectionContent, ScaffoldSectionDetail, } from 'components/layouts/Scaffold' import { useIntegrationsGitHubInstalledConnectionDeleteMutation } from 'data/integrations/integrations-github-connection-delete-mutation' import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only' import { IntegrationName, IntegrationProjectConnection } from 'data/integrations/integrations.types' import { useSelectedOrganization, useStore } from 'hooks' import { pluralize } from 'lib/helpers' import { IntegrationImageHandler } from '../IntegrationsSettings' import GitHubIntegrationConnectionForm from './GitHubIntegrationConnectionForm' const GitHubTitle = `GitHub Connections` const GitHubDetailsSection = ` Connect any of your GitHub repositories to a project. ` const GitHubContentSectionTop = ` ### How will GitHub connections work? You will be able to connect a GitHub repository to a Supabase project. The GitHub app will watch for changes in your repository such as file changes, branch changes as well as pull request activity. These connections will be part of a GitHub workflow that is currently in development. ` const GitHubSection = () => { const { ui } = useStore() const org = useSelectedOrganization() const { data } = useOrgIntegrationsQuery({ orgSlug: org?.slug }) const { ref: projectRef } = useParams() const githubIntegrations = data?.filter( (integration) => integration.integration.name === 'GitHub' ) const { mutate: deleteGitHubConnection } = useIntegrationsGitHubInstalledConnectionDeleteMutation( { onSuccess: () => { ui.setNotification({ category: 'success', message: 'Successfully deleted Github connection', }) }, } ) const onDeleteGitHubConnection = useCallback( async (connection: IntegrationProjectConnection) => { deleteGitHubConnection({ connectionId: connection.id, integrationId: connection.organization_integration_id, orgSlug: org?.slug, }) }, [deleteGitHubConnection, org?.slug] ) return ( {githubIntegrations && githubIntegrations.length > 0 && githubIntegrations.map((integration, i) => { const ConnectionHeaderTitle = `${integration.connections.length} project ${pluralize( integration.connections.length, 'connection' )} ` const connections = integration.connections.filter((connection) => projectRef ? connection.supabase_project_ref === projectRef : true ) return (
{connections.length > 0 ? ( <>
    {connections.map((connection) => (
    ))}
) : ( )}
) })}
) } export default GitHubSection