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/billing/BillingList.js

    r84249b1 ra64c772  
    1313  const user = JSON.parse(localStorage.getItem('user') || '{}');
    1414
    15   useEffect(() => {
    16     fetchBillings();
    17   }, [patientId]);
    18 
    1915  const fetchBillings = async () => {
    2016    try {
     
    2420        response = await billingService.getBillingHistoryForPatient(patientId);
    2521      } else if (user.role === 'PATIENT') {
    26         // Patients can only view their own billing history
    2722        response = await billingService.getBillingHistoryForPatient(user.patientId);
    2823      } else {
     
    3833  };
    3934
     35  useEffect(() => {
     36    fetchBillings();
     37  }, [patientId]);
     38
     39  // Prevent unauthorized access to billing
     40  if (user.role === 'DOCTOR' || user.role === 'LAB_TECHNICIAN') {
     41    return (
     42        <div style={{ padding: '20px', textAlign: 'center' }}>
     43          <h1 className="text-2xl font-bold" style={{ color: '#7c3aed', marginBottom: '10px' }}>Access Denied</h1>
     44          <p style={{ color: 'var(--color-neutral-600)' }}>You do not have permission to access billing records.</p>
     45        </div>
     46    );
     47  }
     48
    4049  if (loading) return <Loading />;
    4150
    4251  return (
    43     <div>
    44       <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>{patientId ? 'Patient Billing History' : 'Billing Records'}</h1>
     52      <div>
     53        <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>{patientId ? 'Patient Billing History' : 'Billing Records'}</h1>
    4554
    46       {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
     55        {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
    4756
    48       <div className="bg-white rounded-lg shadow overflow-hidden">
    49         <table className="w-full">
    50           <thead className="bg-gray-100">
     57        <div className="bg-white rounded-lg shadow overflow-hidden">
     58          <table className="w-full">
     59            <thead className="bg-gray-100">
    5160            <tr>
    5261              <th className="px-6 py-3 text-left text-sm font-semibold">Patient</th>
     
    5665              <th className="px-6 py-3 text-left text-sm font-semibold">Actions</th>
    5766            </tr>
    58           </thead>
    59           <tbody>
     67            </thead>
     68            <tbody>
    6069            {billings.map(billing => (
    61               <tr key={billing.billId} className="border-t hover:bg-gray-50">
    62                 <td className="px-6 py-3">{billing.patientName}</td>
    63                 <td className="px-6 py-3">${billing.totalCost}</td>
    64                 <td className="px-6 py-3">
     70                <tr key={billing.billId} className="border-t hover:bg-gray-50">
     71                  <td className="px-6 py-3">{billing.patientName}</td>
     72                  <td className="px-6 py-3">${billing.totalCost}</td>
     73                  <td className="px-6 py-3">
    6574                  <span className={`px-3 py-1 rounded text-sm font-semibold ${
    66                     billing.paymentStatus === 'PENDING' ? 'bg-yellow-100 text-yellow-800' :
    67                     billing.paymentStatus === 'PAID' ? 'bg-green-100 text-green-800' :
    68                     'bg-red-100 text-red-800'
     75                      billing.paymentStatus === 'PENDING' ? 'bg-yellow-100 text-yellow-800' :
     76                          billing.paymentStatus === 'PAID' ? 'bg-green-100 text-green-800' :
     77                              'bg-red-100 text-red-800'
    6978                  }`}>
    7079                    {billing.paymentStatus}
    7180                  </span>
    72                 </td>
    73                 <td className="px-6 py-3">{billing.paymentDate || 'Not paid'}</td>
    74                 <td className="px-6 py-3">
    75                   <Link to={`/billing/${billing.billId}`} style={{ color: '#7c3aed', textDecoration: 'none', fontWeight: '400' }} onMouseEnter={(e) => e.currentTarget.style.textDecoration = 'underline'} onMouseLeave={(e) => e.currentTarget.style.textDecoration = 'none'}>
    76                     View
    77                   </Link>
    78                 </td>
    79               </tr>
     81                  </td>
     82                  <td className="px-6 py-3">{billing.paymentDate || 'Not paid'}</td>
     83                  <td className="px-6 py-3">
     84                    <Link to={`/billing/${billing.billId}`} style={{ color: '#7c3aed', textDecoration: 'none', fontWeight: '400' }} onMouseEnter={(e) => e.currentTarget.style.textDecoration = 'underline'} onMouseLeave={(e) => e.currentTarget.style.textDecoration = 'none'}>
     85                      View
     86                    </Link>
     87                  </td>
     88                </tr>
    8089            ))}
    81           </tbody>
    82         </table>
     90            </tbody>
     91          </table>
     92        </div>
    8393      </div>
    84     </div>
    8594  );
    8695}
Note: See TracChangeset for help on using the changeset viewer.