The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { isDefined } from 'twenty-shared/utils';
import { useIsOnNewAiChatSlot } from '@/ai/hooks/useIsOnNewAiChatSlot';
import { agentChatErrorFamilyState } from '@/ai/states/agentChatErrorFamilyState';
import { agentChatIsAwaitingFirstChunkFamilyState } from '@/ai/states/agentChatIsAwaitingFirstChunkFamilyState';
import { agentChatIsStreamingFamilyState } from '@/ai/states/agentChatIsStreamingFamilyState';
import { agentChatThreadsLoadingSelector } from '@/ai/states/selectors/agentChatThreadsLoadingSelector';
import { agentChatHasMessageSelector } from '@/ai/states/selectors/agentChatHasMessageSelector';
import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
import { useIsMobile } from 'twenty-ui/utilities';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
export const useShouldShowAiChatEmptyState = () => {
const currentAiChatThread = useAtomStateValue(currentAiChatThreadState);
const agentChatError = useAtomFamilyStateValue(agentChatErrorFamilyState, {
threadId: currentAiChatThread,
});
const agentChatIsAwaitingFirstChunk = useAtomFamilyStateValue(
agentChatIsAwaitingFirstChunkFamilyState,
{ threadId: currentAiChatThread },
);
const agentChatIsStreaming = useAtomFamilyStateValue(
agentChatIsStreamingFamilyState,
{ threadId: currentAiChatThread },
);
const agentChatThreadsLoading = useAtomStateValue(
agentChatThreadsLoadingSelector,
);
const agentChatHasMessage = useAtomStateValue(agentChatHasMessageSelector);
const isMobile = useIsMobile();
const isOnNewAiChatSlot = useIsOnNewAiChatSlot();
return (
isOnNewAiChatSlot &&
!isMobile &&
!agentChatHasMessage &&
!isDefined(agentChatError) &&
!agentChatThreadsLoading &&
!agentChatIsAwaitingFirstChunk &&
!agentChatIsStreaming
);
};