PCB_agentic_ai / frontend /src /components /NewProjectDialog.tsx
mindchainai's picture
Deploy PCB AI Studio: FastAPI + React studio at /, Gradio KiCad check at /gradio
8604d66 verified
Raw History Blame Contribute Delete
2.42 kB
import { X } from 'lucide-react'
import { useEffect, useRef, useState } from 'react'
import { EXAMPLE_SPEC } from '../lib/spec'
import { Spinner } from './ui'
interface Props {
open: boolean
creating: boolean
onClose: () => void
onCreate: (name: string, description: string) => void
}
export function NewProjectDialog({ open, creating, onClose, onCreate }: Props) {
const [name, setName] = useState('ESP32 Temperature Monitor')
const [desc, setDesc] = useState(EXAMPLE_SPEC)
const input = useRef<HTMLInputElement>(null)
useEffect(() => {
if (open) setTimeout(() => input.current?.select(), 30)
}, [open])
if (!open) return null
const valid = name.trim().length > 0
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4" role="dialog" aria-modal="true" aria-labelledby="np-title"
onKeyDown={(e) => e.key === 'Escape' && onClose()}>
<form className="w-full max-w-lg rounded-xl border border-ink-600 bg-ink-850 shadow-2xl"
onSubmit={(e) => { e.preventDefault(); if (valid && !creating) onCreate(name.trim(), desc) }}>
<div className="flex items-center border-b border-ink-700 px-4 py-3">
<h2 id="np-title" className="flex-1 text-[14px] font-semibold text-white">New PCB project</h2>
<button type="button" aria-label="Close" onClick={onClose} className="text-ink-400 hover:text-white"><X size={16} /></button>
</div>
<div className="space-y-3 p-4">
<label className="block">
<span className="label">Project name</span>
<input ref={input} className="field" value={name} maxLength={120} onChange={(e) => setName(e.target.value)} />
</label>
<label className="block">
<span className="label">Describe the board (optional — you can edit it later)</span>
<textarea className="field min-h-[110px]" value={desc} onChange={(e) => setDesc(e.target.value)} />
</label>
</div>
<div className="flex justify-end gap-2 border-t border-ink-700 px-4 py-3">
<button type="button" className="btn-ghost" onClick={onClose}>Cancel</button>
<button type="submit" className="btn-primary" disabled={!valid || creating}>
{creating && <Spinner />} Create project
</button>
</div>
</form>
</div>
)
}