feat(unit-4): Dashboard — availability widget with TanStack Query
- Add @tanstack/react-query 5.101.0; wrap app with QueryClientProvider - Add AvailabilityStatus type and AvailabilityResponse to api/types.ts - Implement useAvailabilityStatus (staleTime 30s, stale-on-error preserved) - Add AvailabilityStatusBadge with green/amber/red states and stale indicator - Replace DashboardPage placeholder card with live availability widget - Add MSW availability handler; update test/utils with QueryClientProvider - 55/55 tests pass (FR-05) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useAuth } from '@/contexts/auth-context';
|
||||
import { useAvailabilityStatus } from '@/api/useAvailability';
|
||||
import { AvailabilityStatusBadge } from '@/components/shared/AvailabilityStatusBadge';
|
||||
|
||||
export function DashboardPage() {
|
||||
const { t } = useTranslation();
|
||||
const { user } = useAuth();
|
||||
const { data, isLoading, isError, refetch } = useAvailabilityStatus();
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -16,12 +20,45 @@ export function DashboardPage() {
|
||||
{t('dashboard.welcome', { name: user?.name ?? '' })}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t('dashboard.title')}</CardTitle>
|
||||
<CardTitle>{t('availability.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">{t('dashboard.placeholder')}</p>
|
||||
{isLoading && (
|
||||
<div
|
||||
data-testid="availability-skeleton"
|
||||
className="h-8 w-32 animate-pulse rounded-full bg-muted"
|
||||
/>
|
||||
)}
|
||||
|
||||
{!isLoading && data && (
|
||||
<AvailabilityStatusBadge
|
||||
status={data.status}
|
||||
message={data.message}
|
||||
stale={isError}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isError && (
|
||||
<div
|
||||
data-testid="availability-error"
|
||||
className="mt-3 flex items-center gap-3 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive"
|
||||
>
|
||||
<span>{t('availability.errorTitle')}</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
data-testid="availability-retry"
|
||||
onClick={() => void refetch()}
|
||||
>
|
||||
{t('availability.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isLoading && !data && !isError && null}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user