diff --git a/src/components/DoctorSelector.jsx b/src/components/DoctorSelector.jsx index 9ec27c5..a894f87 100644 --- a/src/components/DoctorSelector.jsx +++ b/src/components/DoctorSelector.jsx @@ -9,12 +9,11 @@ const DoctorSelector = ({ doctors, selectedDoctorIndex, onChange }) => ( onChange={(e) => onChange(e.target.value !== '' ? parseInt(e.target.value, 10) : null)} className="p-2 border border-gray-300 rounded-md" id="doc-select" - defaultValue={selectedDoctorIndex} > {doctors.map((doctor) => ( ))} @@ -26,8 +25,12 @@ DoctorSelector.propTypes = { id: PropTypes.number.isRequired, name: PropTypes.string.isRequired, })).isRequired, - selectedDoctorIndex: PropTypes.number.isRequired, + selectedDoctorIndex: PropTypes.number, onChange: PropTypes.func.isRequired, }; +DoctorSelector.defaultProps = { + selectedDoctorIndex: null, +}; + export default DoctorSelector; diff --git a/src/components/TimeSelector.jsx b/src/components/TimeSelector.jsx index b0de3ad..32b44cd 100644 --- a/src/components/TimeSelector.jsx +++ b/src/components/TimeSelector.jsx @@ -53,7 +53,6 @@ const TimeSelector = ({ selectedTime, doctor, onChange }) => { onChange={handleTimeChange} id="hour-select" className="p-2 border border-gray-300 rounded-md" - defaultValue={selectedTime} > {availableTimes.map((time) => ( diff --git a/src/routes/AppointmentUpdate.jsx b/src/routes/AppointmentUpdate.jsx index 1182fa3..7b7e0d8 100644 --- a/src/routes/AppointmentUpdate.jsx +++ b/src/routes/AppointmentUpdate.jsx @@ -21,7 +21,7 @@ const AppointmentUpdate = () => { const doctorsState = useSelector((state) => state.doctors); const appointment = appointmentsState.appointments.filter((elem) => elem.id === +appId); const [selectedDate, setSelectedDate] = useState( - appointment[0]?.appointment_date || new Date(), + appointment[0]?.appointment_date ? new Date(appointment[0].appointment_date) : new Date(), ); const [selectedTime, setSelectedTime] = useState( appointment[0]?.appointment_time || '', @@ -82,7 +82,7 @@ const AppointmentUpdate = () => { return (
-

Schedule a new Appointment

+

Update Your Appointment

{ onChange={handleDoctorChange} /> - {selectedDoctorIndex !== null && ( + {selectedDoctorIndex !== null && doctorsState.doctors.length > 0 && ( { const dispatch = useDispatch(); const doctorsState = useSelector((state) => state.doctors); const navigate = useNavigate(); - useEffect(() => { dispatch(fetchdoctors()); }, [dispatch]);