Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat: move account menu from header into sidebar footer

Khuram Niazf0078491746b
diff --git a/__tests__/Sidebar.spec.tsx b/__tests__/Sidebar.spec.tsx
index f1e0202..1d9b1e9 100644
--- a/__tests__/Sidebar.spec.tsx
+++ b/__tests__/Sidebar.spec.tsx
@@ -1,4 +1,4 @@
-import { render, screen } from "@testing-library/react";
+import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { usePathname } from "next/navigation";
import { Briefcase } from "lucide-react";
@@ -13,10 +13,12 @@ vi.mock("next/navigation", () => ({
usePathname: vi.fn().mockReturnValue("/dashboard"),
}));
+const testUser = { id: "1", name: "Test User", email: "[email protected]" };
+
const renderSidebar = () =>
render(
<SidebarProvider initialExpanded>
- <Sidebar />
+ <Sidebar user={testUser} signOutAction={() => {}} />
<SidebarToggle />
</SidebarProvider>
);
@@ -105,7 +107,7 @@ describe("Sidebar", () => {
(usePathname as any).mockReturnValue("/dashboard");
});
- it("renders a link for each nav item plus settings", () => {
+ it("renders a link for each nav item", () => {
renderSidebar();
expect(screen.getByRole("link", { name: "Dashboard" })).toHaveAttribute(
@@ -116,10 +118,20 @@ describe("Sidebar", () => {
"href",
"/dashboard/myjobs"
);
- expect(screen.getByRole("link", { name: "Settings" })).toHaveAttribute(
- "href",
- "/dashboard/settings"
- );
+ });
+
+ it("shows the user's email and a settings link via the account menu", async () => {
+ const user = userEvent.setup();
+ renderSidebar();
+
+ expect(screen.getByText(testUser.email)).toBeInTheDocument();
+
+ await user.click(screen.getByRole("button", { name: "User menu" }));
+
+ // Radix gives the menu item role="menuitem" rather than "link".
+ expect(
+ await screen.findByRole("menuitem", { name: "Settings" })
+ ).toHaveAttribute("href", "/dashboard/settings");
});
it("marks the current page with aria-current", () => {
@@ -139,10 +151,13 @@ describe("Sidebar", () => {
it("does not render a collapse control inside the sidebar", () => {
renderSidebar();
- // The only toggle lives in the header; the rail is nav links only.
+ // The collapse toggle lives in the header, not the rail; the only
+ // button inside the sidebar is the account menu trigger.
+ const sidebar = within(screen.getByRole("complementary"));
expect(
- screen.getByRole("complementary").querySelector("button")
+ sidebar.queryByRole("button", { name: "Collapse sidebar" })
).toBeNull();
+ expect(sidebar.getByRole("button", { name: "User menu" })).toBeInTheDocument();
});
});
diff --git a/src/app/dashboard/layout.tsx b/src/app/dashboard/layout.tsx
index 6a5ae5d..3b1edf6 100644
--- a/src/app/dashboard/layout.tsx
+++ b/src/app/dashboard/layout.tsx
@@ -10,6 +10,8 @@ import { AgentChatProvider } from "@/components/agent/AgentChatProvider";
import { AgentChatPanel } from "@/components/agent/AgentChatPanel";
import { getChatConversation } from "@/actions/agentChat.actions";
import { APP_CONSTANTS } from "@/lib/constants";
+import { getCurrentUser } from "@/utils/user.utils";
+import { signOut } from "@/auth";
export default async function RootLayout({
children,
@@ -23,6 +25,7 @@ export default async function RootLayout({
// every load, and the race where a message sent before hydration completes
// is merged against an empty transcript and then persisted.
const conversation = await getChatConversation();
+ const user = await getCurrentUser();
return (
<ActivityProvider>
@@ -30,7 +33,13 @@ export default async function RootLayout({
<RightRailProvider>
<AgentChatProvider initialMessages={conversation.data ?? []}>
<div className="flex min-h-screen w-full flex-col bg-muted/40">
- <Sidebar />
+ <Sidebar
+ user={user}
+ signOutAction={async () => {
+ "use server";
+ await signOut({ redirectTo: "/signin" });
+ }}
+ />
<SidebarInset>
<Header />
<GlobalActivityBanner />
diff --git a/src/components/Header.tsx b/src/components/Header.tsx
index 69fec07..fa5f471 100644
--- a/src/components/Header.tsx
+++ b/src/components/Header.tsx
@@ -10,15 +10,10 @@ import {
SheetTrigger,
} from "@/components/ui/sheet";
import { SIDEBAR_LINKS } from "@/lib/constants";
-import { signOut } from "@/auth";
-import { getCurrentUser } from "@/utils/user.utils";
-import { ProfileDropdown } from "./ProfileDropdown";
import SidebarToggle from "./SidebarToggle";
import { AgentChatTrigger } from "./AgentChatTrigger";
async function Header() {
- // const session = await auth();
- const user = await getCurrentUser();
return (
<header className="sticky top-0 z-30 flex h-14 items-center gap-4 border-b bg-background px-4 sm:static sm:h-auto sm:border-0 sm:bg-transparent sm:px-6">
<Sheet>
@@ -73,14 +68,6 @@ async function Header() {
</div>
<AgentChatTrigger />
-
- <ProfileDropdown
- user={user}
- signOutAction={async () => {
- "use server";
- await signOut({ redirectTo: "/signin" });
- }}
- />
</header>
);
}
diff --git a/src/components/ProfileDropdown.tsx b/src/components/ProfileDropdown.tsx
index 877afd2..7ffc59a 100644
--- a/src/components/ProfileDropdown.tsx
+++ b/src/components/ProfileDropdown.tsx
@@ -11,25 +11,54 @@ import {
DropdownMenuSeparator,
DropdownMenuItem,
} from "./ui/dropdown-menu";
+import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
import UserAvatar from "./UserAvatar";
import { SupportDialog } from "./SupportDialog";
+import { cn } from "@/lib/utils";
interface ProfileDropdownProps {
user: any;
+ expanded: boolean;
signOutAction: () => void;
}
-export function ProfileDropdown({ user, signOutAction }: ProfileDropdownProps) {
+export function ProfileDropdown({
+ user,
+ expanded,
+ signOutAction,
+}: ProfileDropdownProps) {
const [supportDialogOpen, setSupportDialogOpen] = useState(false);
+ const label = user?.email ?? "My Account";
return (
<>
<DropdownMenu>
- <DropdownMenuTrigger aria-label="User menu">
- <UserAvatar user={user} />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuLabel>{user?.email ?? "My Account"}</DropdownMenuLabel>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <DropdownMenuTrigger asChild>
+ <button
+ type="button"
+ aria-label="User menu"
+ className="navlink h-10 w-full text-muted-foreground hover:text-foreground"
+ >
+ <span className="flex h-full w-14 shrink-0 items-center justify-center">
+ <UserAvatar user={user} />
+ </span>
+ <span
+ className={cn(
+ "truncate text-sm transition-opacity duration-200",
+ expanded ? "opacity-100 delay-100" : "opacity-0"
+ )}
+ >
+ {label}
+ </span>
+ </button>
+ </DropdownMenuTrigger>
+ </TooltipTrigger>
+ {!expanded && <TooltipContent side="right">{label}</TooltipContent>}
+ </Tooltip>
+ <DropdownMenuContent side="right" align="end">
+ <DropdownMenuLabel>{label}</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem asChild>
<Link href="/dashboard/settings" className="cursor-pointer">
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 926147a..b4d1b54 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -2,14 +2,21 @@
import Link from "next/link";
import { TooltipProvider } from "@/components/ui/tooltip";
-import { Briefcase, Settings } from "lucide-react";
+import { Briefcase } from "lucide-react";
import { APP_CONSTANTS, SIDEBAR_LINKS } from "@/lib/constants";
import NavLink from "./NavLink";
+import { ProfileDropdown } from "./ProfileDropdown";
import { usePathname } from "next/navigation";
import { useSidebar } from "@/context/SidebarContext";
import { cn } from "@/lib/utils";
+import { CurrentUser } from "@/models/user.model";
-function Sidebar() {
+interface SidebarProps {
+ user: CurrentUser | null;
+ signOutAction: () => void;
+}
+
+function Sidebar({ user, signOutAction }: SidebarProps) {
const path = usePathname();
const { expanded } = useSidebar();
const isOnDashboard = path === "/dashboard";
@@ -69,12 +76,10 @@ function Sidebar() {
</nav>
<div className="flex flex-col gap-1 border-t py-2">
- <NavLink
- label="Settings"
- Icon={Settings}
- route="/dashboard/settings"
- pathname={path}
+ <ProfileDropdown
+ user={user}
expanded={expanded}
+ signOutAction={signOutAction}
/>
</div>
</aside>