From 13590bf5d12e2f25c92cc37084525c29799055a7 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 24 Jan 2022 00:48:06 -0600 Subject: [PATCH] Surface user emails in /admin --- web/hooks/use-users.ts | 13 ++++++++++++- web/lib/firebase/users.ts | 10 +++++++++- web/pages/admin.tsx | 17 ++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/web/hooks/use-users.ts b/web/hooks/use-users.ts index 6d17be86..fbf5feaf 100644 --- a/web/hooks/use-users.ts +++ b/web/hooks/use-users.ts @@ -1,5 +1,6 @@ import { useState, useEffect } from 'react' -import { listenForAllUsers, User } from '../lib/firebase/users' +import { PrivateUser, User } from '../../common/user' +import { listenForAllUsers, listenForPrivateUsers } from '../lib/firebase/users' export const useUsers = () => { const [users, setUsers] = useState([]) @@ -10,3 +11,13 @@ export const useUsers = () => { return users } + +export const usePrivateUsers = () => { + const [users, setUsers] = useState([]) + + useEffect(() => { + listenForPrivateUsers(setUsers) + }, []) + + return users +} diff --git a/web/lib/firebase/users.ts b/web/lib/firebase/users.ts index 0f9ecf98..4141e6c6 100644 --- a/web/lib/firebase/users.ts +++ b/web/lib/firebase/users.ts @@ -20,7 +20,7 @@ import { } from 'firebase/auth' import { app } from './init' -import { User } from '../../../common/user' +import { PrivateUser, User } from '../../../common/user' import { createUser } from './api-call' import { getValues, listenForValues } from './utils' export type { User } @@ -125,6 +125,14 @@ export function listenForAllUsers(setUsers: (users: User[]) => void) { listenForValues(q, setUsers) } +export function listenForPrivateUsers( + setUsers: (users: PrivateUser[]) => void +) { + const userCollection = collection(db, 'private-users') + const q = query(userCollection) + listenForValues(q, setUsers) +} + const topTradersQuery = query( collection(db, 'users'), orderBy('totalPnLCached', 'desc'), diff --git a/web/pages/admin.tsx b/web/pages/admin.tsx index 992d8bee..e003eacb 100644 --- a/web/pages/admin.tsx +++ b/web/pages/admin.tsx @@ -3,10 +3,11 @@ import { Grid } from 'gridjs-react' import 'gridjs/dist/theme/mermaid.css' import { html } from 'gridjs' import dayjs from 'dayjs' -import { useUsers } from '../hooks/use-users' +import { usePrivateUsers, useUsers } from '../hooks/use-users' import { useUser } from '../hooks/use-user' import Custom404 from './404' import { useContracts } from '../hooks/use-contracts' +import _ from 'lodash' function avatarHtml(avatarUrl: string) { return ` { + // @ts-ignore + user.email = privateUsersById[user.id]?.email + return user + }) + // Sort users by createdTime descending, by default users = users.sort((a, b) => b.createdTime - a.createdTime) @@ -162,6 +176,7 @@ export default function Admin() { 'igi2zGXsfxYPgB0DJTXVJVmwCOr2', // Austin '5LZ4LgYuySdL1huCWe7bti02ghx2', // James 'tlmGNz9kjXc2EteizMORes4qvWl2', // Stephen + 'IPTOzEqrpkWmEzh6hwvAyY9PqFb2', // Manifold ] const isAdmin = adminIds.includes(user?.id || '') return isAdmin ? (