391 lines
14 KiB
TypeScript
391 lines
14 KiB
TypeScript
'use client'
|
|
import React, { useEffect, useState } from 'react';
|
|
import Link from 'next/link';
|
|
import { ChevronRight } from 'lucide-react';
|
|
import { FacultyService, TeamMember } from '../../lib/facultyData';
|
|
|
|
interface TeamListingProps {
|
|
title?: string;
|
|
onMemberClick?: (member: TeamMember) => void;
|
|
}
|
|
|
|
const GUIDES_FRIENDS_PATRONS_CATEGORIES = ['GUIDES', 'FRIENDS', 'PATRONS'];
|
|
const NON_CLICKABLE_CATEGORIES = ['TRAINEE_FELLOW', 'SUPPORT_TEAM', 'GUIDES', 'FRIENDS', 'PATRONS'];
|
|
|
|
const TeamListing: React.FC<TeamListingProps> = ({
|
|
title = "Our Team",
|
|
onMemberClick
|
|
}) => {
|
|
const [teamMembers, setTeamMembers] = useState<TeamMember[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
const loadFacultyData = async () => {
|
|
try {
|
|
setLoading(true);
|
|
const faculty = await FacultyService.getAllFaculty();
|
|
setTeamMembers(faculty);
|
|
setError(null);
|
|
} catch (err) {
|
|
console.error('Failed to load faculty data:', err);
|
|
setError('Failed to load faculty data. Please try again later.');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
loadFacultyData();
|
|
}, []);
|
|
|
|
// Active faculty members only
|
|
const facultyMembers = teamMembers.filter(member =>
|
|
member.category === 'FACULTY' && member.status !== 'RETIRED'
|
|
);
|
|
|
|
// Active support team only
|
|
const supportTeam = teamMembers.filter(member =>
|
|
member.category === 'SUPPORT_TEAM' && member.status !== 'RETIRED'
|
|
);
|
|
|
|
// Active trainees and fellows only
|
|
const traineesAndFellows = teamMembers.filter(member =>
|
|
member.category === 'TRAINEE_FELLOW' && member.status !== 'RETIRED'
|
|
);
|
|
|
|
// Guides, Friends, Patrons — all three categories in one section
|
|
const guidesFriendsPatrons = teamMembers.filter(member =>
|
|
GUIDES_FRIENDS_PATRONS_CATEGORIES.includes(member.category) && member.status !== 'RETIRED'
|
|
);
|
|
|
|
// Alumni = RETIRED (any category) + RESIGNED (any status)
|
|
const alumniStaff = teamMembers.filter(member =>
|
|
member.status === 'RETIRED' || member.category === 'RESIGNED'
|
|
);
|
|
|
|
const handleMemberClick = (member: TeamMember) => {
|
|
if (onMemberClick) {
|
|
onMemberClick(member);
|
|
} else {
|
|
window.location.href = `/faculty/${member.professorId}`;
|
|
}
|
|
};
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center">
|
|
<div className="text-center">
|
|
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"></div>
|
|
<p>Loading faculty data...</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (error) {
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center">
|
|
<div className="text-center">
|
|
<p className="text-red-600 mb-4">{error}</p>
|
|
<button
|
|
onClick={() => window.location.reload()}
|
|
className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"
|
|
>
|
|
Retry
|
|
</button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const TeamMemberCard: React.FC<{ member: TeamMember }> = ({ member }) => {
|
|
const [imageError, setImageError] = useState(false);
|
|
const [imageLoading, setImageLoading] = useState(true);
|
|
|
|
const isNonClickable = NON_CLICKABLE_CATEGORIES.includes(member.category);
|
|
const isRetired = member.status === 'RETIRED';
|
|
const isResigned = member.category === 'RESIGNED';
|
|
|
|
// Check if image URL is valid and not a default placeholder
|
|
const hasValidImage =
|
|
member.image &&
|
|
member.image.trim() !== '' &&
|
|
!member.image.includes('default-avatar') &&
|
|
!member.image.includes('placeholder.') &&
|
|
!member.image.includes('robot') &&
|
|
!(
|
|
member.image.endsWith('/profile-image') ||
|
|
member.image.includes('/profile-image?') ||
|
|
member.image === 'https://via.placeholder.com/400'
|
|
);
|
|
|
|
// Don't show images for non-clickable categories
|
|
const shouldShowImage = !isNonClickable && hasValidImage;
|
|
|
|
const handleImageError = () => {
|
|
setImageError(true);
|
|
setImageLoading(false);
|
|
};
|
|
|
|
const handleImageLoad = () => {
|
|
setImageLoading(false);
|
|
};
|
|
|
|
return (
|
|
<div
|
|
className={`bg-white rounded-lg border border-gray-300 overflow-hidden transition-all duration-300 ${
|
|
!isNonClickable ? 'group cursor-pointer hover:shadow-lg' : 'cursor-default'
|
|
}`}
|
|
onClick={() => !isNonClickable && handleMemberClick(member)}
|
|
>
|
|
{/* Only show image section for clickable categories (Faculty + Alumni) */}
|
|
{!isNonClickable && (
|
|
<div className="relative aspect-square overflow-hidden bg-gray-50">
|
|
{shouldShowImage && !imageError ? (
|
|
<>
|
|
{imageLoading && (
|
|
<div className="absolute inset-0 flex items-center justify-center bg-gray-100">
|
|
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div>
|
|
</div>
|
|
)}
|
|
<img
|
|
src={member.image}
|
|
alt={member.name}
|
|
className={`w-full h-full object-cover transition-transform duration-300 group-hover:scale-105 ${
|
|
imageLoading ? 'opacity-0' : 'opacity-100'
|
|
}`}
|
|
onError={handleImageError}
|
|
onLoad={handleImageLoad}
|
|
loading="lazy"
|
|
/>
|
|
</>
|
|
) : (
|
|
<div
|
|
className="w-full h-full flex items-center justify-center"
|
|
style={{ backgroundColor: '#e0e5eb' }}
|
|
>
|
|
<svg className="w-32 h-32 text-gray-400" fill="currentColor" viewBox="0 0 24 24">
|
|
<path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z" />
|
|
</svg>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
<div className="p-4 sm:p-6">
|
|
{/* Status badge for alumni */}
|
|
{(isRetired || isResigned) && (
|
|
<div className="mb-2">
|
|
<span
|
|
className="inline-block px-2 py-0.5 text-xs font-medium rounded-full text-white"
|
|
style={{ backgroundColor: isResigned ? '#6b7280' : '#dc2626' }}
|
|
>
|
|
{isResigned ? 'Resigned' : 'Retired'}
|
|
</span>
|
|
</div>
|
|
)}
|
|
|
|
<h3
|
|
className="text-lg font-medium mb-2 group-hover:opacity-70 transition-opacity"
|
|
style={{ color: '#012068' }}
|
|
>
|
|
{member.name}
|
|
</h3>
|
|
<p className="text-sm leading-relaxed" style={{ color: '#e64838' }}>
|
|
{member.position}
|
|
</p>
|
|
|
|
{!isNonClickable && (
|
|
<>
|
|
{member.department && (
|
|
<p className="text-xs mt-1" style={{ color: '#666' }}>
|
|
{member.department}
|
|
</p>
|
|
)}
|
|
{member.specialty && (
|
|
<p className="text-xs mt-1 font-medium" style={{ color: '#333' }}>
|
|
{member.specialty}
|
|
</p>
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-screen">
|
|
{/* Breadcrumb Section */}
|
|
<section className="py-4" style={{ backgroundColor: '#f4f4f4' }}>
|
|
<div className="max-w-7xl mx-auto px-4">
|
|
<nav className="flex items-center space-x-2 text-sm">
|
|
<Link
|
|
href="/"
|
|
className="hover:opacity-70 transition-opacity duration-200"
|
|
style={{ color: '#012068' }}
|
|
>
|
|
Home
|
|
</Link>
|
|
<ChevronRight className="w-4 h-4" style={{ color: '#012068' }} />
|
|
<span className="font-medium" style={{ color: '#e64838' }}>
|
|
Faculty
|
|
</span>
|
|
</nav>
|
|
|
|
<div className="mt-6">
|
|
<div className="flex items-center mb-4">
|
|
<h1 className="text-3xl font-bold" style={{ color: '#012068' }}>
|
|
{title}
|
|
</h1>
|
|
</div>
|
|
<p className="text-base max-w-3xl leading-relaxed" style={{ color: '#333' }}>
|
|
Meet our dedicated team of medical professionals, researchers, and support staff
|
|
committed to advancing healthcare, education, and patient outcomes at Christian
|
|
Medical College, Vellore
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
{/* Faculty Section */}
|
|
{facultyMembers.length > 0 && (
|
|
<section className="py-8" style={{ backgroundColor: '#fff' }}>
|
|
<div className="max-w-7xl mx-auto px-4">
|
|
<div className="mb-6">
|
|
<h2 className="text-2xl font-bold mb-2" style={{ color: '#012068' }}>
|
|
Faculty Members
|
|
</h2>
|
|
<p className="text-sm" style={{ color: '#666' }}>
|
|
Our experienced faculty members leading medical education and research
|
|
</p>
|
|
</div>
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
|
{facultyMembers.map((member) => (
|
|
<TeamMemberCard key={member.id} member={member} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
{/* Faculty Alumni Section — RETIRED + RESIGNED */}
|
|
{alumniStaff.length > 0 && (
|
|
<section className="py-8" style={{ backgroundColor: '#f9f9f9' }}>
|
|
<div className="max-w-7xl mx-auto px-4">
|
|
<div className="mb-8">
|
|
<h2 className="text-2xl font-bold mb-4" style={{ color: '#012068' }}>
|
|
Faculty Alumni
|
|
</h2>
|
|
<p className="text-sm mb-2" style={{ color: '#666' }}>
|
|
Honoring our retired and former faculty members for their dedicated service
|
|
</p>
|
|
</div>
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
|
{alumniStaff.map((member) => (
|
|
<TeamMemberCard key={member.id} member={member} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
{/* Support Team Section */}
|
|
{supportTeam.length > 0 && (
|
|
<section className="py-8" style={{ backgroundColor: '#fff' }}>
|
|
<div className="max-w-7xl mx-auto px-4">
|
|
<div className="mb-8">
|
|
<h2 className="text-2xl font-bold mb-4" style={{ color: '#012068' }}>
|
|
Support Team
|
|
</h2>
|
|
<p className="text-base leading-relaxed mb-2" style={{ color: '#012068' }}>
|
|
<strong>Clinical Support Staff</strong> — Essential team members providing
|
|
specialised support services
|
|
</p>
|
|
<p className="text-sm mb-1" style={{ color: '#012068' }}>
|
|
<strong>Administrative & Technical Support</strong> — Dedicated professionals
|
|
ensuring smooth operations
|
|
</p>
|
|
</div>
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
|
{supportTeam.map((member) => (
|
|
<TeamMemberCard key={member.id} member={member} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
{/* Guides / Friends / Patrons Section */}
|
|
{guidesFriendsPatrons.length > 0 && (
|
|
<section className="py-8" style={{ backgroundColor: '#f9f9f9' }}>
|
|
<div className="max-w-7xl mx-auto px-4">
|
|
<div className="mb-8">
|
|
<h2 className="text-2xl font-bold mb-4" style={{ color: '#012068' }}>
|
|
Guides / Friends / Patrons
|
|
</h2>
|
|
<p className="text-base leading-relaxed mb-2" style={{ color: '#012068' }}>
|
|
<strong>Guides</strong> — Mentors and senior professionals who have shaped our
|
|
department
|
|
</p>
|
|
<p className="text-sm mb-1" style={{ color: '#012068' }}>
|
|
<strong>Friends & Patrons</strong> — Valued supporters and well-wishers of our
|
|
institution
|
|
</p>
|
|
</div>
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
|
{guidesFriendsPatrons.map((member) => (
|
|
<TeamMemberCard key={member.id} member={member} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
{/* Trainees & Fellows Section */}
|
|
{traineesAndFellows.length > 0 && (
|
|
<section className="py-8" style={{ backgroundColor: '#fff' }}>
|
|
<div className="max-w-7xl mx-auto px-4">
|
|
<div className="mb-8">
|
|
<h2 className="text-2xl font-bold mb-4" style={{ color: '#012068' }}>
|
|
Trainees & Fellows
|
|
</h2>
|
|
<p className="text-sm mb-2" style={{ color: '#666' }}>
|
|
Medical trainees, residents, and fellows advancing their skills and contributing
|
|
to patient care
|
|
</p>
|
|
</div>
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
|
{traineesAndFellows.map((member) => (
|
|
<TeamMemberCard key={member.id} member={member} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
{/* No data message */}
|
|
{teamMembers.length === 0 && !loading && (
|
|
<section className="py-16 text-center">
|
|
<div className="max-w-2xl mx-auto px-4">
|
|
<h2 className="text-2xl font-bold mb-4" style={{ color: '#012068' }}>
|
|
No Faculty Data Available
|
|
</h2>
|
|
<p className="text-gray-600 mb-6">
|
|
Faculty information is currently being updated. Please check back later or contact
|
|
administration.
|
|
</p>
|
|
<button
|
|
onClick={() => window.location.reload()}
|
|
className="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
|
|
>
|
|
Refresh Page
|
|
</button>
|
|
</div>
|
|
</section>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default TeamListing; |