feat(frontend): Implement Epic/Story/Task Management UI (Story 2)

Complete implementation of Sprint 1 Story 2 with full CRUD operations
for Epic/Story/Task entities including forms, hierarchy visualization,
and breadcrumb navigation.

Changes:
- Add EpicForm, StoryForm, TaskForm components with Zod validation
- Implement HierarchyTree component with expand/collapse functionality
- Add WorkItemBreadcrumb for Epic → Story → Task navigation
- Create centralized exports in components/projects/index.ts
- Fix Project form schemas to match UpdateProjectDto types
- Update dashboard to remove non-existent Project.status field

API Client & Hooks (already completed):
- epicsApi, storiesApi, tasksApi with full CRUD operations
- React Query hooks with optimistic updates and invalidation
- Error handling and JWT authentication integration

Technical Implementation:
- TypeScript type safety throughout
- Zod schema validation for all forms
- React Query optimistic updates
- Hierarchical data loading (lazy loading on expand)
- Responsive UI with Tailwind CSS
- Loading states and error handling

Story Points: 8 SP
Estimated Hours: 16h
Status: Completed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yaojia Wang
2025-11-04 22:58:44 +01:00
parent 01132ee6e4
commit bfcbf6e350
9 changed files with 1244 additions and 8 deletions

View File

@@ -0,0 +1,271 @@
'use client';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import * as z from 'zod';
import { Button } from '@/components/ui/button';
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '@/components/ui/form';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { useCreateTask, useUpdateTask } from '@/lib/hooks/use-tasks';
import { useStories } from '@/lib/hooks/use-stories';
import type { Task, WorkItemPriority } from '@/types/project';
import { toast } from 'sonner';
import { Loader2 } from 'lucide-react';
const taskSchema = z.object({
storyId: z.string().min(1, 'Parent Story is required'),
title: z
.string()
.min(1, 'Title is required')
.max(200, 'Title must be less than 200 characters'),
description: z
.string()
.max(2000, 'Description must be less than 2000 characters')
.optional(),
priority: z.enum(['Low', 'Medium', 'High', 'Critical']),
estimatedHours: z
.number()
.min(0, 'Estimated hours must be positive')
.optional()
.or(z.literal('')),
});
type TaskFormValues = z.infer<typeof taskSchema>;
interface TaskFormProps {
task?: Task;
storyId?: string;
epicId?: string;
onSuccess?: () => void;
onCancel?: () => void;
}
export function TaskForm({
task,
storyId,
epicId,
onSuccess,
onCancel,
}: TaskFormProps) {
const isEditing = !!task;
const createTask = useCreateTask();
const updateTask = useUpdateTask();
// Fetch stories for parent story selection
const { data: stories = [], isLoading: storiesLoading } = useStories(epicId);
const form = useForm<TaskFormValues>({
resolver: zodResolver(taskSchema),
defaultValues: {
storyId: task?.storyId || storyId || '',
title: task?.title || '',
description: task?.description || '',
priority: task?.priority || 'Medium',
estimatedHours: task?.estimatedHours || ('' as any),
},
});
async function onSubmit(data: TaskFormValues) {
try {
if (isEditing && task) {
await updateTask.mutateAsync({
id: task.id,
data: {
title: data.title,
description: data.description,
priority: data.priority,
estimatedHours:
typeof data.estimatedHours === 'number' ? data.estimatedHours : undefined,
},
});
toast.success('Task updated successfully');
} else {
await createTask.mutateAsync({
storyId: data.storyId,
title: data.title,
description: data.description,
priority: data.priority,
estimatedHours:
typeof data.estimatedHours === 'number' ? data.estimatedHours : undefined,
});
toast.success('Task created successfully');
}
onSuccess?.();
} catch (error) {
const message = error instanceof Error ? error.message : 'Operation failed';
toast.error(message);
}
}
const isLoading = createTask.isPending || updateTask.isPending;
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
<FormField
control={form.control}
name="storyId"
render={({ field }) => (
<FormItem>
<FormLabel>Parent Story *</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
disabled={isEditing || !!storyId}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select parent story" />
</SelectTrigger>
</FormControl>
<SelectContent>
{storiesLoading ? (
<div className="p-2 text-sm text-muted-foreground">
Loading stories...
</div>
) : stories.length === 0 ? (
<div className="p-2 text-sm text-muted-foreground">
No stories available
</div>
) : (
stories.map((story) => (
<SelectItem key={story.id} value={story.id}>
{story.title}
</SelectItem>
))
)}
</SelectContent>
</Select>
<FormDescription>
{isEditing ? 'Parent story cannot be changed' : 'Select the parent story'}
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="title"
render={({ field }) => (
<FormItem>
<FormLabel>Task Title *</FormLabel>
<FormControl>
<Input placeholder="e.g., Implement JWT token validation" {...field} />
</FormControl>
<FormDescription>A clear, concise title for this task</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="description"
render={({ field }) => (
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Textarea
placeholder="Detailed description of the task..."
className="resize-none"
rows={6}
{...field}
/>
</FormControl>
<FormDescription>
Optional detailed description (max 2000 characters)
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<div className="grid grid-cols-2 gap-4">
<FormField
control={form.control}
name="priority"
render={({ field }) => (
<FormItem>
<FormLabel>Priority *</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select priority" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="Low">Low</SelectItem>
<SelectItem value="Medium">Medium</SelectItem>
<SelectItem value="High">High</SelectItem>
<SelectItem value="Critical">Critical</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="estimatedHours"
render={({ field }) => (
<FormItem>
<FormLabel>Estimated Hours</FormLabel>
<FormControl>
<Input
type="number"
placeholder="e.g., 2"
min="0"
step="0.5"
{...field}
onChange={(e) => {
const value = e.target.value;
field.onChange(value === '' ? '' : parseFloat(value));
}}
value={field.value === undefined ? '' : field.value}
/>
</FormControl>
<FormDescription>Optional time estimate</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="flex justify-end gap-3">
{onCancel && (
<Button
type="button"
variant="outline"
onClick={onCancel}
disabled={isLoading}
>
Cancel
</Button>
)}
<Button type="submit" disabled={isLoading}>
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{isEditing ? 'Update Task' : 'Create Task'}
</Button>
</div>
</form>
</Form>
);
}