import React from 'react'; import { Badge } from '@/components/ui/badge'; import { ClipboardList } from 'lucide-react'; interface QuestionnaireResponseViewProps { application: any; } const QuestionnaireResponseView: React.FC = ({ application }) => { // If no responses or empty array if (!application.questionnaireResponses || application.questionnaireResponses.length === 0) { return (

Response is Pending

The applicant has not submitted the questionnaire yet.

); } // Sort responses by question order if possible, or just index // Assuming backend returns them in some order, better to sort by question.order if available const responses = [...application.questionnaireResponses].sort((a, b) => { return (a.question?.order || 0) - (b.question?.order || 0); }); const totalScore = application.score || application.questionnaireMarks || 0; // Fallback mapping return (

Questionnaire Responses

{totalScore !== undefined && ( Score: {totalScore}/100 )}
{responses.map((resp: any, index: number) => { const question = resp.question; const questionText = question?.questionText || 'Unknown Question'; const answer = resp.responseValue || 'No Answer'; const section = question?.sectionName || 'General'; const options = question?.questionOptions || []; // Match answer to find score // Note: This relies on exact string match. const matchedOption = options.find((opt: any) => opt.optionText === answer); const score = matchedOption ? matchedOption.score : 0; const maxScore = Math.max(...options.map((o: any) => o.score || 0), 0); const isFile = typeof answer === 'string' && answer.startsWith('data:'); const isImage = isFile && answer.startsWith('data:image'); return (
{index + 1}
{section} {(options.length > 0 && maxScore > 0) && ( 0 ? "bg-green-600" : "bg-slate-400"} data-testid={`onboarding-questionnaire-item-score-${index}`} > {score}/{maxScore} )}

{questionText}

{isImage ? (
Response Attachment
) : isFile ? ( Download Attachment ) : (
{resp.attachmentUrl ? ( View Attachment ) : ( answer )}
)}
); })}
); }; export default QuestionnaireResponseView;