diff --git a/package.json b/package.json index c646905..a7fd19e 100644 --- a/package.json +++ b/package.json @@ -12,12 +12,14 @@ "@clerk/nextjs": "^6.10.2", "@radix-ui/react-dialog": "^1.1.5", "@radix-ui/react-dropdown-menu": "^2.1.5", + "@radix-ui/react-label": "^2.1.1", "@radix-ui/react-navigation-menu": "^1.2.4", "@radix-ui/react-separator": "^1.1.1", "@radix-ui/react-slot": "^1.1.1", "@radix-ui/react-tooltip": "^1.1.7", "@vercel/analytics": "^1.4.1", "@vercel/speed-insights": "^1.1.0", + "axios": "^1.7.9", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "hoyahax-2025": "file:", diff --git a/src/app/(web)/account/page.jsx b/src/app/(web)/account/page.jsx new file mode 100644 index 0000000..c3371be --- /dev/null +++ b/src/app/(web)/account/page.jsx @@ -0,0 +1,162 @@ +"use client" +import { useState, useEffect } from 'react'; +import axios from 'axios'; +import { useUser } from '@clerk/clerk-react'; +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 handleSave = async () => { + await axios.put(`/api/patients/${selectedPatient.email}`, { + medications, + medicalConditions: diagnoses, + }); + alert('Patient data updated successfully'); + }; + + if (!userData) return
Loading...
; + + return ( +
+ + +

Account Page

+
+ +
+ +

{userData.name}

+
+
+ +

{userData.email}

+
+
+ +

{userData.role}

+
+ + + {userData.role === 'caregiver' && ( +
+

Patients

+
    + {patients.map(patient => ( +
  • handlePatientSelect(patient)} + className="cursor-pointer hover:bg-gray-200 p-2" + > + {patient.name} +
  • + ))} +
+ + {selectedPatient && ( + + +

Edit Patient: {selectedPatient.name}

+
+ +
+ + {medications.map((medication, index) => ( +
+ handleMedicationsChange(index, 'name', e.target.value)} + className="mb-2" + /> + handleMedicationsChange(index, 'dosage', e.target.value)} + className="mb-2" + /> + handleMedicationsChange(index, 'frequency', e.target.value)} + className="mb-2" + /> +
+ ))} +
+
+ + +
+
+ + + +
+ )} +
+ )} +
+
+
+ ); +}; + +export default AccountPage; \ No newline at end of file diff --git a/src/app/(web)/layout.tsx b/src/app/(web)/layout.tsx index e69d4da..da9e34c 100644 --- a/src/app/(web)/layout.tsx +++ b/src/app/(web)/layout.tsx @@ -1,5 +1,6 @@ "use client" +import { ClerkProvider } from '@clerk/nextjs'; import { Navbar } from '@/components/navbar'; import { Footer } from '@/components/footer'; import { ThemeProvider } from '@/components/theme-provider'; @@ -14,11 +15,13 @@ export default function RootLayout({ return ( - - -
{children}
-