mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 16:46:29 +00:00
initial commit for new hats app
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
'use client'
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle,
|
||||
} from "@/components/ui/card"
|
||||
import { Switch } from "@/components/ui/switch"
|
||||
import {
|
||||
Popover, PopoverContent, PopoverTrigger,
|
||||
} from "@/components/ui/popover"
|
||||
import { Bell, BellRing } from 'lucide-react';
|
||||
|
||||
const notifications = [
|
||||
{
|
||||
title: "Your call has been confirmed.",
|
||||
description: "1 hour ago",
|
||||
},
|
||||
{
|
||||
title: "You have a new message!",
|
||||
description: "1 hour ago",
|
||||
},
|
||||
{
|
||||
title: "Your subscription is expiring soon!",
|
||||
description: "2 hours ago",
|
||||
},
|
||||
]
|
||||
|
||||
type CardProps = React.ComponentProps<typeof Card>
|
||||
|
||||
function Notification({ className, ...props }: CardProps) {
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="outline" size="icon">
|
||||
<Bell />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align='end' forceMount className='w-[380px] px-0 py-6'>
|
||||
<CardHeader>
|
||||
<CardTitle>Notifications</CardTitle>
|
||||
<CardDescription>You have 3 unread messages.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="grid gap-4 mt-5">
|
||||
<div className=" flex items-center space-x-4 rounded-xl border dark:border-zinc-800 p-4">
|
||||
<BellRing size={32} />
|
||||
<div className="flex-1 space-y-1">
|
||||
<p className="text-sm font-medium leading-none">
|
||||
Push Notifications
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Send notifications to device.
|
||||
</p>
|
||||
</div>
|
||||
{/* <Switch className='cursor-not-allowed' defaultChecked={fcmToken !== '' && notificationPermissionStatus !== ''} checked={fcmToken !== '' && notificationPermissionStatus !== ''} onCheckedChange={() => { }} /> */}
|
||||
<Switch />
|
||||
</div>
|
||||
<div>
|
||||
{notifications.map((notification, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="mb-4 grid grid-cols-[25px_1fr] items-start pb-4 last:mb-0 last:pb-0"
|
||||
>
|
||||
<span className="flex h-2 w-2 translate-y-1 rounded-full bg-sky-500" />
|
||||
<div className="space-y-1">
|
||||
<p className="text-sm font-medium leading-none">
|
||||
{notification.title}
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{notification.description}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
<CardFooter className='mt-6'>
|
||||
<Button className="w-full">
|
||||
<i className="ti ti-check text-lg h-4 w-4 icon"></i> Mark all as read
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
||||
export default Notification;
|
||||
@@ -0,0 +1,151 @@
|
||||
'use client'
|
||||
|
||||
import dynamic from 'next/dynamic';
|
||||
import { FC, FormEvent, useEffect, useRef, useState } from 'react';
|
||||
import { ArrowBigLeft } from 'lucide-react'
|
||||
import SIDEBAR_MENU from '@/lib/data-sidebar';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ISideMenu } from './SidebarItem';
|
||||
import { ToggleTheme } from './ToggleTheme';
|
||||
import Notification from './Notification';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { UserNav } from '@/app/(dashboard)/components/UserNav';
|
||||
|
||||
|
||||
const SidebarItem = dynamic(() => import("./SidebarItem"), {
|
||||
loading: () => <p className='text-zinc-200 dark:text-zinc-800 mb-3 animate-pulse'>loading...</p>,
|
||||
ssr: false
|
||||
})
|
||||
|
||||
type Props = {};
|
||||
|
||||
const Sidebar: FC<Props> = ({ }) => {
|
||||
const [expand, setExpand] = useState(true)
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false)
|
||||
const [search, setSearch] = useState('')
|
||||
|
||||
const trigger = useRef<any>(null);
|
||||
const sidebar = useRef<any>(null);
|
||||
const router = useRouter()
|
||||
|
||||
const menu: ISideMenu[] = SIDEBAR_MENU
|
||||
|
||||
// close on click outside
|
||||
useEffect(() => {
|
||||
const clickHandler = ({ target }: any) => {
|
||||
if (!sidebar.current || !trigger.current) return;
|
||||
if (!sidebarOpen || sidebar.current.contains(target) || trigger.current.contains(target)) return;
|
||||
setSidebarOpen(false);
|
||||
};
|
||||
document.addEventListener('click', clickHandler);
|
||||
return () => document.removeEventListener('click', clickHandler);
|
||||
});
|
||||
|
||||
// close if the esc key is pressed
|
||||
useEffect(() => {
|
||||
const keyHandler = ({ keyCode }: any) => {
|
||||
if (!sidebarOpen || keyCode !== 27) return;
|
||||
setSidebarOpen(false);
|
||||
};
|
||||
document.addEventListener('keydown', keyHandler);
|
||||
return () => document.removeEventListener('keydown', keyHandler);
|
||||
});
|
||||
|
||||
const handleSearch = (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault()
|
||||
|
||||
if (search) {
|
||||
setSearch('')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='z-20'>
|
||||
|
||||
{/* SIDEBAR MOBILE */}
|
||||
<div className={`fixed inset-0 bg-zinc-950 bg-opacity-60 z-20 lg:hidden lg:z-auto transition-opacity duration-200 backdrop-blur-sm ${sidebarOpen ? 'opacity-100' : 'opacity-0 pointer-events-none'}`} aria-hidden="true" onClick={() => setSidebarOpen(false)}></div>
|
||||
|
||||
<div className='lg:hidden sticky bg-white/70 dark:bg-zinc-950/70 top-0 w-full pb-3 px-4 sm:px-6 lg:px-8 z-10 mb-5 rounded-b-2xl'>
|
||||
<div className="flex items-center justify-between pt-5 pb-2 backdrop-blur-xl">
|
||||
<Button variant='outline' size='icon' onClick={() => setSidebarOpen(!sidebarOpen)}>
|
||||
{sidebarOpen ?
|
||||
<svg className="block h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true" >
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
:
|
||||
<svg className="block h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
}
|
||||
</Button>
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className="flex items-center space-x-3 border-r pr-3 dark:border-zinc-800">
|
||||
<Notification />
|
||||
<ToggleTheme />
|
||||
</div>
|
||||
<Link href='/'>
|
||||
<Button variant='outline' size='icon'>
|
||||
<i className="ti ti-home text-xl"></i>
|
||||
</Button>
|
||||
</Link>
|
||||
<UserNav />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* SIDEBAR */}
|
||||
<nav id="sidebar" ref={sidebar}
|
||||
className={`z-30 h-screen duration-300 ${expand ? 'w-72' : 'w-[78px] top-20'} ${sidebarOpen ? 'translate-x-0' : '-translate-x-80'} absolute left-0 top-0 lg:static lg:left-auto lg:top-auto lg:translate-x-0 border-r border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950`}
|
||||
>
|
||||
<Button variant='outline' size='icon' onClick={() => setExpand(!expand)} className={`hidden lg:flex absolute top-8 duration-300 z-10 ${!expand ? 'rotate-180 left-[60px]' : 'left-[270px]'}`}>
|
||||
<ArrowBigLeft />
|
||||
</Button>
|
||||
|
||||
<div className={`overflow-y-auto overflow-x-hidden h-full p-5 ${expand ? 'pt-6' : 'pt-0'} md:scrollbar-hide`}>
|
||||
{expand ?
|
||||
<Link href='/' className='flex items-center hover:opacity-70 duration-300' onClick={() => router.refresh()}>
|
||||
<div className={`flex justify-center items-center text-2xl rounded cursor-pointer float-left mr-3 duration-500 h-16 max-w-[225px]`}>
|
||||
<img alt='logo' loading='lazy' src='/assets/LOGO_HIS_HATs_NI.png' className='h-full w-full object-cover' />
|
||||
</div>
|
||||
</Link>
|
||||
:
|
||||
<Link href='/' className='flex items-center hover:opacity-70 duration-300 mt-6 mb-5' onClick={() => router.refresh()}>
|
||||
<div className={`flex justify-center items-center text-2xl rounded cursor-pointer float-left mr-3 duration-500 h-10 w-12`}>
|
||||
<img alt='logo' loading='lazy' src='/assets/LOGO_HATs.png' className='h-full w-full' />
|
||||
</div>
|
||||
</Link>
|
||||
}
|
||||
|
||||
{/* SEARCH FIELD */}
|
||||
<form onSubmit={handleSearch} className={`mt-4 py-2 ${!expand && 'hidden'}`}>
|
||||
<Input type="search" placeholder="Search..." value={search} onChange={e => setSearch(e.target.value)} className={`w-full focus:outline-none`} />
|
||||
</form>
|
||||
|
||||
<ul className='pt-2'>
|
||||
{menu && menu.length > 0 && menu!.map((menu, index) =>
|
||||
<SidebarItem key={index}
|
||||
menu={menu}
|
||||
expand={expand} onChangeExpand={(status) => setExpand(status)}
|
||||
/>
|
||||
)}
|
||||
{/* <li className={`cursor-pointer p-2 rounded-xl text-zinc-500 dark:text-zinc-400 font-medium text-sm hover:text-black dark:hover:text-white duration-100`}>
|
||||
<Link href={'/dssa'} className={`flex items-center ${expand && 'gap-x-3.5'}`} >
|
||||
<span className='float-left flex justify-center items-center w-5 h-5 text-lg'>
|
||||
<i className="ti ti-layout-dashboard flex justify-center items-center"></i>
|
||||
</span>
|
||||
<span className={`flex-1 duration-200 ${!expand && 'hidden'}`}>{"Test Font Awesome"}</span>
|
||||
</Link>
|
||||
</li> */}
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Sidebar;
|
||||
@@ -0,0 +1,102 @@
|
||||
'use client'
|
||||
|
||||
import { FC, ReactNode } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { ChevronLeft } from 'lucide-react'
|
||||
import useLocalStorage from '@/hooks/useLocalStorage';
|
||||
import { useTheme } from 'next-themes';
|
||||
import { motion } from "framer-motion";
|
||||
|
||||
|
||||
export interface ISideMenu {
|
||||
title: string,
|
||||
Icon?: ReactNode,
|
||||
path?: string,
|
||||
submenuId?: number,
|
||||
submenuItems?: ISideMenu[]
|
||||
}
|
||||
|
||||
type Props = {
|
||||
menu: ISideMenu,
|
||||
expand: boolean,
|
||||
onChangeExpand: (status: boolean) => any,
|
||||
};
|
||||
|
||||
const SidebarItem: FC<Props> = ({ menu, expand, onChangeExpand }) => {
|
||||
const [submenuIdActive, setSubmenuIdActive] = useLocalStorage('submenu', typeof window !== 'undefined' ? localStorage.getItem('submenu') || [] : [])
|
||||
const { title, Icon, path, submenuId, submenuItems } = menu
|
||||
const { systemTheme, theme } = useTheme()
|
||||
|
||||
const pathanme = usePathname()
|
||||
const router = useRouter()
|
||||
|
||||
const handleClickSubMenu = (submenuId: number) => {
|
||||
onChangeExpand(true)
|
||||
if (submenuIdActive?.includes(submenuId)) {
|
||||
setSubmenuIdActive(submenuIdActive?.filter((id: number) => id !== submenuId))
|
||||
} else {
|
||||
setSubmenuIdActive([...submenuIdActive, submenuId])
|
||||
}
|
||||
}
|
||||
|
||||
const getActiveBackgroundMenu = () => {
|
||||
if (pathanme === '/admin' + menu.path) {
|
||||
return {
|
||||
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#fff',
|
||||
fontWeight: theme === 'light' ? 600 : theme === 'system' && systemTheme === 'light' ? 600 : undefined,
|
||||
background: theme === 'dark' ? '#27272a' : theme === 'system' && systemTheme === 'dark' ? '#27272a' : '#EA512C'
|
||||
}
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<li style={getActiveBackgroundMenu()} className={`cursor-pointer p-2.5 rounded-md text-zinc-500 dark:text-zinc-400 font-medium text-sm hover:text-black dark:hover:text-white duration-300`}>
|
||||
{submenuItems && submenuItems.length > 0 ?
|
||||
<div className={`flex items-center gap-x-4 ${submenuIdActive?.includes(submenuId) && 'font-bold text-black dark:text-white'}`} title={title} onClick={() => handleClickSubMenu(submenuId!)}>
|
||||
<span className='block float-left'>
|
||||
{Icon}
|
||||
</span>
|
||||
<span className={`flex-1 duration-200 ${!expand && 'hidden'}`}>{title}</span>
|
||||
{submenuItems && submenuItems.length > 0 && expand &&
|
||||
<ChevronLeft size={16} className={`duration-500 ${submenuIdActive?.includes(submenuId) && '-rotate-90'}`} />
|
||||
}
|
||||
</div>
|
||||
:
|
||||
<Link href={'/admin' + path!} prefetch className={`flex items-center ${expand && 'gap-x-4'}`} title={title} onClick={() => router.push('/admin' + path)} >
|
||||
<span className='block float-left'>
|
||||
{Icon}
|
||||
</span>
|
||||
<span className={`flex-1 duration-200 ${!expand && 'hidden'}`}>{title}</span>
|
||||
</Link>
|
||||
}
|
||||
</li>
|
||||
|
||||
{submenuItems && submenuItems.length > 0 && submenuIdActive?.includes(submenuId) && expand &&
|
||||
<motion.ul
|
||||
// className='ml-4'
|
||||
animate={
|
||||
submenuIdActive?.includes(submenuId) ?
|
||||
{
|
||||
height: "fit-content",
|
||||
}
|
||||
:
|
||||
{
|
||||
height: 0,
|
||||
}
|
||||
}
|
||||
className="flex h-0 flex-col pl-5 overflow-hidden text-white"
|
||||
>
|
||||
{submenuItems!.map((submenu, key) =>
|
||||
<SidebarItem key={key} menu={submenu} expand={expand} onChangeExpand={onChangeExpand} />
|
||||
)}
|
||||
</motion.ul>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default SidebarItem;
|
||||
@@ -0,0 +1,39 @@
|
||||
"use client"
|
||||
|
||||
import { Moon, Sun } from "lucide-react"
|
||||
import { useTheme } from "next-themes"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
|
||||
export function ToggleTheme() {
|
||||
const { setTheme } = useTheme()
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='outline' size="icon">
|
||||
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
||||
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
||||
<span className="sr-only">Toggle theme</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => setTheme("light")}>
|
||||
Light
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setTheme("dark")}>
|
||||
Dark
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setTheme("system")}>
|
||||
System
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user