Skip to content

Fix duplicate logout button#189

Merged
kunalverma2512 merged 1 commit into
kunalverma2512:mainfrom
Arushi28-hub:main
Jun 12, 2026
Merged

Fix duplicate logout button#189
kunalverma2512 merged 1 commit into
kunalverma2512:mainfrom
Arushi28-hub:main

Conversation

@Arushi28-hub

@Arushi28-hub Arushi28-hub commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

📌 Pull Request Summary

🔗 Related Issue

Closes #184


📝 Description

This PR fixes the duplicate logout button implementation in the Navbar component by refactoring two separate button instances into a single reusable component.

-### Changes Made

  • Created reusable LogoutButton component in Navbar.jsx that accepts an optional className prop for style customization
  • Replaced desktop logout button - Now uses with default styles
  • Replaced mobile logout button - Now uses for mobile-specific styling
  • Eliminated code duplication - Single source of truth for logout button logic and base styles

Motivation

The Navbar component had two separate logout button implementations (one for desktop controls, one for mobile menu) with duplicated JSX and event handlers. This refactoring:

  • Follows the DRY (Don't Repeat Yourself) principle
  • Reduces maintenance burden - any future logout button changes only need to be made in one place
  • Improves code readability and maintainability
  • Allows flexible styling via the className prop while keeping core logout logic centralized

🚀 Type of Change

Select all that apply:

  • Bug Fix
  • New Feature
  • Enhancement
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • DevOps / Tooling
  • Other

🧪 Testing

Verification

  • Tested Locally
  • Existing Tests Passed
  • New Tests Added
  • No Testing Required

Test Details

  • Verified the frontend builds successfully with npm run dev

  • Tested logout functionality in both desktop and mobile layouts

  • Confirmed user is redirected to home page and session is cleared on logout

  • Verified no console errors related to the refactored component

  • 📸 Screenshots / Demo (If Applicable)

  • Before

image -After image

✅ Checklist

  • I have read and followed the contribution guidelines.
  • I have self-reviewed my changes.
  • My changes are limited to the scope of this issue.
  • Documentation has been updated where necessary.
  • No unnecessary files or unrelated changes have been included.
  • The related issue has been linked correctly.
  • All applicable testing and validation steps have been completed.

Summary by CodeRabbit

  • Refactor
    • Centralized logout button functionality for improved consistency across the application. Users will continue to access the logout feature from the navigation bar in both desktop and mobile views.

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

@Arushi28-hub is attempting to deploy a commit to the Kunal Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

🚀 PR Received Successfully

Hello @Arushi28-hub,

Thank you for taking the initiative to contribute to this project.

Please ensure that your PR follows all project guidelines properly before requesting review.

⚠️ Important Instructions

  • Maintain proper code quality and structure
  • Do not make unnecessary changes/files
  • Ensure responsiveness across devices
  • Follow existing project conventions strictly
  • Attach screenshots/videos for UI-related changes
  • Resolve merge conflicts before requesting review
  • Avoid AI-generated low quality PRs or copied implementations

📌 Mandatory for GSSoC'26 Participants

Joining the community group and announcement channel is compulsory for all contributors participating through GSSoC'26.

Failure to follow contribution guidelines may lead to PR rejection.

We appreciate your effort and wish you a great open-source journey ahead. ✨

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR consolidates logout button UI by introducing a reusable LogoutButton component in Navbar.jsx and removing the duplicate logout functionality from DashboardPage.jsx, eliminating redundant logout triggers across the application.

Changes

Logout Button Consolidation

Layer / File(s) Summary
LogoutButton component and Navbar integration
frontend/src/components/shared/Navbar.jsx
A new internal LogoutButton component renders a logout button wired to handleLogout with optional className styling. The component replaces inline logout button JSX in desktop auth controls and mobile pinned auth section.
DashboardPage import and logout code removal
frontend/src/pages/DashboardPage.jsx
useNavigate import is removed, logout destructuring from useAuth is removed, handleLogout helper function is removed, and the redundant logout button is removed from the dashboard header.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • kunalverma2512/CodeLens#93: Both PRs modify Navbar.jsx's mobile auth/logout area—this PR refactors inline logout buttons into a shared component, while the retrieved PR adjusts logout button styling/placement for mobile navbar overflow fixes.
  • kunalverma2512/CodeLens#73: Both PRs modify Navbar.jsx's authenticated auth-area logout UI, with this PR introducing component consolidation and the retrieved PR addressing navbar logout presentation updates.

Suggested labels

Frontend, type:refactor, UI/UX, quality:clean, level:intermediate

Poem

🐰 Buttons once scattered, now unite with grace,
Two become one in this cleaner space,
NavBar speaks true, the logout is clear,
Dashboard breathes lighter without its peer,

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main change: creating a reusable LogoutButton component to eliminate duplicate logout button implementations.
Description check ✅ Passed Description follows the template with all required sections including Related Issue, Changes Made, Motivation, Type of Change, Testing verification, checklist items, and supporting screenshots.
Linked Issues check ✅ Passed PR successfully addresses issue #184 objectives by removing the duplicate logout from DashboardPage.jsx, centralizing logout into a single reusable Navbar component, and maintaining proper session clearing and navigation behavior.
Out of Scope Changes check ✅ Passed Changes are focused and within scope: Navbar.jsx refactoring for DRY principle and DashboardPage.jsx cleanup to remove duplicate logout. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
frontend/src/components/shared/Navbar.jsx (2)

349-357: 💤 Low value

Consider extracting LogoutButton outside the component or memoizing it.

Defining a component inside another component's render function creates a new component identity on every render. While the impact is minimal for this simple stateless button, it can cause subtle issues like loss of focus state if the button is focused during a parent re-render.

A cleaner pattern would be to define LogoutButton outside Navbar and pass onLogout as a prop:

♻️ Suggested refactor
+// Outside Navbar component
+function LogoutButton({ className = "", onLogout }) {
+  return (
+    <button
+      type="button"
+      onClick={onLogout}
+      className={`px-2 text-[11px] font-semibold uppercase tracking-[0.09em] text-zinc-400 hover:text-black transition-colors duration-150 ${className}`}
+    >
+      Logout
+    </button>
+  );
+}
+
 export default function Navbar() {
   // ... existing code ...
-
-  const LogoutButton = ({ className = "" }) => (
-    <button
-      type="button"
-      onClick={handleLogout}
-      className={`px-2 text-[11px] font-semibold uppercase tracking-[0.09em] text-zinc-400 hover:text-black transition-colors duration-150 ${className}`}
-    >
-      Logout
-    </button>
-  );

Then use as: <LogoutButton onLogout={handleLogout} /> and <LogoutButton onLogout={handleLogout} className="..." />

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/shared/Navbar.jsx` around lines 349 - 357, Define
LogoutButton as a top-level (module-scope) component instead of inside Navbar:
move the LogoutButton declaration out of Navbar, accept props like onLogout and
className, and replace the inline usage inside Navbar with <LogoutButton
onLogout={handleLogout} className="..."> so you maintain stable component
identity; ensure the moved component uses the same className string and calls
the passed onLogout handler (previously handleLogout) for the onClick.

743-743: ⚡ Quick win

Tailwind class conflicts may cause unexpected styling.

The base className includes px-2 text-[11px] while the mobile override passes px-5 text-[13px]. When conflicting Tailwind utilities appear in the same element, the winner is determined by CSS generation order—not the order in the className string. This can lead to unpredictable results.

Consider using tailwind-merge to properly resolve conflicts, or restructure the component to accept granular style props:

♻️ Option 1: Use tailwind-merge
+import { twMerge } from "tailwind-merge";
+
 const LogoutButton = ({ className = "" }) => (
   <button
     type="button"
     onClick={handleLogout}
-    className={`px-2 text-[11px] font-semibold uppercase tracking-[0.09em] text-zinc-400 hover:text-black transition-colors duration-150 ${className}`}
+    className={twMerge("px-2 text-[11px] font-semibold uppercase tracking-[0.09em] text-zinc-400 hover:text-black transition-colors duration-150", className)}
   >
     Logout
   </button>
 );
♻️ Option 2: Separate base styles from overridable ones
 const LogoutButton = ({ className = "" }) => {
+  const baseStyles = "font-semibold uppercase tracking-[0.09em] text-zinc-400 hover:text-black transition-colors duration-150";
+  const defaultSizeStyles = "px-2 text-[11px]";
   return (
     <button
       type="button"
       onClick={handleLogout}
-      className={`px-2 text-[11px] font-semibold uppercase tracking-[0.09em] text-zinc-400 hover:text-black transition-colors duration-150 ${className}`}
+      className={`${baseStyles} ${className || defaultSizeStyles}`}
     >
       Logout
     </button>
   );
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/shared/Navbar.jsx` at line 743, The LogoutButton
usage in Navbar.jsx passes conflicting Tailwind utilities (e.g., base
px-2/text-[11px] vs override px-5/text-[13px]) which can produce unpredictable
styling; update the component call and/or the LogoutButton implementation to
resolve conflicts deterministically: either import and use tailwind-merge (e.g.,
mergeClasses = twMerge) where Navbar.jsx builds the final className before
passing it to <LogoutButton className={...}>, or change LogoutButton to accept
granular props (e.g., size/variant/padding props) and compute its internal class
string so overrides are explicit (update LogoutButton component signature and
callers); ensure you reference and adjust the LogoutButton component and the
Navbar.jsx caller to use the chosen approach consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@frontend/src/components/shared/Navbar.jsx`:
- Around line 349-357: Define LogoutButton as a top-level (module-scope)
component instead of inside Navbar: move the LogoutButton declaration out of
Navbar, accept props like onLogout and className, and replace the inline usage
inside Navbar with <LogoutButton onLogout={handleLogout} className="..."> so you
maintain stable component identity; ensure the moved component uses the same
className string and calls the passed onLogout handler (previously handleLogout)
for the onClick.
- Line 743: The LogoutButton usage in Navbar.jsx passes conflicting Tailwind
utilities (e.g., base px-2/text-[11px] vs override px-5/text-[13px]) which can
produce unpredictable styling; update the component call and/or the LogoutButton
implementation to resolve conflicts deterministically: either import and use
tailwind-merge (e.g., mergeClasses = twMerge) where Navbar.jsx builds the final
className before passing it to <LogoutButton className={...}>, or change
LogoutButton to accept granular props (e.g., size/variant/padding props) and
compute its internal class string so overrides are explicit (update LogoutButton
component signature and callers); ensure you reference and adjust the
LogoutButton component and the Navbar.jsx caller to use the chosen approach
consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69c079a4-59a7-46c3-8b14-02ab6c3e566f

📥 Commits

Reviewing files that changed from the base of the PR and between 58213ea and 3a4b178.

📒 Files selected for processing (2)
  • frontend/src/components/shared/Navbar.jsx
  • frontend/src/pages/DashboardPage.jsx

@kunalverma2512

Copy link
Copy Markdown
Owner

@coderabbitai please check is the work done is compatible with nearby codes, files and folder and is it readt to merge ?

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
echo "=== Navbar.jsx ==="
cat frontend/src/components/shared/Navbar.jsx

echo ""
echo "=== DashboardPage.jsx ==="
cat frontend/src/pages/DashboardPage.jsx

echo ""
echo "=== AuthContext (find it) ==="
fd -i "AuthContext" --type f | head -5

echo ""
echo "=== useAuth hook (find it) ==="
fd -i "useAuth" --type f | head -5

echo ""
echo "=== Check all files that import/use logout from useAuth ==="
rg -n "logout" frontend/src --type jsx -C2

echo ""
echo "=== Check all files that import useNavigate alongside logout ==="
rg -n "useNavigate" frontend/src -C2

echo ""
echo "=== Check for any other pages that still have logout button logic ==="
rg -n "handleLogout\|logout\b" frontend/src/pages -C2

echo ""
echo "=== Tree of shared components ==="
tree frontend/src/components/shared 2>/dev/null || ls -la frontend/src/components/shared/

echo ""
echo "=== Tree of pages ==="
tree frontend/src/pages 2>/dev/null || ls -la frontend/src/pages/

echo ""
echo "=== Check for any test files related to Navbar or Dashboard ==="
fd -i "navbar\|dashboard" frontend --type f | grep -i "test\|spec"

Length of output: 44497



@kunalverma2512 — Here's the full compatibility and merge-readiness assessment for PR #189.


✅ What's Done Correctly

Area Status
DashboardPage.jsxlogout removed from useAuth destructure
DashboardPage.jsxuseNavigate import removed
DashboardPage.jsxhandleLogout function removed
DashboardPage.jsx — Logout <button> removed from JSX
Navbar.jsxhandleLogout still calls await logout()navigate("/")setIsMenuOpen(false)
AuthContext import path in Navbar.jsx unchanged and valid
No other pages contain residual logout button logic
Mobile menu shows LogoutButton in the pinned auth section
Desktop auth controls show LogoutButton in the right rail

⚠️ Minor Issues (Non-Blocking)

1. LogoutButton defined inside the Navbar function body

// Current — defined inside Navbar(), recreated on every render
const LogoutButton = ({ className = "" }) => ( ... );

React creates a new component type on every Navbar render, forcing React to unmount/remount LogoutButton instead of reconciling it. For a simple stateless button this won't cause visible bugs, but it's an anti-pattern. Best practice is to define it at module level (above Navbar):

// Better — defined at module level, stable reference
const LogoutButton = ({ handleLogout, className = "" }) => (
  <button
    type="button"
    onClick={handleLogout}
    className={`px-2 text-[11px] font-semibold uppercase tracking-[0.09em] text-zinc-400 hover:text-black transition-colors duration-150 ${className}`}
  >
    Logout
  </button>
);

Then pass handleLogout as a prop where it's used.

2. Tailwind class conflicts in mobile LogoutButton

The base className in LogoutButton includes px-2 text-[11px], and the mobile usage appends px-5 text-[13px]. This produces a conflicting class string:

px-2 text-[11px] ... px-5 py-3.5 text-[13px] ...

It works in practice (the last Tailwind-generated rule wins in the CSS cascade), but it's fragile. If the project uses tailwind-merge or clsx, it should be applied here. Otherwise this is fine to merge as-is.


🟢 Merge Verdict

The PR is functionally correct and safe to merge. Issue #184 is fully resolved — the duplicate logout button is gone, DashboardPage.jsx is cleanly decoupled from auth, and Navbar.jsx remains the single source of truth for logout. The two issues above are minor code-quality observations that can be addressed in a follow-up if desired.

@kunalverma2512

Copy link
Copy Markdown
Owner

Well done @Arushi28-hub

A clean, precision-built refactor with excellent execution. The solution is cohesive, maintainable, and resolves the issue effectively.

Approved with confidence — ready to merge

@kunalverma2512

Copy link
Copy Markdown
Owner

@Arushi28-hub Just one more thing , your PR has some bad presentation
make sure to avoid it

Screenshot 2026-06-12 at 8 44 35 PM

@kunalverma2512 kunalverma2512 merged commit 579271d into kunalverma2512:main Jun 12, 2026
2 of 3 checks passed
@kunalverma2512

Copy link
Copy Markdown
Owner

@Arushi28-hub we are going to include AI Assisted interview in codelens
if you are ready for its discussion then let me know in our communication medium
Join it and make sure if you wannen to work on it : https://matrix.to/#/#codelensx:matrix.org

@Arushi28-hub

Copy link
Copy Markdown
Contributor Author

@Arushi28-hub Just one more thing , your PR has some bad presentation make sure to avoid it

Screenshot 2026-06-12 at 8 44 35 PM

Thank you for the feedback. I'll make sure to improve the presentation of my PRs and avoid these issues in future contributions.

@Arushi28-hub

Copy link
Copy Markdown
Contributor Author

@Arushi28-hub we are going to include AI Assisted interview in codelens if you are ready for its discussion then let me know in our communication medium Join it and make sure if you wannen to work on it : https://matrix.to/#/#codelensx:matrix.org

Thank you for the invitation. The feature sounds interesting, but I don't think I'll be able to contribute effectively to it at the moment, so I'll pass for now. Wishing the team the best with the implementation.

@kunalverma2512

Copy link
Copy Markdown
Owner

@Arushi28-hub we are going to include AI Assisted interview in codelens if you are ready for its discussion then let me know in our communication medium Join it and make sure if you wannen to work on it : https://matrix.to/#/#codelensx:matrix.org

Thank you for the invitation. The feature sounds interesting, but I don't think I'll be able to contribute effectively to it at the moment, so I'll pass for now. Wishing the team the best with the implementation.

I was saying to join communication medium because its mandatory for contributors.
Joining channels is for better work

apart from this Ai Interview feature is not going to be made by one person 😂 , I just said to get involved in it like rest other issues

@Arushi28-hub

Copy link
Copy Markdown
Contributor Author

@Arushi28-hub we are going to include AI Assisted interview in codelens if you are ready for its discussion then let me know in our communication medium Join it and make sure if you wannen to work on it : https://matrix.to/#/#codelensx:matrix.org

Thank you for the invitation. The feature sounds interesting, but I don't think I'll be able to contribute effectively to it at the moment, so I'll pass for now. Wishing the team the best with the implementation.

I was saying to join communication medium because its mandatory for contributors. Joining channels is for better work

apart from this Ai Interview feature is not going to be made by one person 😂 , I just said to get involved in it like rest other issues

Got it 😄, my bad. I thought you were specifically asking me to work on the AI Interview feature.

I'll join the channel for coordination. As for the feature, I'll stay updated and see where I can contribute if there's something that fits my skill set.

@kunalverma2512

kunalverma2512 commented Jun 12, 2026

Copy link
Copy Markdown
Owner

@Arushi28-hub we are going to include AI Assisted interview in codelens if you are ready for its discussion then let me know in our communication medium Join it and make sure if you wannen to work on it : https://matrix.to/#/#codelensx:matrix.org

Thank you for the invitation. The feature sounds interesting, but I don't think I'll be able to contribute effectively to it at the moment, so I'll pass for now. Wishing the team the best with the implementation.

I was saying to join communication medium because its mandatory for contributors. Joining channels is for better work
apart from this Ai Interview feature is not going to be made by one person 😂 , I just said to get involved in it like rest other issues

Got it 😄, my bad. I thought you were specifically asking me to work on the AI Interview feature.

I'll join the channel for coordination. As for the feature, I'll stay updated and see where I can contribute if there's something that fits my skill set.

Thats great to hear
In open source , joining , connecting in community will enhance your skills and new information you will get in community plus doubts clarification

Looking for more contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Duplicate Logout Button on Dashboard Page — Remove Redundant Logout from DashboardPage Header

2 participants