Skip to content

Commit f203409

Browse files
committed
improvement: Refactor Profile component menu structure and enhance signOut function
1 parent 39ca758 commit f203409

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/components/Header/Profile.tsx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { useContext } from "react";
22
import { RiLogoutCircleLine } from "react-icons/ri";
3-
import { Box, Flex, Text, Menu, Avatar, MenuList, MenuItem, MenuButton } from "@chakra-ui/react";
3+
import {
4+
Box,
5+
Flex,
6+
Text,
7+
Menu,
8+
Avatar,
9+
MenuList,
10+
MenuItem,
11+
MenuButton,
12+
MenuDivider,
13+
MenuGroup
14+
} from "@chakra-ui/react";
415

516
import { AuthContext } from "@/contexts/AuthContext";
617

@@ -27,18 +38,28 @@ export function Profile({ showProfileData = true }: ProfileProps) {
2738
</MenuButton>
2839

2940
<MenuList bg="gray.900" borderColor="gray.800">
30-
<MenuItem
31-
icon={<RiLogoutCircleLine size={16} />}
32-
onClick={signOut}
33-
color="gray.600"
34-
bg="gray.900"
35-
_hover={{ color: "white" }}
36-
>
37-
Logout
38-
</MenuItem>
39-
<MenuItem color="gray.600" bg="gray.900" _hover={{ color: "white" }}>
40-
{user?.about}
41-
</MenuItem>
41+
<MenuGroup title="Minha conta">
42+
<MenuItem color="gray.600" bg="gray.900" _hover={{ color: "white" }}>
43+
{user?.about}
44+
</MenuItem>
45+
{/* <MenuDivider /> */}
46+
<MenuItem color="gray.600" bg="gray.900" _hover={{ color: "white" }}>
47+
My Account
48+
</MenuItem>
49+
<MenuItem color="gray.600" bg="gray.900" _hover={{ color: "white" }}>
50+
Payments{" "}
51+
</MenuItem>
52+
<MenuDivider />
53+
<MenuItem
54+
icon={<RiLogoutCircleLine size={16} />}
55+
onClick={signOut}
56+
color="gray.600"
57+
bg="gray.900"
58+
_hover={{ color: "white" }}
59+
>
60+
Logout
61+
</MenuItem>
62+
</MenuGroup>
4263
</MenuList>
4364
</Menu>
4465
</Flex>

src/contexts/AuthContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
5959
}
6060

6161
function signOut() {
62+
setUser(null);
6263
destroyCookie(undefined, "nextauth.token");
6364
Router.push("/auth/signin");
64-
setUser(null);
6565
}
6666

6767
return <AuthContext.Provider value={{ user, isAuthenticated, signIn, signOut }}>{children}</AuthContext.Provider>;

0 commit comments

Comments
 (0)