{"ast":null,"code":"var _jsxFileName = \"C:\\\\Users\\\\User\\\\Downloads\\\\medora5\\\\frontend\\\\src\\\\pages\\\\appointments\\\\AppointmentForm.js\",\n _s = $RefreshSig$();\nimport React, { useState, useEffect } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { appointmentService } from '../../services/appointmentService';\nimport { patientService } from '../../services/patientService';\nimport { doctorService } from '../../services/doctorService';\nimport ErrorAlert from '../../components/ErrorAlert';\nimport SuccessAlert from '../../components/SuccessAlert';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\nfunction AppointmentForm() {\n _s();\n const navigate = useNavigate();\n const user = JSON.parse(localStorage.getItem('user') || '{}');\n const isPatient = user.role === 'PATIENT';\n const isDoctor = user.role === 'DOCTOR';\n const [formData, setFormData] = useState({\n patientId: isPatient ? user.patientId || '' : '',\n doctorId: isDoctor ? user.doctorId || '' : '',\n appointmentDate: '',\n appointmentTime: ''\n });\n const [patients, setPatients] = useState([]);\n const [doctors, setDoctors] = useState([]);\n const [error, setError] = useState(null);\n const [success, setSuccess] = useState(null);\n const [loading, setLoading] = useState(false);\n useEffect(() => {\n const fetchData = async () => {\n try {\n if (!isPatient) {\n const patientsRes = await patientService.getAllPatients();\n setPatients(patientsRes.data);\n }\n const doctorsRes = await doctorService.getAllDoctors();\n setDoctors(doctorsRes.data);\n } catch (err) {\n setError('Failed to fetch doctors');\n }\n };\n fetchData();\n }, [isPatient]);\n const handleChange = e => {\n const {\n name,\n value\n } = e.target;\n setFormData(prev => ({\n ...prev,\n [name]: value\n }));\n };\n const handleSubmit = async e => {\n e.preventDefault();\n if (!formData.patientId || !formData.doctorId || !formData.appointmentDate || !formData.appointmentTime) {\n setError('Please fill in all required fields');\n return;\n }\n try {\n setLoading(true);\n await appointmentService.createAppointment({\n patientId: parseInt(formData.patientId),\n doctorId: parseInt(formData.doctorId),\n appointmentDate: formData.appointmentDate,\n appointmentTime: formData.appointmentTime\n });\n setSuccess('Appointment created successfully!');\n setTimeout(() => navigate('/appointments'), 1500);\n } catch (err) {\n var _err$response, _err$response$data;\n setError(((_err$response = err.response) === null || _err$response === void 0 ? void 0 : (_err$response$data = _err$response.data) === null || _err$response$data === void 0 ? void 0 : _err$response$data.error) || 'Failed to create appointment');\n } finally {\n setLoading(false);\n }\n };\n return /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"max-w-2xl mx-auto\",\n children: [/*#__PURE__*/_jsxDEV(\"h1\", {\n className: \"text-3xl font-bold mb-6\",\n children: \"Create Appointment\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 80,\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: 82,\n columnNumber: 17\n }, this), success && /*#__PURE__*/_jsxDEV(SuccessAlert, {\n message: success,\n onClose: () => setSuccess(null)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 83,\n columnNumber: 19\n }, this), /*#__PURE__*/_jsxDEV(\"form\", {\n onSubmit: handleSubmit,\n className: \"bg-white rounded-lg shadow p-6 space-y-4\",\n children: [isPatient ? /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"bg-blue-50 rounded-lg p-4 mb-4\",\n children: /*#__PURE__*/_jsxDEV(\"p\", {\n className: \"text-sm text-gray-700\",\n children: [/*#__PURE__*/_jsxDEV(\"strong\", {\n children: \"Patient:\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 89,\n columnNumber: 15\n }, this), \" \", user.firstName, \" \", user.lastName, \" (\", user.username, \")\"]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 88,\n columnNumber: 13\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 87,\n columnNumber: 11\n }, this) : /*#__PURE__*/_jsxDEV(\"div\", {\n children: [/*#__PURE__*/_jsxDEV(\"label\", {\n className: \"block text-sm font-semibold mb-2\",\n children: \"Patient *\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 94,\n columnNumber: 13\n }, this), /*#__PURE__*/_jsxDEV(\"select\", {\n name: \"patientId\",\n value: formData.patientId,\n onChange: handleChange,\n className: \"w-full px-4 py-2 border rounded-lg\",\n required: true,\n children: [/*#__PURE__*/_jsxDEV(\"option\", {\n value: \"\",\n children: \"Select Patient\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 102,\n columnNumber: 15\n }, this), patients.map(patient => /*#__PURE__*/_jsxDEV(\"option\", {\n value: patient.patientId,\n children: [patient.firstName, \" \", patient.lastName, \" (\", patient.embg, \")\"]\n }, patient.patientId, true, {\n fileName: _jsxFileName,\n lineNumber: 104,\n columnNumber: 17\n }, this))]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 95,\n columnNumber: 13\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 93,\n columnNumber: 11\n }, this), isDoctor ? /*#__PURE__*/_jsxDEV(\"div\", {\n children: [/*#__PURE__*/_jsxDEV(\"label\", {\n className: \"block text-sm font-semibold mb-2\",\n children: \"Doctor\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 114,\n columnNumber: 13\n }, this), /*#__PURE__*/_jsxDEV(\"p\", {\n className: \"px-4 py-2 bg-gray-100 rounded-lg text-gray-700\",\n children: [\"Dr. \", user.firstName, \" \", user.lastName]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 115,\n columnNumber: 13\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 113,\n columnNumber: 11\n }, this) : /*#__PURE__*/_jsxDEV(\"div\", {\n children: [/*#__PURE__*/_jsxDEV(\"label\", {\n className: \"block text-sm font-semibold mb-2\",\n children: \"Doctor *\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 121,\n columnNumber: 13\n }, this), /*#__PURE__*/_jsxDEV(\"select\", {\n name: \"doctorId\",\n value: formData.doctorId,\n onChange: handleChange,\n className: \"w-full px-4 py-2 border rounded-lg\",\n required: true,\n children: [/*#__PURE__*/_jsxDEV(\"option\", {\n value: \"\",\n children: \"Select Doctor\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 129,\n columnNumber: 15\n }, this), doctors.map(doctor => /*#__PURE__*/_jsxDEV(\"option\", {\n value: doctor.doctorId,\n children: [\"Dr. \", doctor.firstName, \" \", doctor.lastName]\n }, doctor.doctorId, true, {\n fileName: _jsxFileName,\n lineNumber: 131,\n columnNumber: 17\n }, this))]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 122,\n columnNumber: 13\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 120,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"grid grid-cols-2 gap-4\",\n children: [/*#__PURE__*/_jsxDEV(\"div\", {\n children: [/*#__PURE__*/_jsxDEV(\"label\", {\n className: \"block text-sm font-semibold mb-2\",\n children: \"Appointment Date *\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 141,\n columnNumber: 13\n }, this), /*#__PURE__*/_jsxDEV(\"input\", {\n type: \"date\",\n name: \"appointmentDate\",\n value: formData.appointmentDate,\n onChange: handleChange,\n className: \"w-full px-4 py-2 border rounded-lg\",\n required: true\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 142,\n columnNumber: 13\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 140,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n children: [/*#__PURE__*/_jsxDEV(\"label\", {\n className: \"block text-sm font-semibold mb-2\",\n children: \"Appointment Time *\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 152,\n columnNumber: 13\n }, this), /*#__PURE__*/_jsxDEV(\"input\", {\n type: \"time\",\n name: \"appointmentTime\",\n value: formData.appointmentTime,\n onChange: handleChange,\n className: \"w-full px-4 py-2 border rounded-lg\",\n required: true\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 153,\n columnNumber: 13\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 151,\n columnNumber: 11\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 139,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"flex gap-4 pt-4\",\n children: [/*#__PURE__*/_jsxDEV(\"button\", {\n type: \"submit\",\n disabled: loading,\n className: \"bg-purple-600 text-white px-6 py-2 rounded hover:bg-purple-700 disabled:opacity-50\",\n children: loading ? 'Creating...' : 'Create Appointment'\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 165,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n type: \"button\",\n onClick: () => navigate('/appointments'),\n className: \"bg-gray-300 text-gray-700 px-6 py-2 rounded hover:bg-gray-400\",\n children: \"Cancel\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 172,\n columnNumber: 11\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 164,\n columnNumber: 9\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 85,\n columnNumber: 7\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 79,\n columnNumber: 5\n }, this);\n}\n_s(AppointmentForm, \"SVNbg5jxNPD7UM5YcXP1kZCh35I=\", false, function () {\n return [useNavigate];\n});\n_c = AppointmentForm;\nexport default AppointmentForm;\nvar _c;\n$RefreshReg$(_c, \"AppointmentForm\");","map":{"version":3,"names":["React","useState","useEffect","useNavigate","appointmentService","patientService","doctorService","ErrorAlert","SuccessAlert","jsxDEV","_jsxDEV","AppointmentForm","_s","navigate","user","JSON","parse","localStorage","getItem","isPatient","role","isDoctor","formData","setFormData","patientId","doctorId","appointmentDate","appointmentTime","patients","setPatients","doctors","setDoctors","error","setError","success","setSuccess","loading","setLoading","fetchData","patientsRes","getAllPatients","data","doctorsRes","getAllDoctors","err","handleChange","e","name","value","target","prev","handleSubmit","preventDefault","createAppointment","parseInt","setTimeout","_err$response","_err$response$data","response","className","children","fileName","_jsxFileName","lineNumber","columnNumber","message","onClose","onSubmit","firstName","lastName","username","onChange","required","map","patient","embg","doctor","type","disabled","onClick","_c","$RefreshReg$"],"sources":["C:/Users/User/Downloads/medora5/frontend/src/pages/appointments/AppointmentForm.js"],"sourcesContent":["import React, { useState, useEffect } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { appointmentService } from '../../services/appointmentService';\nimport { patientService } from '../../services/patientService';\nimport { doctorService } from '../../services/doctorService';\nimport ErrorAlert from '../../components/ErrorAlert';\nimport SuccessAlert from '../../components/SuccessAlert';\n\nfunction AppointmentForm() {\n const navigate = useNavigate();\n const user = JSON.parse(localStorage.getItem('user') || '{}');\n const isPatient = user.role === 'PATIENT';\n const isDoctor = user.role === 'DOCTOR';\n\n const [formData, setFormData] = useState({\n patientId: isPatient ? (user.patientId || '') : '',\n doctorId: isDoctor ? (user.doctorId || '') : '',\n appointmentDate: '',\n appointmentTime: '',\n });\n const [patients, setPatients] = useState([]);\n const [doctors, setDoctors] = useState([]);\n const [error, setError] = useState(null);\n const [success, setSuccess] = useState(null);\n const [loading, setLoading] = useState(false);\n\n useEffect(() => {\n const fetchData = async () => {\n try {\n if (!isPatient) {\n const patientsRes = await patientService.getAllPatients();\n setPatients(patientsRes.data);\n }\n\n const doctorsRes = await doctorService.getAllDoctors();\n setDoctors(doctorsRes.data);\n } catch (err) {\n setError('Failed to fetch doctors');\n }\n };\n\n fetchData();\n }, [isPatient]);\n\n const handleChange = (e) => {\n const { name, value } = e.target;\n setFormData(prev => ({\n ...prev,\n [name]: value\n }));\n };\n\n const handleSubmit = async (e) => {\n e.preventDefault();\n\n if (!formData.patientId || !formData.doctorId || !formData.appointmentDate || !formData.appointmentTime) {\n setError('Please fill in all required fields');\n return;\n }\n\n try {\n setLoading(true);\n await appointmentService.createAppointment({\n patientId: parseInt(formData.patientId),\n doctorId: parseInt(formData.doctorId),\n appointmentDate: formData.appointmentDate,\n appointmentTime: formData.appointmentTime,\n });\n setSuccess('Appointment created successfully!');\n setTimeout(() => navigate('/appointments'), 1500);\n } catch (err) {\n setError(err.response?.data?.error || 'Failed to create appointment');\n } finally {\n setLoading(false);\n }\n };\n\n return (\n