'use client' import { X } from 'lucide-react' import { useState } from 'react' import { createProject } from '../lib/projects/actions' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/primitives/dialog' import { Switch } from '@/components/ui/primitives/switch' import { GoogleAddressSearch } from './google-address-search' interface NewProjectDialogProps { open: boolean onOpenChange: (open: boolean) => void onSuccess?: (projectId: string) => void localProjectData?: { id: string name: string sceneGraph: any } } interface AddressData { streetNumber?: string route?: string city?: string state?: string postalCode?: string country?: string center: [number, number] formattedAddress: string } /** * NewProjectDialog - Dialog for creating a new project with optional Google Maps address search */ export function NewProjectDialog({ open, onOpenChange, onSuccess, localProjectData }: NewProjectDialogProps) { const [projectName, setProjectName] = useState(localProjectData?.name || '') const [address, setAddress] = useState(null) const [showAddressSearch, setShowAddressSearch] = useState(false) const [isPrivate, setIsPrivate] = useState(false) const [isCreating, setIsCreating] = useState(false) const [error, setError] = useState(null) const handleAddressSelect = (addressData: AddressData) => { setAddress(addressData) setError(null) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError(null) const name = projectName.trim() || (address?.formattedAddress ?? 'Untitled Project') if (!name) { setError('Please enter a project name') return } setIsCreating(true) try { const result = await createProject({ name, center: address?.center, streetNumber: address?.streetNumber, route: address?.route, city: address?.city, state: address?.state, postalCode: address?.postalCode, country: address?.country || 'US', isPrivate, sceneGraph: localProjectData?.sceneGraph, }) if (result.success && result.data) { onOpenChange(false) setProjectName('') setAddress(null) setShowAddressSearch(false) setIsPrivate(false) onSuccess?.(result.data.id) } else { setError(result.error || 'Failed to create project') } } catch (err) { setError(err instanceof Error ? err.message : 'An unexpected error occurred') } finally { setIsCreating(false) } } const handleClose = () => { if (!isCreating) { onOpenChange(false) setProjectName('') setAddress(null) setShowAddressSearch(false) setIsPrivate(false) setError(null) } } return ( e.preventDefault()} > Create New Project
{/* Project Name */}
setProjectName(e.target.value)} placeholder="My Project" className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary" disabled={isCreating} autoFocus />
{/* Optional Address Section */} {!showAddressSearch ? ( ) : (
{/* Show selected address */} {address && (

Selected Address:

{address.formattedAddress}

)}
)} {/* Privacy Toggle */}
Privacy
{isPrivate ? 'Only you can view this project' : 'Anyone can view this project'}
Public setIsPrivate(!checked)} />
{localProjectData && (

Saving local project: {localProjectData.name}

Your building data will be preserved

)} {error && (
{error}
)}
) }