"use client"; import { useEffect, useState } from "react"; import { AtlasChat } from "@/components/AtlasChat"; import { useRouter, useParams } from "next/navigation"; import Link from "next/link"; const DISCOVERY_PHASES = [ "big_picture", "users_personas", "features_scope", "business_model", "screens_data", "risks_questions", ]; // Maps discovery phases → the PRD sections they populate const PRD_SECTIONS: { label: string; phase: string | null }[] = [ { label: "Executive Summary", phase: "big_picture" }, { label: "Problem Statement", phase: "big_picture" }, { label: "Vision & Success Metrics", phase: "big_picture" }, { label: "Users & Personas", phase: "users_personas" }, { label: "User Flows", phase: "users_personas" }, { label: "Feature Requirements", phase: "features_scope" }, { label: "Screen Specs", phase: "features_scope" }, { label: "Business Model", phase: "business_model" }, { label: "Integrations & Dependencies", phase: "screens_data" }, { label: "Non-Functional Reqs", phase: null }, // generated at PRD finalization { label: "Risks & Mitigations", phase: "risks_questions" }, { label: "Open Questions", phase: "risks_questions" }, ]; interface FreshIdeaMainProps { projectId: string; projectName: string; } export function FreshIdeaMain({ projectId, projectName }: FreshIdeaMainProps) { const router = useRouter(); const params = useParams(); const workspace = params?.workspace as string; const [savedPhaseIds, setSavedPhaseIds] = useState>(new Set()); const [allDone, setAllDone] = useState(false); const [prdLoading, setPrdLoading] = useState(false); const [dismissed, setDismissed] = useState(false); const [hasPrd, setHasPrd] = useState(false); useEffect(() => { // Check if PRD already exists on the project fetch(`/api/projects/${projectId}`) .then(r => r.json()) .then(d => { if (d.project?.prd) setHasPrd(true); }) .catch(() => {}); const poll = () => { fetch(`/api/projects/${projectId}/save-phase`) .then(r => r.json()) .then(d => { const ids = new Set((d.phases ?? []).map((p: { phase: string }) => p.phase)); setSavedPhaseIds(ids); const done = DISCOVERY_PHASES.every(id => ids.has(id)); setAllDone(done); }) .catch(() => {}); }; poll(); const interval = setInterval(poll, 8_000); return () => clearInterval(interval); }, [projectId]); const handleGeneratePRD = async () => { if (prdLoading) return; setPrdLoading(true); try { router.push(`/${workspace}/project/${projectId}/prd`); } finally { setPrdLoading(false); } }; const handleMVP = () => { router.push(`/${workspace}/project/${projectId}/build`); }; // Once the PRD exists, show a clean "done" state in the main panel. // The Atlas conversation history lives in the left CooChat sidebar. if (hasPrd) { return (
Discovery complete
Your PRD is saved. The full discovery conversation is in the left panel — talk to your COO to plan what to build next.
View PRD → Go to Build
); } const completedSections = PRD_SECTIONS.filter(({ phase }) => phase === null ? allDone : savedPhaseIds.has(phase) ).length; const totalSections = PRD_SECTIONS.length; return (
{/* ── Left: Atlas chat ── */}
{/* Decision banner — shown when all 6 phases are saved */} {allDone && !dismissed && (
✦ Discovery complete — what's next?
All 6 phases captured. Generate your PRD or jump into Build.
)}
{/* ── Right: PRD section tracker ── */}
{/* Header */}
PRD Sections
{/* Progress bar */}
{completedSections} of {totalSections} sections complete
{/* Section list */}
{PRD_SECTIONS.map(({ label, phase }) => { const isDone = phase === null ? allDone // non-functional reqs generated when all done : savedPhaseIds.has(phase); return (
{/* Status dot */}
{label}
{!isDone && (
{phase === null ? "Generated when PRD is finalized" : "Complete this phase in Vibn" }
)}
); })}
{/* Footer CTA */} {allDone && (
Generate PRD →
)}
); }