---
task_id: sprint_4_story_1_task_4
story_id: sprint_4_story_1
sprint_id: sprint_4
status: not_started
type: frontend
assignee: Frontend Developer 1
created_date: 2025-11-05
estimated_hours: 3
---
# Task 4: Integrate Story API Data Loading and Error Handling
## Description
Connect the Story detail page to the backend API using React Query hooks. Implement data loading, error handling, 404 detection, and loading states with skeleton loaders.
## What to Do
1. Use `useStory(id)` hook to fetch Story data
2. Use `useEpic(epicId)` hook to fetch parent Epic data
3. Implement loading states with skeleton loaders
4. Handle 404 errors (Story not found)
5. Handle network errors
6. Handle permission errors (unauthorized)
7. Add breadcrumb navigation with data
8. Display Story description in main content area
9. Test with various Story IDs (valid, invalid, deleted)
## Files to Modify
- `app/(dashboard)/stories/[id]/page.tsx` (modify, ~50 lines added)
## Implementation Details
```typescript
// app/(dashboard)/stories/[id]/page.tsx
'use client';
import { use } from 'react';
import { notFound } from 'next/navigation';
import { useStory } from '@/lib/hooks/use-stories';
import { useEpic } from '@/lib/hooks/use-epics';
import { StoryHeader } from '@/components/projects/story-header';
import { StoryMetadataSidebar } from '@/components/projects/story-metadata-sidebar';
import { Card } from '@/components/ui/card';
import { Skeleton } from '@/components/ui/skeleton';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { AlertCircle } from 'lucide-react';
interface StoryDetailPageProps {
params: Promise<{ id: string }>;
}
export default function StoryDetailPage({ params }: StoryDetailPageProps) {
const { id } = use(params);
// Fetch Story data
const {
data: story,
isLoading: storyLoading,
error: storyError,
} = useStory(id);
// Fetch parent Epic data
const {
data: parentEpic,
isLoading: epicLoading,
} = useEpic(story?.epicId, {
enabled: !!story?.epicId, // Only fetch if Story loaded
});
// Handle loading state
if (storyLoading || epicLoading) {
return ;
}
// Handle 404 - Story not found
if (storyError?.response?.status === 404) {
notFound();
}
// Handle other errors (network, permission, etc.)
if (storyError || !story) {
return (
{storyError?.message || 'Failed to load Story. Please try again.'}