import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { GitBranch, ChevronDown } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { ExternalInput } from '@/components/ui/external-input'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter, } from '@/components/ui/dialog'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { ExternalFavicon } from '@/components/ExternalFavicon'; interface PresetProvider { id: string; name: string; origin: string; username: string; tokenURL?: string; } interface OAuthHook { initiateOAuth: () => void; isLoading: boolean; error: string | null; isOAuthConfigured: boolean; } interface AddGitCredentialDialogProps { open: boolean; onOpenChange: (open: boolean) => void; preset: PresetProvider; oauthHook: OAuthHook | null; forceManualEntry: boolean; onSetForceManualEntry: (force: boolean) => void; onAdd: (token: string) => void; } export function AddGitCredentialDialog({ open, onOpenChange, preset, oauthHook, forceManualEntry, onSetForceManualEntry, onAdd, }: AddGitCredentialDialogProps) { const { t } = useTranslation(); const [token, setToken] = useState(''); const isOAuthConfigured = oauthHook?.isOAuthConfigured ?? false; const isOAuthLoading = oauthHook?.isLoading ?? false; const oauthError = oauthHook?.error ?? null; const handleAdd = () => { onAdd(token); setToken(''); onOpenChange(false); }; return (
} /> {preset.name}
Add {preset.name} credentials for Git operations
{isOAuthConfigured && !forceManualEntry ? ( // Show OAuth button if OAuth is configured and not forced to manual
onSetForceManualEntry(true)}> Enter token manually
{oauthError && (

{oauthError}

)}
) : ( // Show manual token input setToken(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter' && token.trim()) { handleAdd(); } }} url={preset.tokenURL} urlTitle="Get Token" /> )}
{!(isOAuthConfigured && !forceManualEntry) && ( )}
); }