ligdhej
This commit is contained in:
@@ -12,7 +12,7 @@ import { CardContent } from "@/components/ui/card";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { ChevronDown } from "lucide-react";
|
import { ChevronDown } from "lucide-react";
|
||||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
||||||
import {PersonForm} from "./PatientForm";
|
import { PersonForm } from "./PatientForm";
|
||||||
import { Card } from "@/components/ui/card";
|
import { Card } from "@/components/ui/card";
|
||||||
|
|
||||||
import { faker } from "@faker-js/faker";
|
import { faker } from "@faker-js/faker";
|
||||||
@@ -22,17 +22,17 @@ export default function PatientsDOC() {
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const [userData, setUserData] = useState(null);
|
const [userData, setUserData] = useState(null);
|
||||||
const [patients, setPatients] = useState([]);
|
const [patients, setPatients] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user) {
|
if (user) {
|
||||||
axios.get(`/api/user?userId=${user.id}`).then(response => {
|
axios.get(`/api/user?userId=${user.id}`).then(response => {
|
||||||
setUserData(response.data);
|
setUserData(response.data);
|
||||||
if (response.data.role === 'caregiver') {
|
if (response.data.role === 'caregiver') {
|
||||||
axios.get('/api/patients').then(res => setPatients(res.data));
|
axios.get('/api/patients').then(res => setPatients(res.data));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
@@ -71,37 +71,33 @@ export default function PatientsDOC() {
|
|||||||
return (
|
return (
|
||||||
<div className="container mx-auto">
|
<div className="container mx-auto">
|
||||||
<h1 className="text-3xl font-semibold mb-6">Patients</h1>
|
<h1 className="text-3xl font-semibold mb-6">Patients</h1>
|
||||||
<div className="h-20 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="h-20 w-full">
|
||||||
<Card>
|
{userData && userData.role === 'caregiver' && (
|
||||||
<CardContent>
|
<div className="space-y-4 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
|
||||||
{userData && userData.role === 'caregiver' && (
|
<div className="mb-4">
|
||||||
<div className="space-y-4 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
|
{finalPatients.map(patient => (
|
||||||
<div className="mb-4">
|
<Collapsible key={patient.id}>
|
||||||
{finalPatients.map(patient => (
|
<div className="flex items-center justify-between p-2 bg-gray-100 dark:bg-neutral-800 rounded-t-lg">
|
||||||
<Collapsible key={patient.id}>
|
<div>
|
||||||
<div className="flex items-center justify-between p-2 bg-gray-100 dark:bg-neutral-800 rounded-t-lg">
|
<h2 className="text-lg font-semibold">{patient.name}</h2>
|
||||||
<div>
|
<p className="text-sm text-gray-500 dark:text-neutral-400">Age: {patient.age}</p>
|
||||||
<h2 className="text-lg font-semibold">{patient.name}</h2>
|
<p className="text-sm text-gray-500 dark:text-neutral-400">Last Checkup: {new Date(patient.lastCheckup).toLocaleDateString()}</p>
|
||||||
<p className="text-sm text-gray-500 dark:text-neutral-400">Age: {patient.age}</p>
|
</div>
|
||||||
<p className="text-sm text-gray-500 dark:text-neutral-400">Last Checkup: {new Date(patient.lastCheckup).toLocaleDateString()}</p>
|
<CollapsibleTrigger asChild>
|
||||||
</div>
|
<Button variant="ghost" size="sm">
|
||||||
<CollapsibleTrigger asChild>
|
<ChevronDown className="h-4 w-4" />
|
||||||
<Button variant="ghost" size="sm">
|
<span className="sr-only">Toggle</span>
|
||||||
<ChevronDown className="h-4 w-4" />
|
</Button>
|
||||||
<span className="sr-only">Toggle</span>
|
</CollapsibleTrigger>
|
||||||
</Button>
|
</div>
|
||||||
</CollapsibleTrigger>
|
<CollapsibleContent className="p-4 border border-t-0 rounded-b-lg">
|
||||||
</div>
|
<PersonForm person={patient} />
|
||||||
<CollapsibleContent className="p-4 border border-t-0 rounded-b-lg">
|
</CollapsibleContent>
|
||||||
<PersonForm person={patient} />
|
</Collapsible>
|
||||||
</CollapsibleContent>
|
))}
|
||||||
</Collapsible>
|
</div>
|
||||||
))}
|
</div>
|
||||||
</div>
|
)}
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user