import { LegacyProjectRepository } from "./LegacyProjectRepository"; import { useState } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import type { Project, ProjectRepository } from "@paperclipai/shared"; import { projectsApi } from "@/api/projects"; import { queryKeys } from "@/lib/queryKeys"; import { ConnectionSetupFlow } from "@/features/connections/ConnectionSetupFlow"; import { ProjectRepositoryInput, repositoryOptionsKey } from "./ProjectRepositoryInput"; import { Dialog, DialogContent, DialogTitle } from "./ui/dialog"; import { Button } from "./ui/button"; export function ProjectRepositories({ project }: { project: Project }) { const client = useQueryClient(); const saved: ProjectRepository[] = project.workspaces.flatMap((workspace) => { const id = workspace.metadata?.githubRepositoryId; return typeof id === "string" && workspace.repoUrl ? [{ id, fullName: workspace.name, url: workspace.repoUrl, connections: [] }] : []; }); const [draft, setDraft] = useState(null); const [connecting, setConnecting] = useState(false); const save = useMutation({ mutationFn: () => projectsApi.setRepositories(project.id, (draft ?? saved).map((repo) => repo.id)), onSuccess: (updated) => { for (const ref of new Set([project.id, project.urlKey])) { client.setQueriesData({ queryKey: queryKeys.projects.detail(ref) }, updated); void client.invalidateQueries({ queryKey: queryKeys.projects.detail(ref) }); } void client.invalidateQueries({ queryKey: queryKeys.projects.all(project.companyId) }); void client.invalidateQueries({ queryKey: queryKeys.projects.detail(project.id) }); setDraft(null); }, }); return
{ setDraft(repos); save.reset(); }} onConnect={() => setConnecting(true)} disabled={save.isPending} /> {project.workspaces.filter((workspace) => workspace.repoUrl && !workspace.metadata?.githubRepositoryId).map((workspace) => )}
{save.isError &&

{save.error.message}

} {save.isSuccess && Changes saved} {draft && }
Connect GitHub setConnecting(false)} onComplete={() => { void client.invalidateQueries({ queryKey: repositoryOptionsKey(project.companyId) }); setConnecting(false); }} />
; }