source: frontend/src/pages/billing/BillingList.js@ 84249b1

Last change on this file since 84249b1 was f05de05, checked in by MBK <marija.karapandzova@…>, 4 months ago

Add pages and routing for lab tests, procedures and billing with api services

  • Property mode set to 100644
File size: 3.5 KB
Line 
1import React, { useState, useEffect } from 'react';
2import { Link, useSearchParams } from 'react-router-dom';
3import { billingService } from '../../services/billingService';
4import Loading from '../../components/Loading';
5import ErrorAlert from '../../components/ErrorAlert';
6
7function BillingList() {
8 const [billings, setBillings] = useState([]);
9 const [loading, setLoading] = useState(true);
10 const [error, setError] = useState(null);
11 const [searchParams] = useSearchParams();
12 const patientId = searchParams.get('patientId');
13 const user = JSON.parse(localStorage.getItem('user') || '{}');
14
15 useEffect(() => {
16 fetchBillings();
17 }, [patientId]);
18
19 const fetchBillings = async () => {
20 try {
21 setLoading(true);
22 let response;
23 if (patientId) {
24 response = await billingService.getBillingHistoryForPatient(patientId);
25 } else if (user.role === 'PATIENT') {
26 // Patients can only view their own billing history
27 response = await billingService.getBillingHistoryForPatient(user.patientId);
28 } else {
29 response = await billingService.getAllBillings();
30 }
31 setBillings(response.data);
32 } catch (err) {
33 setError('Failed to fetch billing records');
34 console.error(err);
35 } finally {
36 setLoading(false);
37 }
38 };
39
40 if (loading) return <Loading />;
41
42 return (
43 <div>
44 <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>{patientId ? 'Patient Billing History' : 'Billing Records'}</h1>
45
46 {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
47
48 <div className="bg-white rounded-lg shadow overflow-hidden">
49 <table className="w-full">
50 <thead className="bg-gray-100">
51 <tr>
52 <th className="px-6 py-3 text-left text-sm font-semibold">Patient</th>
53 <th className="px-6 py-3 text-left text-sm font-semibold">Total Cost</th>
54 <th className="px-6 py-3 text-left text-sm font-semibold">Payment Status</th>
55 <th className="px-6 py-3 text-left text-sm font-semibold">Payment Date</th>
56 <th className="px-6 py-3 text-left text-sm font-semibold">Actions</th>
57 </tr>
58 </thead>
59 <tbody>
60 {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">
65 <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'
69 }`}>
70 {billing.paymentStatus}
71 </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>
80 ))}
81 </tbody>
82 </table>
83 </div>
84 </div>
85 );
86}
87
88export default BillingList;
Note: See TracBrowser for help on using the repository browser.