import * as DropdownMenu from '@radix-ui/react-dropdown-menu'; import { useStore } from '@nanostores/react'; import { netlifyConnection } from '~/lib/stores/netlify'; import { vercelConnection } from '~/lib/stores/vercel'; import { workbenchStore } from '~/lib/stores/workbench'; import { streamingState } from '~/lib/stores/streaming'; import { classNames } from '~/utils/classNames'; import { useState } from 'react'; import { NetlifyDeploymentLink } from '~/components/chat/NetlifyDeploymentLink.client'; import { VercelDeploymentLink } from '~/components/chat/VercelDeploymentLink.client'; import { useVercelDeploy } from '~/components/deploy/VercelDeploy.client'; import { useNetlifyDeploy } from '~/components/deploy/NetlifyDeploy.client'; import { useGitHubDeploy } from '~/components/deploy/GitHubDeploy.client'; import { GitHubDeploymentDialog } from '~/components/deploy/GitHubDeploymentDialog'; interface DeployButtonProps { onVercelDeploy?: () => Promise; onNetlifyDeploy?: () => Promise; onGitHubDeploy?: () => Promise; } export const DeployButton = ({ onVercelDeploy, onNetlifyDeploy, onGitHubDeploy }: DeployButtonProps) => { const netlifyConn = useStore(netlifyConnection); const vercelConn = useStore(vercelConnection); const [activePreviewIndex] = useState(0); const previews = useStore(workbenchStore.previews); const activePreview = previews[activePreviewIndex]; const [isDeploying, setIsDeploying] = useState(false); const [deployingTo, setDeployingTo] = useState<'netlify' | 'vercel' | 'github' | null>(null); const isStreaming = useStore(streamingState); const { handleVercelDeploy } = useVercelDeploy(); const { handleNetlifyDeploy } = useNetlifyDeploy(); const { handleGitHubDeploy } = useGitHubDeploy(); const [showGitHubDeploymentDialog, setShowGitHubDeploymentDialog] = useState(false); const [githubDeploymentFiles, setGithubDeploymentFiles] = useState | null>(null); const [githubProjectName, setGithubProjectName] = useState(''); const handleVercelDeployClick = async () => { setIsDeploying(true); setDeployingTo('vercel'); try { if (onVercelDeploy) { await onVercelDeploy(); } else { await handleVercelDeploy(); } } finally { setIsDeploying(false); setDeployingTo(null); } }; const handleNetlifyDeployClick = async () => { setIsDeploying(true); setDeployingTo('netlify'); try { if (onNetlifyDeploy) { await onNetlifyDeploy(); } else { await handleNetlifyDeploy(); } } finally { setIsDeploying(false); setDeployingTo(null); } }; const handleGitHubDeployClick = async () => { setIsDeploying(true); setDeployingTo('github'); try { if (onGitHubDeploy) { await onGitHubDeploy(); } else { const result = await handleGitHubDeploy(); if (result && result.success && result.files) { setGithubDeploymentFiles(result.files); setGithubProjectName(result.projectName); setShowGitHubDeploymentDialog(true); } } } finally { setIsDeploying(false); setDeployingTo(null); } }; return ( <>
{isDeploying ? `Deploying to ${deployingTo}...` : 'Deploy'} {!netlifyConn.user ? 'No Netlify Account Connected' : 'Deploy to Netlify'} {netlifyConn.user && } vercel {!vercelConn.user ? 'No Vercel Account Connected' : 'Deploy to Vercel'} {vercelConn.user && } github Deploy to GitHub cloudflare Deploy to Cloudflare (Coming Soon)
{/* GitHub Deployment Dialog */} {showGitHubDeploymentDialog && githubDeploymentFiles && ( setShowGitHubDeploymentDialog(false)} projectName={githubProjectName} files={githubDeploymentFiles} /> )} ); };