'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { AppSwitcher } from '@/components/AppSwitcher'; import { NLInput } from '@/components/NLInput'; import { ParsedTripPreview } from '@/components/ParsedTripPreview'; import { ParsedTrip } from '@/lib/types'; export default function NewTrip() { const router = useRouter(); const [parsed, setParsed] = useState(null); const [rawInput, setRawInput] = useState(''); const [creating, setCreating] = useState(false); const [error, setError] = useState(null); const handleParsed = (data: ParsedTrip, raw: string) => { setParsed(data); setRawInput(raw); }; const handleConfirm = async (finalParsed: ParsedTrip) => { setCreating(true); setError(null); try { const res = await fetch('/api/trips', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ parsed: finalParsed, rawInput }), }); if (!res.ok) { const data = await res.json(); throw new Error(data.error || 'Failed to create trip'); } const trip = await res.json(); router.push(`/trips/${trip.id}`); } catch (err) { setError(err instanceof Error ? err.message : 'Something went wrong'); setCreating(false); } }; return (
{/* Nav */} {/* Content */}

Plan a New Trip

Describe your trip in natural language and we'll structure it for you.

{error && (
{error}
)} {!parsed ? ( ) : ( setParsed(null)} loading={creating} /> )}
); }