'use client'; /** * Project Creation Wizard * * Multi-step wizard for creating new Syndarix projects. * Adapts based on project complexity - scripts use a simplified 4-step flow. */ import { useState } from 'react'; import { useRouter } from '@/lib/i18n/routing'; import { ArrowLeft, ArrowRight, Check, CheckCircle2, Loader2 } from 'lucide-react'; import { useMutation } from '@tanstack/react-query'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Separator } from '@/components/ui/separator'; import { apiClient } from '@/lib/api/client'; import { StepIndicator } from './StepIndicator'; import { useWizardState, type ProjectCreateData } from './useWizardState'; import { WIZARD_STEPS } from './constants'; import { BasicInfoStep, ComplexityStep, ClientModeStep, AutonomyStep, AgentChatStep, ReviewStep, } from './steps'; /** * Project response from API */ interface ProjectResponse { id: string; name: string; slug: string; description: string | null; autonomy_level: string; status: string; settings: Record; owner_id: string | null; created_at: string; updated_at: string; agent_count: number; issue_count: number; active_sprint_name: string | null; } interface ProjectWizardProps { className?: string; } export function ProjectWizard({ className }: ProjectWizardProps) { const router = useRouter(); const [isCreated, setIsCreated] = useState(false); const { state, updateState, resetState, isScriptMode, canProceed, goNext, goBack, getProjectData, } = useWizardState(); // Project creation mutation using the configured API client const createProjectMutation = useMutation({ mutationFn: async (projectData: ProjectCreateData): Promise => { // Call the projects API endpoint // Note: The API client already handles authentication via interceptors const response = await apiClient.instance.post('/api/v1/projects', { name: projectData.name, slug: projectData.slug, description: projectData.description, autonomy_level: projectData.autonomy_level, settings: projectData.settings, }); return response.data; }, onSuccess: () => { setIsCreated(true); }, onError: (error) => { // Error handling - in production, show toast notification console.error('Failed to create project:', error); }, }); const handleCreate = () => { const projectData = getProjectData(); createProjectMutation.mutate(projectData); }; const handleReset = () => { resetState(); setIsCreated(false); createProjectMutation.reset(); }; const handleGoToProject = () => { // Navigate to project dashboard - using slug from successful creation if (createProjectMutation.data) { router.push(`/projects/${createProjectMutation.data.slug}`); } else { router.push(`/projects`); } }; // Success screen if (isCreated && createProjectMutation.data) { return (

Project Created Successfully!

"{createProjectMutation.data.name}" has been created. The Product Owner agent will begin the requirements discovery process shortly.

); } return (
{/* Step Indicator */}
{/* Step Content */} {state.step === WIZARD_STEPS.BASIC_INFO && ( )} {state.step === WIZARD_STEPS.COMPLEXITY && ( )} {state.step === WIZARD_STEPS.CLIENT_MODE && !isScriptMode && ( )} {state.step === WIZARD_STEPS.AUTONOMY && !isScriptMode && ( )} {state.step === WIZARD_STEPS.AGENT_CHAT && } {state.step === WIZARD_STEPS.REVIEW && } {/* Navigation Footer */}
{state.step < WIZARD_STEPS.REVIEW ? ( ) : ( )}
{/* Error display */} {createProjectMutation.isError && (

Failed to create project. Please try again.

)}
); }