diff --git a/components/todos/todo-list.tsx b/components/todos/todo-list.tsx index 398f5b0..2eb7497 100644 --- a/components/todos/todo-list.tsx +++ b/components/todos/todo-list.tsx @@ -1,6 +1,8 @@ 'use client' import { useState, useTransition, useMemo, useEffect, useRef, useCallback } from 'react' +import { useActionState } from 'react' +import { useFormStatus } from 'react-dom' import { useReactTable, getCoreRowModel, @@ -18,11 +20,12 @@ import { Input } from '@/components/ui/input' import { DemoTooltip } from '@/components/shared/demo-tooltip' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table' import { + createTodoAction, + updateTodoAction, archiveSelectedTodosAction, promoteTodoToPbiAction, promoteTodoToStoryAction, } from '@/actions/todos' -import { useActionState } from 'react' interface Todo { id: string @@ -70,6 +73,15 @@ function IndeterminateCheckbox({ ) } +function SaveButton() { + const { pending } = useFormStatus() + return ( + + ) +} + // --- Promote to PBI dialog --- function PromotePbiDialog({ todo, @@ -217,6 +229,141 @@ function PromoteStoryDialog({ ) } +// --- Detail card --- +function TodoCard({ + mode, + activeTodo, + products, + isDemo, + defaultProductId, + onSuccess, + onPromotePbi, + onPromoteStory, +}: { + mode: 'idle' | 'create' | 'edit' + activeTodo: Todo | null + products: Product[] + isDemo: boolean + defaultProductId: string + onSuccess: () => void + onPromotePbi: (todo: Todo) => void + onPromoteStory: (todo: Todo) => void +}) { + const [createState, createFormAction] = useActionState(createTodoAction, undefined) + const [editState, editFormAction] = useActionState(updateTodoAction, undefined) + + useEffect(() => { + if (createState?.success) onSuccess() + }, [createState, onSuccess]) + + useEffect(() => { + if (editState?.success) onSuccess() + }, [editState, onSuccess]) + + if (mode === 'idle') { + return ( +
Selecteer een rij of klik op + om te beginnen.
+Nieuwe todo
+ +Todo bewerken
+ +- {mode === 'create' - ? 'Nieuwe todo aanmaken — kaart wordt gebouwd in ST-510.' - : activeTodo - ? `Geselecteerd: ${activeTodo.title}` - : 'Selecteer een rij of klik op + om te beginnen.'} -
-