-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
411 additions
and
222 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/app/(dashboard)/dashboard/_components/dashboard-header.tsx
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,33 @@ | ||
import Link from "next/link" | ||
import type { User } from "@clerk/nextjs/server" | ||
|
||
import { siteConfig } from "@/config/site" | ||
import { Icons } from "@/components/icons" | ||
import { AuthDropdown } from "@/components/layouts/auth-dropdown" | ||
|
||
interface DashboardHeaderProps { | ||
user: User | null | ||
children: React.ReactNode | ||
} | ||
|
||
export function DashboardHeader({ user, children }: DashboardHeaderProps) { | ||
return ( | ||
<header className="sticky top-0 z-50 w-full border-b bg-background"> | ||
<div className="container flex h-16 items-center"> | ||
<Link href="/" className="hidden items-center space-x-2 lg:flex"> | ||
<Icons.logo className="size-6" aria-hidden="true" /> | ||
<span className="hidden font-bold lg:inline-block"> | ||
{siteConfig.name} | ||
</span> | ||
<span className="sr-only">Home</span> | ||
</Link> | ||
{children} | ||
<div className="flex flex-1 items-center justify-end space-x-4"> | ||
<nav className="flex items-center space-x-2"> | ||
<AuthDropdown user={user} /> | ||
</nav> | ||
</div> | ||
</div> | ||
</header> | ||
) | ||
} |
61 changes: 61 additions & 0 deletions
61
src/app/(dashboard)/dashboard/_components/dashboard-sidebar-sheet.tsx
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,61 @@ | ||
"use client" | ||
|
||
import Link from "next/link" | ||
|
||
import { siteConfig } from "@/config/site" | ||
import { cn } from "@/lib/utils" | ||
import { useMediaQuery } from "@/hooks/use-media-query" | ||
import { Button, type ButtonProps } from "@/components/ui/button" | ||
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet" | ||
import { Icons } from "@/components/icons" | ||
|
||
import { useSidebar } from "./sidebar-provider" | ||
|
||
export interface SidebarSheetProps extends ButtonProps {} | ||
|
||
export function DashboardSidebarSheet({ | ||
children, | ||
className, | ||
...props | ||
}: SidebarSheetProps) { | ||
const { open, setOpen } = useSidebar() | ||
const isDesktop = useMediaQuery("(min-width: 1024px)") | ||
|
||
if (isDesktop) return null | ||
|
||
return ( | ||
<Sheet open={open} onOpenChange={setOpen}> | ||
<SheetTrigger asChild> | ||
<Button | ||
variant="ghost" | ||
size="icon" | ||
className={cn( | ||
"size-5 hover:bg-transparent focus-visible:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0", | ||
className | ||
)} | ||
{...props} | ||
> | ||
<Icons.menu aria-hidden="true" /> | ||
<span className="sr-only">Toggle Menu</span> | ||
</Button> | ||
</SheetTrigger> | ||
<SheetContent | ||
side="left" | ||
className="inset-y-0 flex h-auto w-[300px] flex-col items-center px-0 pt-9" | ||
> | ||
<div className="w-full self-start px-7"> | ||
<Link | ||
href="/" | ||
className="flex items-center" | ||
onClick={() => setOpen(false)} | ||
> | ||
<Icons.logo className="mr-2 size-4" aria-hidden="true" /> | ||
<span className="font-bold">{siteConfig.name}</span> | ||
<span className="sr-only">Home</span> | ||
</Link> | ||
</div> | ||
{children} | ||
</SheetContent> | ||
</Sheet> | ||
) | ||
} |
47 changes: 47 additions & 0 deletions
47
src/app/(dashboard)/dashboard/_components/dashboard-sidebar.tsx
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,47 @@ | ||
"use client" | ||
|
||
import * as React from "react" | ||
import { useParams } from "next/navigation" | ||
|
||
import { dashboardConfig } from "@/config/dashboard" | ||
import { type getStoresByUserId } from "@/lib/actions/store" | ||
import { type getSubscriptionPlan } from "@/lib/actions/stripe" | ||
import { cn } from "@/lib/utils" | ||
import { ScrollArea } from "@/components/ui/scroll-area" | ||
import { SidebarNav } from "@/components/layouts/sidebar-nav" | ||
|
||
import { StoreSwitcher } from "./store-switcher" | ||
|
||
interface DashboardSidebarProps extends React.HTMLAttributes<HTMLElement> { | ||
promises: Promise<{ | ||
stores: Awaited<ReturnType<typeof getStoresByUserId>> | ||
subscriptionPlan: Awaited<ReturnType<typeof getSubscriptionPlan>> | ||
}> | ||
} | ||
|
||
export function DashboardSidebar({ | ||
promises, | ||
className, | ||
...props | ||
}: DashboardSidebarProps) { | ||
const { stores, subscriptionPlan } = React.use(promises) | ||
|
||
const { storeId } = useParams<{ storeId: string }>() | ||
|
||
const currentStore = stores.find((store) => store.id === storeId) | ||
|
||
return ( | ||
<aside className={cn("w-full", className)} {...props}> | ||
<div className="pr-6 pt-4 lg:pt-6"> | ||
<StoreSwitcher | ||
currentStore={currentStore} | ||
stores={stores} | ||
subscriptionPlan={subscriptionPlan} | ||
/> | ||
</div> | ||
<ScrollArea className="h-[calc(100vh-8rem)] py-4 pr-6"> | ||
<SidebarNav items={dashboardConfig.sidebarNav} className="p-1 pt-4" /> | ||
</ScrollArea> | ||
</aside> | ||
) | ||
} |
38 changes: 38 additions & 0 deletions
38
src/app/(dashboard)/dashboard/_components/sidebar-provider.tsx
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,38 @@ | ||
"use client" | ||
|
||
import * as React from "react" | ||
|
||
interface SidebarContextProps { | ||
open: boolean | ||
setOpen: React.Dispatch<React.SetStateAction<boolean>> | ||
} | ||
|
||
const SidebarContext = React.createContext<SidebarContextProps>({ | ||
open: false, | ||
setOpen: () => {}, | ||
}) | ||
|
||
export const SidebarProvider = ({ children }: React.PropsWithChildren) => { | ||
const [open, setOpen] = React.useState(false) | ||
|
||
return ( | ||
<SidebarContext.Provider | ||
value={{ | ||
open, | ||
setOpen, | ||
}} | ||
> | ||
{children} | ||
</SidebarContext.Provider> | ||
) | ||
} | ||
|
||
export const useSidebar = () => { | ||
const context = React.useContext(SidebarContext) | ||
|
||
if (!context) { | ||
throw new Error("useSidebar must be used within a SidebarProvider") | ||
} | ||
|
||
return context | ||
} |
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
Oops, something went wrong.