import {Button} from '@plunk/ui'; import {motion} from 'framer-motion'; import {ArrowLeft, ArrowRight, FileText, ShieldCheck, Workflow, Zap} from 'lucide-react'; import {NextSeo} from 'next-seo'; import Link from 'next/link'; import {useRouter} from 'next/router'; import {useEffect, useMemo} from 'react'; import {ApiKeyDisplay} from '../../components/ApiKeyDisplay'; import {CodeTabs, type CodeSnippet} from '../../components/onboarding/CodeTabs'; import {OnboardingLayout} from '../../components/onboarding/OnboardingLayout'; import {API_URI} from '../../lib/constants'; import {useActiveProject} from '../../lib/contexts/ActiveProjectProvider'; import {useOnboardingGate} from '../../lib/hooks/useOnboardingGate'; import {useOnboardingPath} from '../../lib/hooks/useOnboardingPath'; interface SetupStep { id: string; icon: React.ElementType; title: string; description: string; cta?: string; href?: string; required?: boolean; } const steps: SetupStep[] = [ { id: 'domain', icon: ShieldCheck, title: 'Verify your sender domain', description: 'Workflows send from a verified domain. Two DNS records and you\'re set.', cta: 'Verify domain', href: '/settings?tab=domains', required: true, }, { id: 'track', icon: Zap, title: 'Fire events from your app', description: 'Call /v1/track whenever something interesting happens. Workflows listen and respond.', }, { id: 'template', icon: FileText, title: 'Create an email template', description: 'Design the email your workflow will send — drag blocks or write HTML.', cta: 'Create template', href: '/templates/create', }, { id: 'workflow', icon: Workflow, title: 'Build your first workflow', description: 'Pick a trigger event, attach your template, chain delays, hit publish.', cta: 'Open workflow builder', href: '/workflows', }, ]; function buildTrackSnippets(apiUrl: string, publicKey: string): CodeSnippet[] { const body = { event: 'user.signed-up', email: 'user@example.com', data: {plan: 'pro'}, }; const curl = `curl -X POST ${apiUrl}/v1/track \\ -H "Authorization: Bearer ${publicKey}" \\ -H "Content-Type: application/json" \\ -d '${JSON.stringify(body, null, 2).replace(/\n/g, '\n ')}'`; const node = `await fetch("${apiUrl}/v1/track", { method: "POST", headers: { Authorization: "Bearer ${publicKey}", "Content-Type": "application/json", }, body: JSON.stringify(${JSON.stringify(body, null, 2).replace(/\n/g, '\n ')}), });`; const python = `import requests requests.post( "${apiUrl}/v1/track", headers={"Authorization": "Bearer ${publicKey}"}, json=${JSON.stringify(body, null, 4).replace(/\n/g, '\n ')}, )`; const php = `$ch = curl_init("${apiUrl}/v1/track"); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ "Authorization: Bearer ${publicKey}", "Content-Type: application/json", ], CURLOPT_POSTFIELDS => json_encode(${JSON.stringify(body, null, 4).replace(/\n/g, '\n ')}), ]); curl_exec($ch);`; return [ {id: 'curl', label: 'cURL', code: curl}, {id: 'node', label: 'Node.js', code: node}, {id: 'python', label: 'Python', code: python}, {id: 'php', label: 'PHP', code: php}, ]; } export default function OnboardingWorkflows() { const router = useRouter(); const {activeProject} = useActiveProject(); const {state} = useOnboardingGate(); const {path, setPath} = useOnboardingPath(activeProject?.id); const snippets = useMemo( () => buildTrackSnippets(API_URI, activeProject?.public ?? 'pk_your_public_key'), [activeProject?.public], ); useEffect(() => { if (activeProject && !path) setPath('workflows'); }, [activeProject, path, setPath]); if (state !== 'show') return null; const handleContinue = () => { void router.push('/'); }; const handleStepClick = (href: string) => { void router.push(href); }; return ( <> Automate with workflows. Four steps to your first automated email. Start with your domain so emails actually reach the inbox. {steps.map((step, index) => { const Icon = step.icon; return ( {index + 1} {step.title} {step.required && ( Required )} {step.description} {step.cta && step.href && ( handleStepClick(step.href!)} > {step.cta} )} {step.id === 'track' && ( {activeProject ? ( ) : ( )} )} ); })} Back Continue to dashboard > ); }
Four steps to your first automated email. Start with your domain so emails actually reach the inbox.
{step.description}