Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mobile-sidbar-sync-with-desktop #2180

Merged
4 changes: 1 addition & 3 deletions apps/dashboard/app/(app)/apis/create-api-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export const CreateApiButton = ({ ...rest }: React.ButtonHTMLAttributes<HTMLButt
const create = trpc.api.create.useMutation({
async onSuccess(res) {
toast.success("Your API has been created");

await revalidate("/apis")

await revalidate("/apis");
router.push(`/apis/${res.id}`);
},
onError(err) {
Expand Down
120 changes: 3 additions & 117 deletions apps/dashboard/app/(app)/desktop-sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
"use client";
import { createWorkspaceNavigation, resourcesNavigation } from "@/app/(app)/workspace-navigations";
import { Feedback } from "@/components/dashboard/feedback-component";
import { Badge } from "@/components/ui/badge";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import type { Workspace } from "@/lib/db";
import { useDelayLoader } from "@/lib/hooks/useDelayLoader";
import { cn } from "@/lib/utils";
import {
BookOpen,
Cable,
Crown,
DatabaseZap,
Fingerprint,
Gauge,
List,
Loader2,
type LucideIcon,
MonitorDot,
Settings2,
ShieldCheck,
} from "lucide-react";
import { Loader2, type LucideIcon } from "lucide-react";
import Link from "next/link";
import { useSelectedLayoutSegments } from "next/navigation";
import { useRouter } from "next/navigation";
Expand Down Expand Up @@ -48,111 +36,9 @@ type NavItem = {
hidden?: boolean;
};

const DiscordIcon = () => (
<svg
className="w-4 h-4 fill-current" // Increased height to 6
viewBox="0 -28.5 256 256"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
preserveAspectRatio="xMidYMid"
>
<g>
<path
d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z"
fillRule="nonzero"
/>
</g>
</svg>
);

const Tag: React.FC<{ label: string; className?: string }> = ({ label, className }) => (
<div
className={cn(
"bg-background border text-content-subtle rounded text-xs px-1 py-0.5 font-mono ",
className,
)}
>
{label}
</div>
);

export const DesktopSidebar: React.FC<Props> = ({ workspace, className }) => {
const segments = useSelectedLayoutSegments() ?? [];
const workspaceNavigation: NavItem[] = [
{
icon: Cable,
href: "/apis",
label: "APIs",
active: segments.at(0) === "apis",
},
{
icon: Gauge,
href: "/ratelimits",
label: "Ratelimit",
active: segments.at(0) === "ratelimits",
},
{
icon: ShieldCheck,
label: "Authorization",
href: "/authorization/roles",
active: segments.some((s) => s === "authorization"),
},

{
icon: List,
href: "/audit",
label: "Audit Log",
active: segments.at(0) === "audit",
},
{
icon: MonitorDot,
href: "/monitors/verifications",
label: "Monitors",
active: segments.at(0) === "verifications",
hidden: !workspace.features.webhooks,
},
{
icon: Crown,
href: "/success",
label: "Success",
active: segments.at(0) === "success",
tag: <Tag label="internal" />,
hidden: !workspace.features.successPage,
},
{
icon: DatabaseZap,
href: "/semantic-cache",
label: "Semantic Cache",
active: segments.at(0) === "semantic-cache",
},
{
icon: Fingerprint,
href: "/identities",
label: "Identities",
active: segments.at(0) === "identities",
hidden: !workspace.betaFeatures.identities,
},
{
icon: Settings2,
href: "/settings/general",
label: "Settings",
active: segments.at(0) === "settings",
},
].filter((n) => !n.hidden);
const resourcesNavigation: NavItem[] = [
{
icon: BookOpen,
href: "https://unkey.dev/docs",
external: true,
label: "Docs",
},
{
icon: DiscordIcon,
href: "https://www.unkey.com/discord",
external: true,
label: "Discord",
},
];
const workspaceNavigation = createWorkspaceNavigation(workspace, segments);

const firstOfNextMonth = new Date();
firstOfNextMonth.setUTCMonth(firstOfNextMonth.getUTCMonth() + 1);
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async function Layout({ children, breadcrumb }: LayoutProps) {
<div className="h-[100dvh] relative flex flex-col overflow-hidden bg-background lg:flex-row">
<UsageBanner workspace={workspace} />

<MobileSideBar className="lg:hidden" />
<MobileSideBar className="lg:hidden" workspace={workspace} />
<div className="flex flex-1 overflow-hidden bg-gray-100 dark:bg-gray-950">
<DesktopSidebar
workspace={workspace}
Expand Down
78 changes: 43 additions & 35 deletions apps/dashboard/app/(app)/mobile-sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
"use client";
import { createWorkspaceNavigation, resourcesNavigation } from "@/app/(app)/workspace-navigations";
import { Feedback } from "@/components/dashboard/feedback-component";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import { Sheet, SheetClose, SheetContent, SheetHeader, SheetTrigger } from "@/components/ui/sheet";
import type { Workspace } from "@/lib/db";
import { cn } from "@/lib/utils";
import { SignOutButton } from "@clerk/nextjs";
import { BookOpen, DatabaseZap, FileJson, LogOut, Menu, Settings } from "lucide-react";
import { Menu } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useSelectedLayoutSegments } from "next/navigation";
import { WorkspaceSwitcher } from "./team-switcher";

type Props = {
className?: string;
workspace: Workspace & {
apis: {
id: string;
name: string;
}[];
};
};

export const MobileSideBar = ({ className }: Props) => {
const router = useRouter();
export const MobileSideBar = ({ className, workspace }: Props) => {
const segments = useSelectedLayoutSegments() ?? [];

const workspaceNavigation = createWorkspaceNavigation(workspace, segments);

return (
<div className={cn(className, "w-96")}>
<Sheet>
Expand All @@ -30,36 +42,32 @@ export const MobileSideBar = ({ className }: Props) => {
<div className="flex flex-col w-full p-4 ">
<h2 className="px-2 mb-2 text-lg font-semibold tracking-tight">Workspace</h2>
<div className="space-y-1">
<Link href="/apis">
<SheetClose asChild>
<Button variant="ghost" className="justify-start w-full">
<FileJson className="w-4 h-4 mr-2" />
APIs
</Button>
</SheetClose>
</Link>
<Link href="/settings/general">
<SheetClose asChild>
<Button variant="ghost" className="justify-start w-full border-t">
<Settings className="w-4 h-4 mr-2" />
Settings
</Button>
</SheetClose>
</Link>
<Link href="https://unkey.dev/docs" target="_blank">
<Button variant="ghost" className="justify-start w-full py-2 border-t">
<BookOpen className="w-4 h-4 mr-2" />
Docs
</Button>
</Link>
<SignOutButton signOutCallback={() => router.push("/auth/sign-in")}>
<SheetClose asChild>
<Button variant="ghost" className="justify-start w-full py-2 border-t">
<LogOut className="w-4 h-4 mr-2" />
Sign Out
</Button>
</SheetClose>
</SignOutButton>
{workspaceNavigation.map((item) => (
<Link href={`${item.href}`} key={item.label}>
<SheetClose asChild>
<Button variant="ghost" className="justify-start w-full">
<item.icon className="w-4 h-4 mr-2" />
{item.label}
</Button>
</SheetClose>
</Link>
))}
</div>

<Separator className="my-2" />
<h2 className="px-2 mb-2 text-lg font-semibold tracking-tight">Resources</h2>
<div className="space-y-1">
{resourcesNavigation.map((item) => (
<Link href={`${item.href}`} target="_blank" key={item.label}>
<SheetClose asChild>
<Button variant="ghost" className="justify-start w-full">
<item.icon className="w-4 h-4 mr-2" />
{item.label}
</Button>
</SheetClose>
</Link>
))}
<Feedback />
</div>
</div>
</SheetContent>
Expand Down
137 changes: 137 additions & 0 deletions apps/dashboard/app/(app)/workspace-navigations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import type { Workspace } from "@/lib/db";
import {
BookOpen,
Cable,
Crown,
DatabaseZap,
Fingerprint,
Gauge,
List,
type LucideIcon,
MonitorDot,
Settings2,
ShieldCheck,
} from "lucide-react";
import { cn } from "../../lib/utils";

type NavItem = {
disabled?: boolean;
tooltip?: string;
icon: LucideIcon | React.ElementType;
href: string;
external?: boolean;
label: string;
active?: boolean;
tag?: React.ReactNode;
hidden?: boolean;
};

const DiscordIcon = () => (
<svg
className="w-4 h-4 fill-current" // Increased height to 6
viewBox="0 -28.5 256 256"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
preserveAspectRatio="xMidYMid"
>
<g>
<path
d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z"
fillRule="nonzero"
/>
</g>
</svg>
);

const Tag: React.FC<{ label: string; className?: string }> = ({ label, className }) => (
<div
className={cn(
"bg-background border text-content-subtle rounded text-xs px-1 py-0.5 font-mono ",
className,
)}
>
{label}
</div>
);

export const createWorkspaceNavigation = (
workspace: Pick<Workspace, "features"> & Pick<Workspace, "betaFeatures">,
segments: string[],
) => {
return [
{
icon: Cable,
href: "/apis",
label: "APIs",
active: segments.at(0) === "apis",
},
{
icon: Gauge,
href: "/ratelimits",
label: "Ratelimit",
active: segments.at(0) === "ratelimits",
},
{
icon: ShieldCheck,
label: "Authorization",
href: "/authorization/roles",
active: segments.some((s) => s === "authorization"),
},

{
icon: List,
href: "/audit",
label: "Audit Log",
active: segments.at(0) === "audit",
},
{
icon: MonitorDot,
href: "/monitors/verifications",
label: "Monitors",
active: segments.at(0) === "verifications",
hidden: !workspace.features.webhooks,
},
{
icon: Crown,
href: "/success",
label: "Success",
active: segments.at(0) === "success",
tag: <Tag label="internal" />,
hidden: !workspace.features.successPage,
},
{
icon: DatabaseZap,
href: "/semantic-cache",
label: "Semantic Cache",
active: segments.at(0) === "semantic-cache",
},
{
icon: Fingerprint,
href: "/identities",
label: "Identities",
active: segments.at(0) === "identities",
hidden: !workspace.betaFeatures.identities,
},
{
icon: Settings2,
href: "/settings/general",
label: "Settings",
active: segments.at(0) === "settings",
},
].filter((n) => !n.hidden);
};

export const resourcesNavigation: NavItem[] = [
{
icon: BookOpen,
href: "https://unkey.dev/docs",
external: true,
label: "Docs",
},
{
icon: DiscordIcon,
href: "https://www.unkey.com/discord",
external: true,
label: "Discord",
},
];
Loading