From 48ada6a49a644d8d5466a048d381c797ee7184ed Mon Sep 17 00:00:00 2001 From: Ramkumar kushwah <68776478+kushwahramkumar2003@users.noreply.github.com> Date: Mon, 30 Sep 2024 06:24:08 +0530 Subject: [PATCH] improve dropdown (#670) --- 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 - )} +
-
- )} - + )} + + ); }