mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
107 lines
3.9 KiB
TypeScript
107 lines
3.9 KiB
TypeScript
import { type HTMLAttributes, useEffect, useState } from 'react';
|
|
|
|
import { ReadStatus } from '@prisma/client';
|
|
import { InboxIcon, MenuIcon, SearchIcon } from 'lucide-react';
|
|
import { Link, useParams } from 'react-router';
|
|
|
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
|
import { isPersonalLayout } from '@documenso/lib/utils/organisations';
|
|
import { getRootHref } from '@documenso/lib/utils/params';
|
|
import { trpc } from '@documenso/trpc/react';
|
|
import { cn } from '@documenso/ui/lib/utils';
|
|
import { Button } from '@documenso/ui/primitives/button';
|
|
|
|
import { BrandingLogo } from '~/components/general/branding-logo';
|
|
|
|
import { AppCommandMenu } from './app-command-menu';
|
|
import { AppNavDesktop } from './app-nav-desktop';
|
|
import { AppNavMobile } from './app-nav-mobile';
|
|
import { MenuSwitcher } from './menu-switcher';
|
|
import { OrgMenuSwitcher } from './org-menu-switcher';
|
|
|
|
export type HeaderProps = HTMLAttributes<HTMLDivElement>;
|
|
|
|
export const Header = ({ className, ...props }: HeaderProps) => {
|
|
const params = useParams();
|
|
|
|
const { organisations } = useSession();
|
|
|
|
const [isCommandMenuOpen, setIsCommandMenuOpen] = useState(false);
|
|
const [isHamburgerMenuOpen, setIsHamburgerMenuOpen] = useState(false);
|
|
const [scrollY, setScrollY] = useState(0);
|
|
|
|
const { data: unreadCountData } = trpc.document.inbox.getCount.useQuery(
|
|
{
|
|
readStatus: ReadStatus.NOT_OPENED,
|
|
},
|
|
{
|
|
// refetchInterval: 30000, // Refetch every 30 seconds
|
|
},
|
|
);
|
|
|
|
useEffect(() => {
|
|
const onScroll = () => {
|
|
setScrollY(window.scrollY);
|
|
};
|
|
|
|
window.addEventListener('scroll', onScroll);
|
|
|
|
return () => window.removeEventListener('scroll', onScroll);
|
|
}, []);
|
|
|
|
return (
|
|
<header
|
|
className={cn(
|
|
'supports-backdrop-blur:bg-background/60 bg-background/95 sticky top-0 z-[60] flex h-16 w-full items-center border-b border-b-transparent backdrop-blur duration-200',
|
|
scrollY > 5 && 'border-b-border',
|
|
className,
|
|
)}
|
|
{...props}
|
|
>
|
|
<div className="mx-auto flex w-full max-w-screen-xl items-center justify-between gap-x-4 px-4 md:justify-normal md:px-8">
|
|
<Link
|
|
to={getRootHref(params)}
|
|
className="focus-visible:ring-ring ring-offset-background hidden rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 md:inline"
|
|
>
|
|
<BrandingLogo className="h-6 w-auto" />
|
|
</Link>
|
|
|
|
<AppNavDesktop setIsCommandMenuOpen={setIsCommandMenuOpen} />
|
|
|
|
<Button asChild variant="outline" className="relative hidden h-10 w-10 rounded-lg md:flex">
|
|
<Link to="/inbox" className="relative block h-10 w-10">
|
|
<InboxIcon className="text-muted-foreground hover:text-foreground h-5 w-5 flex-shrink-0 transition-colors" />
|
|
|
|
{unreadCountData && unreadCountData.count > 0 && (
|
|
<span className="bg-primary text-primary-foreground absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full text-[10px] font-semibold">
|
|
{unreadCountData.count > 99 ? '99+' : unreadCountData.count}
|
|
</span>
|
|
)}
|
|
</Link>
|
|
</Button>
|
|
|
|
<div className="md:ml-4">
|
|
{isPersonalLayout(organisations) ? <MenuSwitcher /> : <OrgMenuSwitcher />}
|
|
</div>
|
|
|
|
<div className="flex flex-row items-center space-x-4 md:hidden">
|
|
<button onClick={() => setIsCommandMenuOpen(true)}>
|
|
<SearchIcon className="text-muted-foreground h-6 w-6" />
|
|
</button>
|
|
|
|
<button onClick={() => setIsHamburgerMenuOpen(true)}>
|
|
<MenuIcon className="text-muted-foreground h-6 w-6" />
|
|
</button>
|
|
|
|
<AppCommandMenu open={isCommandMenuOpen} onOpenChange={setIsCommandMenuOpen} />
|
|
|
|
<AppNavMobile
|
|
isMenuOpen={isHamburgerMenuOpen}
|
|
onMenuOpenChange={setIsHamburgerMenuOpen}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
};
|