Skip to content

Commit

Permalink
Clean on logout the session items which create in layout and private …
Browse files Browse the repository at this point in the history
…route
  • Loading branch information
gkatrakazas committed Mar 19, 2024
1 parent 35f94d4 commit 4122cdf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export interface BackendApi {
export function useApi(): BackendApi {
const [appToken, setAppToken, clearAppToken] = useSessionStorage<string | null>("appToken", null);
const [sessionState, setSessionState, clearSessionState] = useSessionStorage<SessionState | null>("sessionState", null);
const clearSessionStorage = useClearStorages(clearAppToken, clearSessionState);
const [, , clearTokenSentInSession] = useSessionStorage<boolean | null>("tokenSentInSession", null);
const [, , clearIsMessageNoGrantedVisible] = useSessionStorage<boolean | null>("isMessageNoGrantedVisible", null);
const [, , clearIsMessageGrantedVisible] = useSessionStorage<boolean | null>("isMessageGrantedVisible", null);
const clearSessionStorage = useClearStorages(clearAppToken, clearSessionState, clearTokenSentInSession, clearIsMessageNoGrantedVisible, clearIsMessageGrantedVisible);

return useMemo(
() => {
Expand Down
11 changes: 5 additions & 6 deletions src/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ const Layout = ({ children, isPermissionGranted, tokenSentInSession }) => {
const [isContentVisible, setIsContentVisible] = useState(false);
const [isOpen, setIsOpen] = useState(false);
const toggleSidebar = () => setIsOpen(!isOpen);
const [isMessageNoGrantedVisible, setIsMessageNoGrantedVisible] = useSessionStorage('isMessageNoGrantedVisible', true);
const [isMessageGrantedVisible, setIsMessageGrantedVisible] = useSessionStorage('isMessageGrantedVisible', true);

const [isMessageNoGrantedVisible, setIsMessageNoGrantedVisible] = useSessionStorage('isMessageNoGrantedVisible', null);
const [isMessageGrantedVisible, setIsMessageGrantedVisible] = useSessionStorage('isMessageGrantedVisible', null);

const handleNavigate = (path) => {
if (location.pathname === path) {
Expand All @@ -26,11 +25,11 @@ const Layout = ({ children, isPermissionGranted, tokenSentInSession }) => {
};

const handleCloseMessageNoGranted = () => {
setIsMessageNoGrantedVisible(false);
setIsMessageNoGrantedVisible(true);
};

const handleCloseMessageGranted = () => {
setIsMessageGrantedVisible(false);
setIsMessageGrantedVisible(true);
};

useEffect(() => {
Expand Down Expand Up @@ -80,7 +79,7 @@ const Layout = ({ children, isPermissionGranted, tokenSentInSession }) => {
{/* Content */}
<div className="flex-grow bg-gray-100 p-6 mt-10 pt-10 sm:mt-0 sm:pt-6 overflow-y-auto">
{/* Conditional Notification Message */}
{(!isPermissionGranted && isMessageNoGrantedVisible) || (isPermissionGranted && tokenSentInSession !== 'true' && isMessageGrantedVisible) ? (
{(!isPermissionGranted && !isMessageNoGrantedVisible) || (isPermissionGranted && tokenSentInSession !== 'true' && !isMessageGrantedVisible) ? (
<div className="bg-orange-100 shadow-lg p-4 rounded-lg mb-4 flex items-center">
<div className="mr-4 text-orange-500">
<FaExclamationTriangle size={24} />
Expand Down

0 comments on commit 4122cdf

Please sign in to comment.