added admin layout

This commit is contained in:
2024-04-27 00:40:27 +03:00
parent f17a002ac6
commit db66161d81
15 changed files with 566 additions and 36 deletions

View File

@@ -0,0 +1,47 @@
// eslint-disable-next-line validate-filename/naming-rules
'use client'
import { Button } from '@/components/ui/button'
import Link from 'next/link'
import { USER_PROFILE_URL } from '@/config/routes'
import { usePathname } from 'next/navigation'
import UserButton from '@/components/auth/user-button'
import LocaleSwitcher from '@/components/locale-switcher'
const Navbar = () => {
const pathname = usePathname()
//
return (
<nav className="bg-secondary flex justify-between items-center top-0 absolute px-6 py-4 w-full shadow-sm">
<div className="flex gap-x-4">
<Button asChild variant={pathname.match(/^\/(en\/|)server/) ? 'default' : 'outline'}>
<Link href={'/server'}>
Server
</Link>
</Button>
<Button asChild variant={pathname.match(/^\/(en\/|)client/) ? 'default' : 'outline'}>
<Link href={'/client'}>
Client
</Link>
</Button>
<Button asChild variant={pathname.match(/^\/(en\/|)admin/) ? 'default' : 'outline'}>
<Link href={'/admin'}>
Admin
</Link>
</Button>
<Button asChild variant={pathname.match(/^\/(en\/|)cabinet/) ? 'default' : 'outline'}>
<Link href={USER_PROFILE_URL}>
Cabinet
</Link>
</Button>
</div>
<div className="flex gap-x-2">
<LocaleSwitcher/>
<UserButton/>
</div>
</nav>
)
}
export default Navbar

View File

@@ -1,17 +1,15 @@
import { auth, signOut } from '@/config/auth'
'use client'
const CabinetPage = async () => {
const session = await auth()
import { logout } from '@/actions/logout'
import { useCurrentUser } from '@/hooks/useCurrentUser'
const CabinetPage = () => {
const user = useCurrentUser()
const btnOnClick = () => logout()
return (
<div>
{JSON.stringify(session)}
<form action={async () => {
'use server'
await signOut()
}}>
<button type="submit">SignOut {session?.user.role}</button>
</form>
<div className="bg-neutral-100 p-10">
<button onClick={btnOnClick} type="submit">SignOut</button>
</div>
)
}

View File

@@ -0,0 +1,17 @@
import Navbar from '@/app/[locale]/(protected)/_components/navbar'
interface ProtectedLayoutProps {
children: React.ReactNode;
}
const ProtectedLayout = ({ children }: ProtectedLayoutProps) => {
return (
<main
className="w-full h-full flex flex-col justify-center items-center gap-y-10 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-sky-400 to-blue-800">
<Navbar/>
{children}
</main>
)
}
export default ProtectedLayout

View File

@@ -4,6 +4,8 @@ import { ReactElement } from 'react'
import { I18nProviderClient } from '@/locales/client'
import { lc } from '@/lib/utils'
import './globals.css'
import { SessionProvider } from 'next-auth/react'
import { auth } from '@/config/auth'
const inter = Inter({ subsets: ['cyrillic'] })
@@ -15,13 +17,16 @@ type RootLayoutProps = {
params: { locale: string }; children: ReactElement;
}
export default function RootLayout ({ params: { locale }, children }: Readonly<RootLayoutProps>) {
export default async function RootLayout ({ params: { locale }, children }: Readonly<RootLayoutProps>) {
const session = await auth()
return (<html lang={lc(locale)?.java}>
<body className={inter.className}>
<I18nProviderClient locale={locale} fallback="Loading...">
{children}
</I18nProviderClient>
</body>
</html>)
return (<SessionProvider session={session}>
<html lang={lc(locale)?.java}>
<body className={inter.className}>
<I18nProviderClient locale={locale} fallback="Loading...">
{children}
</I18nProviderClient>
</body>
</html>
</SessionProvider>)
}