/** * Dialog to create a new project: name + icon. */ import React, { useState } from 'react' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Plus } from 'lucide-react' import { PROJECT_ICON_IDS, type Project, type ProjectIconId } from './types' import { getProjectIcon } from '../../lib/iconMap' type NewProjectDialogProps = { onCreate: (project: Project) => void trigger?: React.ReactNode /** Other project names to check for duplicates (case-insensitive warning only) */ existingNames?: string[] } export function NewProjectDialog({ onCreate, trigger, existingNames = [] }: NewProjectDialogProps) { const [open, setOpen] = useState(false) const [name, setName] = useState('') const [iconId, setIconId] = useState('cat') const trimmed = name.trim() const isDuplicate = trimmed.length > 0 && existingNames.some((n) => n.toLowerCase() === trimmed.toLowerCase()) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (!trimmed) return const project: Project = { id: `proj_${Date.now()}`, name: trimmed, iconId, createdAt: Date.now(), } onCreate(project) setName('') setIconId('cat') setOpen(false) } return ( {trigger ?? ( )}
New project Create a project to start editing a graph canvas.
setName(e.target.value)} placeholder="My project" autoFocus /> {isDuplicate && (

A project with this name already exists.

)}
) }