Ignore:
Timestamp:
05/25/26 13:43:53 (4 months ago)
Author:
MBK <marija.karapandzova@…>
Branches:
master
Children:
f18b11b
Parents:
84249b1
Message:

Fix doctor authorization and prevent canceling other doctors appointments and restrict them from billing access

File:
1 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/pages/appointments/AppointmentList.js

    r84249b1 ra64c772  
    4747        await appointmentService.cancelAppointment(id);
    4848        setAppointments(appointments.map(apt =>
    49           apt.appointmentId === id ? { ...apt, status: 'CANCELLED' } : apt
     49            apt.appointmentId === id ? { ...apt, status: 'CANCELLED' } : apt
    5050        ));
    5151      } catch (err) {
     
    5858
    5959  return (
    60     <div>
    61       <div className="flex justify-between items-center mb-6">
    62         <h1 className="text-3xl font-bold" style={{ color: '#7c3aed' }}>
    63           {patientId ? 'Patient Appointments' : doctorId ? 'My Appointments' : 'All Appointments'}
    64         </h1>
    65         <Link to="/appointments/new" style={{
    66           display: 'inline-block',
    67           background: '#bfdbfe',
    68           color: '#1e1035',
    69           padding: '8px 16px',
    70           borderRadius: '6px',
    71           textDecoration: 'none',
    72           fontSize: '14px',
    73           fontWeight: '400'
    74         }} onMouseEnter={(e) => e.currentTarget.style.background = '#93c5fd'} onMouseLeave={(e) => e.currentTarget.style.background = '#bfdbfe'}>
    75           New Appointment
    76         </Link>
    77       </div>
     60      <div>
     61        <div className="flex justify-between items-center mb-6">
     62          <h1 className="text-3xl font-bold" style={{ color: '#7c3aed' }}>
     63            {patientId ? 'Patient Appointments' : doctorId ? 'My Appointments' : 'All Appointments'}
     64          </h1>
     65          <Link to="/appointments/new" style={{
     66            display: 'inline-block',
     67            background: '#bfdbfe',
     68            color: '#1e1035',
     69            padding: '8px 16px',
     70            borderRadius: '6px',
     71            textDecoration: 'none',
     72            fontSize: '14px',
     73            fontWeight: '400'
     74          }} onMouseEnter={(e) => e.currentTarget.style.background = '#93c5fd'} onMouseLeave={(e) => e.currentTarget.style.background = '#bfdbfe'}>
     75            New Appointment
     76          </Link>
     77        </div>
    7878
    79       {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
     79        {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
    8080
    81       <div className="bg-white rounded-lg shadow overflow-hidden">
    82         <table className="w-full">
    83           <thead className="bg-gray-100">
     81        <div className="bg-white rounded-lg shadow overflow-hidden">
     82          <table className="w-full">
     83            <thead className="bg-gray-100">
    8484            <tr>
    8585              <th className="px-6 py-3 text-left text-sm font-semibold">Patient</th>
     
    9090              <th className="px-6 py-3 text-left text-sm font-semibold">Actions</th>
    9191            </tr>
    92           </thead>
    93           <tbody>
     92            </thead>
     93            <tbody>
    9494            {appointments.map(appointment => (
    95               <tr key={appointment.appointmentId} className="border-t hover:bg-gray-50">
    96                 <td className="px-6 py-3">{appointment.patient?.firstName} {appointment.patient?.lastName}</td>
    97                 <td className="px-6 py-3">Dr. {appointment.doctor?.firstName} {appointment.doctor?.lastName}</td>
    98                 <td className="px-6 py-3">{appointment.appointmentDate}</td>
    99                 <td className="px-6 py-3">{appointment.appointmentTime}</td>
    100                 <td className="px-6 py-3">
     95                <tr key={appointment.appointmentId} className="border-t hover:bg-gray-50">
     96                  <td className="px-6 py-3">{appointment.patient?.firstName} {appointment.patient?.lastName}</td>
     97                  <td className="px-6 py-3">Dr. {appointment.doctor?.firstName} {appointment.doctor?.lastName}</td>
     98                  <td className="px-6 py-3">{appointment.appointmentDate}</td>
     99                  <td className="px-6 py-3">{appointment.appointmentTime}</td>
     100                  <td className="px-6 py-3">
    101101                  <span className={`px-3 py-1 rounded text-sm font-semibold ${
    102                     appointment.status === 'SCHEDULED' ? 'bg-purple-100 text-purple-800' :
    103                     appointment.status === 'COMPLETED' ? 'bg-green-100 text-green-800' :
    104                     'bg-red-100 text-red-800'
     102                      appointment.status === 'SCHEDULED' ? 'bg-purple-100 text-purple-800' :
     103                          appointment.status === 'COMPLETED' ? 'bg-green-100 text-green-800' :
     104                              'bg-red-100 text-red-800'
    105105                  }`}>
    106106                    {appointment.status}
    107107                  </span>
    108                 </td>
    109                 <td className="px-6 py-3">
    110                   {appointment.status === 'SCHEDULED' && (
    111                     <button
    112                       onClick={() => handleCancelAppointment(appointment.appointmentId)}
    113                       className="text-red-600 hover:underline px-3 py-2 text-sm font-medium"
    114                     >
    115                       Cancel
    116                     </button>
    117                   )}
    118                 </td>
    119               </tr>
     108                  </td>
     109                  <td className="px-6 py-3">
     110                    {appointment.status === 'SCHEDULED' && (
     111                        (user.role === 'DOCTOR' && appointment.doctor?.doctorId !== user.doctorId) ? null : (
     112                            <button
     113                                onClick={() => handleCancelAppointment(appointment.appointmentId)}
     114                                className="text-red-600 hover:underline px-3 py-2 text-sm font-medium"
     115                            >
     116                              Cancel
     117                            </button>
     118                        )
     119                    )}
     120                  </td>
     121                </tr>
    120122            ))}
    121           </tbody>
    122         </table>
     123            </tbody>
     124          </table>
     125        </div>
    123126      </div>
    124     </div>
    125127  );
    126128}
Note: See TracChangeset for help on using the changeset viewer.