-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: management dashboard (#699)
Showing
20 changed files
with
824 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,36 @@ | ||
import { Metadata } from 'next'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
import { validateRequest } from '@/lib/auth'; | ||
|
||
import PrivateHeader from '@/components/private/header'; | ||
|
||
export const metadata: Metadata = { | ||
title: 'Dashboard | Sainseni Community', | ||
authors: [ | ||
{ | ||
name: 'Khoironi Kurnia Syah', | ||
url: 'https://zekhoi.dev', | ||
}, | ||
], | ||
description: 'Community for community', | ||
}; | ||
|
||
export default async function PrivateLayout({ | ||
children, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
}>) { | ||
const { session, user } = await validateRequest(); | ||
|
||
if (!session || !user) { | ||
return redirect('/auth'); | ||
} | ||
|
||
return ( | ||
<div className='flex flex-col min-h-screen bg-white text-gray-800'> | ||
<PrivateHeader /> | ||
{children} | ||
</div> | ||
); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,120 @@ | ||
'use client'; | ||
|
||
import { CircleUser, Menu, Sparkles } from 'lucide-react'; | ||
import Link from 'next/link'; | ||
import { usePathname } from 'next/navigation'; | ||
|
||
import { Button } from '@/components/ui/button'; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuLabel, | ||
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from '@/components/ui/dropdown-menu'; | ||
import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'; | ||
|
||
const navbarMenu = [ | ||
{ name: 'Dashboard', url: '/dashboard' }, | ||
{ name: 'Projects', url: '/dashboard/projects' }, | ||
{ name: 'Friends', url: '/dashboard/friends' }, | ||
{ name: 'References', url: '/dashboard/references' }, | ||
{ name: 'Events', url: '/dashboard/events' }, | ||
{ name: 'Users', url: '/dashboard/users' }, | ||
{ name: 'Roles', url: '/dashboard/roles' }, | ||
{ name: 'Keys', url: '/dashboard/keys' }, | ||
]; | ||
|
||
export default function PrivateHeader() { | ||
const pathname = usePathname(); | ||
|
||
const isActive = (path: string) => { | ||
if (path === '/dashboard') { | ||
return pathname === path; | ||
} | ||
return pathname.startsWith(path); | ||
}; | ||
|
||
return ( | ||
<header className='sticky top-0 flex h-16 items-center justify-between border-b bg-background px-4 md:px-6'> | ||
<nav className='hidden flex-col gap-6 text-lg font-medium md:flex md:flex-row md:items-center md:gap-5 md:text-sm lg:gap-6'> | ||
<Link | ||
href='/dashboard' | ||
className='flex items-center gap-2 text-lg font-semibold md:text-base' | ||
> | ||
<Sparkles className='h-6 w-6' /> | ||
<span className='sr-only'>Sainseni</span> | ||
</Link> | ||
{navbarMenu.map((item) => ( | ||
<Link | ||
key={item.url} | ||
href={item.url} | ||
className={`transition-colors hover:text-foreground ${ | ||
isActive(item.url) | ||
? 'text-foreground font-semibold' | ||
: 'text-muted-foreground' | ||
}`} | ||
> | ||
{item.name} | ||
</Link> | ||
))} | ||
</nav> | ||
<Sheet> | ||
<SheetTrigger asChild> | ||
<Button | ||
variant='outline' | ||
size='icon' | ||
className='shrink-0 md:hidden' | ||
> | ||
<Menu className='h-5 w-5' /> | ||
<span className='sr-only'>Toggle navigation menu</span> | ||
</Button> | ||
</SheetTrigger> | ||
<SheetContent side='left'> | ||
<nav className='grid gap-6 text-lg font-medium'> | ||
<Link | ||
href='/dashboard' | ||
className='flex items-center gap-2 text-lg font-semibold' | ||
> | ||
<Sparkles className='h-6 w-6' /> | ||
<span className='sr-only'>Sainseni</span> | ||
</Link> | ||
{navbarMenu.map((item) => ( | ||
<Link | ||
key={item.url} | ||
href={item.url} | ||
className={`transition-colors hover:text-foreground ${ | ||
isActive(item.url) | ||
? 'text-foreground font-semibold' | ||
: 'text-muted-foreground' | ||
}`} | ||
> | ||
{item.name} | ||
</Link> | ||
))} | ||
</nav> | ||
</SheetContent> | ||
</Sheet> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button | ||
variant='secondary' | ||
size='icon' | ||
className='rounded-full' | ||
> | ||
<CircleUser className='h-5 w-5' /> | ||
<span className='sr-only'>User menu</span> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align='end'> | ||
<DropdownMenuLabel>My Name</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuItem>Settings</DropdownMenuItem> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuItem>Logout</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</header> | ||
); | ||
} |
File renamed without changes.
This file contains 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
This file contains 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,50 @@ | ||
'use client'; | ||
|
||
import * as AvatarPrimitive from '@radix-ui/react-avatar'; | ||
import * as React from 'react'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
|
||
const Avatar = React.forwardRef< | ||
React.ElementRef<typeof AvatarPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root> | ||
>(({ className, ...props }, ref) => ( | ||
<AvatarPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
'relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
Avatar.displayName = AvatarPrimitive.Root.displayName; | ||
|
||
const AvatarImage = React.forwardRef< | ||
React.ElementRef<typeof AvatarPrimitive.Image>, | ||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> | ||
>(({ className, ...props }, ref) => ( | ||
<AvatarPrimitive.Image | ||
ref={ref} | ||
className={cn('aspect-square h-full w-full', className)} | ||
{...props} | ||
/> | ||
)); | ||
AvatarImage.displayName = AvatarPrimitive.Image.displayName; | ||
|
||
const AvatarFallback = React.forwardRef< | ||
React.ElementRef<typeof AvatarPrimitive.Fallback>, | ||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> | ||
>(({ className, ...props }, ref) => ( | ||
<AvatarPrimitive.Fallback | ||
ref={ref} | ||
className={cn( | ||
'flex h-full w-full items-center justify-center rounded-full bg-muted', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName; | ||
|
||
export { Avatar, AvatarFallback, AvatarImage }; |
This file contains 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,120 @@ | ||
import * as React from 'react'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
|
||
const Table = React.forwardRef< | ||
HTMLTableElement, | ||
React.HTMLAttributes<HTMLTableElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div className='relative w-full overflow-auto'> | ||
<table | ||
ref={ref} | ||
className={cn('w-full caption-bottom text-sm', className)} | ||
{...props} | ||
/> | ||
</div> | ||
)); | ||
Table.displayName = 'Table'; | ||
|
||
const TableHeader = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<thead ref={ref} className={cn('[&_tr]:border-b', className)} {...props} /> | ||
)); | ||
TableHeader.displayName = 'TableHeader'; | ||
|
||
const TableBody = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<tbody | ||
ref={ref} | ||
className={cn('[&_tr:last-child]:border-0', className)} | ||
{...props} | ||
/> | ||
)); | ||
TableBody.displayName = 'TableBody'; | ||
|
||
const TableFooter = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<tfoot | ||
ref={ref} | ||
className={cn( | ||
'border-t bg-muted/50 font-medium [&>tr]:last:border-b-0', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
TableFooter.displayName = 'TableFooter'; | ||
|
||
const TableRow = React.forwardRef< | ||
HTMLTableRowElement, | ||
React.HTMLAttributes<HTMLTableRowElement> | ||
>(({ className, ...props }, ref) => ( | ||
<tr | ||
ref={ref} | ||
className={cn( | ||
'border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
TableRow.displayName = 'TableRow'; | ||
|
||
const TableHead = React.forwardRef< | ||
HTMLTableCellElement, | ||
React.ThHTMLAttributes<HTMLTableCellElement> | ||
>(({ className, ...props }, ref) => ( | ||
<th | ||
ref={ref} | ||
className={cn( | ||
'h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
TableHead.displayName = 'TableHead'; | ||
|
||
const TableCell = React.forwardRef< | ||
HTMLTableCellElement, | ||
React.TdHTMLAttributes<HTMLTableCellElement> | ||
>(({ className, ...props }, ref) => ( | ||
<td | ||
ref={ref} | ||
className={cn( | ||
'p-4 align-middle [&:has([role=checkbox])]:pr-0', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
TableCell.displayName = 'TableCell'; | ||
|
||
const TableCaption = React.forwardRef< | ||
HTMLTableCaptionElement, | ||
React.HTMLAttributes<HTMLTableCaptionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<caption | ||
ref={ref} | ||
className={cn('mt-4 text-sm text-muted-foreground', className)} | ||
{...props} | ||
/> | ||
)); | ||
TableCaption.displayName = 'TableCaption'; | ||
|
||
export { | ||
Table, | ||
TableBody, | ||
TableCaption, | ||
TableCell, | ||
TableFooter, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,9 +1,35 @@ | ||
export const AUTHENTICATION_ERROR_MESSAGE = | ||
'You must be authenticated to access this resource.'; | ||
|
||
export const AUTHORIZATION_ERROR_MESSAGE = | ||
'You are not authorized to access this resource.'; | ||
|
||
export const AuthenticationError = class AuthenticationError extends Error { | ||
constructor() { | ||
super(AUTHENTICATION_ERROR_MESSAGE); | ||
this.name = 'AuthenticationError'; | ||
} | ||
}; | ||
|
||
export const AuthorizationError = class AuthorizationError extends Error { | ||
constructor() { | ||
super(AUTHORIZATION_ERROR_MESSAGE); | ||
this.name = 'AuthorizationError'; | ||
} | ||
}; | ||
|
||
export function getStatusCode(error: Error) { | ||
if ( | ||
error instanceof AuthenticationError || | ||
error.message === AUTHENTICATION_ERROR_MESSAGE | ||
) { | ||
return 401; | ||
} | ||
if ( | ||
error instanceof AuthorizationError || | ||
error.message === AUTHORIZATION_ERROR_MESSAGE | ||
) { | ||
return 403; | ||
} | ||
return 500; | ||
} |