-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from aarontravass/ashu/webv2
Ashu/webv2
- Loading branch information
Showing
41 changed files
with
9,128 additions
and
9,636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NEXT_PUBLIC_WEB_URL="http://localhost:3001/" | ||
NEXT_PUBLIC_API_URL="http://localhost:3000/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
119 changes: 103 additions & 16 deletions
119
packages/web/src/app/(protected)/doctor/dashboard/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,114 @@ | ||
'use client' | ||
import { usePrivy } from '@privy-io/react-auth' | ||
import { useRouter } from 'next/navigation' | ||
import ErrorText from '@/components/typography/error-text' | ||
import SuccessText from '@/components/typography/success-text' | ||
import { APP_NAME, APP_NAME_TITLE } from '@/helper/constants' | ||
import { PatientsListData } from '@/lib/models' | ||
import { gql, useMutation, useQuery } from '@apollo/client' | ||
import Head from 'next/head' | ||
import { useEffect, useState } from 'react' | ||
|
||
const PatientDashboard = () => { | ||
const { ready, authenticated, user } = usePrivy() | ||
console.log(user) | ||
const router = useRouter() | ||
const [patientsList, setPatientsList] = useState<PatientsListData[]>([]) | ||
const [selectedPatientId, setSelectedPatientId] = useState<string>('') | ||
const [successMessage, setSuccessMessage] = useState<string>('') | ||
const [errorMessage, setErrorMessage] = useState<string>('') | ||
|
||
if (!ready) { | ||
// Do nothing while the PrivyProvider initializes with updated user state | ||
return <></> | ||
} | ||
const FETCH_ALL_PATIENTS = gql` | ||
query FetchAllPatients { | ||
fetchAllPatients { | ||
createdAt | ||
id | ||
name | ||
updatedAt | ||
} | ||
} | ||
` | ||
|
||
const ADD_PATIENT = gql` | ||
mutation AddPatient($patientId: ID!) { | ||
addPatient(patientId: $patientId) | ||
} | ||
` | ||
|
||
if (ready && !authenticated) { | ||
// Replace this code with however you'd like to handle an unauthenticated user | ||
// As an example, you might redirect them to a login page | ||
router.push('/login') | ||
const [addPatient, { data: addPatientData, loading: addPatientLoading, error: addPatientError }] = useMutation( | ||
ADD_PATIENT, | ||
{ | ||
context: { appTokenName: APP_NAME + ':token' } | ||
} | ||
) | ||
|
||
const onAddingThePatient = async () => { | ||
setSuccessMessage('') | ||
setErrorMessage('') | ||
await addPatient({ variables: { patientId: selectedPatientId } }) | ||
.then(async (result) => { | ||
console.log({ result }) | ||
setSuccessMessage('Patient Added successfully!') | ||
}) | ||
.catch((error) => { | ||
console.error({ error }) | ||
setErrorMessage(error?.message) | ||
}) | ||
setSuccessMessage('') | ||
setErrorMessage('') | ||
} | ||
|
||
if (ready && authenticated) { | ||
// Replace this code with however you'd like to handle an authenticated user | ||
return <p>User {user?.email?.address} is logged in.</p> | ||
const onPatientChange = (event: React.ChangeEvent<HTMLSelectElement>) => { | ||
console.log(event.target.value) | ||
setSelectedPatientId(event.target.value) | ||
} | ||
|
||
const { data: patientsListData, error: patientsListDataError } = useQuery(FETCH_ALL_PATIENTS, { | ||
context: { appTokenName: APP_NAME + ':token' } | ||
}) | ||
|
||
useEffect(() => { | ||
const docsData = patientsListData?.fetchAllPatients | ||
if (docsData) { | ||
console.log({ docsData }) | ||
setPatientsList(docsData) | ||
} | ||
}, [patientsListData]) | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>{APP_NAME_TITLE} | Doctors - Add Patient</title> | ||
</Head> | ||
<div className="form-control w-full mt-4"> | ||
<label className="label"> | ||
<p>Select a patient to add to your list</p> | ||
</label> | ||
{patientsList.length > 0 && ( | ||
<select onChange={onPatientChange} defaultValue="" className="select select-bordered w-full max-w-md"> | ||
<option disabled value=""> | ||
Select an email address | ||
</option> | ||
{patientsList.map((pat: PatientsListData, k: number) => ( | ||
<option key={k} value={pat.id}> | ||
{pat.email} | ||
</option> | ||
))} | ||
</select> | ||
)} | ||
</div> | ||
|
||
{selectedPatientId && ( | ||
<div className="grid"> | ||
<button | ||
disabled={addPatientLoading} | ||
className="btn px-6 btn-sm normal-case btn-primary max-w-md mt-4" | ||
onClick={onAddingThePatient} | ||
> | ||
Add patient to the doctor | ||
</button> | ||
</div> | ||
)} | ||
{errorMessage && <ErrorText>{errorMessage}</ErrorText>} | ||
{successMessage && <SuccessText>{successMessage}</SuccessText>} | ||
</> | ||
) | ||
} | ||
|
||
export default PatientDashboard |
Oops, something went wrong.