Skip to content

The open alternative to Salesforce, designed for AI.

2.2 KB
Raw Blame
import {
  IconArchiveOff,
  IconDotsVertical,
  IconEye,
  IconPencil,
  IconTrash,
} from 'twenty-ui/icon';
import { LightIconButton } from 'twenty-ui/components/input';
import { Dropdown } from 'twenty-ui/components/navigation';

import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';
import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
import { GenericDropdownContentWidth } from '@/ui/layout/dropdown/constants/GenericDropdownContentWidth';
import { useLingui } from '@lingui/react/macro';

type SettingsObjectInactiveMenuDropDownProps = {
  isCustomObject: boolean;
  objectMetadataItemNamePlural: string;
  onActivate: () => void;
  onDelete: () => void;
  onEdit: () => void;
  isReadOnly?: boolean;
};

export const SettingsObjectInactiveMenuDropDown = ({
  objectMetadataItemNamePlural,
  onActivate,
  onDelete,
  onEdit,
  isCustomObject,
  isReadOnly = false,
}: SettingsObjectInactiveMenuDropDownProps) => {
  const { t } = useLingui();
  const isEditable = isCustomObject && !isReadOnly;

  return (
    <DropdownRoot
      type="menu"
      dropdownId={`${objectMetadataItemNamePlural}-settings-object-inactive-menu-dropdown`}
    >
      <Dropdown.Trigger
        render={
          <LightIconButton
            aria-label={t`Inactive Object Options`}
            emphasis="subtle"
          >
            <IconDotsVertical />
          </LightIconButton>
        }
      />
      <DropdownContent align="end" width={GenericDropdownContentWidth.Narrow}>
        <Dropdown.Section>
          <Dropdown.ActionItem
            startIcon={isEditable ? <IconPencil /> : <IconEye />}
            onClick={onEdit}
          >
            {isEditable ? t`Edit` : t`View`}
          </Dropdown.ActionItem>
          {!isReadOnly && (
            <Dropdown.ActionItem
              startIcon={<IconArchiveOff />}
              onClick={onActivate}
            >{t`Activate`}</Dropdown.ActionItem>
          )}
          {isCustomObject && !isReadOnly && (
            <Dropdown.ActionItem
              startIcon={<IconTrash />}
              color="danger"
              onClick={onDelete}
            >{t`Delete`}</Dropdown.ActionItem>
          )}
        </Dropdown.Section>
      </DropdownContent>
    </DropdownRoot>
  );
};