Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ConvertKit (email newsletter integration)
CONVERTKIT_API_KEY=your_convertkit_api_key_here
# Multicorn API (for newsletter signup and other client-side API calls)
# Default: https://api.multicorn.ai. Use http://localhost:8080 for local dev.
NEXT_PUBLIC_API_URL=https://api.multicorn.ai

# Plausible Analytics (privacy-friendly analytics)
NEXT_PUBLIC_PLAUSIBLE_DOMAIN=multicorn.ai
88 changes: 0 additions & 88 deletions app/api/subscribe/route.ts

This file was deleted.

2 changes: 1 addition & 1 deletion app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) {
<p className="mb-6 text-sm text-text-secondary">
Get the latest articles and product updates delivered to your inbox.
</p>
<EmailSignupForm />
<EmailSignupForm source="learn-blog" />
</section>
</article>
</main>
Expand Down
2 changes: 1 addition & 1 deletion app/learn/ai-101/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export default async function LearnArticlePage({ params }: LearnArticlePageProps
<p className="mb-6 text-sm text-text-secondary">
Get the latest articles and product updates delivered to your inbox.
</p>
<EmailSignupForm />
<EmailSignupForm source="learn-blog" />
</section>

<ArticleNavigation navigation={navigation} />
Expand Down
2 changes: 1 addition & 1 deletion app/learn/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default function LearnPage() {
for teams. Sign up below to get notified when new courses launch.
</p>
<div className="mt-6 flex justify-center">
<EmailSignupForm />
<EmailSignupForm source="learn-blog" />
</div>
</div>
</div>
Expand Down
68 changes: 65 additions & 3 deletions app/subscribed/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
import { ConfirmationPage } from '@/components/ConfirmationPage'
import Link from 'next/link'

export default function SubscribedPage() {
return <ConfirmationPage variant="subscribed" />
export default async function SubscribedPage({
searchParams,
}: {
searchParams: Promise<{ status?: string }>
}) {
const { status } = await searchParams

const isSuccess = status === 'success'

return (
<main className="flex min-h-screen flex-col items-center justify-center bg-surface px-6 py-14">
<div className="w-full max-w-xl rounded-card border border-border bg-surface-secondary p-8 text-center shadow-sm sm:p-10">
<div className="mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-primary/10">
{isSuccess ? (
<svg
viewBox="0 0 64 64"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className="h-10 w-10 text-primary"
aria-hidden="true"
>
<circle cx="32" cy="32" r="32" fill="currentColor" fillOpacity="0.2" />
<path
d="M19 33.5L27.5 42L45 24.5"
stroke="currentColor"
strokeWidth="4"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
) : (
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
className="h-10 w-10 text-text-tertiary"
aria-hidden="true"
>
<circle cx="12" cy="12" r="10" />
<path d="M12 8v4M12 16h.01" />
</svg>
)}
</div>

<h1 className="mt-6 text-2xl font-bold tracking-tight text-text-primary sm:text-3xl">
{isSuccess ? "You're subscribed!" : 'Link expired'}
</h1>

<p className="mt-3 text-base leading-relaxed text-text-secondary">
{isSuccess
? "We'll email you about new blog posts, features, and SDK releases."
: 'This link has expired or was already used. Try subscribing again.'}
</p>

<Link
href="/"
className="mt-8 inline-flex min-h-[44px] items-center justify-center rounded-lg bg-primary px-6 py-3 text-sm font-semibold text-white transition-colors hover:bg-primary-dark focus:outline-none focus:ring-2 focus:ring-primary/20 focus:ring-offset-2"
>
{isSuccess ? 'Back to multicorn.ai' : 'Subscribe again'}
</Link>
</div>
</main>
)
}
33 changes: 33 additions & 0 deletions app/unsubscribed/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export default function UnsubscribedPage() {
return (
<main className="flex min-h-screen flex-col items-center justify-center bg-surface px-6 py-14">
<div className="w-full max-w-xl rounded-card border border-border bg-surface-secondary p-8 text-center shadow-sm sm:p-10">
<div className="mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-primary/10">
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
className="h-10 w-10 text-primary"
aria-hidden="true"
>
<path d="M18 6L6 18M6 6l12 12" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</div>

<h1 className="mt-6 text-2xl font-bold tracking-tight text-text-primary sm:text-3xl">
You&apos;ve been unsubscribed
</h1>

<p className="mt-3 text-base leading-relaxed text-text-secondary">Sorry to see you go.</p>

<a
href="https://multicorn.ai"
className="mt-8 inline-flex min-h-[44px] items-center justify-center rounded-lg bg-primary px-6 py-3 text-sm font-semibold text-white transition-colors hover:bg-primary-dark focus:outline-none focus:ring-2 focus:ring-primary/20 focus:ring-offset-2"
>
Back to multicorn.ai
</a>
</div>
</main>
)
}
53 changes: 27 additions & 26 deletions components/EmailSignupForm.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use client'

import { useState, useRef } from 'react'
import { usePathname } from 'next/navigation'
import { trackEvent } from '@/lib/plausible'

const API_URL = process.env.NEXT_PUBLIC_API_URL || 'https://api.multicorn.ai'

const FORM_STATES = {
idle: 'idle',
submitting: 'submitting',
success: 'success',
duplicate: 'duplicate',
error: 'error',
} as const

Expand All @@ -17,11 +19,22 @@ function isValidEmail(email: string): boolean {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)
}

interface SubscribeResponse {
readonly status: 'success' | 'already_subscribed' | 'error'
function deriveSource(pathname: string): string {
if (pathname === '/' || pathname === '') return 'learn-landing'
if (pathname.startsWith('/blog') || pathname.startsWith('/learn')) return 'learn-blog'
if (pathname.startsWith('/docs') || pathname.startsWith('/shield')) return 'shield-docs'
if (pathname.startsWith('/pricing')) return 'shield-pricing'
return 'learn-other'
}

interface EmailSignupFormProps {
readonly source?: string
}

export function EmailSignupForm() {
export function EmailSignupForm({ source: sourceProp }: EmailSignupFormProps = {}) {
const pathname = usePathname()
const source = sourceProp ?? deriveSource(pathname ?? '')

const [formState, setFormState] = useState<FormState>(FORM_STATES.idle)
const [email, setEmail] = useState('')
const [validationError, setValidationError] = useState('')
Expand Down Expand Up @@ -56,21 +69,22 @@ export function EmailSignupForm() {
setSubmitError('')

try {
const response = await fetch('/api/subscribe', {
const response = await fetch(`${API_URL}/api/v1/newsletter/subscribe`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email }),
body: JSON.stringify({ email, source }),
})

const data = (await response.json()) as SubscribeResponse

if (data.status === 'already_subscribed') {
setFormState(FORM_STATES.duplicate)
if (response.status === 429) {
setFormState(FORM_STATES.error)
setSubmitError('Too many requests. Please try again in a moment.')
return
}

if (!response.ok) {
throw new Error('Subscription failed')
setFormState(FORM_STATES.error)
setSubmitError('Something went wrong. Please try again.')
return
}

setFormState(FORM_STATES.success)
Expand All @@ -87,26 +101,13 @@ export function EmailSignupForm() {
role="status"
className="rounded-lg border border-green/20 bg-green/5 px-6 py-4 text-center"
>
<p className="font-medium text-text-primary">You&apos;re on the list!</p>
<p className="mt-1 text-sm text-text-secondary">
Check your inbox (and spam folder) for a confirmation email.
<p className="font-medium text-text-primary">
Check your inbox to confirm your subscription.
</p>
</div>
)
}

if (formState === FORM_STATES.duplicate) {
return (
<div
role="status"
className="rounded-lg border border-primary/20 bg-primary/5 px-6 py-4 text-center"
>
<p className="font-medium text-text-primary">Looks like you&apos;re already subscribed.</p>
<p className="mt-1 text-sm text-text-secondary">Check your inbox for updates.</p>
</div>
)
}

const isSubmitting = formState === FORM_STATES.submitting

return (
Expand Down
2 changes: 1 addition & 1 deletion components/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function Hero() {
<p className="mb-3 text-sm font-medium text-text-secondary">
Get updates on Multicorn. No spam, ever.
</p>
<EmailSignupForm />
<EmailSignupForm source="learn-landing" />
</div>
</div>
</section>
Expand Down
12 changes: 4 additions & 8 deletions components/LaunchPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { EmailSignupForm } from '@/components/EmailSignupForm'

export function LaunchPage() {
const hasSignup = !!process.env.NEXT_PUBLIC_CONVERTKIT_FORM_ID?.trim()

return (
<div className="flex min-h-screen flex-col">
<main className="flex flex-1 flex-col items-center justify-center px-6 pb-4 pt-10 sm:pb-8 sm:pt-16">
Expand All @@ -29,12 +27,10 @@ export function LaunchPage() {
Multicorn Shield for agent permissions. Multicorn Learn for AI education.
</p>

{hasSignup && (
<div className="mt-8 w-full max-w-md">
<EmailSignupForm />
<p className="mt-3 text-sm font-medium text-text-secondary">Launching soon</p>
</div>
)}
<div className="mt-8 w-full max-w-md">
<EmailSignupForm source="learn-landing" />
<p className="mt-3 text-sm font-medium text-text-secondary">Launching soon</p>
</div>
</div>
</main>

Expand Down
4 changes: 2 additions & 2 deletions lib/launchGatePaths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const PUBLIC_LAUNCH_PATHS = ['/confirmed', '/subscribed', '/blog'] as const
const PUBLIC_LAUNCH_PATHS = ['/confirmed', '/subscribed', '/unsubscribed', '/blog'] as const
const PUBLIC_LAUNCH_PREFIXES = ['/policies/', '/blog/'] as const

export function isLaunchGatePublicPath(pathname: string): boolean {
Expand All @@ -14,5 +14,5 @@ export function isLaunchGatePublicPath(pathname: string): boolean {
}

export function isLaunchGateStandalonePath(pathname: string): boolean {
return pathname === '/confirmed' || pathname === '/subscribed'
return pathname === '/confirmed' || pathname === '/subscribed' || pathname === '/unsubscribed'
}