import React, { useState } from 'react'; import { toast } from 'react-toastify'; import { updateNetlifyConnection } from '~/lib/stores/netlify'; import { classNames } from '~/utils/classNames'; interface NetlifyQuickConnectProps { onSuccess?: () => void; showInstructions?: boolean; } export const NetlifyQuickConnect: React.FC = ({ onSuccess, showInstructions = true }) => { const [token, setToken] = useState(''); const [isConnecting, setIsConnecting] = useState(false); const [showHelp, setShowHelp] = useState(false); const handleConnect = async () => { if (!token.trim()) { toast.error('Please enter your Netlify API token'); return; } setIsConnecting(true); try { // Validate token with Netlify API const response = await fetch('https://api.netlify.com/api/v1/user', { headers: { Authorization: `Bearer ${token}`, }, }); if (!response.ok) { throw new Error('Invalid token or authentication failed'); } const userData = (await response.json()) as any; // Fetch initial site statistics const sitesResponse = await fetch('https://api.netlify.com/api/v1/sites', { headers: { Authorization: `Bearer ${token}`, }, }); let sites: any[] = []; if (sitesResponse.ok) { sites = (await sitesResponse.json()) as any[]; } // Update the connection store updateNetlifyConnection({ user: userData, token, stats: { sites, totalSites: sites.length, deploys: [], builds: [], lastDeployTime: '', }, }); toast.success(`Connected to Netlify as ${userData.email || userData.name || 'User'}`); setToken(''); // Clear the token field if (onSuccess) { onSuccess(); } } catch (error) { console.error('Netlify connection error:', error); toast.error('Failed to connect to Netlify. Please check your token.'); } finally { setIsConnecting(false); } }; return (
{showInstructions && ( )}
setToken(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter' && token.trim() && !isConnecting) { handleConnect(); } }} placeholder="Enter your Netlify API token" className={classNames( 'w-full px-3 py-2 pr-10 rounded-lg text-sm', 'bg-bolt-elements-background-depth-1', 'border border-bolt-elements-borderColor', 'text-bolt-elements-textPrimary placeholder-bolt-elements-textTertiary', 'focus:outline-none focus:ring-2 focus:ring-accent-500 focus:border-transparent', 'disabled:opacity-50', )} disabled={isConnecting} /> {token && ( )}
{showHelp && showInstructions && (

Getting your Netlify Personal Access Token:

  1. 1. Go to{' '} Netlify Account Settings
  2. 2. Navigate to "Applications" → "Personal access tokens"
  3. 3. Click "New access token"
  4. 4. Give it a descriptive name (e.g., "bolt.diy deployment")
  5. 5. Copy the token and paste it above

Note: Keep your token safe! It provides full access to your Netlify account.

)}
Get Token

Quick Tip

Once connected, you can deploy any project with a single click directly from the editor!

); };