Skip to content

Commit

Permalink
feat: add header and notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ToxicToast committed Jun 15, 2024
1 parent 1e86c1d commit e4a401d
Show file tree
Hide file tree
Showing 9 changed files with 523 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,33 @@ import { Outlet } from 'react-router-dom';
import { Header } from './dashboard/header';
import { useToasts } from '../../hooks';
import { ToasterWidget } from '../../widgets/toaster.widget';
import { useState } from 'react';
import { useAuthState } from '../../store/auth/auth.hook';

function DashboardLayout() {
const [sidebarOpen, setSidebarOpen] = useState<boolean>(false);
const { toasts } = useToasts();
const { username } = useAuthState();

return (
<div className="min-h-screen bg-background">
<div className="flex h-screen overflow-hidden">
SIDEBAR
<div className="relative flex flex-col flex-1 overflow-y-auto overflow-x-hidden">
<Header />
<Header
sidebarOpen={sidebarOpen}
onSidebarChange={(value: boolean) =>
setSidebarOpen(value)
}
username={username ?? ''}
onSignout={() => {
console.log('signout');
}}
notifications={[]}
removeNotification={(id: string) => {
console.log(id);
}}
/>
<main>
<Outlet />
</main>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
import { HeaderLeftSide } from './header-left-side';
import { HeaderRightSide } from './header-right-side';
import { Notifications } from './notifications';
import { Notification } from '../../../types';
import { useState } from 'react';

interface Props {
sidebarOpen: boolean;
onSidebarChange: (value: boolean) => void;
username: string;
onSignout: () => void;
notifications?: Array<Notification>;
removeNotification: (id: string) => void;
}

export function Header(props: Props) {
const [searchModalOpen, setSearchModalOpen] = useState<boolean>(false);
const [dropdownOpen, setDropdownOpen] = useState<boolean>(false);
const [usermenuOpen, setUsermenuOpen] = useState<boolean>(false);

const {
sidebarOpen,
onSidebarChange,
username,
onSignout,
notifications,
removeNotification,
} = props;

export function Header() {
return (
<header className="sticky top-0 bg-white dark:bg-[#182235] border-b border-slate-200 dark:border-slate-700 z-30">
<div className="px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-16 -mb-px">
<HeaderLeftSide />
<HeaderRightSide>
Notifications ThemeToggle
<Notifications
dropdownOpen={dropdownOpen}
setDropdownOpen={(value: boolean) =>
setDropdownOpen(value)
}
notifications={notifications ?? []}
removeNotification={(id: string) =>
removeNotification(id)
}
/>
ThemeToggle
<hr className="w-px h-6 bg-slate-200 dark:bg-slate-700 border-none" />
UserMenu
</HeaderRightSide>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Notification } from '../../../types';
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover';
import { NotificationTriggerPartial } from './notifications/notification-trigger';

interface Props {
dropdownOpen: boolean;
setDropdownOpen: (value: boolean) => void;
notifications: Array<Notification>;
removeNotification: (id: string) => void;
}

export function Notifications(props: Props) {
const { dropdownOpen, setDropdownOpen, notifications, removeNotification } =
props;

return (
<Popover open={dropdownOpen} onOpenChange={setDropdownOpen}>
<PopoverTrigger>
<NotificationTriggerPartial dropdownOpen={dropdownOpen} />
</PopoverTrigger>
<PopoverContent className="w-80">
{JSON.stringify(notifications, null, 4)}
</PopoverContent>
</Popover>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
interface Props {
dropdownOpen: boolean;
}

export function NotificationTriggerPartial(props: Props) {
const { dropdownOpen } = props;

return (
<div
className={`w-8 h-8 flex items-center justify-center bg-slate-100 hover:bg-slate-200 dark:bg-slate-700 dark:hover:bg-slate-600/80 rounded-full ${
dropdownOpen && 'bg-slate-200'
}`}
>
<span className="sr-only">Notifications</span>
<svg
className="w-4 h-4"
viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg"
>
<path
className="fill-current text-slate-500 dark:text-slate-400"
d="M6.5 0C2.91 0 0 2.462 0 5.5c0 1.075.37 2.074 1 2.922V12l2.699-1.542A7.454 7.454 0 006.5 11c3.59 0 6.5-2.462 6.5-5.5S10.09 0 6.5 0z"
/>
<path
className="fill-current text-slate-400 dark:text-slate-500"
d="M16 9.5c0-.987-.429-1.897-1.147-2.639C14.124 10.348 10.66 13 6.5 13c-.103 0-.202-.018-.305-.021C7.231 13.617 8.556 14 10 14c.449 0 .886-.04 1.307-.11L15 16v-4h-.012C15.627 11.285 16 10.425 16 9.5z"
/>
</svg>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import * as PopoverPrimitive from '@radix-ui/react-popover';

import { cn } from './utils';

const Popover = PopoverPrimitive.Root;

const PopoverTrigger = PopoverPrimitive.Trigger;

const PopoverAnchor = PopoverPrimitive.Anchor;

const PopoverContent = React.forwardRef<
React.ElementRef<typeof PopoverPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
>(({ className, align = 'center', sideOffset = 4, ...props }, ref) => (
<PopoverPrimitive.Portal>
<PopoverPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cn(
'z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
className,
)}
{...props}
/>
</PopoverPrimitive.Portal>
));
PopoverContent.displayName = PopoverPrimitive.Content.displayName;

export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
1 change: 1 addition & 0 deletions apps/azkaban-admin-ui/src/features/shared/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './toast.type';
export * from './error.type';
export * from './notification.type';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type Notification = {
id: string;
icon: string;
title: string;
description: string;
date: string;
};
Loading

0 comments on commit e4a401d

Please sign in to comment.