import { useState } from 'react' import { useMutation, useQueryClient } from '@tanstack/react-query' import { createRepo } from '@/api/repos' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { Loader2 } from 'lucide-react' interface AddRepoDialogProps { open: boolean onOpenChange: (open: boolean) => void } export function AddRepoDialog({ open, onOpenChange }: AddRepoDialogProps) { const [repoType, setRepoType] = useState<'remote' | 'local'>('remote') const [repoUrl, setRepoUrl] = useState('') const [localPath, setLocalPath] = useState('') const [branch, setBranch] = useState('') const queryClient = useQueryClient() const mutation = useMutation({ mutationFn: () => { if (repoType === 'local') { return createRepo(undefined, localPath, branch || undefined, undefined, false) } else { return createRepo(repoUrl, undefined, branch || undefined, undefined, false) } }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['repos'] }) setRepoUrl('') setLocalPath('') setBranch('') setRepoType('remote') onOpenChange(false) }, }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if ((repoType === 'remote' && repoUrl) || (repoType === 'local' && localPath)) { mutation.mutate() } } return ( Add Repository
{repoType === 'remote' ? (
setRepoUrl(e.target.value)} disabled={mutation.isPending} className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500" />

Full URL or shorthand format (owner/repo for GitHub)

) : (
setLocalPath(e.target.value)} disabled={mutation.isPending} className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500" />

Directory name for new repo, OR absolute path to existing Git repo (will be copied to workspace)

)}
setBranch(e.target.value)} disabled={mutation.isPending} className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500" />

{branch ? repoType === 'remote' ? `Clones repository directly to '${branch}' branch` : localPath?.startsWith('/') ? `Copies repo and checks out '${branch}' branch (creates if needed)` : `Initializes repository with '${branch}' branch` : repoType === 'remote' ? "Clones repository to default branch" : localPath?.startsWith('/') ? "Copies repo and checks out current branch" : "Initializes repository with 'main' branch" }

{mutation.isError && (

{mutation.error.message}

)}
) }