Panel CSS Fix and Account Path Update

This commit is contained in:
Sir Blob
2025-01-25 10:17:47 -05:00
parent 027b895c5f
commit 891c313d59
10 changed files with 168 additions and 22 deletions

View File

@@ -0,0 +1,171 @@
"use client"
import { useState, useEffect } from 'react';
import axios from 'axios';
import { useUser } from '@clerk/nextjs';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Card, CardHeader, CardContent, CardFooter } from '@/components/ui/card';
const AccountPage = () => {
const { user } = useUser();
const [userData, setUserData] = useState(null);
const [patients, setPatients] = useState([]);
const [selectedPatient, setSelectedPatient] = useState(null);
const [medications, setMedications] = useState([]);
const [diagnoses, setDiagnoses] = useState([]);
useEffect(() => {
if (user) {
axios.get(`/api/user?userId=${user.id}`).then(response => {
setUserData(response.data);
if (response.data.role === 'caregiver') {
axios.get('/api/patients').then(res => setPatients(res.data));
}
});
}
}, [user]);
const handleRoleChange = async () => {
const newRole = userData.role === 'patient' ? 'caregiver' : 'patient';
await axios.put(`/api/user?userId=${user.id}`, { role: newRole });
setUserData({ ...userData, role: newRole });
if (newRole === 'caregiver') {
axios.get('/api/patients').then(res => setPatients(res.data));
} else {
setPatients([]);
setSelectedPatient(null);
}
};
const handlePatientSelect = (patient) => {
setSelectedPatient(patient);
setMedications(patient.medications);
setDiagnoses(patient.medicalConditions);
};
const handleMedicationsChange = (index, field, value) => {
const updatedMedications = [...medications];
updatedMedications[index][field] = value;
setMedications(updatedMedications);
};
const handleDiagnosesChange = (e) => {
setDiagnoses(e.target.value.split(','));
};
const handleAddMedication = () => {
setMedications([...medications, { name: '', dosage: '', frequency: '' }]);
};
const handleSave = async () => {
try {
await axios.put(`/api/patients?email=${selectedPatient.email}`, {
medications,
medicalConditions: diagnoses,
});
alert('Patient data updated successfully');
} catch (error) {
console.error('Error updating patient data:', error);
alert('Failed to update patient data');
}
};
if (!userData) return <div>Loading...</div>;
return (
<div className="container mx-auto p-4">
<Card>
<CardHeader>
<h1 className="text-2xl font-bold">Account Page</h1>
</CardHeader>
<CardContent>
<div className="mb-4">
<Label>Name:</Label>
<p>{userData.name}</p>
</div>
<div className="mb-4">
<Label>Email:</Label>
<p>{userData.email}</p>
</div>
<div className="mb-4">
<Label>Role:</Label>
<p>{userData.role}</p>
</div>
<Button onClick={handleRoleChange} className="mb-4">
Change role to {userData.role === 'patient' ? 'caregiver' : 'patient'}
</Button>
{userData.role === 'caregiver' && (
<div>
<h2 className="text-xl font-bold mb-4">Patients</h2>
<ul className="mb-4">
{patients.map(patient => (
<li
key={patient.email}
onClick={() => handlePatientSelect(patient)}
className="cursor-pointer hover:bg-gray-200 p-2"
>
{patient.name}
</li>
))}
</ul>
{selectedPatient && (
<Card>
<CardHeader>
<h3 className="text-xl font-bold">Edit Patient: {selectedPatient.name}</h3>
</CardHeader>
<CardContent>
<div className="mb-4">
<Label>Medications:</Label>
{medications.map((medication, index) => (
<div key={index} className="mb-2">
<Input
type="text"
placeholder="Name"
value={medication.name}
onChange={(e) => handleMedicationsChange(index, 'name', e.target.value)}
className="mb-2"
/>
<Input
type="text"
placeholder="Dosage"
value={medication.dosage}
onChange={(e) => handleMedicationsChange(index, 'dosage', e.target.value)}
className="mb-2"
/>
<Input
type="text"
placeholder="Frequency"
value={medication.frequency}
onChange={(e) => handleMedicationsChange(index, 'frequency', e.target.value)}
className="mb-2"
/>
</div>
))}
<Button onClick={handleAddMedication} className="mt-2">Add Medication</Button>
</div>
<div className="mb-4">
<Label>Diagnoses:</Label>
<Input
type="text"
value={diagnoses.join(',')}
onChange={handleDiagnosesChange}
/>
</div>
</CardContent>
<CardFooter>
<Button onClick={handleSave}>Save</Button>
</CardFooter>
</Card>
)}
</div>
)}
</CardContent>
</Card>
</div>
);
};
export default AccountPage;

View File

@@ -3,12 +3,12 @@
export default function Dashboard() {
return (
<div className="container mx-auto">
<h1 className="text-3xl font-semibold text-white mb-6">Dashboard</h1>
<h1 className="text-3xl font-semibold mb-6">Dashboard</h1>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{[...Array(6)].map((_, i) => (
<div key={i} className="bg-white rounded-lg shadow-md p-6">
<div key={i} className="bg-white dark:bg-neutral-800 rounded-lg shadow-md p-6">
<h2 className="text-xl font-semibold mb-4">Card {i + 1}</h2>
<p className="text-gray-600">This is some placeholder content for Card {i + 1}.</p>
<p className="">This is some placeholder content for Card {i + 1}.</p>
</div>
))}
</div>

View File

@@ -17,7 +17,7 @@ export default function RootLayout({
<Sidebar/>
<div className="flex-1 flex flex-col overflow-hidden">
<Navbar />
<main className="flex-1 overflow-x-hidden overflow-y-auto bg-gray-200 p-6">
<main className="flex-1 overflow-x-hidden overflow-y-auto text-black dark:text-white bg-neutral-100 dark:bg-neutral-900 p-6">
{children}
</main>
</div>

View File

@@ -0,0 +1,18 @@
"use client"
export default function Dashboard() {
return (
<div className="container mx-auto">
<h1 className="text-3xl font-semibold mb-6">Dashboard</h1>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{[...Array(6)].map((_, i) => (
<div key={i} className="bg-white dark:bg-neutral-800 rounded-lg shadow-md p-6">
<h2 className="text-xl font-semibold mb-4">Card {i + 1}</h2>
<p className="">This is some placeholder content for Card {i + 1}.</p>
</div>
))}
</div>
</div>
)
}

View File

@@ -1,11 +1,26 @@
"use client"
import { useState } from "react"
import Sidebar from "@/components/panel-ui/patient/app-sidebar"
import Navbar from "@/components/panel-ui/patient/app-navbar"
import { SidebarProvider } from "@/components/ui/sidebar"
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
const [isSidebarOpen] = useState(true)
return (
<section>{children}</section>
<SidebarProvider defaultOpen={isSidebarOpen} >
<Sidebar/>
<div className="flex-1 flex flex-col overflow-hidden">
<Navbar />
<main className="flex-1 overflow-x-hidden overflow-y-auto text-black dark:text-white bg-neutral-100 dark:bg-neutral-900 p-6">
{children}
</main>
</div>
</SidebarProvider>
)
}
}