Skip to content

The open alternative to Salesforce, designed for AI.

3.0 KB
Raw Blame
import { type AppErrorDisplayProps } from '@/error-handler/types/AppErrorDisplayProps';
import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
import { IconReload } from 'twenty-ui/icon';
import { Button } from 'twenty-ui/primitives/input';
import { themeCssVariables } from 'twenty-ui/theme';

type AppRootErrorFallbackProps = AppErrorDisplayProps;

const StyledContainer = styled.div`
  background: ${themeCssVariables.background.noisy};
  box-sizing: border-box;
  display: flex;
  height: calc(100vh / var(--t-zoom, 1));
  padding: 12px;
  width: calc(100vw / var(--t-zoom, 1));
`;

const StyledPanel = styled.div`
  background: ${themeCssVariables.grayScale.gray1};
  border: 1px solid ${themeCssVariables.grayScale.gray5};
  border-radius: ${themeCssVariables.border.radius.md};
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  width: 100%;
`;

const StyledEmptyContainer = styled.div`
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100%;
  justify-content: center;
  text-align: center;
  width: 100%;
`;

const StyledImageContainer = styled.div`
  align-items: center;
  display: flex;
  justify-content: center;
  position: relative;
`;

const StyledBackgroundImage = styled.img`
  max-height: 160px;
  max-width: 160px;
`;

const StyledInnerImage = styled.img`
  max-height: 130px;
  max-width: 130px;
  position: absolute;
`;

const StyledEmptyTextContainer = styled.div`
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  text-align: center;
  width: 100%;
`;

const StyledEmptyTitle = styled.div`
  color: ${themeCssVariables.grayScale.gray12};
  font-size: 1.23rem;
  font-weight: 600;
`;

const StyledEmptySubTitle = styled.div`
  color: ${themeCssVariables.grayScale.gray11};
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.5;
  max-height: 2.8em;
  overflow: hidden;
  width: 50%;
`;

export const AppRootErrorFallback = ({
  resetErrorBoundary,
  title = t`Sorry, something went wrong`,
}: AppRootErrorFallbackProps) => {
  return (
    <StyledContainer>
      <StyledPanel>
        <StyledEmptyContainer>
          <StyledImageContainer>
            <StyledBackgroundImage
              src="/images/placeholders/background/error_index_bg.png"
              alt={t`Background`}
            />
            <StyledInnerImage
              src="/images/placeholders/moving-image/error_index.png"
              alt={t`Error illustration`}
            />
          </StyledImageContainer>
          <StyledEmptyTextContainer>
            <StyledEmptyTitle>{title}</StyledEmptyTitle>
            <StyledEmptySubTitle>
              {t`Please refresh the page.`}
            </StyledEmptySubTitle>
          </StyledEmptyTextContainer>
          <Button
            variant="outline"
            startIcon={<IconReload />}
            onClick={resetErrorBoundary}
          >
            {t`Reload`}
          </Button>
        </StyledEmptyContainer>
      </StyledPanel>
    </StyledContainer>
  );
};