Skip to content

Commit

Permalink
fixing redirect to login on orders page
Browse files Browse the repository at this point in the history
  • Loading branch information
shema-surge committed Jul 26, 2024
1 parent 279f829 commit 4adaa4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
20 changes: 7 additions & 13 deletions src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ const NavBar: React.FC<Props> = ({sideBarActive,updateSideBarActive}) => {

const token: string | null = localStorage.getItem('token')

const { id } = useParams<{ id?: string | undefined }>();

if(!id || id==="undefined"){
navigate('/login')
}

function handleResize() {
if (window.innerWidth >= 1000) {
updateSideBarActive(false)
Expand All @@ -50,10 +44,6 @@ const NavBar: React.FC<Props> = ({sideBarActive,updateSideBarActive}) => {
setProfileActive(prev=>!prev)
}

function handleProfileRedirect(event: any){
navigate(`/MyAccount/${id}`)
}

function handleClickOutsideProfile(event: any){
if(!event.target.closest(".accountContainer")) setProfileActive(false)
}
Expand All @@ -76,9 +66,13 @@ const NavBar: React.FC<Props> = ({sideBarActive,updateSideBarActive}) => {
dispatch(fetchUser(decodedUser.userId))
}
}, [])

const { user } = useSelector((state: RootState) => state.user);

const { user } = useSelector((state: RootState) => state.user);

function handleProfileRedirect(event: any){
navigate(`/MyAccount/${user?.userId}`)
}


return (
<>
Expand All @@ -89,7 +83,7 @@ const NavBar: React.FC<Props> = ({sideBarActive,updateSideBarActive}) => {
<hr />
<h4>OnesAndZeros</h4>
</div>
<Link to={`/${id}`} className="start-buying-link">
<Link to={`/${user?.userId}`} className="start-buying-link">
Start buying
</Link>
<div className="accountContainer">
Expand Down
2 changes: 0 additions & 2 deletions src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const SideBar: React.FC<SideBarProps> = ({children,className}) => {
navigate('/')
}

const { id } = useParams<{ id?: string }>();

return (
<>
<nav ref={ref} className={`SideBar ${className}`}>
Expand Down

0 comments on commit 4adaa4f

Please sign in to comment.