feat: implement NextUI & header

This commit is contained in:
M1000fr 2024-12-26 00:23:23 +01:00
parent 40e002e998
commit c54d6b2ea8
9 changed files with 2143 additions and 72 deletions

View File

@ -9,7 +9,12 @@
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {
"@nextui-org/navbar": "^2.2.7",
"@nextui-org/react": "^2.6.10",
"@nextui-org/system": "^2.4.5",
"@nextui-org/theme": "^2.4.4",
"axios": "^1.7.9", "axios": "^1.7.9",
"framer-motion": "^11.15.0",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.2",
"moment": "^2.30.1", "moment": "^2.30.1",
"next": "15.0.3", "next": "15.0.3",

View File

@ -0,0 +1,16 @@
"use client";
import { NextUIProvider } from "@nextui-org/react";
import { SessionProvider } from "next-auth/react";
export default function AppWrapper({
children,
}: {
children: React.ReactNode;
}) {
return (
<SessionProvider>
<NextUIProvider>{children}</NextUIProvider>
</SessionProvider>
);
}

View File

@ -1,31 +0,0 @@
"use client";
import { axiosInstance } from "@/app/lib/axios";
import { useState } from "react";
export const FetchApi = () => {
const [date, setDate] = useState<string | null>(null);
const handleFetch = async () => {
const response = await axiosInstance.get<{
message: string;
}>("/ping");
setDate(response.data.message);
};
return (
<div>
<button
className="text-white px-2 py-2 bg-green-500 rounded-md"
onClick={handleFetch}
>
Fetch API
</button>
{date ? (
<p>Server time: {date}</p>
) : (
<p>Click the button to fetch the API</p>
)}
</div>
);
};

View File

@ -1,28 +1,54 @@
import { getServerSession, Session } from "next-auth"; "use client";
import Link from "next/link"; import {
Avatar,
Dropdown,
DropdownItem,
DropdownMenu,
DropdownTrigger,
Navbar,
NavbarBrand,
NavbarContent,
} from "@nextui-org/react";
import { useSession } from "next-auth/react";
const Header = async () => { export const Header = () => {
const session = (await getServerSession()) as Session; const { data: session } = useSession();
return ( return (
<header className="bg-gray-900 text-white p-4"> <Navbar>
<div className="container mx-auto flex justify-between items-center"> <NavbarBrand>
<h1 className="text-xl font-bold">Toogether</h1> <p className="font-bold text-inherit">Toogether</p>
<div className="flex items-center gap-2"> </NavbarBrand>
<p> <NavbarContent as="div" justify="end">
Logged in as <strong>{session.user.name}</strong> <Dropdown placement="bottom-end">
</p> <DropdownTrigger>
<nav className="space-x-4"> <Avatar
<Link href="/auth/logout"> isBordered
<button className="bg-gray-800 px-4 py-2 rounded hover:scale-105 transition duration-200"> as="button"
Logout className="transition-transform"
</button> color="secondary"
</Link> name={session?.user?.name}
</nav> size="sm"
</div> />
</div> </DropdownTrigger>
</header> <DropdownMenu aria-label="Profile Actions" variant="flat">
<DropdownItem key="profile" className="h-14 gap-2">
<p>Signed in as</p>
<p className="font-semibold">
{session?.user?.name}
</p>
</DropdownItem>
<DropdownItem key="settings">Settings</DropdownItem>
<DropdownItem
key="logout"
color="danger"
href="/auth/logout"
>
Logout
</DropdownItem>
</DropdownMenu>
</Dropdown>
</NavbarContent>
</Navbar>
); );
}; };
export default Header;

View File

@ -1,11 +0,0 @@
"use client";
import { SessionProvider } from "next-auth/react";
export default function SessionProviderWrapper({
children,
}: {
children: React.ReactNode;
}) {
return <SessionProvider>{children}</SessionProvider>;
}

View File

@ -1,4 +1,4 @@
import SessionProviderWrapper from "./components/SessionProviderWrapper"; import AppWrapper from "./components/AppWrapper";
import "./globals.css"; import "./globals.css";
export default function RootLayout({ export default function RootLayout({
@ -9,7 +9,7 @@ export default function RootLayout({
return ( return (
<html lang="fr"> <html lang="fr">
<body> <body>
<SessionProviderWrapper>{children}</SessionProviderWrapper> <AppWrapper>{children}</AppWrapper>
</body> </body>
</html> </html>
); );

View File

@ -1,11 +1,9 @@
import Header from "./components/Header"; import { Header } from "./components/Header";
import { FetchApi } from "./components/FetchApi";
const HomePage = () => { const HomePage = () => {
return ( return (
<> <>
<Header /> <Header />
<FetchApi />
</> </>
); );
}; };

View File

@ -1,10 +1,12 @@
import type { Config } from "tailwindcss"; import type { Config } from "tailwindcss";
import { nextui } from "@nextui-org/react";
export default { export default {
content: [ content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}", "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}", "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}", "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
"./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}",
], ],
theme: { theme: {
extend: { extend: {
@ -24,5 +26,6 @@ export default {
}, },
}, },
}, },
plugins: [], darkMode: "class",
plugins: [nextui()],
} satisfies Config; } satisfies Config;

2067
yarn.lock

File diff suppressed because it is too large Load Diff