import { useState } from 'react'; import { toast } from 'react-toastify'; import { Dialog, DialogButton, DialogDescription, DialogRoot, DialogTitle } from '~/components/ui/Dialog'; interface GitCloneDialogProps { isOpen: boolean; onClose: () => void; onClone?: (repoUrl: string) => Promise; } export function GitCloneDialog({ isOpen, onClose, onClone }: GitCloneDialogProps) { const [isPrivate, setIsPrivate] = useState(false); const [repoUrl, setRepoUrl] = useState(''); const [token, setToken] = useState(''); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); try { // if it's a private repo, construct the URL with the token const cloneUrl = isPrivate ? repoUrl.replace('https://', `https://${token}@`) : repoUrl; if (onClone) { await onClone(cloneUrl); } toast.success('Repository cloned successfully!'); onClose(); } catch (error) { toast.error(error instanceof Error ? error.message : 'Failed to clone repository'); } finally { setIsLoading(false); } }; return ( Clone Repository
{isPrivate && (
)}
Cancel {isLoading ? 'Cloning...' : 'Clone Repository'}
); }