Skip to content

Commit

Permalink
Dashboard & Sidebar (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-maker authored Feb 13, 2024
2 parents 13e4812 + 0df4035 commit 154efcf
Show file tree
Hide file tree
Showing 15 changed files with 1,113 additions and 136 deletions.
10 changes: 10 additions & 0 deletions app/(dashboard)/_components/navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { UserButton } from "@clerk/nextjs";
import React from "react";

export const Navbar = () => {
return (
<div className="flex items-center gap-x-4 p-5">
<UserButton afterSignOutUrl="/" />
</div>
);
};
11 changes: 11 additions & 0 deletions app/(dashboard)/_components/org-sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use client";

import React from "react";

export const OrgSidebar = () => {
return (
<div className="hidden lg:flex flex-col space-y-6 w-[206px] pl-5 pt-5">
OrgSidebar
</div>
);
};
12 changes: 12 additions & 0 deletions app/(dashboard)/_components/sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import { NewButton } from "./new-button";
import { List } from "./list";

export const Sidebar = () => {
return (
<aside className="fixed z-[1] left-0 bg-blue-950 h-full w-[60px] flex p-3 flex-col gap-y-4 text-white">
<List />
<NewButton />
</aside>
);
};
43 changes: 43 additions & 0 deletions app/(dashboard)/_components/sidebar/item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use client";

import { Hint } from "@/components/hont";
import { cn } from "@/lib/utils";
import { useOrganization, useOrganizationList } from "@clerk/nextjs";
import Image from "next/image";
import React from "react";

interface ItemProps {
id: string;
name: string;
imageUrl: string;
}

export const Item = ({ id, name, imageUrl }: ItemProps) => {
const { organization } = useOrganization();
const { setActive } = useOrganizationList();

const isActive = organization?.id === id;

const onClick = () => {
if (!setActive) return;

setActive({ organization: id });
};

return (
<div className="aspect-square relative">
<Hint label={name} side="right" align="start" sideOffset={18}>
<Image
src={imageUrl}
alt={name}
onClick={onClick}
fill
className={cn(
"rounded-md cursor-pointer opacity-75 hover:opacity-100 transition",
isActive && "opacity-100"
)}
/>
</Hint>
</div>
);
};
27 changes: 27 additions & 0 deletions app/(dashboard)/_components/sidebar/list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use client";

import { useOrganizationList } from "@clerk/nextjs";
import { Item } from "./item";

export const List = () => {
const { userMemberships } = useOrganizationList({
userMemberships: {
infinite: true,
},
});

if (!userMemberships.data?.length) return null;

return (
<ul className="space-y-4">
{userMemberships.data?.map((mem) => (
<Item
key={mem.organization.id}
id={mem.organization.id}
name={mem.organization.name}
imageUrl={mem.organization.imageUrl}
/>
))}
</ul>
);
};
30 changes: 30 additions & 0 deletions app/(dashboard)/_components/sidebar/new-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";

import { Hint } from "@/components/hont";
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
import { CreateOrganization } from "@clerk/nextjs";
import { Plus } from "lucide-react";

export const NewButton = () => {
return (
<Dialog>
<DialogTrigger asChild>
<div className="aspect-square">
<Hint
label="Create organization"
side="right"
align="start"
sideOffset={18}
>
<button className="bg-white/25 h-full w-full rounded-md flex items-center justify-center opacity-60 hover:opacity-100 transition">
<Plus className="text-white" />
</button>
</Hint>
</div>
</DialogTrigger>
<DialogContent className="p-0 bg-transparent border-none max-w-[480px]">
<CreateOrganization />
</DialogContent>
</Dialog>
);
};
27 changes: 27 additions & 0 deletions app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { Navbar } from "./_components/navbar";
import { OrgSidebar } from "./_components/org-sidebar";
import { Sidebar } from "./_components/sidebar";

interface DashboardLayoutProps {
children: React.ReactNode;
}

const DashboardLayout = ({ children }: DashboardLayoutProps) => {
return (
<main className="h-full">
<Sidebar />
<div className="pl-[60px] h-full">
<div className="flex gap-x-3 h-full">
<OrgSidebar />
<div className="h-full flex-1">
<Navbar />
{children}
</div>
</div>
</div>
</main>
);
};

export default DashboardLayout;
7 changes: 7 additions & 0 deletions app/(dashboard)/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

const DashboardPage = () => {
return <div>DashboardPage</div>;
};

export default DashboardPage;
11 changes: 0 additions & 11 deletions app/page.tsx

This file was deleted.

42 changes: 42 additions & 0 deletions components/hont.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "./ui/tooltip";

export interface HintProps {
label: string;
children: React.ReactNode;
side?: "top" | "bottom" | "left" | "right";
align?: "start" | "center" | "end";
sideOffset?: number;
alignOffset?: number;
}

export const Hint = ({
label,
children,
side,
align,
sideOffset,
alignOffset,
}: HintProps) => {
return (
<TooltipProvider>
<Tooltip delayDuration={100}>
<TooltipTrigger asChild>{children}</TooltipTrigger>
<TooltipContent
className="text-white bg-black border-black"
side={side}
align={align}
sideOffset={sideOffset}
alignOffset={alignOffset}
>
<p className="font-semibold capitalize">{label}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
);
};
122 changes: 122 additions & 0 deletions components/ui/dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"use client"

import * as React from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
import { X } from "lucide-react"

import { cn } from "@/lib/utils"

const Dialog = DialogPrimitive.Root

const DialogTrigger = DialogPrimitive.Trigger

const DialogPortal = DialogPrimitive.Portal

const DialogClose = DialogPrimitive.Close

const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
/>
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName

const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName

const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
className
)}
{...props}
/>
)
DialogHeader.displayName = "DialogHeader"

const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
DialogFooter.displayName = "DialogFooter"

const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
DialogTitle.displayName = DialogPrimitive.Title.displayName

const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
DialogDescription.displayName = DialogPrimitive.Description.displayName

export {
Dialog,
DialogPortal,
DialogOverlay,
DialogClose,
DialogTrigger,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
}
30 changes: 30 additions & 0 deletions components/ui/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client"

import * as React from "react"
import * as TooltipPrimitive from "@radix-ui/react-tooltip"

import { cn } from "@/lib/utils"

const TooltipProvider = TooltipPrimitive.Provider

const Tooltip = TooltipPrimitive.Root

const TooltipTrigger = TooltipPrimitive.Trigger

const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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}
/>
))
TooltipContent.displayName = TooltipPrimitive.Content.displayName

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
11 changes: 10 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
images: {
remotePatterns: [
{
protocol: "https",
hostname: "img.clerk.com",
},
],
},
};

export default nextConfig;
Loading

0 comments on commit 154efcf

Please sign in to comment.