Skip to content

The open alternative to Salesforce, designed for AI.

1.3 KB
Raw Blame
import { agentChatIsScrolledToBottomComponentSelector } from '@/ai/states/selectors/agentChatIsScrolledToBottomComponentSelector';
import { scrollAiChatToBottom } from '@/ai/utils/scrollAiChatToBottom';
import { ScrollOverlayButton } from '@/ui/utilities/scroll/components/ScrollOverlayButton';
import { useScrollWrapperHTMLElement } from '@/ui/utilities/scroll/hooks/useScrollWrapperHTMLElement';
import { useAtomComponentSelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentSelectorValue';
import { isDefined } from 'twenty-shared/utils';
import { IconArrowDown } from 'twenty-ui/icon';
import { useLingui } from '@lingui/react/macro';

export const AiChatScrollToBottomButton = () => {
  const { t } = useLingui();
  const agentChatIsScrolledToBottom = useAtomComponentSelectorValue(
    agentChatIsScrolledToBottomComponentSelector,
  );

  const { getScrollWrapperElement } = useScrollWrapperHTMLElement();

  const handleClick = () => {
    const { scrollWrapperElement } = getScrollWrapperElement();

    if (isDefined(scrollWrapperElement)) {
      scrollAiChatToBottom(scrollWrapperElement);
    }
  };

  return (
    <ScrollOverlayButton
      Icon={IconArrowDown}
      ariaLabel={t`Scroll to bottom`}
      isVisible={!agentChatIsScrolledToBottom}
      onClick={handleClick}
    />
  );
};