Surface user emails in /admin

This commit is contained in:
Austin Chen 2022-01-24 00:48:06 -06:00
parent e7ef6134b5
commit 13590bf5d1
3 changed files with 37 additions and 3 deletions

View File

@ -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<User[]>([])
@ -10,3 +11,13 @@ export const useUsers = () => {
return users
}
export const usePrivateUsers = () => {
const [users, setUsers] = useState<PrivateUser[]>([])
useEffect(() => {
listenForPrivateUsers(setUsers)
}, [])
return users
}

View File

@ -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'),

View File

@ -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 `<img
@ -18,6 +19,19 @@ function avatarHtml(avatarUrl: string) {
function UsersTable() {
let users = useUsers()
let privateUsers = usePrivateUsers()
// Map private users by user id
const privateUsersById = _.mapKeys(privateUsers, 'id')
console.log('private users by id', privateUsersById)
// For each user, set their email from the PrivateUser
users = users.map((user) => {
// @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 ? (