"use client"; import { motion, AnimatePresence } from "framer-motion"; import { useState } from "react"; import { toast } from "sonner"; interface ShareWorkflowModalProps { isOpen: boolean; onClose: () => void; workflowId: string; workflowName: string; } export default function ShareWorkflowModal({ isOpen, onClose, workflowId, workflowName }: ShareWorkflowModalProps) { const [copied, setCopied] = useState(null); const baseUrl = typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000'; const executeUrl = `${baseUrl}/api/workflows/${workflowId}/execute`; const streamUrl = `${baseUrl}/api/workflows/${workflowId}/execute-stream`; const curlExample = `curl -X POST ${executeUrl} \\ -H "Content-Type: application/json" \\ -d '{"url": "https://example.com"}'`; const curlStreamExample = `curl -X POST ${streamUrl} \\ -H "Content-Type: application/json" \\ -d '{"url": "https://example.com"}' \\ --no-buffer`; const fetchExample = `// JavaScript/TypeScript const response = await fetch('${executeUrl}', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: 'https://example.com' }), }); const result = await response.json(); console.log(result);`; const fetchStreamExample = `// JavaScript/TypeScript - Streaming const response = await fetch('${streamUrl}', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: 'https://example.com' }), }); const reader = response.body?.getReader(); const decoder = new TextDecoder(); while (true) { const { done, value } = await reader.read(); if (done) break; const chunk = decoder.decode(value); const events = chunk.split('\\n\\n'); for (const event of events) { if (event.startsWith('data: ')) { const data = JSON.parse(event.slice(6)); console.log('Update:', data); } } }`; const handleCopy = (text: string, label: string) => { navigator.clipboard.writeText(text); setCopied(label); toast.success('Copied to clipboard!'); setTimeout(() => setCopied(null), 2000); }; return ( {isOpen && ( <> {/* Backdrop */} {/* Modal */} {/* Header */}

Workflow Saved!

Your workflow is ready to use via API

{/* Content */}
{/* URLs Section */}

Real-time updates as each node executes

{/* Code Examples */}

Code Examples

{/* cURL */}
{curlExample}
                  
{/* JavaScript */}
{fetchExample}
                  
{/* Streaming Info */}

Streaming Available

Use execute-stream endpoint for real-time updates

node_started Node begins
node_completed Node finishes
workflow_completed All done
{/* Footer */}
)}
); }