Skip to content

The open alternative to Salesforce, designed for AI.

Switch between Home, AI and Settings from one segmented control (#25059)

Félix Malfait9b4c4ef7d723
diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawer.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawer.tsx
index 99faec2b850..d3b3f0e42dc 100644
--- a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawer.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawer.tsx
@@ -1,34 +1,26 @@
-import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
+import { MainNavigationDrawerModeSwitcher } from '@/navigation/components/MainNavigationDrawerModeSwitcher';
import { MainNavigationDrawerNavigationContent } from '@/navigation/components/MainNavigationDrawerNavigationContent';
-import { MainNavigationDrawerTabsRow } from '@/navigation/components/MainNavigationDrawerTabsRow';
import { NavigationDrawerTabbedContent } from '@/navigation/components/NavigationDrawerTabbedContent';
+import { useActiveNavigationDrawerMode } from '@/navigation/hooks/useActiveNavigationDrawerMode';
import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
import { NavigationDrawer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawer';
import { NavigationDrawerFixedContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerFixedContent';
import { NavigationDrawerScrollableContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerScrollableContent';
-import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';
-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { PermissionFlagType } from '~/generated-metadata/graphql';
export const MainNavigationDrawer = ({ className }: { className?: string }) => {
- const currentWorkspace = useAtomStateValue(currentWorkspaceState);
- const navigationDrawerActiveTab = useAtomStateValue(
- navigationDrawerActiveTabState,
- );
+ const activeNavigationDrawerMode = useActiveNavigationDrawerMode();
const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
const showAiChatContent =
hasAiPermission &&
- navigationDrawerActiveTab === NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY;
+ activeNavigationDrawerMode === NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY;
return (
- <NavigationDrawer
- className={className}
- title={currentWorkspace?.displayName ?? ''}
- >
+ <NavigationDrawer className={className}>
<NavigationDrawerFixedContent>
- <MainNavigationDrawerTabsRow />
+ <MainNavigationDrawerModeSwitcher />
</NavigationDrawerFixedContent>
<NavigationDrawerScrollableContent>
diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx
new file mode 100644
index 00000000000..54ce845d52e
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerModeSwitcher.tsx
@@ -0,0 +1,161 @@
+import { styled } from '@linaria/react';
+import { useLingui } from '@lingui/react/macro';
+import { useContext } from 'react';
+import {
+ type IconComponent,
+ IconComment,
+ IconHome,
+ IconSettings,
+} from 'twenty-ui/icon';
+import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
+
+import { useActiveNavigationDrawerMode } from '@/navigation/hooks/useActiveNavigationDrawerMode';
+import { useSwitchNavigationDrawerMode } from '@/navigation/hooks/useSwitchNavigationDrawerMode';
+import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
+import { useIsWorkspaceActivationStatusEqualsTo } from '@/workspace/hooks/useIsWorkspaceActivationStatusEqualsTo';
+import { NavigationDrawerAnimatedCollapseWrapper } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper';
+import {
+ type NavigationDrawerActiveTab,
+ NAVIGATION_DRAWER_TABS,
+} from '@/ui/navigation/states/navigationDrawerTabs';
+import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
+import { PermissionFlagType } from '~/generated-metadata/graphql';
+
+const StyledSwitcher = styled.div`
+ align-items: center;
+ display: flex;
+ gap: ${themeCssVariables.spacing['0.5']};
+`;
+
+const StyledMode = styled.button<{ isActive: boolean }>`
+ align-items: center;
+ background: ${({ isActive }) =>
+ isActive ? themeCssVariables.background.transparent.light : 'transparent'};
+ border: none;
+ border-radius: ${themeCssVariables.border.radius.smRound};
+ color: ${({ isActive }) =>
+ isActive
+ ? themeCssVariables.font.color.primary
+ : themeCssVariables.font.color.tertiary};
+ corner-shape: round;
+ cursor: pointer;
+ display: flex;
+ flex-shrink: 0;
+ font-family: inherit;
+ font-size: ${themeCssVariables.font.size.md};
+ font-weight: ${themeCssVariables.font.weight.medium};
+ gap: ${({ isActive }) => (isActive ? themeCssVariables.spacing[1] : '0')};
+ height: ${themeCssVariables.spacing[7]};
+ padding: 0 ${themeCssVariables.spacing['1.5']};
+ transition:
+ background calc(${themeCssVariables.animation.duration.fast} * 1s) ease,
+ color calc(${themeCssVariables.animation.duration.fast} * 1s) ease,
+ gap calc(${themeCssVariables.animation.duration.normal} * 1s) ease;
+
+ &:hover {
+ background: ${({ isActive }) =>
+ isActive
+ ? themeCssVariables.background.transparent.light
+ : themeCssVariables.background.transparent.lighter};
+ color: ${themeCssVariables.font.color.primary};
+ }
+`;
+
+const StyledModeIcon = styled.span`
+ align-items: center;
+ display: flex;
+ flex-shrink: 0;
+ height: ${themeCssVariables.spacing[4]};
+ justify-content: center;
+ width: ${themeCssVariables.spacing[4]};
+`;
+
+// The label of an inactive mode stays in the tree so the button keeps an
+// accessible name, and the collapsed track wipes it open on activation.
+const StyledModeLabel = styled.span<{ isActive: boolean }>`
+ display: grid;
+ grid-template-columns: ${({ isActive }) => (isActive ? '1fr' : '0fr')};
+ transition: grid-template-columns
+ calc(${themeCssVariables.animation.duration.normal} * 1s) ease;
+`;
+
+const StyledModeLabelText = styled.span`
+ min-width: 0;
+ overflow: hidden;
+ white-space: nowrap;
+`;
+
+type NavigationDrawerMode = {
+ Icon: IconComponent;
+ label: string;
+ mode: NavigationDrawerActiveTab;
+};
+
+export const MainNavigationDrawerModeSwitcher = () => {
+ const { t } = useLingui();
+ const { theme } = useContext(ThemeContext);
+
+ const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
+ const activeNavigationDrawerMode = useActiveNavigationDrawerMode();
+ const { switchNavigationDrawerMode } = useSwitchNavigationDrawerMode();
+
+ const isWorkspaceSuspended = useIsWorkspaceActivationStatusEqualsTo(
+ WorkspaceActivationStatus.SUSPENDED,
+ );
+
+ // A suspended workspace is held on the billing settings by the route guard,
+ // so offering the modes it would bounce back from only flashes the user out
+ // and in again.
+ if (isWorkspaceSuspended) {
+ return null;
+ }
+
+ const modes: NavigationDrawerMode[] = [
+ {
+ Icon: IconHome,
+ label: t`Home`,
+ mode: NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ },
+ ...(hasAiPermission
+ ? [
+ {
+ Icon: IconComment,
+ label: t`AI`,
+ mode: NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ },
+ ]
+ : []),
+ {
+ Icon: IconSettings,
+ label: t`Settings`,
+ mode: NAVIGATION_DRAWER_TABS.SETTINGS,
+ },
+ ];
+
+ return (
+ <NavigationDrawerAnimatedCollapseWrapper>
+ <StyledSwitcher role="group" aria-label={t`Navigation modes`}>
+ {modes.map(({ Icon, label, mode }) => {
+ const isActive = mode === activeNavigationDrawerMode;
+
+ return (
+ <StyledMode
+ key={mode}
+ type="button"
+ isActive={isActive}
+ aria-current={isActive}
+ onClick={() => switchNavigationDrawerMode(mode)}
+ >
+ <StyledModeIcon>
+ <Icon size={theme.icon.size.md} />
+ </StyledModeIcon>
+ <StyledModeLabel isActive={isActive}>
+ <StyledModeLabelText>{label}</StyledModeLabelText>
+ </StyledModeLabel>
+ </StyledMode>
+ );
+ })}
+ </StyledSwitcher>
+ </NavigationDrawerAnimatedCollapseWrapper>
+ );
+};
diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerTabsRow.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerTabsRow.tsx
deleted file mode 100644
index 0c69b1fc8f9..00000000000
--- a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerTabsRow.tsx
+++ /dev/null
@@ -1,263 +0,0 @@
-import { styled } from '@linaria/react';
-import { t } from '@lingui/core/macro';
-import {
- type IconComponent,
- IconComment,
- IconHome,
- IconMessageCirclePlus,
-} from 'twenty-ui/icon';
-import { OverflowingTextWithTooltip } from 'twenty-ui/surfaces';
-import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
-
-import { useContext } from 'react';
-
-import { useSwitchToNewAiChat } from '@/ai/hooks/useSwitchToNewAiChat';
-import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
-import { NavigationDrawerAnimatedCollapseWrapper } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper';
-import { useIsNavigationDrawerContentExpanded } from '@/navigation/hooks/useIsNavigationDrawerContentExpanded';
-import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
-import {
- type NavigationDrawerActiveTab,
- NAVIGATION_DRAWER_TABS,
-} from '@/ui/navigation/states/navigationDrawerTabs';
-import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
-import { PermissionFlagType } from '~/generated-metadata/graphql';
-
-const StyledRow = styled.div<{ isExpanded: boolean }>`
- align-items: center;
- display: flex;
- gap: ${({ isExpanded }) => (isExpanded ? themeCssVariables.spacing[2] : 0)};
- justify-content: ${({ isExpanded }) =>
- isExpanded ? 'space-between' : 'center'};
- transition: gap calc(${themeCssVariables.animation.duration.normal} * 1s) ease;
- width: ${({ isExpanded }) => (isExpanded ? '100%' : 'max-content')};
-`;
-
-const StyledTabsPill = styled.div`
- align-items: center;
- background: ${themeCssVariables.background.secondary};
- border: 1px solid ${themeCssVariables.border.color.medium};
- border-radius: ${themeCssVariables.border.radius.pill};
- box-sizing: border-box;
- corner-shape: round;
- display: flex;
- flex-shrink: 0;
- gap: ${themeCssVariables.spacing[0.5]};
- height: ${themeCssVariables.spacing[7]};
- padding: 3px;
- width: ${themeCssVariables.spacing[18]};
-`;
-
-const StyledTabWrapper = styled.div<{ isActive: boolean }>`
- align-items: center;
- background: ${({ isActive }) =>
- isActive ? themeCssVariables.background.transparent.light : 'transparent'};
- border-radius: ${themeCssVariables.border.radius.pill};
- color: ${({ isActive }) =>
- isActive
- ? themeCssVariables.font.color.primary
- : themeCssVariables.font.color.tertiary};
- corner-shape: round;
- cursor: pointer;
- display: flex;
- flex: 1;
- height: 100%;
- justify-content: center;
-
- &:hover {
- background: ${({ isActive }) =>
- isActive
- ? themeCssVariables.background.transparent.light
- : themeCssVariables.background.transparent.lighter};
- }
-`;
-
-const StyledTabIcon = styled.div`
- align-items: center;
- display: flex;
- height: ${themeCssVariables.spacing[5]};
- justify-content: center;
- width: ${themeCssVariables.spacing[5]};
-`;
-
-const StyledNewChatIcon = styled.div`
- align-items: center;
- display: flex;
- flex-grow: 0;
- flex-shrink: 0;
- justify-content: center;
-`;
-
-const StyledNewChatButtonWrapper = styled.div<{ isExpanded: boolean }>`
- align-items: center;
- background: ${themeCssVariables.background.secondary};
- border: 1px solid ${themeCssVariables.border.color.medium};
- border-radius: ${themeCssVariables.border.radius.pill};
- box-sizing: border-box;
- corner-shape: round;
- display: flex;
- height: ${({ isExpanded }) =>
- isExpanded ? themeCssVariables.spacing[7] : themeCssVariables.spacing[6]};
- justify-content: center;
- max-width: 100%;
- min-width: ${({ isExpanded }) =>
- isExpanded ? themeCssVariables.spacing[7] : themeCssVariables.spacing[6]};
- padding: ${({ isExpanded }) =>
- isExpanded ? '3px' : themeCssVariables.spacing[0.5]};
- transition:
- height calc(${themeCssVariables.animation.duration.normal} * 1s) ease,
- padding calc(${themeCssVariables.animation.duration.normal} * 1s) ease;
- width: ${({ isExpanded }) =>
- isExpanded ? 'max-content' : themeCssVariables.spacing[6]};
-`;
-
-const StyledNewChatButton = styled.div`
- align-items: center;
- border-radius: inherit;
- color: ${themeCssVariables.font.color.secondary};
- corner-shape: round;
- cursor: pointer;
- display: flex;
- font-size: ${themeCssVariables.font.size.sm};
- font-weight: ${themeCssVariables.font.weight.medium};
- gap: ${themeCssVariables.spacing[1]};
- height: 100%;
- justify-content: center;
- min-width: 0;
- overflow: hidden;
- padding-inline: ${themeCssVariables.spacing[2]};
- transition:
- background calc(${themeCssVariables.animation.duration.fast} * 1s) ease,
- color calc(${themeCssVariables.animation.duration.fast} * 1s) ease;
- width: 100%;
-
- &:hover {
- background: ${themeCssVariables.background.transparent.light};
- color: ${themeCssVariables.font.color.primary};
- }
-`;
-
-type MainNavigationDrawerTabsRowProps = {
- NavigationMenuTabIcon?: IconComponent;
- navigationMenuTabLabel?: string;
-};
-
-export const MainNavigationDrawerTabsRow = ({
- NavigationMenuTabIcon = IconHome,
- navigationMenuTabLabel = t`Home`,
-}: MainNavigationDrawerTabsRowProps) => {
- const { theme } = useContext(ThemeContext);
- const [navigationDrawerActiveTab, setNavigationDrawerActiveTab] =
- useAtomState(navigationDrawerActiveTabState);
- const { switchToNewChat } = useSwitchToNewAiChat({
- shouldOpenInFullPage: true,
- });
- const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
-
- const isExpanded = useIsNavigationDrawerContentExpanded();
-
- if (!hasAiPermission) {
- return null;
- }
-
- const handleTabClick = (tab: NavigationDrawerActiveTab) => () => {
- setNavigationDrawerActiveTab(tab);
- };
-
- const handleTabKeyDown =
- (tab: NavigationDrawerActiveTab) => (event: React.KeyboardEvent) => {
- if (event.key === 'Enter' || event.key === ' ') {
- event.preventDefault();
- setNavigationDrawerActiveTab(tab);
- }
- };
-
- const handleNewChatClick = () => {
- setNavigationDrawerActiveTab(NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY);
- switchToNewChat();
- };
-
- const handleNewChatKeyDown = (event: React.KeyboardEvent) => {
- if (event.key === 'Enter' || event.key === ' ') {
- event.preventDefault();
- handleNewChatClick();
- }
- };
-
- const getTabIconColor = (isActive: boolean) =>
- isActive ? theme.font.color.primary : theme.font.color.tertiary;
-
- // The mobile home page adds a settings tab this two-tab pill does not have, so
- // anything that is not the chat tab belongs to the menu tab here.
- const isNavigationMenuTabActive =
- navigationDrawerActiveTab !== NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY;
-
- return (
- <StyledRow isExpanded={isExpanded}>
- <NavigationDrawerAnimatedCollapseWrapper>
- <StyledTabsPill role="tablist" aria-label={t`Navigation tabs`}>
- <StyledTabWrapper
- isActive={isNavigationMenuTabActive}
- role="tab"
- aria-selected={isNavigationMenuTabActive}
- aria-label={navigationMenuTabLabel}
- tabIndex={isNavigationMenuTabActive ? 0 : -1}
- onClick={handleTabClick(NAVIGATION_DRAWER_TABS.NAVIGATION_MENU)}
- onKeyDown={handleTabKeyDown(NAVIGATION_DRAWER_TABS.NAVIGATION_MENU)}
- >
- <StyledTabIcon>
- <NavigationMenuTabIcon
- size={theme.icon.size.md}
- color={getTabIconColor(isNavigationMenuTabActive)}
- />
- </StyledTabIcon>
- </StyledTabWrapper>
- <StyledTabWrapper
- isActive={
- navigationDrawerActiveTab ===
- NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY
- }
- role="tab"
- aria-selected={
- navigationDrawerActiveTab ===
- NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY
- }
- aria-label={t`Chat`}
- tabIndex={
- navigationDrawerActiveTab ===
- NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY
- ? 0
- : -1
- }
- onClick={handleTabClick(NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY)}
- onKeyDown={handleTabKeyDown(NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY)}
- >
- <StyledTabIcon>
- <IconComment
- size={theme.icon.size.md}
- color={getTabIconColor(
- navigationDrawerActiveTab ===
- NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
- )}
- />
- </StyledTabIcon>
- </StyledTabWrapper>
- </StyledTabsPill>
- </NavigationDrawerAnimatedCollapseWrapper>
- <StyledNewChatButtonWrapper isExpanded={isExpanded}>
- <StyledNewChatButton
- role="button"
- tabIndex={0}
- aria-label={t`New chat`}
- onClick={handleNewChatClick}
- onKeyDown={handleNewChatKeyDown}
- >
- <StyledNewChatIcon>
- <IconMessageCirclePlus size={theme.icon.size.md} />
- </StyledNewChatIcon>
- {isExpanded && <OverflowingTextWithTooltip text={t`New chat`} />}
- </StyledNewChatButton>
- </StyledNewChatButtonWrapper>
- </StyledRow>
- );
-};
diff --git a/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx b/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx
index c208c59903e..5e91423a914 100644
--- a/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx
@@ -1,24 +1,17 @@
-import { MainNavigationDrawerTabsRow } from '@/navigation/components/MainNavigationDrawerTabsRow';
-import { NavigationDrawerTabbedContent } from '@/navigation/components/NavigationDrawerTabbedContent';
-import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
+import { MainNavigationDrawerModeSwitcher } from '@/navigation/components/MainNavigationDrawerModeSwitcher';
import { SettingsNavigationDrawerItems } from '@/settings/components/SettingsNavigationDrawerItems';
import { NavigationDrawer } from '@/ui/navigation/navigation-drawer/components/NavigationDrawer';
import { NavigationDrawerFixedContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerFixedContent';
-import { NavigationDrawerSection } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSection';
import { NavigationDrawerScrollableContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerScrollableContent';
+import { NavigationDrawerSection } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSection';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
-import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
-import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { css } from '@linaria/core';
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
-import { useIsMobile } from 'twenty-ui/utilities';
import { AdvancedSettingsToggle } from 'twenty-ui/input';
-import { IconSettings } from 'twenty-ui/icon';
import { themeCssVariables } from 'twenty-ui/theme-constants';
-import { PermissionFlagType } from '~/generated-metadata/graphql';
+import { useIsMobile } from 'twenty-ui/utilities';
const StyledAdvancedToggleFixedContent = styled.div<{ isMobile: boolean }>`
flex-shrink: 0;
@@ -43,50 +36,27 @@ export const SettingsNavigationDrawer = ({
const [isAdvancedModeEnabled, setIsAdvancedModeEnabled] = useAtomState(
isAdvancedModeEnabledState,
);
- const navigationDrawerActiveTab = useAtomStateValue(
- navigationDrawerActiveTabState,
- );
- const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
-
- // The tab is shared with the desktop drawer, so gating the content on the row
- // too stops a tab set there stranding this drawer with no way back.
- const showTabsRow = hasAiPermission && !isMobile;
-
- const showAiChatContent =
- showTabsRow &&
- navigationDrawerActiveTab === NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY;
return (
- <NavigationDrawer className={className} title={t`Settings`}>
- {showTabsRow && (
- <NavigationDrawerFixedContent>
- <MainNavigationDrawerTabsRow
- NavigationMenuTabIcon={IconSettings}
- navigationMenuTabLabel={t`Settings`}
- />
- </NavigationDrawerFixedContent>
- )}
+ <NavigationDrawer className={className}>
+ <NavigationDrawerFixedContent>
+ <MainNavigationDrawerModeSwitcher />
+ </NavigationDrawerFixedContent>
<NavigationDrawerScrollableContent>
- <NavigationDrawerTabbedContent
- showAiChatContent={showAiChatContent}
- shouldMountAiChatContent={showTabsRow}
- navigationContent={<SettingsNavigationDrawerItems />}
- />
+ <SettingsNavigationDrawerItems />
</NavigationDrawerScrollableContent>
- {!showAiChatContent && (
- <StyledAdvancedToggleFixedContent isMobile={isMobile}>
- <NavigationDrawerSection>
- <AdvancedSettingsToggle
- className={advancedSettingsToggleClassName}
- isAdvancedModeEnabled={isAdvancedModeEnabled}
- setIsAdvancedModeEnabled={setIsAdvancedModeEnabled}
- label={t`Advanced`}
- />
- </NavigationDrawerSection>
- </StyledAdvancedToggleFixedContent>
- )}
+ <StyledAdvancedToggleFixedContent isMobile={isMobile}>
+ <NavigationDrawerSection>
+ <AdvancedSettingsToggle
+ className={advancedSettingsToggleClassName}
+ isAdvancedModeEnabled={isAdvancedModeEnabled}
+ setIsAdvancedModeEnabled={setIsAdvancedModeEnabled}
+ label={t`Advanced`}
+ />
+ </NavigationDrawerSection>
+ </StyledAdvancedToggleFixedContent>
</NavigationDrawer>
);
};
diff --git a/packages/twenty-front/src/modules/navigation/hooks/__tests__/useActiveNavigationDrawerMode.test.tsx b/packages/twenty-front/src/modules/navigation/hooks/__tests__/useActiveNavigationDrawerMode.test.tsx
new file mode 100644
index 00000000000..d74c9b5e412
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/hooks/__tests__/useActiveNavigationDrawerMode.test.tsx
@@ -0,0 +1,66 @@
+import { useActiveNavigationDrawerMode } from '@/navigation/hooks/useActiveNavigationDrawerMode';
+import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
+import {
+ type NavigationDrawerActiveTab,
+ NAVIGATION_DRAWER_TABS,
+} from '@/ui/navigation/states/navigationDrawerTabs';
+import { renderHook } from '@testing-library/react';
+import { createStore, Provider } from 'jotai';
+import { type ReactNode } from 'react';
+import { MemoryRouter } from 'react-router-dom';
+
+const renderActiveNavigationDrawerMode = ({
+ pathname,
+ activeTab = NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+}: {
+ pathname: string;
+ activeTab?: NavigationDrawerActiveTab;
+}) => {
+ const store = createStore();
+
+ store.set(navigationDrawerActiveTabState.atom, activeTab);
+
+ return renderHook(() => useActiveNavigationDrawerMode(), {
+ wrapper: ({ children }: { children: ReactNode }) => (
+ <Provider store={store}>
+ <MemoryRouter initialEntries={[pathname]}>{children}</MemoryRouter>
+ </Provider>
+ ),
+ });
+};
+
+describe('useActiveNavigationDrawerMode', () => {
+ it('is the settings mode on a settings page', () => {
+ const { result } = renderActiveNavigationDrawerMode({
+ pathname: '/settings/profile',
+ activeTab: NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ });
+
+ expect(result.current).toBe(NAVIGATION_DRAWER_TABS.SETTINGS);
+ });
+
+ it('is the AI mode on the AI chat page', () => {
+ const { result } = renderActiveNavigationDrawerMode({
+ pathname: '/chat/20202020-0687-4c41-b707-ed1bfca972a7',
+ });
+
+ expect(result.current).toBe(NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY);
+ });
+
+ it('is the AI mode when the chat history is open on another page', () => {
+ const { result } = renderActiveNavigationDrawerMode({
+ pathname: '/objects/people',
+ activeTab: NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ });
+
+ expect(result.current).toBe(NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY);
+ });
+
+ it('is the navigation menu mode anywhere else', () => {
+ const { result } = renderActiveNavigationDrawerMode({
+ pathname: '/objects/people',
+ });
+
+ expect(result.current).toBe(NAVIGATION_DRAWER_TABS.NAVIGATION_MENU);
+ });
+});
diff --git a/packages/twenty-front/src/modules/navigation/hooks/__tests__/useSwitchNavigationDrawerMode.test.tsx b/packages/twenty-front/src/modules/navigation/hooks/__tests__/useSwitchNavigationDrawerMode.test.tsx
new file mode 100644
index 00000000000..0fe42aeb6e3
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/hooks/__tests__/useSwitchNavigationDrawerMode.test.tsx
@@ -0,0 +1,205 @@
+import { useReturnFromExpandedAiChat } from '@/ai/hooks/useReturnFromExpandedAiChat';
+import { useSwitchToNewAiChat } from '@/ai/hooks/useSwitchToNewAiChat';
+import { useDefaultHomePagePath } from '@/navigation/hooks/useDefaultHomePagePath';
+import { useSwitchNavigationDrawerMode } from '@/navigation/hooks/useSwitchNavigationDrawerMode';
+import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
+import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
+import { navigationDrawerExpandedMemorizedState } from '@/ui/navigation/states/navigationDrawerExpandedMemorizedState';
+import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';
+import { navigationMemorizedUrlState } from '@/ui/navigation/states/navigationMemorizedUrlState';
+import { act, renderHook } from '@testing-library/react';
+import { createStore, Provider } from 'jotai';
+import { type ReactNode } from 'react';
+import { MemoryRouter, useLocation } from 'react-router-dom';
+
+jest.mock('@/ai/hooks/useReturnFromExpandedAiChat');
+jest.mock('@/ai/hooks/useSwitchToNewAiChat');
+jest.mock('@/navigation/hooks/useDefaultHomePagePath');
+
+const DEFAULT_HOME_PAGE_PATH = '/objects/companies';
+const AI_CHAT_PATH = '/chat/20202020-0687-4c41-b707-ed1bfca972a7';
+
+const mockSwitchToNewChat = jest.fn();
+const mockReturnFromExpandedAiChat = jest.fn();
+
+const renderSwitchNavigationDrawerMode = ({
+ pathname,
+ memorizedUrl = '/objects/people',
+ expandedMemorized = true,
+}: {
+ pathname: string;
+ memorizedUrl?: string;
+ expandedMemorized?: boolean;
+}) => {
+ const store = createStore();
+
+ store.set(navigationMemorizedUrlState.atom, memorizedUrl);
+ store.set(navigationDrawerExpandedMemorizedState.atom, expandedMemorized);
+ store.set(isNavigationDrawerExpandedState.atom, true);
+
+ const { result } = renderHook(
+ () => ({
+ ...useSwitchNavigationDrawerMode(),
+ location: useLocation(),
+ }),
+ {
+ wrapper: ({ children }: { children: ReactNode }) => (
+ <Provider store={store}>
+ <MemoryRouter initialEntries={[pathname]}>{children}</MemoryRouter>
+ </Provider>
+ ),
+ },
+ );
+
+ return { result, store };
+};
+
+describe('useSwitchNavigationDrawerMode', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ localStorage.clear();
+
+ jest.mocked(useSwitchToNewAiChat).mockReturnValue({
+ switchToNewChat: mockSwitchToNewChat,
+ });
+ jest
+ .mocked(useReturnFromExpandedAiChat)
+ .mockReturnValue(mockReturnFromExpandedAiChat);
+ jest.mocked(useDefaultHomePagePath).mockReturnValue({
+ defaultHomePagePath: DEFAULT_HOME_PAGE_PATH,
+ });
+ });
+
+ it('leaves settings for the memorized location and restores the drawer', () => {
+ const { result, store } = renderSwitchNavigationDrawerMode({
+ pathname: '/settings/profile',
+ expandedMemorized: false,
+ });
+
+ act(() =>
+ result.current.switchNavigationDrawerMode(
+ NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ ),
+ );
+
+ expect(result.current.location.pathname).toBe('/objects/people');
+ expect(store.get(isNavigationDrawerExpandedState.atom)).toBe(false);
+ expect(store.get(navigationDrawerActiveTabState.atom)).toBe(
+ NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ );
+ });
+
+ it('leaves settings for the default home page when it was opened from the chat', () => {
+ const { result } = renderSwitchNavigationDrawerMode({
+ pathname: '/settings/profile',
+ memorizedUrl: AI_CHAT_PATH,
+ });
+
+ act(() =>
+ result.current.switchNavigationDrawerMode(
+ NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ ),
+ );
+
+ expect(result.current.location.pathname).toBe(DEFAULT_HOME_PAGE_PATH);
+ });
+
+ it('returns from the chat page without navigating itself', () => {
+ const { result, store } = renderSwitchNavigationDrawerMode({
+ pathname: AI_CHAT_PATH,
+ });
+
+ act(() =>
+ result.current.switchNavigationDrawerMode(
+ NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ ),
+ );
+
+ expect(mockReturnFromExpandedAiChat).toHaveBeenCalled();
+ expect(store.get(navigationDrawerActiveTabState.atom)).toBe(
+ NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ );
+ });
+
+ it('opens the chat page from the settings mode', () => {
+ const { result, store } = renderSwitchNavigationDrawerMode({
+ pathname: '/settings/profile',
+ });
+
+ act(() =>
+ result.current.switchNavigationDrawerMode(
+ NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ ),
+ );
+
+ expect(mockSwitchToNewChat).toHaveBeenCalled();
+ expect(store.get(navigationDrawerActiveTabState.atom)).toBe(
+ NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ );
+ });
+
+ it('opens the chat page when the chat history is listed on another page', () => {
+ const { result } = renderSwitchNavigationDrawerMode({
+ pathname: '/objects/people',
+ });
+
+ act(() =>
+ result.current.switchNavigationDrawerMode(
+ NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ ),
+ );
+ act(() =>
+ result.current.switchNavigationDrawerMode(
+ NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ ),
+ );
+
+ expect(mockSwitchToNewChat).toHaveBeenCalledTimes(2);
+ });
+
+ it('does not start a new chat when the chat page is already open', () => {
+ const { result } = renderSwitchNavigationDrawerMode({
+ pathname: AI_CHAT_PATH,
+ });
+
+ act(() =>
+ result.current.switchNavigationDrawerMode(
+ NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ ),
+ );
+
+ expect(mockSwitchToNewChat).not.toHaveBeenCalled();
+ });
+
+ it('opens settings and memorizes where it came from', () => {
+ const { result, store } = renderSwitchNavigationDrawerMode({
+ pathname: '/objects/people',
+ });
+
+ act(() =>
+ result.current.switchNavigationDrawerMode(
+ NAVIGATION_DRAWER_TABS.SETTINGS,
+ ),
+ );
+
+ expect(result.current.location.pathname).toBe('/settings/profile');
+ expect(store.get(navigationMemorizedUrlState.atom)).toBe('/objects/people');
+ expect(store.get(navigationDrawerActiveTabState.atom)).toBe(
+ NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ );
+ });
+
+ it('stays put when settings is already open', () => {
+ const { result } = renderSwitchNavigationDrawerMode({
+ pathname: '/settings/experience',
+ });
+
+ act(() =>
+ result.current.switchNavigationDrawerMode(
+ NAVIGATION_DRAWER_TABS.SETTINGS,
+ ),
+ );
+
+ expect(result.current.location.pathname).toBe('/settings/experience');
+ });
+});
diff --git a/packages/twenty-front/src/modules/navigation/hooks/useActiveNavigationDrawerMode.ts b/packages/twenty-front/src/modules/navigation/hooks/useActiveNavigationDrawerMode.ts
new file mode 100644
index 00000000000..a344dbf8408
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/hooks/useActiveNavigationDrawerMode.ts
@@ -0,0 +1,34 @@
+import { useLocation } from 'react-router-dom';
+
+import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';
+import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
+import {
+ type NavigationDrawerActiveTab,
+ NAVIGATION_DRAWER_TABS,
+} from '@/ui/navigation/states/navigationDrawerTabs';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { isAiChatPath } from '~/utils/isAiChatPath';
+
+// Settings and the AI chat own a full page each, so the route decides those two
+// modes. The stored tab only has the final say when neither page is open, which
+// is what keeps the chat history listed while the user works on another page.
+export const useActiveNavigationDrawerMode = (): NavigationDrawerActiveTab => {
+ const { pathname } = useLocation();
+ const isSettingsDrawer = useIsSettingsDrawer();
+ const navigationDrawerActiveTab = useAtomStateValue(
+ navigationDrawerActiveTabState,
+ );
+
+ if (isSettingsDrawer) {
+ return NAVIGATION_DRAWER_TABS.SETTINGS;
+ }
+
+ if (
+ isAiChatPath(pathname) ||
+ navigationDrawerActiveTab === NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY
+ ) {
+ return NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY;
+ }
+
+ return NAVIGATION_DRAWER_TABS.NAVIGATION_MENU;
+};
diff --git a/packages/twenty-front/src/modules/navigation/hooks/useIsSettingsPage.ts b/packages/twenty-front/src/modules/navigation/hooks/useIsSettingsPage.ts
index d0335c42835..0fa744ea443 100644
--- a/packages/twenty-front/src/modules/navigation/hooks/useIsSettingsPage.ts
+++ b/packages/twenty-front/src/modules/navigation/hooks/useIsSettingsPage.ts
@@ -1,4 +1,5 @@
import { useLocation } from 'react-router-dom';
-export const useIsSettingsPage = () =>
- useLocation().pathname.match(/\/settings\//g) !== null;
+import { isSettingsPath } from '~/utils/isSettingsPath';
+
+export const useIsSettingsPage = () => isSettingsPath(useLocation().pathname);
diff --git a/packages/twenty-front/src/modules/navigation/hooks/useSwitchNavigationDrawerMode.ts b/packages/twenty-front/src/modules/navigation/hooks/useSwitchNavigationDrawerMode.ts
new file mode 100644
index 00000000000..d5285c17672
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/hooks/useSwitchNavigationDrawerMode.ts
@@ -0,0 +1,115 @@
+import { useLocation, useNavigate } from 'react-router-dom';
+import { SettingsPath } from 'twenty-shared/types';
+
+import { useReturnFromExpandedAiChat } from '@/ai/hooks/useReturnFromExpandedAiChat';
+import { useSwitchToNewAiChat } from '@/ai/hooks/useSwitchToNewAiChat';
+import { getExpandedAiChatReturnLocation } from '@/ai/utils/getExpandedAiChatReturnLocation';
+import { useActiveNavigationDrawerMode } from '@/navigation/hooks/useActiveNavigationDrawerMode';
+import { useDefaultHomePagePath } from '@/navigation/hooks/useDefaultHomePagePath';
+import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';
+import { currentMobileNavigationDrawerState } from '@/navigation/states/currentMobileNavigationDrawerState';
+import { getNavigationDrawerHomeDestination } from '@/navigation/utils/getNavigationDrawerHomeDestination';
+import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
+import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
+import { navigationDrawerExpandedMemorizedState } from '@/ui/navigation/states/navigationDrawerExpandedMemorizedState';
+import {
+ type NavigationDrawerActiveTab,
+ NAVIGATION_DRAWER_TABS,
+} from '@/ui/navigation/states/navigationDrawerTabs';
+import { navigationMemorizedUrlState } from '@/ui/navigation/states/navigationMemorizedUrlState';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
+import { useNavigateSettings } from '~/hooks/useNavigateSettings';
+import { isAiChatPath } from '~/utils/isAiChatPath';
+
+export const useSwitchNavigationDrawerMode = () => {
+ const location = useLocation();
+ const navigate = useNavigate();
+ const navigateSettings = useNavigateSettings();
+
+ const activeNavigationDrawerMode = useActiveNavigationDrawerMode();
+ const isSettingsDrawer = useIsSettingsDrawer();
+ const isAiChatPage = isAiChatPath(location.pathname);
+
+ const navigationMemorizedUrl = useAtomStateValue(navigationMemorizedUrlState);
+ const navigationDrawerExpandedMemorized = useAtomStateValue(
+ navigationDrawerExpandedMemorizedState,
+ );
+ const setIsNavigationDrawerExpanded = useSetAtomState(
+ isNavigationDrawerExpandedState,
+ );
+ const setCurrentMobileNavigationDrawer = useSetAtomState(
+ currentMobileNavigationDrawerState,
+ );
+ const setNavigationDrawerActiveTab = useSetAtomState(
+ navigationDrawerActiveTabState,
+ );
+
+ const { defaultHomePagePath } = useDefaultHomePagePath();
+ const { switchToNewChat } = useSwitchToNewAiChat({
+ shouldOpenInFullPage: true,
+ });
+ const returnFromExpandedAiChat = useReturnFromExpandedAiChat({
+ reopenSidePanel: false,
+ destinationPath: getNavigationDrawerHomeDestination({
+ memorizedUrl: getExpandedAiChatReturnLocation(location.state),
+ defaultHomePagePath,
+ }),
+ });
+
+ const switchToNavigationMenu = () => {
+ setNavigationDrawerActiveTab(NAVIGATION_DRAWER_TABS.NAVIGATION_MENU);
+
+ if (isSettingsDrawer) {
+ setCurrentMobileNavigationDrawer('main');
+ setIsNavigationDrawerExpanded(navigationDrawerExpandedMemorized);
+ navigate(
+ getNavigationDrawerHomeDestination({
+ memorizedUrl: navigationMemorizedUrl,
+ defaultHomePagePath,
+ }),
+ { replace: true },
+ );
+ return;
+ }
+
+ if (isAiChatPage) {
+ returnFromExpandedAiChat();
+ }
+ };
+
+ const switchToAiChat = () => {
+ setCurrentMobileNavigationDrawer('main');
+ setNavigationDrawerActiveTab(NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY);
+ switchToNewChat();
+ };
+
+ // The AI mode also covers the chat history listed next to another page, so it
+ // is the chat page rather than the active mode that makes a click a no-op.
+ const switchNavigationDrawerMode = (mode: NavigationDrawerActiveTab) => {
+ switch (mode) {
+ case NAVIGATION_DRAWER_TABS.NAVIGATION_MENU:
+ if (
+ activeNavigationDrawerMode === NAVIGATION_DRAWER_TABS.NAVIGATION_MENU
+ ) {
+ return;
+ }
+ switchToNavigationMenu();
+ break;
+ case NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY:
+ if (isAiChatPage) {
+ return;
+ }
+ switchToAiChat();
+ break;
+ case NAVIGATION_DRAWER_TABS.SETTINGS:
+ if (isSettingsDrawer) {
+ return;
+ }
+ navigateSettings(SettingsPath.ProfilePage);
+ break;
+ }
+ };
+
+ return { switchNavigationDrawerMode };
+};
diff --git a/packages/twenty-front/src/modules/navigation/utils/__tests__/getNavigationDrawerHomeDestination.test.ts b/packages/twenty-front/src/modules/navigation/utils/__tests__/getNavigationDrawerHomeDestination.test.ts
new file mode 100644
index 00000000000..5266b40b944
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/utils/__tests__/getNavigationDrawerHomeDestination.test.ts
@@ -0,0 +1,44 @@
+import { getNavigationDrawerHomeDestination } from '@/navigation/utils/getNavigationDrawerHomeDestination';
+
+const defaultHomePagePath = '/objects/companies';
+
+describe('getNavigationDrawerHomeDestination', () => {
+ it('returns the memorized url when it points at the app', () => {
+ expect(
+ getNavigationDrawerHomeDestination({
+ memorizedUrl: '/objects/people?viewId=42',
+ defaultHomePagePath,
+ }),
+ ).toBe('/objects/people?viewId=42');
+ });
+
+ it('falls back to the default home page when the memorized url is settings', () => {
+ expect(
+ getNavigationDrawerHomeDestination({
+ memorizedUrl: '/settings/profile',
+ defaultHomePagePath,
+ }),
+ ).toBe(defaultHomePagePath);
+ });
+
+ it('falls back to the default home page when the memorized url is the AI chat', () => {
+ expect(
+ getNavigationDrawerHomeDestination({
+ memorizedUrl: '/chat/20202020-0687-4c41-b707-ed1bfca972a7',
+ defaultHomePagePath,
+ }),
+ ).toBe(defaultHomePagePath);
+ });
+
+ it.each([null, undefined, ''])(
+ 'falls back to the default home page when the memorized url is %p',
+ (memorizedUrl) => {
+ expect(
+ getNavigationDrawerHomeDestination({
+ memorizedUrl,
+ defaultHomePagePath,
+ }),
+ ).toBe(defaultHomePagePath);
+ },
+ );
+});
diff --git a/packages/twenty-front/src/modules/navigation/utils/getNavigationDrawerHomeDestination.ts b/packages/twenty-front/src/modules/navigation/utils/getNavigationDrawerHomeDestination.ts
new file mode 100644
index 00000000000..30d3da9829e
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/utils/getNavigationDrawerHomeDestination.ts
@@ -0,0 +1,28 @@
+import { isNonEmptyString } from '@sniptt/guards';
+
+import { isAiChatPath } from '~/utils/isAiChatPath';
+import { isSettingsPath } from '~/utils/isSettingsPath';
+
+type GetNavigationDrawerHomeDestinationParams = {
+ memorizedUrl: string | null | undefined;
+ defaultHomePagePath: string;
+};
+
+// Each mode memorizes where it was opened from, so a memorized url can point at
+// another mode when the user chained them (settings opened from the chat, or
+// the reverse). Going back there would leave the switcher on the mode the user
+// just asked to leave.
+export const getNavigationDrawerHomeDestination = ({
+ memorizedUrl,
+ defaultHomePagePath,
+}: GetNavigationDrawerHomeDestinationParams) => {
+ if (!isNonEmptyString(memorizedUrl)) {
+ return defaultHomePagePath;
+ }
+
+ const [pathname] = memorizedUrl.split('?');
+
+ return isSettingsPath(pathname) || isAiChatPath(pathname)
+ ? defaultHomePagePath
+ : memorizedUrl;
+};
diff --git a/packages/twenty-front/src/modules/ui/layout/page/components/MainAppLayoutWithSidePanel.tsx b/packages/twenty-front/src/modules/ui/layout/page/components/MainAppLayoutWithSidePanel.tsx
index 02c132723cc..a801a225593 100644
--- a/packages/twenty-front/src/modules/ui/layout/page/components/MainAppLayoutWithSidePanel.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/page/components/MainAppLayoutWithSidePanel.tsx
@@ -6,20 +6,15 @@ import { styled } from '@linaria/react';
import { AnimatePresence, motion } from 'framer-motion';
import { useEffect, useState } from 'react';
import { useLocation, useOutlet } from 'react-router-dom';
-import { AppPath } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
+import { isSettingsPath } from '~/utils/isSettingsPath';
const ROUTE_SECTION_DATA_ATTRIBUTE = 'data-main-app-route-section';
const APP_TO_SETTINGS_TRANSITION_DURATION_IN_SECONDS = 0.3;
-const SETTINGS_PATH_PREFIX = `/${AppPath.Settings}`;
-
const getMainAppLayoutRouteSection = (pathname: string) =>
- pathname === SETTINGS_PATH_PREFIX ||
- pathname.startsWith(`${SETTINGS_PATH_PREFIX}/`)
- ? 'settings'
- : 'app';
+ isSettingsPath(pathname) ? 'settings' : 'app';
const StyledRow = styled.div`
display: flex;
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawer.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawer.tsx
index c6d3817b8b0..c1a6269c85a 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawer.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawer.tsx
@@ -20,13 +20,11 @@ import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { MOBILE_VIEWPORT, themeCssVariables } from 'twenty-ui/theme-constants';
-import { NavigationDrawerBackButton } from './NavigationDrawerBackButton';
import { NavigationDrawerHeader } from './NavigationDrawerHeader';
export type NavigationDrawerProps = {
children?: ReactNode;
className?: string;
- title: string;
};
const StyledAnimatedContainer = styled.div<{
@@ -75,7 +73,6 @@ const StyledContainer = styled.div<{
export const NavigationDrawer = ({
children,
className,
- title,
}: NavigationDrawerProps) => {
const [isResizing, setIsResizing] = useState(false);
const isMobile = useIsMobile();
@@ -122,11 +119,9 @@ export const NavigationDrawer = ({
isResizing={isResizing}
>
<StyledContainer isExpanded={isExpanded}>
- {!isMobile && isSettingsDrawer && title ? (
- <NavigationDrawerBackButton title={title} />
- ) : (
- <NavigationDrawerHeader showCollapseButton />
- )}
+ <NavigationDrawerHeader
+ showCollapseButton={isMobile || !isSettingsDrawer}
+ />
{children}
</StyledContainer>
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerBackButton.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerBackButton.tsx
deleted file mode 100644
index a79e3fe3129..00000000000
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerBackButton.tsx
+++ /dev/null
@@ -1,96 +0,0 @@
-import { styled } from '@linaria/react';
-
-import { currentMobileNavigationDrawerState } from '@/navigation/states/currentMobileNavigationDrawerState';
-import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
-import { navigationDrawerExpandedMemorizedState } from '@/ui/navigation/states/navigationDrawerExpandedMemorizedState';
-import { navigationMemorizedUrlState } from '@/ui/navigation/states/navigationMemorizedUrlState';
-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
-import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
-import { useIsWorkspaceActivationStatusEqualsTo } from '@/workspace/hooks/useIsWorkspaceActivationStatusEqualsTo';
-import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
-import { useContext } from 'react';
-import { IconX } from 'twenty-ui/icon';
-import { UndecoratedLink } from 'twenty-ui/navigation';
-import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
-
-type NavigationDrawerBackButtonProps = {
- title: string;
-};
-
-const StyledIconAndButtonContainer = styled.button`
- align-items: center;
- background: inherit;
- border: 1px solid transparent;
- border-radius: ${themeCssVariables.border.radius.md};
- box-sizing: border-box;
- color: ${themeCssVariables.font.color.primary};
- cursor: pointer;
- display: flex;
- flex-direction: row;
- font-family: ${themeCssVariables.font.family};
- font-size: ${themeCssVariables.font.size.md};
- font-weight: ${themeCssVariables.font.weight.medium};
- gap: ${themeCssVariables.spacing[2]};
- height: ${themeCssVariables.spacing[7]};
- padding: 2px ${themeCssVariables.spacing[1]} 2px 2px;
- width: fit-content;
- &:hover {
- background: ${themeCssVariables.background.transparent.light};
- }
-`;
-
-const StyledContainer = styled.div`
- align-items: center;
- display: flex;
- flex-direction: row;
- flex-shrink: 0;
- height: ${themeCssVariables.spacing[8]};
- justify-content: space-between;
-`;
-
-export const NavigationDrawerBackButton = ({
- title,
-}: NavigationDrawerBackButtonProps) => {
- const { theme } = useContext(ThemeContext);
- const navigationMemorizedUrl = useAtomStateValue(navigationMemorizedUrlState);
-
- const setIsNavigationDrawerExpanded = useSetAtomState(
- isNavigationDrawerExpandedState,
- );
- const setCurrentMobileNavigationDrawer = useSetAtomState(
- currentMobileNavigationDrawerState,
- );
- const navigationDrawerExpandedMemorized = useAtomStateValue(
- navigationDrawerExpandedMemorizedState,
- );
-
- const isWorkspaceSuspended = useIsWorkspaceActivationStatusEqualsTo(
- WorkspaceActivationStatus.SUSPENDED,
- );
-
- if (isWorkspaceSuspended) {
- return <StyledContainer />;
- }
-
- return (
- <StyledContainer>
- <UndecoratedLink
- to={navigationMemorizedUrl}
- replace
- onClick={() => {
- setIsNavigationDrawerExpanded(navigationDrawerExpandedMemorized);
- setCurrentMobileNavigationDrawer('main');
- }}
- >
- <StyledIconAndButtonContainer>
- <IconX
- size={theme.icon.size.md}
- stroke={theme.icon.stroke.sm}
- color={theme.font.color.secondary}
- />
- <span>{title}</span>
- </StyledIconAndButtonContainer>
- </UndecoratedLink>
- </StyledContainer>
- );
-};
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__stories__/NavigationDrawer.stories.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__stories__/NavigationDrawer.stories.tsx
index c0432be621b..e1536b83785 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__stories__/NavigationDrawer.stories.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__stories__/NavigationDrawer.stories.tsx
@@ -77,7 +77,6 @@ type Story = StoryObj<typeof NavigationDrawer>;
export const Default: Story = {
args: {
- title: 'Default',
children: (
<>
<NavigationDrawerSection>
@@ -123,7 +122,6 @@ export const Default: Story = {
export const Settings: Story = {
args: {
- title: 'Settings',
children: (
<>
<NavigationDrawerSection>
diff --git a/packages/twenty-front/src/utils/__tests__/isSettingsPath.test.ts b/packages/twenty-front/src/utils/__tests__/isSettingsPath.test.ts
new file mode 100644
index 00000000000..9fe25d96179
--- /dev/null
+++ b/packages/twenty-front/src/utils/__tests__/isSettingsPath.test.ts
@@ -0,0 +1,20 @@
+import { isSettingsPath } from '~/utils/isSettingsPath';
+
+describe('isSettingsPath', () => {
+ it.each(['/settings', '/settings/profile', '/settings/objects/companies'])(
+ 'matches %p',
+ (pathname) => {
+ expect(isSettingsPath(pathname)).toBe(true);
+ },
+ );
+
+ it.each([
+ '/objects/companies',
+ '/objects/settings',
+ '/settingsomething',
+ // A custom object named "settings" gives a record path with the segment in it
+ '/object/settings/20202020-0687-4c41-b707-ed1bfca972a7',
+ ])('does not match %p', (pathname) => {
+ expect(isSettingsPath(pathname)).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/utils/isSettingsPath.ts b/packages/twenty-front/src/utils/isSettingsPath.ts
new file mode 100644
index 00000000000..66f5c02942e
--- /dev/null
+++ b/packages/twenty-front/src/utils/isSettingsPath.ts
@@ -0,0 +1,5 @@
+import { AppBasePath } from 'twenty-shared/types';
+
+export const isSettingsPath = (pathname: string) =>
+ pathname === AppBasePath.Settings ||
+ pathname.startsWith(`${AppBasePath.Settings}/`);