After investiagting the different options ([see related issue](https://github.com/twentyhq/core-team-issues/issues/660#issuecomment-2766030972)) I decided to add a "Verify Component" and a to build a custom Layout for this route. Reason I cannot use the default one is to have all preloaded once the user changes website and lands on the verify route. Reason I did not modify the DefaultLayout to match our need is that is would require many changes in order to avoid preloading states for our specific usecase. Fixes https://github.com/twentyhq/core-team-issues/issues/660 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
131 lines
4.6 KiB
TypeScript
131 lines
4.6 KiB
TypeScript
import { AuthModal } from '@/auth/components/AuthModal';
|
|
import { CommandMenuRouter } from '@/command-menu/components/CommandMenuRouter';
|
|
import { AppErrorBoundary } from '@/error-handler/components/AppErrorBoundary';
|
|
import { AppFullScreenErrorFallback } from '@/error-handler/components/AppFullScreenErrorFallback';
|
|
import { AppPageErrorFallback } from '@/error-handler/components/AppPageErrorFallback';
|
|
import { KeyboardShortcutMenu } from '@/keyboard-shortcut-menu/components/KeyboardShortcutMenu';
|
|
import { AppNavigationDrawer } from '@/navigation/components/AppNavigationDrawer';
|
|
import { MobileNavigationBar } from '@/navigation/components/MobileNavigationBar';
|
|
import { useIsSettingsPage } from '@/navigation/hooks/useIsSettingsPage';
|
|
import { OBJECT_SETTINGS_WIDTH } from '@/settings/data-model/constants/ObjectSettings';
|
|
import { SignInAppNavigationDrawerMock } from '@/sign-in-background-mock/components/SignInAppNavigationDrawerMock';
|
|
import { SignInBackgroundMockPage } from '@/sign-in-background-mock/components/SignInBackgroundMockPage';
|
|
import { useShowFullscreen } from '@/ui/layout/fullscreen/hooks/useShowFullscreen';
|
|
import { useShowAuthModal } from '@/ui/layout/hooks/useShowAuthModal';
|
|
import { NAV_DRAWER_WIDTHS } from '@/ui/navigation/navigation-drawer/constants/NavDrawerWidths';
|
|
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
|
|
import { Global, css, useTheme } from '@emotion/react';
|
|
import styled from '@emotion/styled';
|
|
import { AnimatePresence, LayoutGroup, motion } from 'framer-motion';
|
|
import { Outlet, useSearchParams } from 'react-router-dom';
|
|
import { useScreenSize } from 'twenty-ui/utilities';
|
|
|
|
const StyledLayout = styled.div`
|
|
background: ${({ theme }) => theme.background.noisy};
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100dvh;
|
|
position: relative;
|
|
scrollbar-color: ${({ theme }) => theme.border.color.medium};
|
|
scrollbar-width: 4px;
|
|
width: 100%;
|
|
|
|
*::-webkit-scrollbar-thumb {
|
|
border-radius: ${({ theme }) => theme.border.radius.sm};
|
|
}
|
|
`;
|
|
|
|
const StyledPageContainer = styled(motion.div)`
|
|
display: flex;
|
|
flex: 1 1 auto;
|
|
flex-direction: row;
|
|
min-height: 0;
|
|
`;
|
|
|
|
const StyledAppNavigationDrawer = styled(AppNavigationDrawer)`
|
|
flex-shrink: 0;
|
|
`;
|
|
|
|
const StyledAppNavigationDrawerMock = styled(SignInAppNavigationDrawerMock)`
|
|
flex-shrink: 0;
|
|
`;
|
|
|
|
const StyledMainContainer = styled.div`
|
|
display: flex;
|
|
flex: 0 1 100%;
|
|
overflow: hidden;
|
|
`;
|
|
|
|
export const DefaultLayout = () => {
|
|
const isMobile = useIsMobile();
|
|
const isSettingsPage = useIsSettingsPage();
|
|
const theme = useTheme();
|
|
const windowsWidth = useScreenSize().width;
|
|
const showAuthModal = useShowAuthModal();
|
|
const useShowFullScreen = useShowFullscreen();
|
|
const [searchParams] = useSearchParams();
|
|
const animateModal = searchParams.get('animateModal') !== 'false';
|
|
|
|
return (
|
|
<>
|
|
<Global
|
|
styles={css`
|
|
body {
|
|
background: ${theme.background.tertiary};
|
|
}
|
|
`}
|
|
/>
|
|
<StyledLayout>
|
|
<AppErrorBoundary FallbackComponent={AppFullScreenErrorFallback}>
|
|
<StyledPageContainer
|
|
animate={{
|
|
marginLeft:
|
|
isSettingsPage && !isMobile && !useShowFullScreen
|
|
? (windowsWidth -
|
|
(OBJECT_SETTINGS_WIDTH +
|
|
NAV_DRAWER_WIDTHS.menu.desktop.expanded +
|
|
64)) /
|
|
2
|
|
: 0,
|
|
}}
|
|
transition={{
|
|
duration: theme.animation.duration.normal,
|
|
}}
|
|
>
|
|
{!showAuthModal && (
|
|
<>
|
|
<CommandMenuRouter />
|
|
<KeyboardShortcutMenu />
|
|
</>
|
|
)}
|
|
{showAuthModal ? (
|
|
<StyledAppNavigationDrawerMock />
|
|
) : useShowFullScreen ? null : (
|
|
<StyledAppNavigationDrawer />
|
|
)}
|
|
{showAuthModal ? (
|
|
<>
|
|
<SignInBackgroundMockPage />
|
|
<AnimatePresence mode="wait">
|
|
<LayoutGroup>
|
|
<AuthModal isOpenAnimated={animateModal}>
|
|
<Outlet />
|
|
</AuthModal>
|
|
</LayoutGroup>
|
|
</AnimatePresence>
|
|
</>
|
|
) : (
|
|
<StyledMainContainer>
|
|
<AppErrorBoundary FallbackComponent={AppPageErrorFallback}>
|
|
<Outlet />
|
|
</AppErrorBoundary>
|
|
</StyledMainContainer>
|
|
)}
|
|
</StyledPageContainer>
|
|
{isMobile && <MobileNavigationBar />}
|
|
</AppErrorBoundary>
|
|
</StyledLayout>
|
|
</>
|
|
);
|
|
};
|