-
Notifications
You must be signed in to change notification settings - Fork 2
modularize:patientappointments page into managable componenets #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
161 changes: 161 additions & 0 deletions
161
client/src/components/Patient/PatientAppointments/AppointmentCard.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| import { format } from 'date-fns'; | ||
| import { | ||
| Calendar, | ||
| CheckCircle, | ||
| Clock, | ||
| Clock3, | ||
| Eye, | ||
| FileText, | ||
| MapPin, | ||
| User, | ||
| Video, | ||
| XCircle, | ||
| AlertCircle, | ||
| } from 'lucide-react'; | ||
|
|
||
| const AppointmentCard = ({ appointment, prescriptionStatus, onAppointmentClick }) => { | ||
| const formatDateTime = (date, time) => { | ||
| try { | ||
| const appointmentDate = new Date(date); | ||
| const formattedDate = format(appointmentDate, 'MMM dd, yyyy'); | ||
| const formattedTime = format(new Date(`2000-01-01T${time}`), 'hh:mm a'); | ||
| return { date: formattedDate, time: formattedTime }; | ||
| } catch (error) { | ||
| console.log(error); | ||
| return { date: 'Invalid date', time: 'Invalid time' }; | ||
| } | ||
| }; | ||
|
|
||
| const getStatusBadge = (status) => { | ||
| const statusConfig = { | ||
| pending: { | ||
| color: 'bg-yellow-100 text-yellow-800 border-yellow-200', | ||
| icon: <Clock3 className="w-3 h-3" />, | ||
| text: 'Pending', | ||
| }, | ||
| confirmed: { | ||
| color: 'bg-blue-100 text-blue-800 border-blue-200', | ||
| icon: <CheckCircle className="w-3 h-3" />, | ||
| text: 'Confirmed', | ||
| }, | ||
| completed: { | ||
| color: 'bg-green-100 text-green-800 border-green-200', | ||
| icon: <CheckCircle className="w-3 h-3" />, | ||
| text: 'Completed', | ||
| }, | ||
| cancelled: { | ||
| color: 'bg-red-100 text-red-800 border-red-200', | ||
| icon: <XCircle className="w-3 h-3" />, | ||
| text: 'Cancelled', | ||
| }, | ||
| 'no-show': { | ||
| color: 'bg-gray-100 text-gray-800 border-gray-200', | ||
| icon: <AlertCircle className="w-3 h-3" />, | ||
| text: 'No Show', | ||
| }, | ||
| }; | ||
|
|
||
| const config = statusConfig[status] || statusConfig.pending; | ||
|
|
||
| return ( | ||
| <span | ||
| className={`inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium border ${config.color}`} | ||
| > | ||
| {config.icon} | ||
| {config.text} | ||
| </span> | ||
| ); | ||
| }; | ||
|
|
||
| const { date: formattedDate, time: formattedTime } = formatDateTime( | ||
| appointment.date, | ||
| appointment.startTime | ||
| ); | ||
| const hasPrescription = prescriptionStatus[appointment._id]; | ||
|
|
||
| return ( | ||
| <div | ||
| onClick={() => onAppointmentClick(appointment._id)} | ||
| className="bg-white rounded-xl shadow-sm border border-gray-100 p-6 hover:shadow-md hover:border-blue-200 transition-all duration-200 cursor-pointer group" | ||
| > | ||
| {/* Header */} | ||
| <div className="flex items-start justify-between mb-4"> | ||
| <div className="flex items-center gap-3"> | ||
| <div className="w-12 h-12 bg-gradient-to-br from-blue-500 to-indigo-600 rounded-full flex items-center justify-center text-white font-semibold"> | ||
| {appointment.doctorId?.firstName?.[0]} | ||
| {appointment.doctorId?.lastName?.[0]} | ||
| </div> | ||
| <div> | ||
| <h3 className="font-semibold text-gray-900 group-hover:text-blue-600 transition-colors"> | ||
| Dr. {appointment.doctorId?.firstName} {appointment.doctorId?.lastName} | ||
| </h3> | ||
| <p className="text-sm text-gray-600">{appointment.doctorId?.specialization}</p> | ||
| </div> | ||
| </div> | ||
| {getStatusBadge(appointment.status)} | ||
| </div> | ||
|
|
||
| {/* Appointment Details */} | ||
| <div className="space-y-3"> | ||
| {/* Date and Time */} | ||
| <div className="flex items-center gap-4"> | ||
| <div className="flex items-center gap-2 text-gray-700"> | ||
| <Calendar className="w-4 h-4" /> | ||
| <span className="text-sm">{formattedDate}</span> | ||
| </div> | ||
| <div className="flex items-center gap-2 text-gray-700"> | ||
| <Clock className="w-4 h-4" /> | ||
| <span className="text-sm">{formattedTime}</span> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Clinic */} | ||
| <div className="flex items-center gap-2 text-gray-700"> | ||
| <MapPin className="w-4 h-4 flex-shrink-0" /> | ||
| <span className="text-sm truncate">{appointment.clinicId?.name}</span> | ||
| </div> | ||
|
|
||
| {/* Consultation Type */} | ||
| <div className="flex items-center gap-2"> | ||
| {appointment.isTeleconsultation ? ( | ||
| <> | ||
| <Video className="w-4 h-4 text-green-600" /> | ||
| <span className="text-sm text-green-600 font-medium">Video Consultation</span> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <User className="w-4 h-4 text-blue-600" /> | ||
| <span className="text-sm text-blue-600 font-medium">In-Person Visit</span> | ||
| </> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Reason */} | ||
| {appointment.reason && ( | ||
| <div className="bg-gray-50 rounded-lg p-3"> | ||
| <p className="text-sm text-gray-700"> | ||
| <span className="font-medium">Reason: </span> | ||
| {appointment.reason} | ||
| </p> | ||
| </div> | ||
| )} | ||
|
|
||
| {/* Prescription Status */} | ||
| <div className="flex items-center justify-between pt-3 border-t border-gray-100"> | ||
| <div className="flex items-center gap-2"> | ||
| <FileText className="w-4 h-4" /> | ||
| <span className="text-sm text-gray-600">Prescription:</span> | ||
| {hasPrescription ? ( | ||
| <span className="text-sm text-green-600 font-medium">Available</span> | ||
| ) : ( | ||
| <span className="text-sm text-gray-400">Not available</span> | ||
| )} | ||
| </div> | ||
| <Eye className="w-4 h-4 text-gray-400 group-hover:text-blue-600 transition-colors" /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default AppointmentCard; |
45 changes: 45 additions & 0 deletions
45
client/src/components/Patient/PatientAppointments/AppointmentHeader.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { Search, Filter } from 'lucide-react'; | ||
|
|
||
| const AppointmentHeader = ({ searchTerm, setSearchTerm, filterStatus, setFilterStatus }) => { | ||
| return ( | ||
| <div className="bg-white rounded-xl shadow-sm border border-gray-100 p-6 mb-8"> | ||
| <div className="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4"> | ||
| <div> | ||
| <h1 className="text-2xl font-bold text-gray-900 mb-2">My Appointments</h1> | ||
| <p className="text-gray-600">Manage and view your medical appointments</p> | ||
| </div> | ||
|
|
||
| {/* Search and Filter */} | ||
| <div className="flex flex-col sm:flex-row gap-3 lg:w-96"> | ||
| <div className="relative flex-1"> | ||
| <Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4" /> | ||
| <input | ||
| type="text" | ||
| placeholder="Search by doctor, clinic, or reason..." | ||
| value={searchTerm} | ||
| onChange={(e) => setSearchTerm(e.target.value)} | ||
| className="w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="relative"> | ||
| <Filter className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4" /> | ||
| <select | ||
| value={filterStatus} | ||
| onChange={(e) => setFilterStatus(e.target.value)} | ||
| className="pl-10 pr-8 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent appearance-none bg-white" | ||
| > | ||
| <option value="all">All Status</option> | ||
| <option value="pending">Pending</option> | ||
| <option value="confirmed">Confirmed</option> | ||
| <option value="completed">Completed</option> | ||
| <option value="cancelled">Cancelled</option> | ||
| </select> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default AppointmentHeader; |
56 changes: 56 additions & 0 deletions
56
client/src/components/Patient/PatientAppointments/AppointmentStats.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { Calendar, Clock, CheckCircle, FileText } from 'lucide-react'; | ||
|
|
||
| const AppointmentStats = ({ appointments, prescriptionStatus }) => { | ||
| const completedCount = appointments.filter((apt) => apt.status === 'completed').length; | ||
| const prescriptionCount = Object.values(prescriptionStatus).filter(Boolean).length; | ||
|
|
||
| const stats = [ | ||
| { | ||
| label: 'Total', | ||
| value: appointments.length, | ||
| icon: Calendar, | ||
| color: 'text-gray-900', | ||
| iconColor: 'text-gray-400', | ||
| }, | ||
| { | ||
| label: 'Upcoming', | ||
| value: appointments.filter((apt) => apt.status === 'confirmed' || apt.status === 'pending') | ||
| .length, | ||
| icon: Clock, | ||
| color: 'text-blue-600', | ||
| iconColor: 'text-blue-400', | ||
| }, | ||
| { | ||
| label: 'Completed', | ||
| value: completedCount, | ||
| icon: CheckCircle, | ||
| color: 'text-green-600', | ||
| iconColor: 'text-green-400', | ||
| }, | ||
| { | ||
| label: 'With Prescription', | ||
| value: prescriptionCount, | ||
| icon: FileText, | ||
| color: 'text-purple-600', | ||
| iconColor: 'text-purple-400', | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <div className="grid grid-cols-2 md:grid-cols-4 gap-4"> | ||
| {stats.map((stat, index) => ( | ||
| <div key={index} className="bg-white rounded-xl shadow-sm border border-gray-100 p-4"> | ||
| <div className="flex items-center justify-between"> | ||
| <div> | ||
| <p className="text-sm text-gray-600">{stat.label}</p> | ||
| <p className={`text-2xl font-bold ${stat.color}`}>{stat.value}</p> | ||
| </div> | ||
| <stat.icon className={`w-8 h-8 ${stat.iconColor}`} /> | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default AppointmentStats; |
126 changes: 126 additions & 0 deletions
126
client/src/components/Patient/PatientAppointments/AppointmentTabs.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { useMemo } from 'react'; | ||
| import { differenceInHours, isFuture, isPast, isToday } from 'date-fns'; | ||
| import { Calendar } from 'lucide-react'; | ||
| import AppointmentCard from './AppointmentCard'; | ||
|
|
||
| const AppointmentTabs = ({ | ||
| appointments, | ||
| prescriptionStatus, | ||
| activeTab, | ||
| setActiveTab, | ||
| onAppointmentClick, | ||
| }) => { | ||
| // Categorize appointments | ||
| const categorizedAppointments = useMemo(() => { | ||
| const today = new Date(); | ||
|
|
||
| return { | ||
| upcoming: appointments | ||
| .filter((apt) => { | ||
| const aptDate = new Date(apt.date); | ||
| return ( | ||
| isFuture(aptDate) || | ||
| (isToday(aptDate) && | ||
| differenceInHours(new Date(`${apt.date}T${apt.startTime}`), today) > 0) | ||
| ); | ||
| }) | ||
| .sort((a, b) => new Date(a.date) - new Date(b.date)), | ||
|
|
||
| today: appointments | ||
| .filter((apt) => { | ||
| const aptDate = new Date(apt.date); | ||
| return isToday(aptDate); | ||
| }) | ||
| .sort((a, b) => a.startTime.localeCompare(b.startTime)), | ||
|
|
||
| past: appointments | ||
| .filter((apt) => { | ||
| const aptDate = new Date(apt.date); | ||
| return isPast(aptDate) && !isToday(aptDate); | ||
| }) | ||
| .sort((a, b) => new Date(b.date) - new Date(a.date)), | ||
| }; | ||
| }, [appointments]); | ||
|
|
||
| // Tab Navigation | ||
| const tabs = [ | ||
| { | ||
| key: 'upcoming', | ||
| label: 'Upcoming', | ||
| count: categorizedAppointments.upcoming?.length || 0, | ||
| }, | ||
| { | ||
| key: 'today', | ||
| label: 'Today', | ||
| count: categorizedAppointments.today?.length || 0, | ||
| }, | ||
| { | ||
| key: 'past', | ||
| label: 'Past', | ||
| count: categorizedAppointments.past?.length || 0, | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <div className="bg-white rounded-xl shadow-sm border border-gray-100 mb-6"> | ||
| <div className="border-b border-gray-200"> | ||
| <nav className="flex space-x-8 px-6" aria-label="Tabs"> | ||
| {tabs.map((tab) => ( | ||
| <button | ||
| key={tab.key} | ||
| onClick={() => setActiveTab(tab.key)} | ||
| className={`whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm transition-colors ${ | ||
| activeTab === tab.key | ||
| ? 'border-blue-500 text-blue-600' | ||
| : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300' | ||
| }`} | ||
| > | ||
| {tab.label} | ||
| {tab.count > 0 && ( | ||
| <span | ||
| className={`ml-2 py-0.5 px-2 rounded-full text-xs ${ | ||
| activeTab === tab.key | ||
| ? 'bg-blue-100 text-blue-600' | ||
| : 'bg-gray-100 text-gray-900' | ||
| }`} | ||
| > | ||
| {tab.count} | ||
| </span> | ||
| )} | ||
| </button> | ||
| ))} | ||
| </nav> | ||
| </div> | ||
|
|
||
| {/* Appointments Content */} | ||
| <div className="p-6"> | ||
| {categorizedAppointments[activeTab]?.length > 0 ? ( | ||
| <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3"> | ||
| {categorizedAppointments[activeTab].map((appointment) => ( | ||
| <AppointmentCard | ||
| key={appointment._id} | ||
| appointment={appointment} | ||
| prescriptionStatus={prescriptionStatus} | ||
| onAppointmentClick={onAppointmentClick} | ||
| /> | ||
| ))} | ||
| </div> | ||
| ) : ( | ||
| <div className="text-center py-12"> | ||
| <Calendar className="w-12 h-12 text-gray-400 mx-auto mb-4" /> | ||
| <h3 className="text-lg font-medium text-gray-900 mb-2">No {activeTab} appointments</h3> | ||
| <p className="text-gray-600"> | ||
| {activeTab === 'upcoming' | ||
| ? 'You have no upcoming appointments.' | ||
| : activeTab === 'today' | ||
| ? 'No appointments scheduled for today.' | ||
| : 'No past appointments found.'} | ||
| </p> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default AppointmentTabs; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix upcoming filter to include sub-hour appointments.
Line 24 calls
differenceInHours(...) > 0, but date-fns truncates the result to whole hours. When an appointment starts within the next 59 minutes, Line 24 evaluates to0 > 0, so the entry never appears in the Upcoming tab—even though it is still in the future. Users therefore lose sight of imminent appointments until they are an hour away (or less). Switch to a direct date comparison (or a minute-level diff) so any future start time, even within the hour, is included.📝 Committable suggestion