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.3 KB
Raw Blame
import { usePending } from '@app/observability/flow';
import type { CrmViewConfig } from '../core/saved-view';
import { createDefaultCrmView } from '../primitives/default-view';
import { useApplyCrmView } from './apply-view';
import { usePersonalCrmViews, useTeamCrmViews } from './use-crm';

/**
 * Applies the default saved view (personal wins over team) once its queries
 * settle. Mounted only on a fresh Customers entry — never for restored
 * (back/forward) entries or `?crmView=` share links, which carry their own
 * state. One-shot: later refetches never re-apply, so a default set while
 * the view is open doesn't yank the user's state out from under them.
 */
export function CrmDefaultViewLoader(props: {
  withReplaceHistory(apply: () => void): void;
}) {
  const personal = usePersonalCrmViews();
  const team = useTeamCrmViews();
  const applyView = useApplyCrmView();
  usePending('crm.personal-views', personal.isLoading);
  usePending('crm.team-views', team.isLoading);

  createDefaultCrmView({
    personalLoading: personal.isLoading,
    teamLoading: team.isLoading,
    personal: () => personal.defaultView()?.config,
    team: () => team.defaultView()?.config as CrmViewConfig | undefined,
    apply: (config) => props.withReplaceHistory(() => applyView(config)),
  });

  return null;
}