Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

3.3 KB
Raw Blame
import EmptyStateEmailGraphic from '@design/empty-state-email.svg';
import type { CrmCompanyEntity } from '@entity';
import { Tabs } from '@ui';
import { createMemo, createSignal } from 'solid-js';
import { CrmListEmpty } from '../components/list-state';
import {
  RecordSection,
  RecordSectionFilters,
} from '../components/record-section';
import { useCrmContext } from '../context/crm-context';
import type {
  CrmEmailSignal as EmailSignalView,
  CrmEmailScope as EmailView,
} from '../context/crm-sources';
import { RecordItemList } from './record-item-list';
import { useCompanyEmailsQuery } from './use-crm';

export function CompanyEmailsSection(props: { company?: CrmCompanyEntity }) {
  const domains = createMemo(
    () => props.company?.domains.map((domain) => domain.domain) ?? []
  );
  const [search, setSearch] = createSignal('');
  const crm = useCrmContext();
  const [view, setView] = createSignal<EmailView>('team');
  const [signalView, setSignalView] = createSignal<EmailSignalView>('all');
  const emailsQuery = useCompanyEmailsQuery(domains, view, signalView);

  const emptyMessage = () => {
    const kind = signalView() === 'signal' ? 'signal emails' : 'emails';
    if (view() === 'me') return `No ${kind} with this company in your inbox.`;
    if (props.company?.emailSync === false) {
      return 'Email sync is disabled for this company.';
    }
    return `No ${kind} with this company yet.`;
  };

  return (
    <RecordSection
      title="Emails"
      search={search()}
      onSearchChange={setSearch}
      createAction={{
        label: 'New email',
        disabled: props.company?.emailSync === false,
        onClick: () => crm.openEmailComposer(),
      }}
      actions={
        <RecordSectionFilters
          activeCount={
            Number(signalView() !== 'all') + Number(view() !== 'team')
          }
          onClear={() => {
            setSignalView('all');
            setView('team');
          }}
        >
          <Tabs
            aria-label="Email importance"
            size="sm"
            touch="inset"
            options={[
              { value: 'signal', label: 'Signal' },
              { value: 'all', label: 'All' },
            ]}
            value={signalView()}
            onChange={setSignalView}
          />
          <Tabs
            aria-label="Email inboxes"
            size="sm"
            touch="inset"
            options={[
              { value: 'team', label: 'Team' },
              { value: 'me', label: 'Me' },
            ]}
            value={view()}
            onChange={setView}
          />
        </RecordSectionFilters>
      }
    >
      <RecordItemList
        source={emailsQuery}
        search={search()}
        pending={!props.company}
        onClearSearch={() => setSearch('')}
        emptyContent={
          <CrmListEmpty
            graphic={EmptyStateEmailGraphic}
            title={emptyMessage()}
            description="Conversations with this company's email domains will appear here."
            action={
              props.company?.emailSync === false
                ? undefined
                : {
                    label: 'New email',
                    onClick: () => crm.openEmailComposer(),
                  }
            }
          />
        }
      />
    </RecordSection>
  );
}