Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

2.5 KB
Raw Blame
import { useTranslations } from 'next-intl';
import type { ProjectDetail } from '@/lib/api/endpoints/projects';
import ListSkeleton from '@/components/common/skeleton/ListSkeleton';
import SettingsCard from '@/components/common/page/SettingsCard';
import SettingsRow from '@/components/common/page/SettingsRow';
import { Switch } from '@/components/ui/switch';
import { useGitSettingsQuery, useUpdateGitSettings } from '../../services/settings.service';
import GitConnectionCard from './GitConnectionCard';
import GitAutomationsCard from './GitAutomationsCard';
import GitProviderConnections from './GitProviderConnections';
import GitRepositoryList from './GitRepositoryList';
import SettingsSection from '@/components/common/page/SettingsSection';

// The repository integration tab: a master switch, and — while it is on — the
// webhook connection and the pull request automations. Every control writes
// immediately; there is no form-level save.
export default function SettingsGit({ project }: { project: ProjectDetail }) {
  const t = useTranslations('settings.git');
  const projectKey = project.project.ref;
  const settingsQuery = useGitSettingsQuery(projectKey);
  const updateSettings = useUpdateGitSettings(projectKey);

  if (settingsQuery.isPending || !settingsQuery.data)
    return <ListSkeleton rows={3} rowClassName="h-16" />;

  const settings = settingsQuery.data;
  return (
    <div className="space-y-10">
      <SettingsCard>
        <SettingsRow
          title={t('enable')}
          description={t('enableHint')}
          control={
            <Switch
              checked={settings.enabled}
              onCheckedChange={(enabled) => updateSettings.mutate({ enabled })}
            />
          }
        />
      </SettingsCard>
      {settings.enabled && (
        <>
          <GitConnectionCard projectKey={projectKey} settings={settings} />
          <GitProviderConnections
            projectKey={projectKey}
            teamRef={project.project.teamRef}
            canManageTeam={
              project.viewer.teamRole === 'owner' || project.viewer.teamRole === 'manager'
            }
          />
          <GitAutomationsCard
            columns={project.columns}
            settings={settings}
            onChange={(patch) => updateSettings.mutate(patch)}
          />
          <SettingsSection title={t('repositories')} description={t('repositoriesHint')}>
            <SettingsCard>
              <GitRepositoryList repositories={settings.repositories} />
            </SettingsCard>
          </SettingsSection>
        </>
      )}
    </div>
  );
}