Surface user emails in /admin
This commit is contained in:
parent
e7ef6134b5
commit
13590bf5d1
|
@ -1,5 +1,6 @@
|
||||||
import { useState, useEffect } from 'react'
|
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 = () => {
|
export const useUsers = () => {
|
||||||
const [users, setUsers] = useState<User[]>([])
|
const [users, setUsers] = useState<User[]>([])
|
||||||
|
@ -10,3 +11,13 @@ export const useUsers = () => {
|
||||||
|
|
||||||
return users
|
return users
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const usePrivateUsers = () => {
|
||||||
|
const [users, setUsers] = useState<PrivateUser[]>([])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
listenForPrivateUsers(setUsers)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return users
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import {
|
||||||
} from 'firebase/auth'
|
} from 'firebase/auth'
|
||||||
|
|
||||||
import { app } from './init'
|
import { app } from './init'
|
||||||
import { User } from '../../../common/user'
|
import { PrivateUser, User } from '../../../common/user'
|
||||||
import { createUser } from './api-call'
|
import { createUser } from './api-call'
|
||||||
import { getValues, listenForValues } from './utils'
|
import { getValues, listenForValues } from './utils'
|
||||||
export type { User }
|
export type { User }
|
||||||
|
@ -125,6 +125,14 @@ export function listenForAllUsers(setUsers: (users: User[]) => void) {
|
||||||
listenForValues(q, setUsers)
|
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(
|
const topTradersQuery = query(
|
||||||
collection(db, 'users'),
|
collection(db, 'users'),
|
||||||
orderBy('totalPnLCached', 'desc'),
|
orderBy('totalPnLCached', 'desc'),
|
||||||
|
|
|
@ -3,10 +3,11 @@ import { Grid } from 'gridjs-react'
|
||||||
import 'gridjs/dist/theme/mermaid.css'
|
import 'gridjs/dist/theme/mermaid.css'
|
||||||
import { html } from 'gridjs'
|
import { html } from 'gridjs'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { useUsers } from '../hooks/use-users'
|
import { usePrivateUsers, useUsers } from '../hooks/use-users'
|
||||||
import { useUser } from '../hooks/use-user'
|
import { useUser } from '../hooks/use-user'
|
||||||
import Custom404 from './404'
|
import Custom404 from './404'
|
||||||
import { useContracts } from '../hooks/use-contracts'
|
import { useContracts } from '../hooks/use-contracts'
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
function avatarHtml(avatarUrl: string) {
|
function avatarHtml(avatarUrl: string) {
|
||||||
return `<img
|
return `<img
|
||||||
|
@ -18,6 +19,19 @@ function avatarHtml(avatarUrl: string) {
|
||||||
|
|
||||||
function UsersTable() {
|
function UsersTable() {
|
||||||
let users = useUsers()
|
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
|
// Sort users by createdTime descending, by default
|
||||||
users = users.sort((a, b) => b.createdTime - a.createdTime)
|
users = users.sort((a, b) => b.createdTime - a.createdTime)
|
||||||
|
|
||||||
|
@ -162,6 +176,7 @@ export default function Admin() {
|
||||||
'igi2zGXsfxYPgB0DJTXVJVmwCOr2', // Austin
|
'igi2zGXsfxYPgB0DJTXVJVmwCOr2', // Austin
|
||||||
'5LZ4LgYuySdL1huCWe7bti02ghx2', // James
|
'5LZ4LgYuySdL1huCWe7bti02ghx2', // James
|
||||||
'tlmGNz9kjXc2EteizMORes4qvWl2', // Stephen
|
'tlmGNz9kjXc2EteizMORes4qvWl2', // Stephen
|
||||||
|
'IPTOzEqrpkWmEzh6hwvAyY9PqFb2', // Manifold
|
||||||
]
|
]
|
||||||
const isAdmin = adminIds.includes(user?.id || '')
|
const isAdmin = adminIds.includes(user?.id || '')
|
||||||
return isAdmin ? (
|
return isAdmin ? (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user