2026-02-14 21:14:16 +01:00
|
|
|
import { useState, useRef, useEffect } from 'react'
|
2026-02-16 16:56:44 +01:00
|
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'
|
|
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
|
import { Input } from '@/components/ui/input'
|
|
|
|
|
import { cn } from '@/lib/utils'
|
2026-02-14 21:14:16 +01:00
|
|
|
|
|
|
|
|
const NOTE_TYPES = [
|
|
|
|
|
'Note',
|
|
|
|
|
'Project',
|
|
|
|
|
'Experiment',
|
|
|
|
|
'Responsibility',
|
|
|
|
|
'Procedure',
|
|
|
|
|
'Person',
|
|
|
|
|
'Event',
|
|
|
|
|
'Topic',
|
|
|
|
|
] as const
|
|
|
|
|
|
|
|
|
|
export type NoteType = (typeof NOTE_TYPES)[number]
|
|
|
|
|
|
|
|
|
|
interface CreateNoteDialogProps {
|
|
|
|
|
open: boolean
|
|
|
|
|
onClose: () => void
|
|
|
|
|
onCreate: (title: string, type: NoteType) => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function CreateNoteDialog({ open, onClose, onCreate }: CreateNoteDialogProps) {
|
|
|
|
|
const [title, setTitle] = useState('')
|
|
|
|
|
const [type, setType] = useState<NoteType>('Note')
|
|
|
|
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (open) {
|
|
|
|
|
setTitle('')
|
|
|
|
|
setType('Note')
|
|
|
|
|
setTimeout(() => inputRef.current?.focus(), 50)
|
|
|
|
|
}
|
|
|
|
|
}, [open])
|
|
|
|
|
|
|
|
|
|
const handleSubmit = (e: React.FormEvent) => {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
const trimmed = title.trim()
|
|
|
|
|
if (!trimmed) return
|
|
|
|
|
onCreate(trimmed, type)
|
|
|
|
|
onClose()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-02-16 16:56:44 +01:00
|
|
|
<Dialog open={open} onOpenChange={(isOpen) => { if (!isOpen) onClose() }}>
|
|
|
|
|
<DialogContent showCloseButton={false} className="sm:max-w-[420px]">
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle>Create New Note</DialogTitle>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<label className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
|
|
|
Title
|
|
|
|
|
</label>
|
|
|
|
|
<Input
|
2026-02-14 21:14:16 +01:00
|
|
|
ref={inputRef}
|
|
|
|
|
placeholder="Enter note title..."
|
|
|
|
|
value={title}
|
|
|
|
|
onChange={(e) => setTitle(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-02-16 16:56:44 +01:00
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<label className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
|
|
|
Type
|
|
|
|
|
</label>
|
|
|
|
|
<div className="flex flex-wrap gap-1.5">
|
2026-02-14 21:14:16 +01:00
|
|
|
{NOTE_TYPES.map((t) => (
|
2026-02-16 16:56:44 +01:00
|
|
|
<Button
|
2026-02-14 21:14:16 +01:00
|
|
|
key={t}
|
|
|
|
|
type="button"
|
2026-02-16 16:56:44 +01:00
|
|
|
variant={type === t ? 'default' : 'outline'}
|
|
|
|
|
size="sm"
|
|
|
|
|
className={cn(
|
|
|
|
|
"rounded-full text-xs",
|
|
|
|
|
type === t && "bg-primary text-primary-foreground"
|
|
|
|
|
)}
|
2026-02-14 21:14:16 +01:00
|
|
|
onClick={() => setType(t)}
|
|
|
|
|
>
|
|
|
|
|
{t}
|
2026-02-16 16:56:44 +01:00
|
|
|
</Button>
|
2026-02-14 21:14:16 +01:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-16 16:56:44 +01:00
|
|
|
<DialogFooter>
|
|
|
|
|
<Button type="button" variant="outline" onClick={onClose}>
|
2026-02-14 21:14:16 +01:00
|
|
|
Cancel
|
2026-02-16 16:56:44 +01:00
|
|
|
</Button>
|
|
|
|
|
<Button type="submit" disabled={!title.trim()}>
|
2026-02-14 21:14:16 +01:00
|
|
|
Create
|
2026-02-16 16:56:44 +01:00
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
2026-02-14 21:14:16 +01:00
|
|
|
</form>
|
2026-02-16 16:56:44 +01:00
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
2026-02-14 21:14:16 +01:00
|
|
|
)
|
|
|
|
|
}
|