From ca600f40285161c22b656aad9994728fd2aa7fbe Mon Sep 17 00:00:00 2001 From: VitalyDevico Date: Mon, 18 Dec 2023 20:10:39 +0200 Subject: [PATCH 1/2] X2-8266 | Cannot Decline Reservation through the Notifications Tab --- src/components/Sidebar/Sidebar.jsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/Sidebar/Sidebar.jsx b/src/components/Sidebar/Sidebar.jsx index bc968216..0d76e567 100644 --- a/src/components/Sidebar/Sidebar.jsx +++ b/src/components/Sidebar/Sidebar.jsx @@ -29,14 +29,20 @@ export const Sidebar = ({ onLogoClick, isStickyHeader = true, isStickyFooter = true, + shouldCloseOnRouteChange = true, }) => { const [isLeftDrawerOpen, setIsLeftDrawerOpen] = useState(false); const [isRightDrawerOpen, setIsRightDrawerOpen] = useState(false); + // eslint-disable-next-line no-undef + const location = typeof window === "undefined" ? undefined : window.location; + useEffect(() => { - setIsLeftDrawerOpen(false); // Close the drawer if notifications changes - setIsRightDrawerOpen(false); - }, [notifications]); + if (shouldCloseOnRouteChange && location?.search?.includes("redirect=true")) { + setIsLeftDrawerOpen(false); + setIsRightDrawerOpen(false); + } + }, [location.search, shouldCloseOnRouteChange]); const toggleLeftDrawer = () => { if (!isLeftDrawerOpen) { @@ -168,6 +174,7 @@ Sidebar.propTypes = { isFixed: PropTypes.bool, isStickyHeader: PropTypes.bool, isStickyFooter: PropTypes.bool, + shouldCloseOnRouteChange: PropTypes.bool, onLogoClick: PropTypes.func.isRequired, notifications: PropTypes.shape({ announcements: PropTypes.shape({ From 04cfef0e119a0f52a367fc53d9c168232b1883b0 Mon Sep 17 00:00:00 2001 From: VitalyDevico Date: Tue, 19 Dec 2023 18:44:34 +0200 Subject: [PATCH 2/2] resolved PR comments --- src/components/Sidebar/Sidebar.jsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/Sidebar/Sidebar.jsx b/src/components/Sidebar/Sidebar.jsx index 0d76e567..fae390b7 100644 --- a/src/components/Sidebar/Sidebar.jsx +++ b/src/components/Sidebar/Sidebar.jsx @@ -1,6 +1,7 @@ import clsx from "clsx"; import PropTypes from "prop-types"; import React, { useState, useEffect } from "react"; +import { isNil } from "lodash"; import { AnnounceIcon } from "../../icons/AnnounceIcon"; import { BellIcon } from "../../icons/BellIcon"; import { XolaLogoSimple } from "../../images/XolaLogoSimple"; @@ -29,20 +30,26 @@ export const Sidebar = ({ onLogoClick, isStickyHeader = true, isStickyFooter = true, - shouldCloseOnRouteChange = true, + shouldCloseOnChanges = true, + isRightDrawerVisible = null, + setIsRightDrawerVisible, }) => { const [isLeftDrawerOpen, setIsLeftDrawerOpen] = useState(false); const [isRightDrawerOpen, setIsRightDrawerOpen] = useState(false); - // eslint-disable-next-line no-undef - const location = typeof window === "undefined" ? undefined : window.location; - useEffect(() => { - if (shouldCloseOnRouteChange && location?.search?.includes("redirect=true")) { - setIsLeftDrawerOpen(false); + if (shouldCloseOnChanges) { + setIsLeftDrawerOpen(false); // Close the drawer if notifications changes setIsRightDrawerOpen(false); } - }, [location.search, shouldCloseOnRouteChange]); + }, [notifications, shouldCloseOnChanges]); + + useEffect(() => { + if (!shouldCloseOnChanges && !isNil(isRightDrawerVisible)) { + setIsRightDrawerOpen(isRightDrawerVisible); + setIsRightDrawerVisible(null); + } + }, [isRightDrawerVisible, shouldCloseOnChanges, setIsRightDrawerVisible]); const toggleLeftDrawer = () => { if (!isLeftDrawerOpen) { @@ -174,8 +181,10 @@ Sidebar.propTypes = { isFixed: PropTypes.bool, isStickyHeader: PropTypes.bool, isStickyFooter: PropTypes.bool, - shouldCloseOnRouteChange: PropTypes.bool, onLogoClick: PropTypes.func.isRequired, + shouldCloseOnChanges: PropTypes.bool, + isRightDrawerVisible: PropTypes.bool, + setIsRightDrawerVisible: PropTypes.func, notifications: PropTypes.shape({ announcements: PropTypes.shape({ count: PropTypes.number,