/** * Request Card Component * Displays a single request card in the My Requests list */ import { Card, CardContent } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { ArrowRight, User, TrendingUp, Clock, FileText } from 'lucide-react'; import { motion } from 'framer-motion'; import { MyRequest } from '../types/myRequests.types'; import { getPriorityConfig, getStatusConfig } from '../utils/configMappers'; import { formatDateDDMMYYYY } from '@/utils/dateFormatter'; /** * Strip HTML tags and convert to plain text for card preview */ const stripHtmlTags = (html: string): string => { if (!html) return ''; // Check if we're in a browser environment if (typeof document === 'undefined') { // Fallback for SSR: use regex to strip HTML tags return html.replace(/<[^>]*>/g, '').replace(/\s+/g, ' ').trim(); } // Create a temporary div to parse HTML const tempDiv = document.createElement('div'); tempDiv.innerHTML = html; // Get text content (automatically strips HTML tags) let text = tempDiv.textContent || tempDiv.innerText || ''; // Clean up extra whitespace text = text.replace(/\s+/g, ' ').trim(); return text; }; interface RequestCardProps { request: MyRequest; index: number; onViewRequest: (requestId: string, requestTitle?: string, status?: string) => void; } export function RequestCard({ request, index, onViewRequest }: RequestCardProps) { const statusConfig = getStatusConfig(request.status); const priorityConfig = getPriorityConfig(request.priority); const StatusIcon = statusConfig.icon; const PriorityIcon = priorityConfig.icon; return ( onViewRequest(request.id, request.title, request.status)} data-testid={`request-card-${request.id}`} >
{/* Header with Title and Status Badges */}

{request.title}

{request.status} {request.priority} {request.templateType && ( Template: {request.templateName} )}

{stripHtmlTags(request.description || '') || 'No description provided'}

ID: {request.displayId || request.id} Submitted:{' '} {formatDateDDMMYYYY(request.submittedDate)}
{/* Current Approver and Level Info */}
Current Approver:{' '} {request.currentApprover}
Approval Level:{' '} {request.approverLevel}
Submitted: {formatDateDDMMYYYY(request.submittedDate)}
); }