import { useState } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import type { Project } from "@paperclipai/shared"; import { projectsApi } from "@/api/projects"; import { Button } from "./ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"; export function ProjectGitAuthorization({ project }: { project: Project }) { const client = useQueryClient(); const key = ["project-git-authorization", project.companyId, project.id]; const authorization = useQuery({ queryKey: key, queryFn: () => projectsApi.gitAuthorization(project.id), }); const [selected, setSelected] = useState(""); const save = useMutation({ mutationFn: (grantId: string | null) => projectsApi.setGitAuthorization(project.id, grantId), onSuccess: (data) => { client.setQueryData(key, data); setSelected(""); }, }); const data = authorization.data; return (

Background GitHub authorization

Allow this project’s workspace provider to use your GitHub Connector for repository provisioning and maintenance until revoked. This shares the Connector credential with the provider using its existing GitHub permissions. Project repository editors can add repositories covered by this connection. Manage repository access in the GitHub connection. Task runs continue to use their own identity.

{data?.grantId && (

Authorized:{" "} {data.options.find((option) => option.grantId === data.grantId)?.login ?? "selected grant (unavailable or owned by another member)"}

)} {data && (
{data.grantId && ( )}
)} {data && !data.options.length && (

Connect your GitHub account and install the Connector for this company to authorize it.

)} {(authorization.error || save.error) && (

{(authorization.error || save.error)?.message}

)}
); }