Skip to content

Commit

Permalink
Merge pull request #12 from aarontravass/ashu/webv2
Browse files Browse the repository at this point in the history
Ashu/webv2
  • Loading branch information
ashutoshspunyani99-tamu authored Jul 14, 2024
2 parents 7c5b868 + 1ce1f05 commit 5598651
Show file tree
Hide file tree
Showing 41 changed files with 9,128 additions and 9,636 deletions.
2 changes: 1 addition & 1 deletion packages/upload/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const PORT = parseInt(process.env.PORT || '3000')
export const PORT = parseInt(process.env.PORT || '3002')
export const APP_ENV = process.env.APP_ENV
export const FILEBASE_ACCESS_KEY_ID = process.env.FILEBASE_ACCESS_KEY_ID
export const FILEBASE_SECRET_ACCESS_KEY = process.env.FILEBASE_SECRET_ACCESS_KEY
Expand Down
2 changes: 2 additions & 0 deletions packages/web/.env
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/"
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"@privy-io/react-auth": "^1.73.2",
"@reduxjs/toolkit": "^2.2.6",
"@tailwindcss/typography": "^0.5.13",
"dotenv": "^16.4.5",
"graphql": "^16.9.0",
"next": "14.2.4",
"react": "^18",
"react-dom": "^18",
"react-file-previewer": "^0.6.3",
"react-redux": "^9.1.2",
"react-toastify": "^10.0.5",
"theme-change": "^2.5.0"
Expand Down
9 changes: 9 additions & 0 deletions packages/web/public/images/login/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed packages/web/public/images/login/mainLogo.png
Binary file not shown.
119 changes: 103 additions & 16 deletions packages/web/src/app/(protected)/doctor/dashboard/page.tsx
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
email
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
Loading

0 comments on commit 5598651

Please sign in to comment.