From 8c9d59f22531dd998b656a18113c118946d13d11 Mon Sep 17 00:00:00 2001 From: Sir Blob <76974209+GamerBoss101@users.noreply.github.com> Date: Sat, 25 Jan 2025 08:05:21 -0500 Subject: [PATCH] More Buggy Code --- src/app/(panels)/suite/doctor/layout.tsx | 2 +- src/app/(web)/account/page.jsx | 162 ++++++++++++++++++ src/app/{ => (web)}/signup/page.tsx | 0 src/app/account/page.jsx | 162 ------------------ src/app/layout.tsx | 15 -- src/app/page.tsx | 13 -- .../panel-ui/doctor/app-sidebar.tsx | 1 - tsconfig.json | 2 +- 8 files changed, 164 insertions(+), 193 deletions(-) create mode 100644 src/app/(web)/account/page.jsx rename src/app/{ => (web)}/signup/page.tsx (100%) delete mode 100644 src/app/account/page.jsx delete mode 100644 src/app/layout.tsx delete mode 100644 src/app/page.tsx diff --git a/src/app/(panels)/suite/doctor/layout.tsx b/src/app/(panels)/suite/doctor/layout.tsx index 6c39b7d..091fbc7 100644 --- a/src/app/(panels)/suite/doctor/layout.tsx +++ b/src/app/(panels)/suite/doctor/layout.tsx @@ -10,7 +10,7 @@ export default function RootLayout({ }: { children: React.ReactNode }) { - const [isSidebarOpen, setIsSidebarOpen] = useState(true) + const [isSidebarOpen] = useState(true) return ( diff --git a/src/app/(web)/account/page.jsx b/src/app/(web)/account/page.jsx new file mode 100644 index 0000000..d42d1f6 --- /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/signup/page.tsx b/src/app/(web)/signup/page.tsx similarity index 100% rename from src/app/signup/page.tsx rename to src/app/(web)/signup/page.tsx diff --git a/src/app/account/page.jsx b/src/app/account/page.jsx deleted file mode 100644 index b52c66a..0000000 --- a/src/app/account/page.jsx +++ /dev/null @@ -1,162 +0,0 @@ -"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/layout.tsx b/src/app/layout.tsx deleted file mode 100644 index e4315e8..0000000 --- a/src/app/layout.tsx +++ /dev/null @@ -1,15 +0,0 @@ -"use client"; - -import './globals.css'; -import React from 'react'; - - -export default function RootLayout({ children }: { children: React.ReactNode }) { - return ( - - - {children} - - - ); -} diff --git a/src/app/page.tsx b/src/app/page.tsx deleted file mode 100644 index 1cff04d..0000000 --- a/src/app/page.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import RootLayout from './layout' -import SignupPage from './signup/page' - -export default function Home() { - return ( - -
-

Welcome to Hoya

- -
-
- ) -} diff --git a/src/components/panel-ui/doctor/app-sidebar.tsx b/src/components/panel-ui/doctor/app-sidebar.tsx index c35edd7..ed1f7a2 100644 --- a/src/components/panel-ui/doctor/app-sidebar.tsx +++ b/src/components/panel-ui/doctor/app-sidebar.tsx @@ -10,7 +10,6 @@ import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, - SidebarProvider, } from "@/components/ui/sidebar" export default function Sidebar() { diff --git a/tsconfig.json b/tsconfig.json index 32fdff5..b7a29c2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,6 +22,6 @@ "@/*": ["./src/*"] } }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app/api/connectDB.js", "src/lib/utils.js", "src/app/account/page.jsx"], + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app/api/connectDB.js", "src/lib/utils.js", "src/app/(web)/account/page.jsx"], "exclude": ["node_modules"] }