From 134e0344b9774ea3f4e0c9efe1cf5da925d361ad Mon Sep 17 00:00:00 2001 From: Arkadiusz Bachorski <60391032+arkadiuszbachorski@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:50:57 +0200 Subject: [PATCH] Add additional field from patient to the table --- app/(dashboard)/patients/PatientsTable.tsx | 1 + app/(dashboard)/patients/page.tsx | 22 +++++++++++++++++----- modules/firebase/utils.ts | 9 ++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/(dashboard)/patients/PatientsTable.tsx b/app/(dashboard)/patients/PatientsTable.tsx index 473ef4ec..c1c43df6 100644 --- a/app/(dashboard)/patients/PatientsTable.tsx +++ b/app/(dashboard)/patients/PatientsTable.tsx @@ -32,6 +32,7 @@ const columns = [ cell: (props) => props.getValue() ?? '-', }), columnHelper.accessor('email', { header: 'Email' }), + columnHelper.accessor('gender', { header: 'Gender' }), columnHelper.display({ id: 'actions', cell: () => ( diff --git a/app/(dashboard)/patients/page.tsx b/app/(dashboard)/patients/page.tsx index 8f1e13c1..3f288777 100644 --- a/app/(dashboard)/patients/page.tsx +++ b/app/(dashboard)/patients/page.tsx @@ -39,17 +39,29 @@ export const listPatients = async () => { const patientsQuery = await getPatientsQuery() const patients = await getDocs(patientsQuery) const userIdsToGet = patients.docs.map((patient) => ({ uid: patient.id })) + const patientsById = new Map( + patients.docs.map( + (patient) => [patient.id, { id: patient.id, ...patient.data() }] as const, + ), + ) const adminApp = getAdminApp() const adminAuth = getAuth(adminApp) // TODO: It can take max 100 users. Batch/paginate? Use getting by id? Fetch all and match? const users = await adminAuth.getUsers(userIdsToGet) - const usersData = users.users.map((user) => ({ - uid: user.uid, - email: user.email, - displayName: user.displayName, - })) + const usersData = users.users + .map((user) => { + const patient = patientsById.get(user.uid) + if (!patient) return null + return { + uid: user.uid, + email: user.email, + displayName: user.displayName, + gender: patient.GenderIdentityKey, + } + }) + .filter(Boolean) return usersData } diff --git a/modules/firebase/utils.ts b/modules/firebase/utils.ts index bb7f822e..cd9b940c 100644 --- a/modules/firebase/utils.ts +++ b/modules/firebase/utils.ts @@ -24,7 +24,14 @@ export interface Organization { export interface Admin {} -export interface User {} +export interface User { + GenderIdentityKey: string + invitationCode: string + clinician?: string + organization?: string + language?: string + timeZone?: string +} export interface Clinician { organization?: string