'use client'; import { useState } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; import { Loader2, CheckCircle2, Sparkles } from 'lucide-react'; import { toast } from 'sonner'; import { cn } from '@/lib/utils'; interface VisionFormProps { projectId: string; workspace?: string; onComplete?: () => void; } export function VisionForm({ projectId, workspace, onComplete }: VisionFormProps) { const [currentQuestion, setCurrentQuestion] = useState(1); const [answers, setAnswers] = useState({ q1: '', q2: '', q3: '', }); const [saving, setSaving] = useState(false); const [generating, setGenerating] = useState(false); const questions = [ { number: 1, key: 'q1' as const, question: 'Who has the problem you want to fix and what is it?', placeholder: 'E.g., Fantasy hockey GMs need an advantage over their competitors...', }, { number: 2, key: 'q2' as const, question: 'Tell me a story of this person using your tool and experiencing your vision?', placeholder: 'E.g., The user connects their hockey pool site...', }, { number: 3, key: 'q3' as const, question: 'How much did that improve things for them?', placeholder: 'E.g., They feel relieved and excited...', }, ]; const currentQ = questions[currentQuestion - 1]; const handleNext = () => { if (!answers[currentQ.key].trim()) { toast.error('Please answer the question before continuing'); return; } setCurrentQuestion(currentQuestion + 1); }; const handleBack = () => { setCurrentQuestion(currentQuestion - 1); }; const handleSubmit = async () => { if (!answers.q3.trim()) { toast.error('Please answer the question'); return; } try { setSaving(true); // Save vision answers to Firestore const response = await fetch(`/api/projects/${projectId}/vision`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ visionAnswers: { q1: answers.q1, q2: answers.q2, q3: answers.q3, allAnswered: true, updatedAt: new Date().toISOString(), }, }), }); if (!response.ok) { throw new Error('Failed to save vision answers'); } toast.success('Vision captured! Generating your MVP plan...'); setSaving(false); setGenerating(true); // Trigger MVP generation const mvpResponse = await fetch(`/api/projects/${projectId}/mvp-checklist`, { method: 'POST', }); if (!mvpResponse.ok) { throw new Error('Failed to generate MVP plan'); } setGenerating(false); toast.success('MVP plan generated! Redirecting to plan page...'); // Redirect to plan page if (workspace) { setTimeout(() => { window.location.href = `/${workspace}/project/${projectId}/plan`; }, 1000); } onComplete?.(); } catch (error) { console.error('Error saving vision:', error); toast.error('Failed to save vision and generate plan'); setSaving(false); setGenerating(false); } }; if (generating) { return (
This may take up to a minute
Q{q.number}: {q.question}
{answers[q.key]}