- {/* Rangée principale déplaçable */}
Promise
onCancel: () => void
- extended?: boolean // true = tous les champs (vue laptop)
+ extended?: boolean
+ initialValues?: Partial
+ submitLabel?: string
}
const inputStyle: React.CSSProperties = {
@@ -24,14 +26,16 @@ const inputStyle: React.CSSProperties = {
boxSizing: 'border-box',
}
-export default function TodoForm({ onSubmit, onCancel, extended = false }: TodoFormProps) {
- const [title, setTitle] = useState('')
- const [domain, setDomain] = useState('')
- const [priority, setPriority] = useState<'low' | 'medium' | 'high'>('medium')
- const [dueDate, setDueDate] = useState('')
- const [body, setBody] = useState('')
- const [url, setUrl] = useState('')
- const [tags, setTags] = useState('')
+export default function TodoForm({ onSubmit, onCancel, extended = false, initialValues, submitLabel = 'Créer' }: TodoFormProps) {
+ const [title, setTitle] = useState(initialValues?.title ?? '')
+ const [domain, setDomain] = useState(initialValues?.domain ?? '')
+ const [priority, setPriority] = useState<'low' | 'medium' | 'high'>(initialValues?.priority ?? 'medium')
+ const [dueDate, setDueDate] = useState(
+ initialValues?.due_date ? initialValues.due_date.slice(0, 10) : ''
+ )
+ const [body, setBody] = useState(initialValues?.body ?? '')
+ const [url, setUrl] = useState(initialValues?.url ?? '')
+ const [tags, setTags] = useState((initialValues?.tags ?? []).join(', '))
const [loading, setLoading] = useState(false)
async function handleSubmit(e: React.FormEvent) {
@@ -81,7 +85,6 @@ export default function TodoForm({ onSubmit, onCancel, extended = false }: TodoF
type="date"
value={dueDate}
onChange={e => setDueDate(e.target.value)}
- placeholder="Date objectif"
/>
{extended && (
@@ -139,7 +142,7 @@ export default function TodoForm({ onSubmit, onCancel, extended = false }: TodoF
minHeight: 48,
}}
>
- {loading ? '…' : 'Créer'}
+ {loading ? '…' : submitLabel}
diff --git a/frontend/src/pages/TodosPage.tsx b/frontend/src/pages/TodosPage.tsx
index c0c9edf..c087bf2 100644
--- a/frontend/src/pages/TodosPage.tsx
+++ b/frontend/src/pages/TodosPage.tsx
@@ -5,6 +5,8 @@ import { fetchTodos, createTodo, updateTodo, deleteTodo, postponeTodo } from '..
import SwipeableRow from '../components/todos/SwipeableRow'
import TodoForm from '../components/todos/TodoForm'
+type EditingTodo = Todo | null
+
const DOMAINS = [
'informatique', 'diy', 'electronique', 'domotique',
'bricolage', 'jardin', 'cuisine', 'voyage', 'animaux',
@@ -31,6 +33,7 @@ export default function TodosPage() {
const [loading, setLoading] = useState(true)
const [error, setError] = useState
(null)
const [showForm, setShowForm] = useState(false)
+ const [editingTodo, setEditingTodo] = useState(null)
const [filters, setFilters] = useState({ status: 'pending' })
const load = useCallback(async () => {
@@ -57,6 +60,16 @@ export default function TodosPage() {
}
}
+ async function handleUpdate(id: string, data: TodoCreate) {
+ try {
+ await updateTodo(id, data)
+ setEditingTodo(null)
+ void load()
+ } catch {
+ setError('Erreur lors de la mise à jour')
+ }
+ }
+
async function handleDone(id: string) {
try {
await updateTodo(id, { status: 'done' })
@@ -148,6 +161,30 @@ export default function TodosPage() {
)}
+ {/* Formulaire d'édition */}
+ {editingTodo && (
+
)}
@@ -177,6 +214,7 @@ export default function TodosPage() {