import React, { useState } from 'react'; import { IconButton } from '~/components/ui/IconButton'; import type { ProviderInfo } from '~/types/model'; interface APIKeyManagerProps { provider: ProviderInfo; apiKey: string; setApiKey: (key: string) => void; getApiKeyLink?: string; labelForGetApiKey?: string; } export const APIKeyManager: React.FC = ({ provider, apiKey, setApiKey }) => { const [isEditing, setIsEditing] = useState(false); const [tempKey, setTempKey] = useState(apiKey); const handleSave = () => { setApiKey(tempKey); setIsEditing(false); }; return (
{provider?.name} API Key: {!isEditing && (
{apiKey ? '••••••••' : 'Not set (will still work if set in .env file)'} setIsEditing(true)} title="Edit API Key">
)}
{isEditing ? (
setTempKey(e.target.value)} className="flex-1 px-2 py-1 text-xs lg:text-sm rounded border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary focus:outline-none focus:ring-2 focus:ring-bolt-elements-focus" />
setIsEditing(false)} title="Cancel">
) : ( <> {provider?.getApiKeyLink && ( window.open(provider?.getApiKeyLink)} title="Edit API Key"> {provider?.labelForGetApiKey || 'Get API Key'}
)} )}
); };