From 91cbdd48c8c8ac99b7c1c4cbfd62b97bf21bfd95 Mon Sep 17 00:00:00 2001 From: Alec M Date: Tue, 21 Nov 2023 12:49:16 -0500 Subject: [PATCH] CRDCDH-621 Restore current URL on login --- .../Header/HeaderTabletAndMobile.tsx | 33 ++++++++++++------- .../Header/components/NavbarDesktop.tsx | 20 ++++++++--- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/components/Header/HeaderTabletAndMobile.tsx b/src/components/Header/HeaderTabletAndMobile.tsx index 3b391a45..fb5102a0 100644 --- a/src/components/Header/HeaderTabletAndMobile.tsx +++ b/src/components/Header/HeaderTabletAndMobile.tsx @@ -1,5 +1,5 @@ -import React, { useState } from 'react'; -import { NavLink, Link, useNavigate } from 'react-router-dom'; +import React, { useEffect, useState } from 'react'; +import { NavLink, Link, useNavigate, useLocation } from 'react-router-dom'; import styled from 'styled-components'; import Logo from "./components/LogoMobile"; import menuClearIcon from '../../assets/header/Menu_Cancel_Icon.svg'; @@ -148,7 +148,7 @@ const MenuArea = styled.div` .clickable { cursor: pointer; } - + .action { cursor: pointer; } @@ -169,10 +169,12 @@ const Header = () => { const navbarMobileList: NavbarMobileList = navMobileListHookResult[0]; const setNavbarMobileList = navMobileListHookResult[1]; const [showLogoutAlert, setShowLogoutAlert] = useState(false); + const [restorePath, setRestorePath] = useState(null); const authData = useAuthContext(); const displayName = authData?.user?.firstName || "N/A"; const navigate = useNavigate(); + const location = useLocation(); const handleLogout = async () => { const logoutStatus = await authData.logout(); @@ -228,6 +230,15 @@ const Header = () => { setNavbarMobileList(navbarSublists[clickTitle]); }; + useEffect(() => { + if (!location?.pathname || location?.pathname === "/") { + setRestorePath(null); + return; + } + + setRestorePath(location?.pathname); + }, [location]); + return ( <> @@ -393,15 +404,13 @@ const Header = () => { > {displayName} - ) - : ( - -
{ if (e.key === "Enter") { setNavMobileDisplay('none'); } }} onClick={() => setNavMobileDisplay('none')}> - Login -
- - - )) : null} + ) : ( + +
{ if (e.key === "Enter") { setNavMobileDisplay('none'); } }} onClick={() => setNavMobileDisplay('none')}> + Login +
+ + )) : null}
{ const clickableTitle = clickableObject.map((item) => item.name); const navigate = useNavigate(); const authData = useAuthContext(); + const location = useLocation(); const displayName = authData?.user?.firstName?.toUpperCase() || "N/A"; const [showLogoutAlert, setShowLogoutAlert] = useState(false); + const [restorePath, setRestorePath] = useState(null); + clickableTitle.push(displayName); useOutsideAlerter(dropdownSelection, nameDropdownSelection); @@ -430,6 +433,16 @@ const NavBar = () => { useEffect(() => { setClickedTitle(""); }, []); + + useEffect(() => { + if (!location?.pathname || location?.pathname === "/") { + setRestorePath(null); + return; + } + + setRestorePath(location?.pathname); + }, [location]); + return (
- ) - : ( - + ) : ( + Login )}