Skip to content
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

Minor Fixes #12

Merged
merged 3 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/DoctorSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
>
<option value="">Select a doctor</option>
{doctors.map((doctor) => (
<option key={doctor.id} value={doctor.id}>
{doctor.name}
{`${doctor.name}, ${doctor.specialization.name}`}
</option>
))}
</select>
Expand All @@ -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;
1 change: 0 additions & 1 deletion src/components/TimeSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
>
<option value="">Select a time</option>
{availableTimes.map((time) => (
Expand Down
6 changes: 3 additions & 3 deletions src/routes/AppointmentUpdate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '',
Expand Down Expand Up @@ -82,15 +82,15 @@ const AppointmentUpdate = () => {
return (
<div className="flex flex-col items-center justify-center w-full min-h-screen p-4 space-y-4 bg-gray-100 appointment-booking-container">
<div className="bg-white md:px-24 md:py-6 md:rounded-2xl md:border-2 md:border-green-400">
<h1 className="my-5 text-2xl font-bold text-center md:mt-10">Schedule a new Appointment</h1>
<h1 className="my-5 text-2xl font-bold text-center md:mt-10">Update Your Appointment</h1>
<form className="flex flex-col items-center justify-center w-full gap-4">
<DoctorSelector
doctors={doctorsState.doctors}
selectedDoctorIndex={selectedDoctorIndex}
onChange={handleDoctorChange}
/>
<DateSelector selectedDate={selectedDate} onChange={handleDateChange} />
{selectedDoctorIndex !== null && (
{selectedDoctorIndex !== null && doctorsState.doctors.length > 0 && (
<TimeSelector
selectedTime={selectedTime}
doctor={
Expand Down
1 change: 0 additions & 1 deletion src/routes/CreateAppointment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const CreateAppointment = () => {
const dispatch = useDispatch();
const doctorsState = useSelector((state) => state.doctors);
const navigate = useNavigate();

useEffect(() => {
dispatch(fetchdoctors());
}, [dispatch]);
Expand Down