'use client' import { useState } from 'react' import { useFormStatus } from 'react-dom' import { toast } from 'sonner' import { Sheet, SheetContent, SheetHeader, SheetTitle, } from '@/components/ui/sheet' import { DemoTooltip } from '@/components/shared/demo-tooltip' import { CodeBadge } from '@/components/shared/code-badge' import { claimStoryAction } from '@/actions/stories' import { cn } from '@/lib/utils' import { debugProps } from '@/lib/debug' export interface UnassignedStoryTask { id: string title: string description: string | null priority: number status: string } export interface UnassignedStory { id: string code: string | null title: string tasks: UnassignedStoryTask[] } interface UnassignedStoriesSheetProps { stories: UnassignedStory[] productId: string isDemo: boolean open: boolean onOpenChange: (open: boolean) => void onClaim: (storyId: string) => void } const PRIORITY_BORDER: Record = { 1: 'border-l-2 border-l-priority-critical', 2: 'border-l-2 border-l-priority-high', 3: 'border-l-2 border-l-priority-medium', 4: 'border-l-2 border-l-priority-low', } const STATUS_COLORS: Record = { TO_DO: 'bg-status-todo/15 text-status-todo', IN_PROGRESS: 'bg-status-in-progress/15 text-status-in-progress', REVIEW: 'bg-status-in-progress/15 text-status-in-progress', DONE: 'bg-status-done/15 text-status-done', } const STATUS_LABELS: Record = { TO_DO: 'To Do', IN_PROGRESS: 'Bezig', REVIEW: 'Review', DONE: 'Klaar', } const PRIORITY_LABELS: Record = { 1: 'Kritiek', 2: 'Hoog', 3: 'Gemiddeld', 4: 'Laag' } function TaskRow({ task }: { task: UnassignedStoryTask }) { const [expanded, setExpanded] = useState(false) return (
setExpanded(e => !e)} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setExpanded(v => !v) } }} className={cn( 'px-3 py-2 cursor-pointer select-none', PRIORITY_BORDER[task.priority], )} >
{task.title} {STATUS_LABELS[task.status] ?? task.status} {PRIORITY_LABELS[task.priority]}
{expanded && (

{task.description ?? 'Geen beschrijving.'}

)}
) } function ClaimButton({ isDemo }: { isDemo: boolean }) { const { pending } = useFormStatus() return ( ) } function ClaimStoryRow({ story, productId, isDemo, onClaim, }: { story: UnassignedStory; productId: string; isDemo: boolean; onClaim: (id: string) => void }) { async function formAction() { const result = await claimStoryAction(story.id, productId) if (result && 'error' in result) { toast.error(result.error) } else { onClaim(story.id) toast.success(`"${story.title}" geclaimd`) } } return (

{story.title}

{story.code && }

{story.tasks.length} {story.tasks.length === 1 ? 'taak' : 'taken'}

{story.tasks.length > 0 && (
{story.tasks.map(task => ( ))}
)}
) } export function UnassignedStoriesSheet({ stories: initialStories, productId, isDemo, open, onOpenChange, onClaim, }: UnassignedStoriesSheetProps) { const [stories, setStories] = useState(initialStories) function handleClaim(storyId: string) { setStories(prev => prev.filter(s => s.id !== storyId)) onClaim(storyId) } return ( Openstaande stories
{stories.length === 0 ? (

Geen ongeclaimde stories. Lekker bezig!

) : (
{stories.map(story => ( ))}
)}
) }