-
Notifications
You must be signed in to change notification settings - Fork 53
updated dashboard #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
updated dashboard #192
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| 'use client'; | ||
|
|
||
| import { useRouter } from 'next/navigation'; | ||
| import { useEffect, type ReactNode } from 'react'; | ||
| import { Sidebar } from '../../components/Sidebar'; | ||
| import { useAuth } from '../../lib/auth-context'; | ||
|
|
||
| export default function DashboardLayout({ children }: { children: ReactNode }) { | ||
| const { user, isLoading } = useAuth(); | ||
| const router = useRouter(); | ||
|
|
||
| useEffect(() => { | ||
| if (!isLoading && !user) { | ||
| router.replace('/login'); | ||
| } | ||
| }, [isLoading, user, router]); | ||
|
|
||
| if (isLoading || !user) return null; | ||
|
|
||
| return ( | ||
| <div style={{ display: 'flex', minHeight: '100vh' }}> | ||
| <Sidebar /> | ||
| <main style={{ flex: 1, padding: '2rem' }}>{children}</main> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export default function DashboardPage() { | ||
| return ( | ||
| <div> | ||
| <h1 style={{ fontWeight: 700, fontSize: '1.5rem', marginBottom: '0.5rem' }}>Dashboard</h1> | ||
| <p style={{ color: '#6b7280' }}>Welcome back. More stats coming soon.</p> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| 'use client'; | ||
|
|
||
| import Link from 'next/link'; | ||
| import { usePathname } from 'next/navigation'; | ||
| import { useAuth } from '../lib/auth-context'; | ||
|
|
||
| const NAV_LINKS = [ | ||
| { href: '/dashboard', label: 'Dashboard' }, | ||
| { href: '/dashboard/restaurants', label: 'Restaurants' }, | ||
| { href: '/dashboard/menu', label: 'Menu' }, | ||
| { href: '/dashboard/orders', label: 'Orders' }, | ||
| { href: '/dashboard/settings', label: 'Settings' }, | ||
| ] as const; | ||
|
|
||
| export function Sidebar() { | ||
| const pathname = usePathname(); | ||
| const { user, logout } = useAuth(); | ||
|
|
||
| return ( | ||
| <aside | ||
| style={{ | ||
| width: '220px', | ||
| minHeight: '100vh', | ||
| borderRight: '1px solid #e5e7eb', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| padding: '1.5rem 1rem', | ||
| gap: '0.25rem', | ||
| }} | ||
| > | ||
| <p style={{ fontWeight: 700, fontSize: '1.1rem', marginBottom: '1rem' }}>Discoverly</p> | ||
|
|
||
| <nav style={{ display: 'flex', flexDirection: 'column', gap: '0.25rem', flex: 1 }}> | ||
| {NAV_LINKS.map(({ href, label }) => { | ||
| const isActive = pathname === href; | ||
| return ( | ||
| <Link | ||
| key={href} | ||
| href={href} | ||
| aria-current={isActive ? 'page' : undefined} | ||
| style={{ | ||
| padding: '0.5rem 0.75rem', | ||
| borderRadius: '6px', | ||
| textDecoration: 'none', | ||
| fontWeight: isActive ? 600 : 400, | ||
| background: isActive ? '#f3f4f6' : 'transparent', | ||
| color: '#111827', | ||
| }} | ||
| > | ||
| {label} | ||
| </Link> | ||
| ); | ||
| })} | ||
| </nav> | ||
|
|
||
| {user && ( | ||
| <div style={{ borderTop: '1px solid #e5e7eb', paddingTop: '1rem' }}> | ||
| <p style={{ fontSize: '0.8rem', color: '#6b7280', marginBottom: '0.5rem' }}>{user.email}</p> | ||
| <button | ||
| type="button" | ||
| onClick={logout} | ||
| style={{ fontSize: '0.85rem', cursor: 'pointer', background: 'none', border: 'none', color: '#ef4444' }} | ||
| > | ||
| Sign out | ||
| </button> | ||
| </div> | ||
| )} | ||
| </aside> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auth guard destructs user from useAuth() but ignores isLoading. On first render user is null (localStorage hasn't been read yet), so the guard fires router.replace('/login') immediately — an authenticated user gets bounced to login and back in a flash. The fix is to wait until isLoading === false before evaluating user.