Files
ProjectE/apps/web-legacy/components/projects/project-create-dialog.tsx
T
Hermes fca56ab77e T1/Phase 1: scaffold Vite SPA + Hono API + Bun worker
- apps/web: Vite + React 19 + TanStack Router/Query + shadcn/ui
   - apps/api: Hono + Bun on :3001 with /api/health, /api/auth/*, /mcp stubs
   - apps/worker: Bun worker stub, DB connection, graceful SIGTERM
   - apps/web-legacy/: old Next.js code moved aside (preserved for T2-T8 reference)
   - Dockerfiles: api (Bun), worker (Bun), spa (multi-stage Caddy)
   - Caddyfile: serves dist + reverse-proxies /api/* + /mcp to api
   - docker-compose.yml: 4-service target (api, spa, db, worker)
   - packages/db/src/client.ts: shared Drizzle client for api + worker
   - db/client.ts: root-level alias for convenience

   Parent: t_e1cbd87d -> t_24c9c3fd (T0)
2026-08-01 01:15:31 +00:00

177 lines
5.3 KiB
TypeScript

'use client';
import { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { toast } from 'sonner';
interface ProjectCreateDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
domainId: string;
onCreated: () => void;
}
export function ProjectCreateDialog({
open,
onOpenChange,
domainId,
onCreated,
}: ProjectCreateDialogProps) {
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [status, setStatus] = useState<'active' | 'paused' | 'completed' | 'archived'>('active');
const [color, setColor] = useState('');
const [targetDate, setTargetDate] = useState('');
const [submitting, setSubmitting] = useState(false);
const [error, setError] = useState('');
useEffect(() => {
if (open) {
setName('');
setDescription('');
setStatus('active');
setColor('');
setTargetDate('');
setError('');
}
}, [open]);
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
if (!domainId) {
setError('No domain selected');
return;
}
setSubmitting(true);
setError('');
const body: Record<string, unknown> = { name, status };
if (description) body.description = description;
if (color) body.color = color;
if (targetDate) body.targetDate = new Date(targetDate).toISOString();
try {
const response = await fetch(`/api/domains/${domainId}/projects`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.error?.message || 'Unable to create project');
}
toast.success('Project created');
onOpenChange(false);
onCreated();
} catch (err) {
setError(err instanceof Error ? err.message : 'Unable to create project');
} finally {
setSubmitting(false);
}
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
<DialogTitle>New Project</DialogTitle>
<DialogDescription>Create a new project to organize your work.</DialogDescription>
</DialogHeader>
<form className="space-y-4" onSubmit={handleSubmit}>
<div className="space-y-2">
<Label htmlFor="project-name">Name *</Label>
<Input
id="project-name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Project name"
autoFocus
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="project-description">Description</Label>
<Textarea
id="project-description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Optional description..."
rows={2}
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="project-status">Status</Label>
<Select value={status} onValueChange={(v) => setStatus(v as any)}>
<SelectTrigger id="project-status">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="active">Active</SelectItem>
<SelectItem value="paused">Paused</SelectItem>
<SelectItem value="completed">Completed</SelectItem>
<SelectItem value="archived">Archived</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="project-color">Color</Label>
<Input
id="project-color"
type="color"
value={color}
onChange={(e) => setColor(e.target.value)}
className="h-10"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="project-target-date">Target date</Label>
<Input
id="project-target-date"
type="date"
value={targetDate}
onChange={(e) => setTargetDate(e.target.value)}
/>
</div>
{error && <p className="text-sm text-destructive" role="alert">{error}</p>}
<DialogFooter>
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button type="submit" disabled={submitting || !name || !domainId}>
{submitting ? 'Creating...' : 'Create Project'}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
}