chore: update devbook.md to mark completion of layout, UI components, and homepage; update dev.db

This commit is contained in:
Julien Froidefond
2025-11-27 13:11:11 +01:00
parent 6a9bf88a65
commit 27e409fb76
12 changed files with 701 additions and 10 deletions

View File

@@ -0,0 +1,103 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { Card, CardHeader, CardTitle, CardDescription, CardContent, Button, Input } from '@/components/ui';
export default function NewSessionPage() {
const router = useRouter();
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
setError(null);
setLoading(true);
const formData = new FormData(e.currentTarget);
const title = formData.get('title') as string;
const collaborator = formData.get('collaborator') as string;
if (!title || !collaborator) {
setError('Veuillez remplir tous les champs');
setLoading(false);
return;
}
try {
const res = await fetch('/api/sessions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title, collaborator }),
});
const data = await res.json();
if (!res.ok) {
setError(data.error || 'Une erreur est survenue');
setLoading(false);
return;
}
router.push(`/sessions/${data.id}`);
} catch {
setError('Une erreur est survenue');
setLoading(false);
}
}
return (
<main className="mx-auto max-w-2xl px-4 py-8">
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<span></span>
Nouvelle Session SWOT
</CardTitle>
<CardDescription>
Créez une nouvelle session d&apos;atelier SWOT pour un collaborateur
</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit} className="space-y-6">
{error && (
<div className="rounded-lg border border-destructive/20 bg-destructive/10 p-3 text-sm text-destructive">
{error}
</div>
)}
<Input
label="Titre de la session"
name="title"
placeholder="Ex: Entretien annuel 2025"
required
/>
<Input
label="Nom du collaborateur"
name="collaborator"
placeholder="Ex: Jean Dupont"
required
/>
<div className="flex gap-3 pt-4">
<Button
type="button"
variant="outline"
onClick={() => router.back()}
disabled={loading}
>
Annuler
</Button>
<Button type="submit" loading={loading} className="flex-1">
Créer la session
</Button>
</div>
</form>
</CardContent>
</Card>
</main>
);
}

105
src/app/sessions/page.tsx Normal file
View File

@@ -0,0 +1,105 @@
import Link from 'next/link';
import { auth } from '@/lib/auth';
import { prisma } from '@/services/database';
import { Card, CardContent, Badge, Button } from '@/components/ui';
async function getSessions(userId: string) {
return prisma.session.findMany({
where: { userId },
include: {
_count: {
select: {
items: true,
actions: true,
},
},
},
orderBy: { updatedAt: 'desc' },
});
}
export default async function SessionsPage() {
const session = await auth();
if (!session?.user?.id) {
return null;
}
const sessions = await getSessions(session.user.id);
return (
<main className="mx-auto max-w-7xl px-4 py-8">
{/* Header */}
<div className="mb-8 flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold text-foreground">Mes Sessions SWOT</h1>
<p className="mt-1 text-muted">
Gérez vos ateliers SWOT avec vos collaborateurs
</p>
</div>
<Link href="/sessions/new">
<Button>
<span></span>
Nouvelle Session
</Button>
</Link>
</div>
{/* Sessions Grid */}
{sessions.length === 0 ? (
<Card className="p-12 text-center">
<div className="text-5xl mb-4">📋</div>
<h2 className="text-xl font-semibold text-foreground mb-2">
Aucune session pour le moment
</h2>
<p className="text-muted mb-6">
Créez votre première session SWOT pour commencer à analyser les forces,
faiblesses, opportunités et menaces de vos collaborateurs.
</p>
<Link href="/sessions/new">
<Button>Créer ma première session</Button>
</Link>
</Card>
) : (
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
{sessions.map((s) => (
<Link key={s.id} href={`/sessions/${s.id}`}>
<Card hover className="h-full p-6">
<div className="mb-4 flex items-start justify-between">
<div>
<h3 className="font-semibold text-foreground line-clamp-1">
{s.title}
</h3>
<p className="text-sm text-muted">{s.collaborator}</p>
</div>
<span className="text-2xl">📊</span>
</div>
<CardContent className="p-0">
<div className="flex flex-wrap gap-2 mb-4">
<Badge variant="primary">
{s._count.items} items
</Badge>
<Badge variant="success">
{s._count.actions} actions
</Badge>
</div>
<p className="text-xs text-muted">
Mis à jour le{' '}
{new Date(s.updatedAt).toLocaleDateString('fr-FR', {
day: 'numeric',
month: 'long',
year: 'numeric',
})}
</p>
</CardContent>
</Card>
</Link>
))}
</div>
)}
</main>
);
}