Skip to content

Commit

Permalink
Made toggleDrawer() function and passed it notifications drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
justinorringer committed Jan 17, 2025
1 parent 92b96f4 commit af51cd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/components/NotificationsDrawer/DrawerPanelContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import { ScalprumComponent } from '@scalprum/react-core';

export type DrawerPanelProps = {
panelRef: React.Ref<unknown>;
// toggle: () => void;
toggleDrawer: () => void;
};

const DrawerPanelBase = ({ panelRef }: DrawerPanelProps) => {
// toggle drawer will be an api or prop

const DrawerPanelBase: React.FC<DrawerPanelProps> = ({ panelRef, toggleDrawer }) => {
const auth = useContext(ChromeAuthContext);
const isOrgAdmin = auth?.user?.identity?.user?.is_org_admin;
const { getUserPermissions } = useContext(InternalChromeContext);
Expand All @@ -23,9 +21,9 @@ const DrawerPanelBase = ({ panelRef }: DrawerPanelProps) => {
isOrgAdmin: isOrgAdmin,
getUserPermissions: getUserPermissions,
panelRef: panelRef,
expanded: true,
// toggle: toggle,
toggleDrawer: toggleDrawer,
};

const PanelContent = () => {
return (
<ScalprumComponent scope="notifications" module="./NotificationsDrawer" fallback={null} ErrorComponent={<Fragment />} {...notificationProps} />
Expand All @@ -39,6 +37,8 @@ const DrawerPanelBase = ({ panelRef }: DrawerPanelProps) => {
);
};

const DrawerPanel = React.forwardRef((props, innerRef) => <DrawerPanelBase panelRef={innerRef} {...props} />);
const DrawerPanel = React.forwardRef<unknown, Omit<DrawerPanelProps, 'panelRef'>>((props, innerRef) => (
<DrawerPanelBase panelRef={innerRef} {...props} />
));

export default DrawerPanel;
10 changes: 6 additions & 4 deletions src/layouts/DefaultLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import isEqual from 'lodash/isEqual';
import ChromeRoutes from '../components/Routes/Routes';
import useOuiaTags from '../utils/useOuiaTags';
import RedirectBanner from '../components/Stratosphere/RedirectBanner';
import { useAtomValue } from 'jotai';
import { useAtom } from 'jotai';

import { useIntl } from 'react-intl';
import messages from '../locales/Messages';
Expand Down Expand Up @@ -49,7 +49,6 @@ type DefaultLayoutProps = {

const DefaultLayout: React.FC<DefaultLayoutProps> = ({ hasBanner, selectedAccountNumber, hideNav, isNavOpen, setIsNavOpen, Sidebar, Footer }) => {
const drawerPanelRef = useRef<HTMLDivElement>(null);
// const toggleDrawer = useSetAtom(notificationDrawerExpandedAtom);
useEffect(() => {
if (drawerPanelRef.current !== null) {
focusDrawer();
Expand All @@ -65,9 +64,12 @@ const DefaultLayout: React.FC<DefaultLayoutProps> = ({ hasBanner, selectedAccoun
tabbableElement.focus();
}
};
const toggleDrawer = () => {
setIsNotificationsDrawerExpanded((prev) => !prev);
};
const intl = useIntl();
const { loaded, schema, noNav } = useNavigation();
const isNotificationsDrawerExpanded = useAtomValue(notificationDrawerExpandedAtom);
const [isNotificationsDrawerExpanded, setIsNotificationsDrawerExpanded] = useAtom(notificationDrawerExpandedAtom);
const isNotificationsEnabled = useFlag('platform.chrome.notifications-drawer');

return (
Expand All @@ -90,7 +92,7 @@ const DefaultLayout: React.FC<DefaultLayoutProps> = ({ hasBanner, selectedAccoun
}
{...(isNotificationsEnabled && {
onNotificationDrawerExpand: focusDrawer,
notificationDrawer: <DrawerPanel ref={drawerPanelRef} />,
notificationDrawer: <DrawerPanel ref={drawerPanelRef} toggleDrawer={toggleDrawer} />,
isNotificationDrawerExpanded: isNotificationsDrawerExpanded,
})}
sidebar={
Expand Down

0 comments on commit af51cd5

Please sign in to comment.