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.

2.8 KB
Raw Blame
import { useFeatureFlag } from '@app/lib/analytics/posthog';
import {
  enableCalendarAddSharedEvent,
  enableCalendarGuestInvites,
  enableCalendarInvitationForward,
  enableCalendarPromptMobile,
  enableCalendarPromptWeb,
  enableCalendarSearchUi,
  enableCalendarTeamOoo,
  enableCalendarTeamSharing,
  enableCalendarUi,
} from '@core/constant/featureFlags';
import { isMobile } from '@core/mobile/isMobile';
import type { Accessor } from 'solid-js';

export function useCalendarUiFlag(): Accessor<boolean> {
  const flag = useFeatureFlag(enableCalendarUi);
  return () => flag().enabled;
}

/**
 * Whether the calendar search UI (Search-view calendar type/rows and the
 * in-calendar keyword search) is enabled. A sub-feature of the calendar UI, so
 * it requires `enable-calendar-ui` on top of its own flag.
 */
export function useCalendarSearchUiFlag(): Accessor<boolean> {
  const calendarUi = useCalendarUiFlag();
  const searchFlag = useFeatureFlag(enableCalendarSearchUi);
  return () => calendarUi() && searchFlag().enabled;
}

/**
 * Whether the "Enable calendar" prompt may surface on this device. Each form
 * factor has its own kill switch: a phone defers to
 * `enable-calendar-prompt-mobile`, which is off until the mobile toast layout
 * can present the prompt properly, and everything else defers to
 * `enable-calendar-prompt-web`. Both are gated by `enable-calendar-ui` at the
 * call site.
 */
export function useCalendarPromptAllowed(): Accessor<boolean> {
  const mobileFlag = useFeatureFlag(enableCalendarPromptMobile);
  const webFlag = useFeatureFlag(enableCalendarPromptWeb);
  return () => (isMobile() ? mobileFlag() : webFlag()).enabled;
}

/**
 * Whether the team out-of-office surfaces (the side panel section and the
 * teammate absence overlay on the grid) are enabled.
 */
export function useCalendarTeamOooFlag(): Accessor<boolean> {
  const flag = useFeatureFlag(enableCalendarTeamOoo);
  return () => flag().enabled;
}

/** Whether a guest the organizer allows to invite may add guests. */
export function useCalendarGuestInvitesFlag(): Accessor<boolean> {
  const flag = useFeatureFlag(enableCalendarGuestInvites);
  return () => flag().enabled;
}

/** Whether a guest who cannot add guests may forward the invitation instead. */
export function useCalendarInvitationForwardFlag(): Accessor<boolean> {
  const flag = useFeatureFlag(enableCalendarInvitationForward);
  return () => flag().enabled;
}

/** Whether a channel member may add a shared event to their own calendar. */
export function useCalendarAddSharedEventFlag(): Accessor<boolean> {
  const flag = useFeatureFlag(enableCalendarAddSharedEvent);
  return () => flag().enabled;
}

export function useCalendarTeamSharingFlag(): Accessor<boolean> {
  const calendarUi = useCalendarUiFlag();
  const flag = useFeatureFlag(enableCalendarTeamSharing);
  return () => calendarUi() && flag().enabled;
}