diff --git a/src/app/(web)/account/page.jsx b/src/app/(web)/account/page.jsx index 7a6711f..2eff506 100644 --- a/src/app/(web)/account/page.jsx +++ b/src/app/(web)/account/page.jsx @@ -1,31 +1,32 @@ -"use client"; +"use client" import { useState, useEffect } from 'react'; import axios from 'axios'; -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'; +import { useUser } from '@clerk/clerk-react'; +import { Button, Input, Label, Card, CardHeader, CardBody, CardFooter } from 'components/ui'; const AccountPage = () => { - const [user, setUser] = useState(null); + 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(() => { - axios.get('/api/user').then(response => { - setUser(response.data); - if (response.data.role === 'caregiver') { - axios.get('/api/patients').then(res => setPatients(res.data)); - } - }); - }, []); + 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 = user.role === 'patient' ? 'caregiver' : 'patient'; - await axios.put('/api/user', { role: newRole }); - setUser({ ...user, role: newRole }); + 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 { @@ -58,7 +59,7 @@ const AccountPage = () => { alert('Patient data updated successfully'); }; - if (!user) return
{user.name}
+{userData.name}
{user.email}
+{userData.email}
{user.role}
+{userData.role}