Skip to content

Commit

Permalink
link doctorPage to appointmentPage to book an appointment
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzair-Manzoor committed Feb 14, 2024
1 parent 05e2b38 commit 6d5da2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/components/appointmentForm/AppointmentForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ function BookAppointment() {
onChange={handleInputChange}
value={selectedReason}
type="text"
placeholder="Enter-reason"
id="image"
name="image"
placeholder="Enter the reason"
required
/>
</div>
Expand Down
20 changes: 18 additions & 2 deletions src/components/doctors/DoctorDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import { useState } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import { FaArrowLeft } from 'react-icons/fa';
import styles from './doctorDetails.module.css';
import { createAppointment } from '../../redux/appointment/appointmentsSlice';

function DoctorDetails() {
const { doctors } = useSelector((state) => state.doctors);
const { id } = useParams();
const doctor = doctors.doctors.find((p) => p.id === Number(id));
const navigate = useNavigate();
const [doctorId] = useState();

const dispatch = useDispatch();

const handleSubmit = (event) => {
event.preventDefault();
const dataAppointment = {
appointment: {
doctor_id: doctorId,
},
};
dispatch(createAppointment(dataAppointment));
navigate('/doctors/book-appointment');
};

return (
<section className={styles.container}>
Expand All @@ -19,7 +35,7 @@ function DoctorDetails() {
<h2 className={styles.doctor_name}>{doctor.name}</h2>
<p>{doctor.bio}</p>
<p>{doctor.specialization}</p>
<button className={styles.reserve_btn} type="button">Book an appointment</button>
<button className={styles.reserve_btn} onClick={handleSubmit} type="button">Book an appointment</button>
</div>
</section>
);
Expand Down

0 comments on commit 6d5da2d

Please sign in to comment.