Skip to content

Commit 1a7f5ae

Browse files
committed
Login menu has been improved.
1 parent 234bc17 commit 1a7f5ae

File tree

3 files changed

+45
-41
lines changed

3 files changed

+45
-41
lines changed

day-15/bs-store/src/components/adminAppbar/AdminAppbar.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import AdbIcon from "@mui/icons-material/Adb";
1515
import { Link } from "react-router-dom";
1616
import { useNavigate } from "react-router-dom";
1717
import ThemeMenu from "../theme/ThemeMenu";
18+
import { useSelector } from "react-redux";
1819

1920
const pages = ["Books", "Categories", "Authors"];
2021
const paths = [
@@ -25,6 +26,8 @@ const paths = [
2526
const settings = ["Profile", "Account", "Dashboard", "Logout"];
2627

2728
const AdminAppbar = () => {
29+
const { authItems } = useSelector((state) => state.auth);
30+
2831
const [anchorElNav, setAnchorElNav] = React.useState(null);
2932
const [anchorElUser, setAnchorElUser] = React.useState(null);
3033
const navigate = useNavigate();
@@ -133,53 +136,52 @@ const AdminAppbar = () => {
133136
{page}
134137
</Button>
135138
))}
136-
137-
</Box>
138-
<Box>
139-
140139
</Box>
140+
<Box></Box>
141+
142+
{authItems?.isLogin && (
143+
<Box sx={{ flexGrow: 0 }}>
144+
<Tooltip title='Open settings'>
145+
<IconButton onClick={handleOpenUserMenu} sx={{ p: 0 }}>
146+
<Avatar alt='Remy Sharp' src='/static/images/avatar/2.jpg' />
147+
</IconButton>
148+
</Tooltip>
149+
<Menu
150+
sx={{ mt: "45px" }}
151+
id='menu-appbar'
152+
anchorEl={anchorElUser}
153+
anchorOrigin={{
154+
vertical: "top",
155+
horizontal: "right",
156+
}}
157+
keepMounted
158+
transformOrigin={{
159+
vertical: "top",
160+
horizontal: "right",
161+
}}
162+
open={Boolean(anchorElUser)}
163+
onClose={handleCloseUserMenu}
164+
>
165+
{settings.map((setting) => (
166+
<MenuItem key={setting} onClick={handleCloseUserMenu}>
167+
<Typography textAlign='center'>{setting}</Typography>
168+
</MenuItem>
169+
))}
170+
</Menu>
171+
</Box>
172+
)}
141173

142-
<Box sx={{ flexGrow: 0 }}>
143-
<Tooltip title='Open settings'>
144-
<IconButton onClick={handleOpenUserMenu} sx={{ p: 0 }}>
145-
<Avatar alt='Remy Sharp' src='/static/images/avatar/2.jpg' />
146-
</IconButton>
147-
</Tooltip>
148-
<Menu
149-
sx={{ mt: "45px" }}
150-
id='menu-appbar'
151-
anchorEl={anchorElUser}
152-
anchorOrigin={{
153-
vertical: "top",
154-
horizontal: "right",
155-
}}
156-
keepMounted
157-
transformOrigin={{
158-
vertical: "top",
159-
horizontal: "right",
160-
}}
161-
open={Boolean(anchorElUser)}
162-
onClose={handleCloseUserMenu}
163-
>
164-
{settings.map((setting) => (
165-
<MenuItem key={setting} onClick={handleCloseUserMenu}>
166-
<Typography textAlign='center'>{setting}</Typography>
167-
</MenuItem>
168-
))}
169-
</Menu>
170-
171-
</Box>
172174
<ThemeMenu />
175+
173176
<div>
174-
<Button
175-
key="login"
177+
<Button
178+
key='login'
176179
onClick={() => navigate("/auth/login")}
177180
sx={{ my: 2, color: "white", display: "block" }}
178-
>Login</Button>
181+
>
182+
Login
183+
</Button>
179184
</div>
180-
181-
182-
183185
</Toolbar>
184186
</Container>
185187
</AppBar>

day-15/bs-store/src/store/initialValues/authItems.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export const authItems = {
55
lastName: "",
66
accessToken: "",
77
refreshToken: "",
8+
isLogin:false
89
};

day-15/bs-store/src/store/reducers/authReducer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function authReducer(state={}, { type, payload }) {
1313
return {
1414
...state,
1515
authItems:{
16-
...payload
16+
...payload,
17+
isLogin:true
1718
}
1819
};
1920

0 commit comments

Comments
 (0)