From 5ab6c3304b4a2d055767b8195fac9c9eec776d16 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Tue, 9 Apr 2024 16:32:41 +0100
Subject: fix(web): Fix the toggle theme button allowing clicks from anywhere
 in the dropdown item

---
 .../components/dashboard/sidebar/SidebarProfileOptions.tsx | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

(limited to 'apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx')

diff --git a/apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx b/apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx
index bf56b805..3fe4d52f 100644
--- a/apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx
+++ b/apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx
@@ -1,5 +1,6 @@
 "use client";
 
+import { useToggleTheme } from "@/components/theme-provider";
 import { Button } from "@/components/ui/button";
 import {
   DropdownMenu,
@@ -13,28 +14,29 @@ import { signOut } from "next-auth/react";
 import { useTheme } from "next-themes";
 
 function DarkModeToggle() {
-  const { theme, setTheme } = useTheme();
+  const { theme } = useTheme();
 
   let comp;
   if (theme == "dark") {
     comp = (
-      <button onClick={() => setTheme("light")}>
+      <span>
         <Sun className="size-4" />
         <p>Light Mode</p>
-      </button>
+      </span>
     );
   } else {
     comp = (
-      <button onClick={() => setTheme("dark")}>
+      <span>
         <Moon className="size-4" />
         <p>Dark Mode</p>
-      </button>
+      </span>
     );
   }
   return <Slot className="flex flex-row gap-2">{comp}</Slot>;
 }
 
 export default function SidebarProfileOptions() {
+  const toggleTheme = useToggleTheme();
   return (
     <DropdownMenu>
       <DropdownMenuTrigger asChild>
@@ -43,7 +45,7 @@ export default function SidebarProfileOptions() {
         </Button>
       </DropdownMenuTrigger>
       <DropdownMenuContent className="w-fit">
-        <DropdownMenuItem>
+        <DropdownMenuItem onClick={toggleTheme}>
           <DarkModeToggle />
         </DropdownMenuItem>
         <DropdownMenuItem
-- 
cgit v1.2.3-70-g09d2

