feat(ui): add shift management UI with list, detail, and sign-up

Implements Task 20: Shift Sign-Up UI - List + Detail + Create Pages

New components:
- useShifts hook: TanStack Query hooks (useShifts, useShift, useCreateShift, useSignUpShift, useCancelSignUp)
- Shift list page: Card-based UI (NOT table) with capacity bars and Past badges
- Shift detail page: Full info with sign-up/cancel buttons, member list
- New shift form: Create shifts with title, description, location, times, capacity
- ShiftCard component: Reusable card with capacity Progress bar

Key features:
- Card-based UI pattern (shadcn Card, NOT Table - more visual for schedules)
- Capacity calculation: (currentSignups / capacity) * 100 for Progress bar
- Past shift detection: new Date(startTime) < new Date() → shows 'Past' badge
- Sign-up button visibility: !isPast && !isFull && !isSignedUp
- Cancel button visibility: !isPast && isSignedUp
- Role-based 'New Shift' button: Manager/Admin only
- TanStack Query with automatic cache invalidation on mutations
- Navigation includes Shifts link in sidebar

New shadcn components:
- Progress: Radix UI progress bar with transform-based fill
- Textarea: Styled textarea for shift descriptions

TDD:
- 3 shift card tests (capacity display, full capacity, past shifts)
- 3 shift detail tests (sign-up button, cancel button, mutation calls)

All tests pass (37/37: 31 existing + 6 new). Build succeeds.
This commit is contained in:
WorkClub Automation
2026-03-03 20:22:52 +01:00
parent c8ae47c0bc
commit 817c9ba537
11 changed files with 687 additions and 1 deletions

View File

@@ -0,0 +1,50 @@
import Link from 'next/link';
import { Card, CardHeader, CardTitle, CardDescription, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Progress } from '@/components/ui/progress';
import { Badge } from '@/components/ui/badge';
import { ShiftListItemDto } from '@/hooks/useShifts';
interface ShiftCardProps {
shift: ShiftListItemDto;
}
export function ShiftCard({ shift }: ShiftCardProps) {
const capacityPercentage = (shift.currentSignups / shift.capacity) * 100;
const isFull = shift.currentSignups >= shift.capacity;
const isPast = new Date(shift.startTime) < new Date();
return (
<Card>
<CardHeader>
<div className="flex justify-between items-start">
<CardTitle>{shift.title}</CardTitle>
{isPast && <Badge variant="secondary">Past</Badge>}
</div>
<CardDescription>
{new Date(shift.startTime).toLocaleString()} - {new Date(shift.endTime).toLocaleTimeString()}
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-3">
<div>
<div className="flex justify-between text-sm mb-1">
<span>Capacity</span>
<span>{shift.currentSignups}/{shift.capacity} spots filled</span>
</div>
<Progress value={capacityPercentage} />
</div>
<div className="flex gap-2">
<Link href={`/shifts/${shift.id}`}>
<Button variant="outline" size="sm">View Details</Button>
</Link>
{!isPast && !isFull && (
<Button size="sm">Sign Up</Button>
)}
</div>
</div>
</CardContent>
</Card>
);
}