import { Page } from '../components/page' import { Grid } from 'gridjs-react' import 'gridjs/dist/theme/mermaid.css' import { html } from 'gridjs' import dayjs from 'dayjs' 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 `` } 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) return ( html(avatarHtml(cell as string)), }, { id: 'username', name: 'Username', formatter: (cell) => html(`@${cell}`), }, 'Email', { id: 'createdTime', name: 'Created Time', formatter: (cell) => html( `${dayjs(cell as number).format( 'MMM D, h:mma' )}` ), }, { id: 'balance', name: 'Balance', formatter: (cell) => (cell as number).toFixed(0), }, { id: 'id', name: 'ID', formatter: (cell) => html(`${cell}`), }, ]} search={true} sort={true} pagination={{ enabled: true, limit: 25, }} /> ) } function ContractsTable() { let contracts = useContracts() ?? [] // Sort users by createdTime descending, by default contracts.sort((a, b) => b.createdTime - a.createdTime) return ( html(`@${cell}`), }, { id: 'question', name: 'Question', formatter: (cell) => html(`
${cell}
`), }, { id: 'volume24Hours', name: '24h vol', formatter: (cell) => (cell as number).toFixed(0), }, { id: 'createdTime', name: 'Created time', formatter: (cell) => html( `${dayjs(cell as number).format( 'MMM D, h:mma' )}` ), }, { id: 'closeTime', name: 'Close time', formatter: (cell) => html( `${dayjs(cell as number).format( 'MMM D, h:mma' )}` ), }, { id: 'resolvedTime', name: 'Resolved time', formatter: (cell) => html( `${dayjs(cell as number).format( 'MMM D, h:mma' )}` ), }, { id: 'visibility', name: 'Visibility', formatter: (cell) => cell, }, { id: 'id', name: 'ID', formatter: (cell) => html(`${cell}`), }, ]} search={true} sort={true} pagination={{ enabled: true, limit: 25, }} /> ) } export default function Admin() { const user = useUser() const adminIds = [ 'igi2zGXsfxYPgB0DJTXVJVmwCOr2', // Austin '5LZ4LgYuySdL1huCWe7bti02ghx2', // James 'tlmGNz9kjXc2EteizMORes4qvWl2', // Stephen 'IPTOzEqrpkWmEzh6hwvAyY9PqFb2', // Manifold ] const isAdmin = adminIds.includes(user?.id || '') return isAdmin ? ( ) : ( ) }