From 0d2b18217d00ee32b9bb1a0ea1fc9b1f8c2b2d34 Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Wed, 20 Nov 2024 22:50:17 -0500 Subject: [PATCH] Update participants page UI --- src/app/api/participants/[id]/route.ts | 6 +- src/app/dashboard/participants/page.tsx | 126 +++++++++++++++++------- 2 files changed, 96 insertions(+), 36 deletions(-) diff --git a/src/app/api/participants/[id]/route.ts b/src/app/api/participants/[id]/route.ts index 3dc79c5..2cc878f 100644 --- a/src/app/api/participants/[id]/route.ts +++ b/src/app/api/participants/[id]/route.ts @@ -4,15 +4,15 @@ import { auth } from "@clerk/nextjs/server"; import { db } from "~/db"; import { participants } from "~/db/schema"; -export async function DELETE(request: Request, { params }: { params: { id: string } }) { + +export async function DELETE(request: Request, { params }: any) { const { userId } = await auth(); if (!userId) { return new NextResponse("Unauthorized", { status: 401 }); } - const { id } = await params; - const participantId = parseInt(id); + const participantId = parseInt(params.id); try { const result = await db diff --git a/src/app/dashboard/participants/page.tsx b/src/app/dashboard/participants/page.tsx index a22c635..5dbab1d 100644 --- a/src/app/dashboard/participants/page.tsx +++ b/src/app/dashboard/participants/page.tsx @@ -1,18 +1,24 @@ 'use client'; +import { PlusIcon, Trash2Icon } from "lucide-react"; import { useEffect, useState } from "react"; import { Button } from "~/components/ui/button"; -import { Card, CardHeader, CardTitle, CardContent } from "~/components/ui/card"; +import { + Card, + CardContent, + CardHeader, + CardTitle, + CardDescription, + CardFooter +} from "~/components/ui/card"; import { Input } from "~/components/ui/input"; import { Label } from "~/components/ui/label"; -import { PlusIcon, Trash2Icon } from "lucide-react"; import { Select, - SelectTrigger, - SelectValue, SelectContent, SelectItem, - SelectLabel, + SelectTrigger, + SelectValue } from "~/components/ui/select"; interface Study { @@ -51,7 +57,13 @@ export default function Participants() { const fetchParticipants = async (studyId: number) => { try { + console.log(`Fetching participants for studyId: ${studyId}`); const response = await fetch(`/api/participants?studyId=${studyId}`); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = await response.json(); setParticipants(data); } catch (error) { @@ -115,26 +127,42 @@ export default function Participants() { return (
-

Manage Participants

-
- - +
+

Participants

- + + + Study Selection + + Select a study to manage its participants + + + +
+ + +
+
+
+ + Add New Participant + + Add a new participant to the selected study +
@@ -156,18 +184,50 @@ export default function Participants() { -
-

Participant List

-
    - {participants.map((participant) => ( -
  • - {participant.name} - -
  • - ))} -
+
+ {participants.map((participant) => ( + + +
+
+ {participant.name} + + Participant ID: {participant.id} + +
+ +
+
+ + Study ID: {participant.studyId} + +
+ ))} + {participants.length === 0 && selectedStudyId && ( + + +

+ No participants found for this study. Add one above to get started. +

+
+
+ )} + {!selectedStudyId && ( + + +

+ Please select a study to view its participants. +

+
+
+ )}
);