import { Stack } from '@servicetitan/design-system'; import { useDependencies } from '@servicetitan/react-ioc'; import { CHAT_UI_STORE_TOKEN, ChatCustomizations } from '@servicetitan/titan-chat-ui-common'; import { observer } from 'mobx-react'; import { FC, Fragment, useEffect, useRef } from 'react'; import { ChatConnecting } from './chat-connecting'; import { ChatInput } from './chat-input'; import { ChatInputFile } from './chat-input-file'; import { ChatMessages } from './chat-messages'; import { ChatNotifications } from './chat-notifications'; export interface IChatProps { className?: string; customizations?: ChatCustomizations; } export const Chat: FC = observer(({ className, customizations }) => { const scrollRef = useRef(null); const [chatUiStore] = useDependencies(CHAT_UI_STORE_TOKEN); const footerComponent = customizations?.footerComponent; const loadingComponent = customizations?.loadingComponent; useEffect(() => { chatUiStore.setCustomizationContext(customizations); }, [chatUiStore, customizations]); useEffect(() => { setTimeout(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, 0); }, [chatUiStore.scrollCounter]); return ( {chatUiStore.isStarting ? ( (loadingComponent ?? ) ) : (
{!customizations?.input?.isDisabled && ( {Boolean(footerComponent) && footerComponent} )}
)}
); });