Files
pfadi-bussle/components/navigation.tsx
2022-12-22 23:36:33 +01:00

50 lines
1.3 KiB
TypeScript

import { useRouter } from 'next/router'
import Link from 'next/link'
import { useSession } from 'next-auth/react'
import User from './user'
const pathNameLabelMap = {
'/login': 'Login',
'/admin': 'Buchungsübersicht',
'/admin/booking/[uuid]': 'Buchung Bearbeiten',
'/admin/booking/[uuid]/bill': 'Buchung Rechnungsstellung',
'/book': 'Buchungsanfrage',
'/booking/[uuid]': 'Ihre Buchung',
'/booking/[uuid]/stored': 'Buchungsanfrage angenommen',
}
function getPathNameMap(route: string) {
return pathNameLabelMap[route]
}
export default function Navigation() {
const { data, status } = useSession()
const router = useRouter()
const pathname = router.pathname
if (pathname.length === 0 || pathname === '/') {
return null
}
const pathLabel = getPathNameMap(pathname)
return (
<div className="flex flex-row items-center px-3 py-1 text-white text-base bg-blue-400 rounded-b-sm">
<>
<h2 className="mx-1">
<span className="font-extrabold">{pathLabel}</span>
</h2>
{status === 'authenticated' && data.user.email && (
<Link href="/admin" className="text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium">
Buchungen
</Link>
)}
<div className="flex-grow" />
<User />
</>
</div>
)
}