manifold/web/pages/[username]/index.tsx
Austin Chen 279437ba08
List users on admin page (#28)
* Admin page using gridjs

* Move hook into separate file

* Link to each user's Manifold and Firestore /user entry

* Gate admin access to Austin/James/Stephen

* Don't leak the existence of /admin

* Add a custom 404 page that directs to Discord.

* Fix broken window.location.href on NextJS server
2022-01-15 22:09:15 -05:00

29 lines
795 B
TypeScript

import { useRouter } from 'next/router'
import React, { useEffect, useState } from 'react'
import { getUserByUsername, User } from '../../lib/firebase/users'
import { UserPage } from '../../components/user-page'
import { useUser } from '../../hooks/use-user'
import Custom404 from '../404'
export default function UserProfile() {
const router = useRouter()
const [user, setUser] = useState<User | null | 'loading'>('loading')
const { username } = router.query as { username: string }
useEffect(() => {
if (username) {
getUserByUsername(username).then(setUser)
}
}, [username])
const currentUser = useUser()
if (user === 'loading') return <></>
return user ? (
<UserPage user={user} currentUser={currentUser || undefined} />
) : (
<Custom404 />
)
}