Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions apps/web/hooks/use-company-brain.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { useAuth } from "@lib/auth-context"
import {
getBrainMode,
getCompanyBrainOverride,
hasCompanyBrain,
} from "@/lib/billing-utils"
import { isCompanyBrainOrg } from "@/lib/billing-utils"

export function useHasCompanyBrain(): boolean {
const { org } = useAuth()
const metadata = org?.metadata as Record<string, unknown> | string | undefined
// An explicit concierge override wins over the team-onboarding fallback.
const override = getCompanyBrainOverride(metadata)
if (override !== undefined) return override
// Team-brain orgs use brain spaces even before the add-on webhook lands.
return hasCompanyBrain(metadata) || getBrainMode(metadata) === "team"
return isCompanyBrainOrg(metadata)
}
9 changes: 9 additions & 0 deletions apps/web/lib/billing-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ export function getBrainMode(
: null
}

export function isCompanyBrainOrg(
metadataRaw: Record<string, unknown> | string | null | undefined,
): boolean {
const override = getCompanyBrainOverride(metadataRaw)
if (override !== undefined) return override
if (hasCompanyBrain(metadataRaw)) return true
return getBrainMode(metadataRaw) === "team"
}

export type BrainTrialStatus =
| "active"
| "exhausted"
Expand Down
22 changes: 4 additions & 18 deletions apps/web/lib/company-brain-entry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
getBrainMode,
getBrainWorkspaceDomain,
getCompanyBrainOverride,
hasCompanyBrain,
} from "./billing-utils"
import { getBrainWorkspaceDomain, isCompanyBrainOrg } from "./billing-utils"

export type BrainEntryOrganization = {
id: string
Expand All @@ -18,21 +13,12 @@ export type CompanyBrainEntryDecision =
| { action: "choose"; organizations: BrainEntryOrganization[] }
| { action: "create" }

export function isCompanyBrainOrganization(
organization: BrainEntryOrganization,
): boolean {
const override = getCompanyBrainOverride(organization.metadata)
if (override !== undefined) return override
return (
hasCompanyBrain(organization.metadata) ||
getBrainMode(organization.metadata) === "team"
)
}

export function getCompanyBrainOrganizations(
organizations: BrainEntryOrganization[],
): BrainEntryOrganization[] {
return organizations.filter(isCompanyBrainOrganization)
return organizations.filter((organization) =>
isCompanyBrainOrg(organization.metadata),
)
}

function normalizeDomain(domain: string): string {
Expand Down
Loading