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.2 KB
Raw Blame
import { getMeetingUrl } from '@channel/Call/call-link';
import { fireAndForget } from '@core/util/fireAndForget';
import { thrownResultErrorHasCode } from '@core/util/result';
import { useActiveMeetingsQuery } from '@queries/call/meetings';
import type { Accessor } from 'solid-js';
import type { CallSidebarSources } from '../context/call-sidebar';

export function useActiveQuickCallsSource(
  userId: Accessor<string | undefined>
): CallSidebarSources['active'] {
  const query = useActiveMeetingsQuery(userId);
  const accessDenied = () =>
    thrownResultErrorHasCode(query.error, 'UNAUTHORIZED') ||
    thrownResultErrorHasCode(query.error, 'FORBIDDEN');
  return {
    calls: () =>
      userId() && !query.isPending && !accessDenied()
        ? (query.data ?? []).map((meeting) => ({
            id: meeting.id,
            callId: meeting.callId ?? undefined,
            createdBy: meeting.createdBy,
            title: meeting.title,
            url: getMeetingUrl(meeting.shareToken),
          }))
        : [],
    error: () =>
      userId() && query.isError ? 'Could not load active calls.' : undefined,
    refresh: () => {
      fireAndForget(query.refetch(), 'meetings');
    },
  };
}