Skip to content

Commit

Permalink
Merge branch 'feature/admin'
Browse files Browse the repository at this point in the history
  • Loading branch information
ad956 committed Sep 18, 2024
2 parents d153295 + 000561e commit dd1b0d5
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 291 deletions.
9 changes: 1 addition & 8 deletions app/(pages)/admin/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import React, { useState } from "react";
import Link from "next/link";
import { Image } from "@nextui-org/react";
import { usePathname } from "next/navigation";
import {
FiHome,
FiUserPlus,
FiBarChart2,
FiSettings,
FiHeart,
} from "react-icons/fi";
import { FiHome, FiUserPlus, FiSettings, FiHeart } from "react-icons/fi";
import { TbCurrencyRupee } from "react-icons/tb";

// Sidebar configuration
Expand All @@ -19,7 +13,6 @@ const SidebarConfig = [
{ title: "Add Admin", uri: "add-admin", icon: <FiUserPlus /> },
{ title: "Transactions", uri: "transactions", icon: <TbCurrencyRupee /> },
{ title: "Hospitals", uri: "hospitals", icon: <FiHeart /> },
{ title: "Reports", uri: "reports", icon: <FiBarChart2 /> },
{ title: "Settings", uri: "settings", icon: <FiSettings /> },
];

Expand Down
25 changes: 19 additions & 6 deletions app/(pages)/admin/hospitals/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
Card,
} from "@nextui-org/react";
import {
AiOutlineSearch as SearchIcon,
AiOutlineStop as BlockIcon,
AiOutlineTeam as UsersIcon,
AiOutlineFileDone,
AiOutlineSearch,
AiOutlineStop,
AiOutlineTeam,
} from "react-icons/ai";
import SpinnerLoader from "@components/SpinnerLoader";
import Link from "next/link";
Expand Down Expand Up @@ -97,7 +98,7 @@ const HospitalManagement: React.FC = () => {
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearchTerm(e.target.value)
}
startContent={<SearchIcon className="w-5 h-5 text-gray-400" />}
startContent={<AiOutlineSearch className="w-5 h-5 text-gray-400" />}
className="rounded-full pl-10 pr-4 py-2 max-w-sm focus:outline-none focus:ring-2 focus:ring-purple-300"
/>
</div>
Expand Down Expand Up @@ -149,15 +150,27 @@ const HospitalManagement: React.FC = () => {
href={`/admin/hospitals/${hospital.id}`}
size="sm"
variant="light"
startContent={<UsersIcon className="w-4 h-4" />}
startContent={<AiOutlineTeam className="w-4 h-4" />}
className="bg-blue-50 text-blue-600 hover:bg-blue-100 rounded-full px-4 py-1 transition-colors duration-200"
>
Manage Users
</Button>
<Button
as={Link}
href={`/admin/hospitals/report/${hospital.id}`}
size="sm"
variant="light"
startContent={
<AiOutlineFileDone className="w-4 h-4" />
}
className="bg-amber-50 text-amber-600 hover:bg-amber-100 rounded-full px-4 py-1 transition-colors duration-200"
>
Reports
</Button>
<Button
size="sm"
variant="light"
startContent={<BlockIcon className="w-4 h-4" />}
startContent={<AiOutlineStop className="w-4 h-4" />}
onClick={() => handleBlockHospital(hospital.id)}
className="bg-red-50 text-red-600 hover:bg-red-100 rounded-full px-4 py-1 transition-colors duration-200"
>
Expand Down
210 changes: 210 additions & 0 deletions app/(pages)/admin/hospitals/report/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
"use client";

import React, { useState, useEffect } from "react";
import {
Card,
CardBody,
CardHeader,
Dropdown,
Button,
DropdownMenu,
DropdownItem,
} from "@nextui-org/react";
import { ResponsivePie } from "@nivo/pie";
import { ResponsiveLine } from "@nivo/line";
import { ResponsiveBar } from "@nivo/bar";
import { getHospitalDetails } from "@/lib/admin";
import SpinnerLoader from "@components/SpinnerLoader";

function HospitalReports({ params }: { params: { id: string } }) {
const [loading, setLoading] = useState(true);
const [reportData, setReportData] = useState(null);
const [selectedTimeRange, setSelectedTimeRange] = useState("This Month");

useEffect(() => {
fetchReportData();
}, [selectedTimeRange]);

const fetchReportData = async () => {
try {
setLoading(true);
// Assuming getHospitalDetails is modified to return report data
// const data = await getHospitalDetails(params.id, selectedTimeRange);
// setReportData(data);
} catch (error) {
console.error("Error fetching report data:", error);
} finally {
setLoading(false);
}
};

// Sample data - replace with actual data from API
const pieData = [
{ id: "Cardiology", value: 30 },
{ id: "Neurology", value: 20 },
{ id: "Pediatrics", value: 15 },
{ id: "Oncology", value: 25 },
{ id: "Other", value: 10 },
];

const lineData = [
{
id: "Patients",
data: [
{ x: "Jan", y: 100 },
{ x: "Feb", y: 120 },
{ x: "Mar", y: 90 },
{ x: "Apr", y: 140 },
{ x: "May", y: 160 },
],
},
];

const barData = [
{ department: "Emergency", revenue: 50000 },
{ department: "Surgery", revenue: 75000 },
{ department: "ICU", revenue: 60000 },
{ department: "Radiology", revenue: 45000 },
];

if (loading) {
return (
<div className="flex justify-center items-center h-screen">
<SpinnerLoader />
</div>
);
}

return (
<div className="p-4 max-h-screen">
<Card className="p-6 w-full h-full flex flex-col overflow-y-scroll scrollbar-hide">
<h1 className="text-2xl font-bold mb-6">Hospital Reports Dashboard</h1>

<div className="mb-6">
<Dropdown>
<Button variant="flat">{selectedTimeRange}</Button>
<DropdownMenu
aria-label="Time range selection"
onAction={(key: any) => setSelectedTimeRange(key.toString())}
>
<DropdownItem key="This Week">This Week</DropdownItem>
<DropdownItem key="This Month">This Month</DropdownItem>
<DropdownItem key="This Year">This Year</DropdownItem>
</DropdownMenu>
</Dropdown>
</div>

<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<Card className="w-full h-80">
<CardHeader>
<h2 className="text-lg font-semibold">
Patient Distribution by Department
</h2>
</CardHeader>
<CardBody>
<ResponsivePie
data={pieData}
margin={{ top: 40, right: 80, bottom: 80, left: 80 }}
innerRadius={0.5}
padAngle={0.7}
cornerRadius={3}
activeOuterRadiusOffset={8}
colors={{ scheme: "nivo" }}
arcLinkLabelsSkipAngle={10}
arcLinkLabelsTextColor="#333333"
arcLinkLabelsThickness={2}
arcLabelsSkipAngle={10}
arcLabelsTextColor="#ffffff"
/>
</CardBody>
</Card>

<Card className="w-full h-80">
<CardHeader>
<h2 className="text-lg font-semibold">Patient Trends</h2>
</CardHeader>
<CardBody>
<ResponsiveLine
data={lineData}
margin={{ top: 50, right: 110, bottom: 50, left: 60 }}
xScale={{ type: "point" }}
yScale={{
type: "linear",
min: "auto",
max: "auto",
stacked: true,
reverse: false,
}}
axisTop={null}
axisRight={null}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: "Month",
legendOffset: 36,
legendPosition: "middle",
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: "Patient Count",
legendOffset: -40,
legendPosition: "middle",
}}
pointSize={10}
pointColor={{ theme: "background" }}
pointBorderWidth={2}
pointBorderColor={{ from: "serieColor" }}
pointLabelYOffset={-12}
useMesh={true}
/>
</CardBody>
</Card>

<Card className="w-full h-80 md:col-span-2">
<CardHeader>
<h2 className="text-lg font-semibold">Revenue by Department</h2>
</CardHeader>
<CardBody>
<ResponsiveBar
data={barData}
keys={["revenue"]}
indexBy="department"
margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
padding={0.3}
valueScale={{ type: "linear" }}
indexScale={{ type: "band", round: true }}
colors={{ scheme: "nivo" }}
axisTop={null}
axisRight={null}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: "Department",
legendPosition: "middle",
legendOffset: 32,
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: "Revenue ($)",
legendPosition: "middle",
legendOffset: -40,
}}
labelSkipWidth={12}
labelSkipHeight={12}
labelTextColor="#ffffff"
/>
</CardBody>
</Card>
</div>
</Card>
</div>
);
}

export default HospitalReports;
Loading

0 comments on commit dd1b0d5

Please sign in to comment.