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 [repoUrl, setRepoUrl] = useState('') const [branch, setBranch] = useState('') const queryClient = useQueryClient() const mutation = useMutation({ mutationFn: () => createRepo(repoUrl, branch || undefined, undefined, false), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['repos'] }) setRepoUrl('') setBranch('') onOpenChange(false) }, }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (repoUrl) { mutation.mutate() } } return ( Add Repository
setRepoUrl(e.target.value)} disabled={mutation.isPending} className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500" />
setBranch(e.target.value)} disabled={mutation.isPending} className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500" />

{branch ? `Clones repository directly to '${branch}' branch` : "Clones repository to default branch" }

{mutation.isError && (

{mutation.error.message}

)}
) }