Skip to content

Commit

Permalink
Merge pull request #36 from nokierae/authenticated_layout
Browse files Browse the repository at this point in the history
Base authenticated layout
  • Loading branch information
nokierae committed Dec 18, 2023
2 parents a83081b + e50106a commit 979d019
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 3,213 deletions.
6 changes: 3 additions & 3 deletions .husky/check_unstaged.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@


def print_red(text):
return f"\033[91m{text}\033[0m"
return "\033[91m{}\033[0m".format(text)


def print_green(text):
# ANSI escape code for green text
return f"\033[92m{text}\033[0m"
return "\033[92m{}\033[0m".format(text)


def check_unstaged_files():
Expand All @@ -24,7 +24,7 @@ def check_unstaged_files():
)
print(print_red("git commit --amend"))
except subprocess.CalledProcessError as e:
print(f"Error: Unable to execute 'git hook'. {e}")
print("Error: Unable to execute 'git hook'. {}".format(e))


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function create(): Response
public function store(LoginRequest $request): RedirectResponse
{
$request->authenticate();

$request->session()->regenerate();

return redirect()->intended(RouteServiceProvider::HOME);
Expand Down
2,985 changes: 112 additions & 2,873 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
},
"devDependencies": {
"@headlessui/react": "^1.4.2",
"@heroicons/react": "^2.0.18",
"@inertiajs/react": "^1.0.0",
"@nextui-org/react": "^2.2.9",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.10",
"@types/node": "^18.13.0",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.10",
"@types/ziggy-js": "^1.3.2",
"@vitejs/plugin-react": "^4.0.3",
"autoprefixer": "^10.4.12",
"axios": "^1.6.1",
"daisyui": "^4.4.19",
"framer-motion": "^10.16.5",
"husky": "^8.0.3",
"laravel-vite-plugin": "^0.8.0",
Expand Down
12 changes: 12 additions & 0 deletions resources/js/Components/Brand.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function Brand() {
return (
<div className="flex justify-between items-center space-x-2">
<img className="h-6" src="/ul-logo.png" />
<div className="text-2xl">
<span className="text-primary">Unlock</span>
<span className="text-secondary">Ed</span>
<span className="text-base">v2</span>
</div>
</div>
);
}
42 changes: 20 additions & 22 deletions resources/js/Components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,30 @@ const Content = ({
}

return (
<>
<Transition
as={Fragment}
show={open}
enter="transition ease-out duration-200"
enterFrom="opacity-0 scale-95"
enterTo="opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95"
<Transition
as={Fragment}
show={open}
enter="transition ease-out duration-200"
enterFrom="opacity-0 scale-95"
enterTo="opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95"
>
<div
className={`absolute z-50 mt-2 rounded-md shadow-lg ${alignmentClasses} ${widthClasses}`}
onClick={() => setOpen(false)}
>
<div
className={`absolute z-50 mt-2 rounded-md shadow-lg ${alignmentClasses} ${widthClasses}`}
onClick={() => setOpen(false)}
className={
`rounded-md ring-1 ring-black ring-opacity-5 ` +
contentClasses
}
>
<div
className={
`rounded-md ring-1 ring-black ring-opacity-5 ` +
contentClasses
}
>
{children}
</div>
{children}
</div>
</Transition>
</>
</div>
</Transition>
);
};

Expand Down
57 changes: 57 additions & 0 deletions resources/js/Components/LeftMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Brand from "./Brand";
import { HomeIcon, UsersIcon, ArchiveBoxIcon } from "@heroicons/react/24/solid";

export default function LeftMenu() {
return (
<ul className="menu bg-base-200 w-64 rounded-box">
<li>
<a href="/" className="mb-4">
<Brand />
</a>
</li>

<li>
<a>
<HomeIcon className="w-4" /> Dashboard
</a>
</li>
<li>
<a>
<UsersIcon className="w-4" /> Users
</a>
</li>
<li>
<details>
<summary>
<ArchiveBoxIcon className="w-4" />
Category 1
</summary>
<ul>
<li>
<a>Link 1</a>
</li>
<li>
<a>Link 2</a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary>
<ArchiveBoxIcon className="w-4" />
Category 2
</summary>
<ul>
<li>
<a>Link 1</a>
</li>
<li>
<a>Link 2</a>
</li>
</ul>
</details>
</li>
</ul>
);
}
183 changes: 13 additions & 170 deletions resources/js/Layouts/AuthenticatedLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,179 +1,22 @@
import { useState, PropsWithChildren, ReactNode } from "react";
import ApplicationLogo from "@/Components/ApplicationLogo";
import Dropdown from "@/Components/Dropdown";
import NavLink from "@/Components/NavLink";
import ResponsiveNavLink from "@/Components/ResponsiveNavLink";
import { Link } from "@inertiajs/react";
import { PropsWithChildren } from "react";
import { User } from "@/types";
import { Head } from "@inertiajs/react";
import LeftMenu from "@/Components/LeftMenu";

export default function Authenticated({
user,
header,
title,
children,
}: PropsWithChildren<{ user: User; header?: ReactNode }>) {
const [showingNavigationDropdown, setShowingNavigationDropdown] =
useState(false);

}: PropsWithChildren<{ user: User; title: string }>) {
return (
<div className="min-h-screen bg-slate-100 dark:bg-slate-900">
<nav className="bg-white dark:bg-slate-800 border-b border-slate-100 dark:border-slate-700">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex justify-between h-16">
<div className="flex">
<div className="shrink-0 flex items-center">
<Link href="/">
<ApplicationLogo className="block h-8 w-auto fill-current text-slate-800 dark:text-slate-200" />
</Link>
</div>

<div className="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
<NavLink
href={route("dashboard")}
active={route().current("dashboard")}
>
Dashboard
</NavLink>
</div>
</div>

<div className="hidden sm:flex sm:items-center sm:ms-6">
<div className="ms-3 relative">
<Dropdown>
<Dropdown.Trigger>
<span className="inline-flex rounded-md">
<button
type="button"
className="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-slate-500 dark:text-slate-400 bg-white dark:bg-slate-800 hover:text-slate-700 dark:hover:text-slate-300 focus:outline-none transition ease-in-out duration-150"
>
{`${user.name_first} ${user.name_last}`}

<svg
className="ms-2 -me-0.5 h-4 w-4"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fillRule="evenodd"
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
clipRule="evenodd"
/>
</svg>
</button>
</span>
</Dropdown.Trigger>

<Dropdown.Content>
<Dropdown.Link
href={route("profile.edit")}
>
Profile
</Dropdown.Link>
<Dropdown.Link
href={route("logout")}
method="post"
as="button"
>
Log Out
</Dropdown.Link>
</Dropdown.Content>
</Dropdown>
</div>
</div>

<div className="-me-2 flex items-center sm:hidden">
<button
onClick={() =>
setShowingNavigationDropdown(
(previousState) => !previousState,
)
}
className="inline-flex items-center justify-center p-2 rounded-md text-slate-400 dark:text-slate-500 hover:text-slate-500 dark:hover:text-slate-400 hover:bg-slate-100 dark:hover:bg-slate-900 focus:outline-none focus:bg-slate-100 dark:focus:bg-slate-900 focus:text-slate-500 dark:focus:text-slate-400 transition duration-150 ease-in-out"
>
<svg
className="h-6 w-6"
stroke="currentColor"
fill="none"
viewBox="0 0 24 24"
>
<path
className={
!showingNavigationDropdown
? "inline-flex"
: "hidden"
}
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M4 6h16M4 12h16M4 18h16"
/>
<path
className={
showingNavigationDropdown
? "inline-flex"
: "hidden"
}
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
</div>
</div>

<div
className={
(showingNavigationDropdown ? "block" : "hidden") +
" sm:hidden"
}
>
<div className="pt-2 pb-3 space-y-1">
<ResponsiveNavLink
href={route("dashboard")}
active={route().current("dashboard")}
>
Dashboard
</ResponsiveNavLink>
</div>

<div className="pt-4 pb-1 border-t border-slate-200 dark:border-slate-600">
<div className="px-4">
<div className="font-medium text-base text-slate-800 dark:text-slate-200">
{`${user.name_first} ${user.name_last}`}
</div>
<div className="font-medium text-sm text-slate-500">
{user.email}
</div>
</div>

<div className="mt-3 space-y-1">
<ResponsiveNavLink href={route("profile.edit")}>
Profile
</ResponsiveNavLink>
<ResponsiveNavLink
method="post"
href={route("logout")}
as="button"
>
Log Out
</ResponsiveNavLink>
</div>
</div>
</div>
</nav>

{header && (
<header className="bg-white dark:bg-slate-800 shadow">
<div className="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
{header}
</div>
</header>
)}

<main>{children}</main>
<div>
<Head title={title} />
<div className="flex">
<LeftMenu />
<main className="w-full min-h-screen bg-slate-300 text-base-100 p-4">
{children}
</main>
</div>
</div>
);
}
15 changes: 2 additions & 13 deletions resources/js/Pages/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { Head } from "@inertiajs/react";
import { PageProps } from "@/types";

export default function Dashboard({ auth }: PageProps) {
return (
<AuthenticatedLayout user={auth.user}>
<Head title="Dashboard" />

<div className="py-12">
<div className="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div className="bg-white dark:bg-slate-800 overflow-hidden shadow-sm sm:rounded-lg">
<div className="p-6 text-slate-900 dark:text-slate-100">
You're logged in!
</div>
</div>
</div>
</div>
<AuthenticatedLayout user={auth.user} title="Dashboard">
<h1 className="font-semibold text-2xl">Dashboard</h1>
</AuthenticatedLayout>
);
}
Loading

0 comments on commit 979d019

Please sign in to comment.