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 { isGitLabConnected } from '~/lib/stores/gitlabConnection'; 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 { useGitLabDeploy } from '~/components/deploy/GitLabDeploy.client'; import { GitHubDeploymentDialog } from '~/components/deploy/GitHubDeploymentDialog'; import { GitLabDeploymentDialog } from '~/components/deploy/GitLabDeploymentDialog'; interface DeployButtonProps { onVercelDeploy?: () => Promise; onNetlifyDeploy?: () => Promise; onGitHubDeploy?: () => Promise; onGitLabDeploy?: () => Promise; } export const DeployButton = ({ onVercelDeploy, onNetlifyDeploy, onGitHubDeploy, onGitLabDeploy, }: DeployButtonProps) => { const netlifyConn = useStore(netlifyConnection); const vercelConn = useStore(vercelConnection); const gitlabIsConnected = useStore(isGitLabConnected); 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' | 'gitlab' | null>(null); const isStreaming = useStore(streamingState); const { handleVercelDeploy } = useVercelDeploy(); const { handleNetlifyDeploy } = useNetlifyDeploy(); const { handleGitHubDeploy } = useGitHubDeploy(); const { handleGitLabDeploy } = useGitLabDeploy(); const [showGitHubDeploymentDialog, setShowGitHubDeploymentDialog] = useState(false); const [showGitLabDeploymentDialog, setShowGitLabDeploymentDialog] = useState(false); const [githubDeploymentFiles, setGithubDeploymentFiles] = useState | null>(null); const [gitlabDeploymentFiles, setGitlabDeploymentFiles] = useState | null>(null); const [githubProjectName, setGithubProjectName] = useState(''); const [gitlabProjectName, setGitlabProjectName] = 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); } }; const handleGitLabDeployClick = async () => { setIsDeploying(true); setDeployingTo('gitlab'); try { if (onGitLabDeploy) { await onGitLabDeploy(); } else { const result = await handleGitLabDeploy(); if (result && result.success && result.files) { setGitlabDeploymentFiles(result.files); setGitlabProjectName(result.projectName); setShowGitLabDeploymentDialog(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 gitlab {!gitlabIsConnected ? 'No GitLab Account Connected' : 'Deploy to GitLab'} cloudflare Deploy to Cloudflare (Coming Soon)
{/* GitHub Deployment Dialog */} {showGitHubDeploymentDialog && githubDeploymentFiles && ( setShowGitHubDeploymentDialog(false)} projectName={githubProjectName} files={githubDeploymentFiles} /> )} {/* GitLab Deployment Dialog */} {showGitLabDeploymentDialog && gitlabDeploymentFiles && ( setShowGitLabDeploymentDialog(false)} projectName={gitlabProjectName} files={gitlabDeploymentFiles} /> )} ); };