Files
twenty/packages/twenty-front/src/modules/navigation/components/MobileNavigationBar.tsx
gitstart-app[bot] c6ef14acc4 Migrate to twenty-ui - navigation/navigation-bar (#7996)
This PR was created by [GitStart](https://gitstart.com/) to address the
requirements from this ticket:
[TWNTY-7537](https://clients.gitstart.com/twenty/5449/tickets/TWNTY-7537).

 --- 

### Description

- Move navigation-bar components to `twenty-ui`  

Fixes  twentyhq/private-issues#81

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
2024-10-24 13:45:52 +02:00

75 lines
2.3 KiB
TypeScript

import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
import { isCommandMenuOpenedState } from '@/command-menu/states/isCommandMenuOpenedState';
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { useRecoilState } from 'recoil';
import {
IconComponent,
IconList,
IconSearch,
IconSettings,
NavigationBar,
} from 'twenty-ui';
import { useIsSettingsPage } from '../hooks/useIsSettingsPage';
import { currentMobileNavigationDrawerState } from '../states/currentMobileNavigationDrawerState';
type NavigationBarItemName = 'main' | 'search' | 'tasks' | 'settings';
export const MobileNavigationBar = () => {
const [isCommandMenuOpened] = useRecoilState(isCommandMenuOpenedState);
const { closeCommandMenu, openCommandMenu } = useCommandMenu();
const isSettingsPage = useIsSettingsPage();
const [isNavigationDrawerExpanded, setIsNavigationDrawerExpanded] =
useRecoilState(isNavigationDrawerExpandedState);
const [currentMobileNavigationDrawer, setCurrentMobileNavigationDrawer] =
useRecoilState(currentMobileNavigationDrawerState);
const activeItemName = isNavigationDrawerExpanded
? currentMobileNavigationDrawer
: isCommandMenuOpened
? 'search'
: isSettingsPage
? 'settings'
: 'main';
const items: {
name: NavigationBarItemName;
Icon: IconComponent;
onClick: () => void;
}[] = [
{
name: 'main',
Icon: IconList,
onClick: () => {
closeCommandMenu();
setIsNavigationDrawerExpanded(
(previousIsOpen) => activeItemName !== 'main' || !previousIsOpen,
);
setCurrentMobileNavigationDrawer('main');
},
},
{
name: 'search',
Icon: IconSearch,
onClick: () => {
if (!isCommandMenuOpened) {
openCommandMenu();
}
setIsNavigationDrawerExpanded(false);
},
},
{
name: 'settings',
Icon: IconSettings,
onClick: () => {
closeCommandMenu();
setIsNavigationDrawerExpanded(
(previousIsOpen) => activeItemName !== 'settings' || !previousIsOpen,
);
setCurrentMobileNavigationDrawer('settings');
},
},
];
return <NavigationBar activeItemName={activeItemName} items={items} />;
};