use-has-crm-connected.ts874 BView on GitHub import { useTRPC } from '@/providers/query-provider';
import { useQuery } from '@tanstack/react-query';
/** Integration ids that count as "the org's CRM" for canvas defaults. */
export const CRM_PROVIDERS = ['hubspot', 'salesforce', 'attio', 'copper'] as const;
/**
* Whether the user has a CRM connected.
*
* Canvas templates use this to decide whether a new pipeline view should default to showing only
* CRM-synced deals — a default that is right for a CRM-backed pipeline and wrong (an empty board)
* without one.
*/
export function useHasCrmConnected(): boolean {
const trpc = useTRPC();
const { data } = useQuery(trpc.integrations.list.queryOptions());
return (
data?.integrations.some(
(integration) =>
CRM_PROVIDERS.includes(integration.id as (typeof CRM_PROVIDERS)[number]) &&
integration.connected,
) ?? false
);
}