Skip to content

The open alternative to Salesforce, designed for AI.

5.0 KB
Raw Blame
import { styled } from '@linaria/react';
import { type BackgroundMockCompany } from '@/sign-in-background-mock/constants/BackgroundMockCompanies';
import { BACKGROUND_MOCK_COLUMN_WIDTHS } from '@/sign-in-background-mock/constants/BackgroundMockColumnWidths';
import { BACKGROUND_MOCK_TABLE_DIMENSIONS } from '@/sign-in-background-mock/constants/BackgroundMockTableDimensions';
import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
import { Avatar, Chip } from 'twenty-ui/primitives/data-display';
import { Checkbox } from 'twenty-ui/primitives/input';
import { IconLink } from 'twenty-ui/icon';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';

import { getLogoUrlFromDomainName } from 'twenty-shared/utils';
import { useLingui } from '@lingui/react/macro';

const StyledRow = styled.div`
  display: flex;
  height: ${BACKGROUND_MOCK_TABLE_DIMENSIONS.rowHeight}px;
`;

const StyledDragHandleColumn = styled.div`
  flex-shrink: 0;
  height: ${BACKGROUND_MOCK_TABLE_DIMENSIONS.rowHeight}px;
  width: ${BACKGROUND_MOCK_TABLE_DIMENSIONS.dragHandleColumnWidth}px;
`;

const StyledCheckboxColumn = styled.div`
  align-items: center;
  border-bottom: 1px solid ${themeCssVariables.border.color.light};
  box-sizing: border-box;
  display: flex;
  flex-shrink: 0;
  height: ${BACKGROUND_MOCK_TABLE_DIMENSIONS.rowHeight}px;
  justify-content: center;
  padding-right: ${themeCssVariables.spacing[1]};
  width: ${BACKGROUND_MOCK_TABLE_DIMENSIONS.checkboxColumnWidth}px;
`;

const StyledCell = styled.div<{ width: number }>`
  align-items: center;
  border-bottom: 1px solid ${themeCssVariables.border.color.light};
  border-right: 1px solid ${themeCssVariables.border.color.light};
  box-sizing: border-box;
  color: ${themeCssVariables.font.color.primary};
  display: flex;
  flex-shrink: 0;
  height: ${BACKGROUND_MOCK_TABLE_DIMENSIONS.rowHeight}px;
  overflow: hidden;
  padding-left: ${themeCssVariables.spacing[2]};
  white-space: nowrap;
  width: ${({ width }) => width}px;
`;

const StyledTruncated = styled.span`
  overflow: hidden;
  text-overflow: ellipsis;
`;

const StyledMutedText = styled.span`
  color: ${themeCssVariables.font.color.tertiary};
  overflow: hidden;
  text-overflow: ellipsis;
`;

const StyledLastEmptyCell = styled.div`
  border-bottom: 1px solid ${themeCssVariables.border.color.light};
  flex: 1;
  height: ${BACKGROUND_MOCK_TABLE_DIMENSIONS.rowHeight}px;
  min-width: ${BACKGROUND_MOCK_TABLE_DIMENSIONS.addColumnButtonWidth}px;
`;

type BackgroundMockTableRowProps = {
  company: BackgroundMockCompany;
};

const formatNumber = (value: number) => value.toLocaleString('en-US');

const PersonChip = ({ fullName }: { fullName: string | null }) => {
  if (fullName === null) {
    return null;
  }

  return (
    <Chip
      size="sm"
      variant="plain"
      color="primary"
      startElement={
        <Avatar shape="circle" name={fullName} colorSeed={fullName} size="md" />
      }
    >
      {fullName}
    </Chip>
  );
};

export const BackgroundMockTableRow = ({
  company,
}: BackgroundMockTableRowProps) => {
  const { t } = useLingui();
  const theme = useTheme();

  const logoUrl = getLogoUrlFromDomainName(company.domainName);

  return (
    <StyledRow>
      <StyledDragHandleColumn />
      <StyledCheckboxColumn>
        <Checkbox hoverable checked={false} />
      </StyledCheckboxColumn>
      <StyledCell width={BACKGROUND_MOCK_COLUMN_WIDTHS.Name}>
        <Chip
          size="sm"
          variant="plain"
          color="primary"
          startElement={
            <Avatar
              shape="square"
              src={getAbsoluteImageUrl(logoUrl)}
              name={company.name}
              colorSeed={company.id}
              size="md"
            />
          }
        >
          {company.name}
        </Chip>
      </StyledCell>
      <StyledCell width={BACKGROUND_MOCK_COLUMN_WIDTHS.Domain}>
        <Chip
          size="sm"
          variant="plain"
          color="secondary"
          weight="medium"
          startElement={
            <IconLink
              size={theme.icon.size.sm}
              stroke={theme.icon.stroke.sm}
              color={theme.font.color.tertiary}
            />
          }
        >
          {company.domainName}
        </Chip>
      </StyledCell>
      <StyledCell width={BACKGROUND_MOCK_COLUMN_WIDTHS['Created by']}>
        <PersonChip fullName={company.createdBy} />
      </StyledCell>
      <StyledCell width={BACKGROUND_MOCK_COLUMN_WIDTHS['Account Owner']}>
        <PersonChip fullName={company.accountOwner} />
      </StyledCell>
      <StyledCell width={BACKGROUND_MOCK_COLUMN_WIDTHS['Creation date']}>
        <StyledMutedText>{t`about 13 hours ago`}</StyledMutedText>
      </StyledCell>
      <StyledCell width={BACKGROUND_MOCK_COLUMN_WIDTHS.Employees}>
        <StyledTruncated>{formatNumber(company.employees)}</StyledTruncated>
      </StyledCell>
      <StyledCell width={BACKGROUND_MOCK_COLUMN_WIDTHS.Address}>
        <StyledTruncated>{company.address}</StyledTruncated>
      </StyledCell>
      <StyledLastEmptyCell />
    </StyledRow>
  );
};