{"ast":null,"code":"var _jsxFileName = \"C:\\\\Users\\\\User\\\\Downloads\\\\medora5\\\\frontend\\\\src\\\\pages\\\\appointments\\\\AppointmentList.js\",\n _s = $RefreshSig$();\nimport React, { useState, useEffect } from 'react';\nimport { Link, useSearchParams } from 'react-router-dom';\nimport { appointmentService } from '../../services/appointmentService';\nimport Loading from '../../components/Loading';\nimport ErrorAlert from '../../components/ErrorAlert';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\nfunction AppointmentList() {\n _s();\n const [appointments, setAppointments] = useState([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n const [searchParams] = useSearchParams();\n const doctorId = searchParams.get('doctorId');\n const patientId = searchParams.get('patientId');\n const user = JSON.parse(localStorage.getItem('user') || '{}');\n useEffect(() => {\n const fetchAppointmentsData = async () => {\n try {\n setLoading(true);\n let response;\n if (patientId) {\n response = await appointmentService.getAppointmentsForPatient(patientId);\n } else if (doctorId) {\n response = await appointmentService.getAppointmentsForDoctor(doctorId);\n } else {\n response = await appointmentService.getAllAppointments();\n }\n setAppointments(response.data || []);\n } catch (err) {\n setError('Failed to fetch appointments');\n console.error(err);\n } finally {\n setLoading(false);\n }\n };\n fetchAppointmentsData();\n }, [doctorId, patientId]);\n const handleCancelAppointment = async id => {\n if (window.confirm('Are you sure you want to cancel this appointment?')) {\n try {\n await appointmentService.cancelAppointment(id);\n setAppointments(appointments.map(apt => apt.appointmentId === id ? {\n ...apt,\n status: 'CANCELLED'\n } : apt));\n } catch (err) {\n setError('Failed to cancel appointment');\n }\n }\n };\n if (loading) return /*#__PURE__*/_jsxDEV(Loading, {}, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 53,\n columnNumber: 23\n }, this);\n return /*#__PURE__*/_jsxDEV(\"div\", {\n children: [/*#__PURE__*/_jsxDEV(\"div\", {\n className: \"flex justify-between items-center mb-6\",\n children: [/*#__PURE__*/_jsxDEV(\"h1\", {\n className: \"text-3xl font-bold\",\n style: {\n color: '#7c3aed'\n },\n children: patientId ? 'Patient Appointments' : doctorId ? 'My Appointments' : 'All Appointments'\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 58,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(Link, {\n to: \"/appointments/new\",\n style: {\n display: 'inline-block',\n background: '#bfdbfe',\n color: '#1e1035',\n padding: '8px 16px',\n borderRadius: '6px',\n textDecoration: 'none',\n fontSize: '14px',\n fontWeight: '400'\n },\n onMouseEnter: e => e.currentTarget.style.background = '#93c5fd',\n onMouseLeave: e => e.currentTarget.style.background = '#bfdbfe',\n children: \"New Appointment\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 61,\n columnNumber: 9\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 57,\n columnNumber: 7\n }, this), error && /*#__PURE__*/_jsxDEV(ErrorAlert, {\n message: error,\n onClose: () => setError(null)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 75,\n columnNumber: 17\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"bg-white rounded-lg shadow overflow-hidden\",\n children: /*#__PURE__*/_jsxDEV(\"table\", {\n className: \"w-full\",\n children: [/*#__PURE__*/_jsxDEV(\"thead\", {\n className: \"bg-gray-100\",\n children: /*#__PURE__*/_jsxDEV(\"tr\", {\n children: [/*#__PURE__*/_jsxDEV(\"th\", {\n className: \"px-6 py-3 text-left text-sm font-semibold\",\n children: \"Patient\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 81,\n columnNumber: 15\n }, this), /*#__PURE__*/_jsxDEV(\"th\", {\n className: \"px-6 py-3 text-left text-sm font-semibold\",\n children: \"Doctor\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 82,\n columnNumber: 15\n }, this), /*#__PURE__*/_jsxDEV(\"th\", {\n className: \"px-6 py-3 text-left text-sm font-semibold\",\n children: \"Date\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 83,\n columnNumber: 15\n }, this), /*#__PURE__*/_jsxDEV(\"th\", {\n className: \"px-6 py-3 text-left text-sm font-semibold\",\n children: \"Time\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 84,\n columnNumber: 15\n }, this), /*#__PURE__*/_jsxDEV(\"th\", {\n className: \"px-6 py-3 text-left text-sm font-semibold\",\n children: \"Status\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 85,\n columnNumber: 15\n }, this), /*#__PURE__*/_jsxDEV(\"th\", {\n className: \"px-6 py-3 text-left text-sm font-semibold\",\n children: \"Actions\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 86,\n columnNumber: 15\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 80,\n columnNumber: 13\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 79,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"tbody\", {\n children: appointments.map(appointment => {\n var _appointment$patient, _appointment$patient2, _appointment$doctor, _appointment$doctor2, _appointment$doctor3;\n return /*#__PURE__*/_jsxDEV(\"tr\", {\n className: \"border-t hover:bg-gray-50\",\n children: [/*#__PURE__*/_jsxDEV(\"td\", {\n className: \"px-6 py-3\",\n children: [(_appointment$patient = appointment.patient) === null || _appointment$patient === void 0 ? void 0 : _appointment$patient.firstName, \" \", (_appointment$patient2 = appointment.patient) === null || _appointment$patient2 === void 0 ? void 0 : _appointment$patient2.lastName]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 92,\n columnNumber: 17\n }, this), /*#__PURE__*/_jsxDEV(\"td\", {\n className: \"px-6 py-3\",\n children: [\"Dr. \", (_appointment$doctor = appointment.doctor) === null || _appointment$doctor === void 0 ? void 0 : _appointment$doctor.firstName, \" \", (_appointment$doctor2 = appointment.doctor) === null || _appointment$doctor2 === void 0 ? void 0 : _appointment$doctor2.lastName]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 93,\n columnNumber: 17\n }, this), /*#__PURE__*/_jsxDEV(\"td\", {\n className: \"px-6 py-3\",\n children: appointment.appointmentDate\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 94,\n columnNumber: 17\n }, this), /*#__PURE__*/_jsxDEV(\"td\", {\n className: \"px-6 py-3\",\n children: appointment.appointmentTime\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 95,\n columnNumber: 17\n }, this), /*#__PURE__*/_jsxDEV(\"td\", {\n className: \"px-6 py-3\",\n children: /*#__PURE__*/_jsxDEV(\"span\", {\n className: `px-3 py-1 rounded text-sm font-semibold ${appointment.status === 'SCHEDULED' ? 'bg-purple-100 text-purple-800' : appointment.status === 'COMPLETED' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}`,\n children: appointment.status\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 97,\n columnNumber: 19\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 96,\n columnNumber: 17\n }, this), /*#__PURE__*/_jsxDEV(\"td\", {\n className: \"px-6 py-3\",\n children: appointment.status === 'SCHEDULED' && (user.role === 'DOCTOR' && ((_appointment$doctor3 = appointment.doctor) === null || _appointment$doctor3 === void 0 ? void 0 : _appointment$doctor3.doctorId) !== user.doctorId ? null : /*#__PURE__*/_jsxDEV(\"button\", {\n onClick: () => handleCancelAppointment(appointment.appointmentId),\n className: \"text-red-600 hover:underline px-3 py-2 text-sm font-medium\",\n children: \"Cancel\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 108,\n columnNumber: 23\n }, this))\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 105,\n columnNumber: 17\n }, this)]\n }, appointment.appointmentId, true, {\n fileName: _jsxFileName,\n lineNumber: 91,\n columnNumber: 15\n }, this);\n })\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 89,\n columnNumber: 11\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 78,\n columnNumber: 9\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 77,\n columnNumber: 7\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 56,\n columnNumber: 5\n }, this);\n}\n_s(AppointmentList, \"kaA7w7TG1lAuDMeI9v16u8BtWuM=\", false, function () {\n return [useSearchParams];\n});\n_c = AppointmentList;\nexport default AppointmentList;\nvar _c;\n$RefreshReg$(_c, \"AppointmentList\");","map":{"version":3,"names":["React","useState","useEffect","Link","useSearchParams","appointmentService","Loading","ErrorAlert","jsxDEV","_jsxDEV","AppointmentList","_s","appointments","setAppointments","loading","setLoading","error","setError","searchParams","doctorId","get","patientId","user","JSON","parse","localStorage","getItem","fetchAppointmentsData","response","getAppointmentsForPatient","getAppointmentsForDoctor","getAllAppointments","data","err","console","handleCancelAppointment","id","window","confirm","cancelAppointment","map","apt","appointmentId","status","fileName","_jsxFileName","lineNumber","columnNumber","children","className","style","color","to","display","background","padding","borderRadius","textDecoration","fontSize","fontWeight","onMouseEnter","e","currentTarget","onMouseLeave","message","onClose","appointment","_appointment$patient","_appointment$patient2","_appointment$doctor","_appointment$doctor2","_appointment$doctor3","patient","firstName","lastName","doctor","appointmentDate","appointmentTime","role","onClick","_c","$RefreshReg$"],"sources":["C:/Users/User/Downloads/medora5/frontend/src/pages/appointments/AppointmentList.js"],"sourcesContent":["import React, { useState, useEffect } from 'react';\nimport { Link, useSearchParams } from 'react-router-dom';\nimport { appointmentService } from '../../services/appointmentService';\nimport Loading from '../../components/Loading';\nimport ErrorAlert from '../../components/ErrorAlert';\n\nfunction AppointmentList() {\n const [appointments, setAppointments] = useState([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n const [searchParams] = useSearchParams();\n const doctorId = searchParams.get('doctorId');\n const patientId = searchParams.get('patientId');\n const user = JSON.parse(localStorage.getItem('user') || '{}');\n\n useEffect(() => {\n const fetchAppointmentsData = async () => {\n try {\n setLoading(true);\n let response;\n if (patientId) {\n response = await appointmentService.getAppointmentsForPatient(patientId);\n } else if (doctorId) {\n response = await appointmentService.getAppointmentsForDoctor(doctorId);\n } else {\n response = await appointmentService.getAllAppointments();\n }\n setAppointments(response.data || []);\n } catch (err) {\n setError('Failed to fetch appointments');\n console.error(err);\n } finally {\n setLoading(false);\n }\n };\n\n fetchAppointmentsData();\n }, [doctorId, patientId]);\n\n const handleCancelAppointment = async (id) => {\n if (window.confirm('Are you sure you want to cancel this appointment?')) {\n try {\n await appointmentService.cancelAppointment(id);\n setAppointments(appointments.map(apt =>\n apt.appointmentId === id ? { ...apt, status: 'CANCELLED' } : apt\n ));\n } catch (err) {\n setError('Failed to cancel appointment');\n }\n }\n };\n\n if (loading) return
| Patient | \nDoctor | \nDate | \nTime | \nStatus | \nActions | \n
|---|---|---|---|---|---|
| {appointment.patient?.firstName} {appointment.patient?.lastName} | \nDr. {appointment.doctor?.firstName} {appointment.doctor?.lastName} | \n{appointment.appointmentDate} | \n{appointment.appointmentTime} | \n\n \n {appointment.status}\n \n | \n\n {appointment.status === 'SCHEDULED' && (\n (user.role === 'DOCTOR' && appointment.doctor?.doctorId !== user.doctorId) ? null : (\n \n )\n )}\n | \n