Skip to content

Commit

Permalink
Merge pull request #36 from atlp-rwanda/bgfix-orders-redirection
Browse files Browse the repository at this point in the history
fixing redirect to login on orders page
  • Loading branch information
UmuhireJessie authored Jul 26, 2024
2 parents 53b1756 + d1b9102 commit 94e13a0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 10 additions & 21 deletions src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,21 @@ import { fetchUser } from "../../redux/slices/userSlices";
import { logoutUser } from "../../redux/slices/loginSlice";
import { resetToken } from "../../redux/slices/tokenSlice";

interface Props{
interface Props {
sideBarActive: boolean,
updateSideBarActive: ((state:boolean)=>void)
updateSideBarActive: ((state: boolean) => void)
}


const NavBar: React.FC<Props> = ({sideBarActive,updateSideBarActive}) => {
const NavBar: React.FC<Props> = ({ sideBarActive, updateSideBarActive }) => {

const [profileActive, setProfileActive] = useState<boolean>(false)
const [profileActive, setProfileActive] = useState<boolean>(false)

const dispatch = useDispatch<AppDispatch>()
const navigate = useNavigate()

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 @@ -46,16 +40,12 @@ const NavBar: React.FC<Props> = ({sideBarActive,updateSideBarActive}) => {
navigate("/");
}

function handleProfileClick(event: any){
setProfileActive(prev=>!prev)
}

function handleProfileRedirect(event: any){
navigate(`/MyAccount/${id}`)
function handleProfileClick(event: any) {
setProfileActive(prev => !prev)
}

function handleClickOutsideProfile(event: any){
if(!event.target.closest(".accountContainer")) setProfileActive(false)
function handleClickOutsideProfile(event: any) {
if (!event.target.closest(".accountContainer")) setProfileActive(false)
}

interface User {
Expand All @@ -78,7 +68,6 @@ const NavBar: React.FC<Props> = ({sideBarActive,updateSideBarActive}) => {
}, [])

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


return (
<>
Expand All @@ -89,7 +78,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 All @@ -105,7 +94,7 @@ const NavBar: React.FC<Props> = ({sideBarActive,updateSideBarActive}) => {
{
profileActive ?
<div className="profileContainer">
<div className="userDetails" onClick={handleProfileRedirect}>
<div className="userDetails" onClick={() => navigate(`/MyAccount/${user?.userId}`)}>
<FontAwesomeIcon icon={faUser}></FontAwesomeIcon>
<p>{user ? `${user.firstName}` : `Account`}</p>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/Sidebar/Sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;

ul {
list-style: none;
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 94e13a0

Please sign in to comment.