From 7acd982d21747b5f02920f56b8e6f19e7dfa2d7e Mon Sep 17 00:00:00 2001 From: kushwahramkumar2003 Date: Mon, 30 Sep 2024 00:06:01 +0530 Subject: [PATCH] user dropdown menu updat --- apps/web/components/UserAccountDropDown.tsx | 127 ++++++++++++-------- 1 file changed, 78 insertions(+), 49 deletions(-) diff --git a/apps/web/components/UserAccountDropDown.tsx b/apps/web/components/UserAccountDropDown.tsx index 46307b94..98945bc9 100644 --- a/apps/web/components/UserAccountDropDown.tsx +++ b/apps/web/components/UserAccountDropDown.tsx @@ -1,4 +1,6 @@ "use client"; + +import { useState, useEffect } from "react"; import { DropdownMenu, DropdownMenuContent, @@ -6,12 +8,13 @@ import { DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, + Button, } from "@repo/ui"; -import { signOut } from "next-auth/react"; -import { useSession } from "next-auth/react"; +import { signOut, useSession } from "next-auth/react"; import { LogOut, UserRound } from "lucide-react"; import { useRouter } from "next/navigation"; import UserImage from "./UserImage"; +import { motion, AnimatePresence } from "framer-motion"; const dropDownData = [ { @@ -22,66 +25,92 @@ const dropDownData = [ ]; export default function UserAccountDropDown() { - const session = useSession(); - const user = session.data?.user; + const { data: session, status } = useSession(); + const user = session?.user; const router = useRouter(); - return ( - <> - {user && ( - - - {!user.image ? ( -
- -
- ) : ( - - )} -
+ const [isOpen, setIsOpen] = useState(false); + const [mounted, setMounted] = useState(false); - - -
- {!user.image ? ( -
- -
- ) : ( - - )} -
+ useEffect(() => { + setMounted(true); + }, []); -
- {user?.name} - {user?.email} + if (!mounted || status === "loading") return null; + if (!user) return null; + + return ( + + + + - {dropDownData.map((item, index) => { - return ( - router.push("/profile")} key={index}> - {item.icon} - {item.name} + + {isOpen && ( + + + +
+ {user.image ? ( + + ) : ( +
+ +
+ )} +
+
+ {user.name} + {user.email} +
+
+ + {dropDownData.map((item, index) => ( + router.push(item.href)} + > + {item.icon} + {item.name} - ); - })} - - {user && ( + ))} + { await signOut(); router.push("/"); }} - className=" flex gap-2 focus:bg-[#f34e4e]" > - - Logout + + Logout - )} +
-
- )} - + )} + + ); }