'use client'; import { use } from 'react'; import { useShift, useSignUpShift, useCancelSignUp } from '@/hooks/useShifts'; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Progress } from '@/components/ui/progress'; import { Badge } from '@/components/ui/badge'; import { useRouter } from 'next/navigation'; import { useSession } from 'next-auth/react'; export default function ShiftDetailPage({ params }: { params: Promise<{ id: string }> }) { const resolvedParams = use(params); const { data: shift, isLoading } = useShift(resolvedParams.id); const signUpMutation = useSignUpShift(); const cancelMutation = useCancelSignUp(); const router = useRouter(); const { data: session } = useSession(); if (isLoading) return
Loading shift...
; if (!shift) return
Shift not found
; const capacityPercentage = (shift.signups.length / shift.capacity) * 100; const isFull = shift.signups.length >= shift.capacity; const isPast = new Date(shift.startTime) < new Date(); const isSignedUp = shift.signups.some((s) => s.memberId === session?.user?.id); const handleSignUp = async () => { await signUpMutation.mutateAsync(shift.id); }; const handleCancelSignUp = async () => { await cancelMutation.mutateAsync(shift.id); }; return (
{shift.title} {isPast && Past}
Time: {new Date(shift.startTime).toLocaleString()} - {new Date(shift.endTime).toLocaleTimeString()}
{shift.location && (
Location: {shift.location}
)} {shift.description && (
Description: {shift.description}
)}
Capacity {shift.signups.length}/{shift.capacity} spots filled

Signed Up Members ({shift.signups.length})

{shift.signups.length === 0 ? (

No sign-ups yet

) : (
    {shift.signups.map((signup) => (
  • Member ID: {signup.memberId}
  • ))}
)}
{!isPast && !isFull && !isSignedUp && ( )} {!isPast && isSignedUp && ( )}
); }