"use client"; import { Briefcase, Clock, GraduationCap, Info, Shield } from "lucide-react"; import { Avatar, AvatarFallback } from "~/components/ui/avatar"; interface ParticipantInfoProps { participant: { id: string; participantCode: string; demographics: Record | null; }; trialStatus: "scheduled" | "in_progress" | "completed" | "aborted" | "failed"; } export function ParticipantInfo({ participant, trialStatus: _trialStatus, }: ParticipantInfoProps) { const demographics = participant.demographics ?? {}; // Extract common demographic fields const age = demographics.age as string | number | undefined; const gender = demographics.gender as string | undefined; const occupation = demographics.occupation as string | undefined; const education = demographics.education as string | undefined; const language = (demographics.primaryLanguage as string | undefined) ?? (demographics.language as string | undefined); const experience = (demographics.robotExperience as string | undefined) ?? (demographics.experience as string | undefined); // Get participant initials for avatar const getInitials = () => { return participant.participantCode.substring(0, 2).toUpperCase(); }; const formatDemographicValue = (key: string, value: unknown) => { if (value === null || value === undefined || value === "") return null; // Handle different data types if (typeof value === "boolean") { return value ? "Yes" : "No"; } if (Array.isArray(value)) { return value.join(", "); } if (typeof value === "object") { return JSON.stringify(value); } return typeof value === "string" ? value : JSON.stringify(value); }; return (
{/* Basic Info */}
{getInitials()}
Participant {participant.participantCode}
ID: {participant.participantCode}
{/* Quick Demographics */} {(age ?? gender ?? language) && (
{age && (
Age: {age}
)} {gender && (
Gender: {gender}
)} {language && (
Language: {language}
)}
)} {/* Background Info */} {(occupation ?? education ?? experience) && (
Background
{occupation && (
Occupation
{occupation}
)} {education && (
Education
{education}
)} {experience && (
Robot Experience
{experience}
)}
)} {/* Additional Demographics */} {Object.keys(demographics).length > 0 && (
Additional Info
{Object.entries(demographics) .filter( ([key, value]) => ![ "age", "gender", "occupation", "education", "language", "primaryLanguage", "robotExperience", "experience", "location", "city", ].includes(key) && value !== null && value !== undefined && value !== "", ) .slice(0, 5) // Limit to 5 additional fields .map(([key, value]) => { const formattedValue = formatDemographicValue(key, value); if (!formattedValue) return null; return (
{key .replace(/([A-Z])/g, " $1") .replace(/^./, (str) => str.toUpperCase())} : {formattedValue}
); })}
)} {/* Consent Status */}
Consent Verified
Participant has provided informed consent
{/* Session Info */}
Session active
); }