import React, { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { departmentService } from '../../services/departmentService';
import Loading from '../../components/Loading';
import ErrorAlert from '../../components/ErrorAlert';
function DepartmentDetail() {
const formatDepartmentName = (name) => {
if (!name) return 'N/A';
return name.replace(/_DEPT$/, '').replace(/_/g, ' ').split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(' ');
};
const { departmentId } = useParams();
const navigate = useNavigate();
const [department, setDepartment] = useState(null);
const [doctors, setDoctors] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
const fetchDepartmentAndDoctors = async () => {
try {
setLoading(true);
// Fetch department details
const deptResponse = await departmentService.getDepartmentById(departmentId);
setDepartment(deptResponse.data);
// Fetch doctors for this department
const doctorsResponse = await departmentService.getDoctorsByDepartment(departmentId);
setDoctors(doctorsResponse.data);
} catch (err) {
setError('Failed to fetch data');
console.error(err);
} finally {
setLoading(false);
}
};
fetchDepartmentAndDoctors();
}, [departmentId]);
if (loading) return
| Name | Actions | |
|---|---|---|
| {doctor.firstName} {doctor.lastName} | {doctor.emailAddress} |
No doctors assigned to this department
)}