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.

1.6 KB
Raw Blame
import { UserCardTrigger } from '@core/component/UserCardTrigger';
import { getDisplayName, macroIdToEmail, tryMacroId } from '@core/user';
import { cn } from '@ui';
import { Show } from 'solid-js';
import { useMessage } from './context';

type FromPillProps = {
  class?: string;
};

/**
 * Shows who triggered an agent (bot) message, e.g. `from Eric Hayes`, where the
 * name is a hoverable user reference (same hover card as an `@mention`).
 * Rendered only when the message's sender carries a `triggered_by` user id.
 */
export function FromPill(props: FromPillProps) {
  const message = useMessage();
  const triggeredBy = () => message().sender?.triggered_by ?? undefined;
  const macroId = () => {
    const id = triggeredBy();
    return id ? tryMacroId(id) : undefined;
  };
  const displayName = () => getDisplayName(macroId());
  const email = () => {
    const id = macroId();
    return id ? macroIdToEmail(id) : (triggeredBy() ?? '');
  };
  const label = () => displayName() || email() || (triggeredBy() ?? '');

  return (
    <Show when={triggeredBy()}>
      <span
        class={cn(
          'inline-flex items-center gap-1 text-xs text-ink-muted',
          props.class
        )}
      >
        from
        <UserCardTrigger
          placement="top"
          triggerAs="span"
          user={{
            displayName: label(),
            email: email(),
            id: triggeredBy(),
          }}
          trigger={
            <span class="cursor-default rounded-md p-0.5 font-medium text-accent hover:bg-accent/20 focus:bg-accent/20">
              {label()}
            </span>
          }
        />
      </span>
    </Show>
  );
}