'use client'; import { useAction, useQuery } from 'convex/react'; import { makeFunctionReference } from 'convex/server'; import { Github, RefreshCw } from 'lucide-react'; import { toast } from 'sonner'; import { api } from '@spoon/backend/convex/_generated/api.js'; import { Button, Card, CardContent, CardHeader, CardTitle } from '@spoon/ui'; const listReposRef = makeFunctionReference< 'action', Record, { id: number; name: string; fullName: string; owner: string; private: boolean; fork: boolean; url: string; defaultBranch: string; description?: string; }[] >('githubNode:listInstallationRepositories'); export const GithubIntegrationPanel = () => { const connection = useQuery(api.github.getConnection, {}); const installUrl = useQuery(api.github.getInstallUrl, {}); const listRepos = useAction(listReposRef); const refresh = async () => { try { const repos = await listRepos({}); toast.success(`GitHub can access ${repos.length} repositories.`); } catch (error) { console.error(error); toast.error('Could not list GitHub repositories.'); } }; return ( GitHub App {connection && connection.status !== 'active' ? (

{connection.status === 'revoked' ? 'GitHub App installation removed' : 'GitHub access needs re-authorization'}

{connection.status === 'revoked' ? 'Reinstall the app to resume syncing.' : 'Reconnect the app to resume syncing.'}

{installUrl ? ( Reconnect GitHub App ) : null}
) : null} {connection ? (

Connected account

{connection.displayName}

Installation ID

{connection.installationId}

) : (

Install the GitHub App to let Spoon create forks and refresh repository state.

)}
{installUrl ? ( ) : null}
); };