Skip to content

Commit 9ccb760

Browse files
authored
fix(organizations): remove org calls when billing is disabled (#1211)
1 parent 43cb124 commit 9ccb760

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

apps/sim/stores/organization/store.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { create } from 'zustand'
22
import { devtools } from 'zustand/middleware'
33
import { client } from '@/lib/auth-client'
44
import { checkEnterprisePlan } from '@/lib/billing/subscriptions/utils'
5+
import { getEnv, isTruthy } from '@/lib/env'
56
import { createLogger } from '@/lib/logs/console/logger'
67
import type {
78
OrganizationStore,
@@ -17,6 +18,8 @@ import {
1718

1819
const logger = createLogger('OrganizationStore')
1920

21+
const isBillingEnabled = isTruthy(getEnv('NEXT_PUBLIC_BILLING_ENABLED'))
22+
2023
const CACHE_DURATION = 30 * 1000
2124

2225
export const useOrganizationStore = create<OrganizationStore>()(
@@ -49,6 +52,20 @@ export const useOrganizationStore = create<OrganizationStore>()(
4952
hasEnterprisePlan: false,
5053

5154
loadData: async () => {
55+
if (!isBillingEnabled) {
56+
logger.debug('Billing disabled, skipping organization data loading')
57+
set({
58+
organizations: [],
59+
activeOrganization: null,
60+
hasTeamPlan: false,
61+
hasEnterprisePlan: false,
62+
isLoading: false,
63+
error: null,
64+
lastFetched: Date.now(),
65+
})
66+
return
67+
}
68+
5269
const state = get()
5370

5471
if (state.lastFetched && Date.now() - state.lastFetched < CACHE_DURATION) {
@@ -287,6 +304,11 @@ export const useOrganizationStore = create<OrganizationStore>()(
287304
},
288305

289306
refreshOrganization: async () => {
307+
if (!isBillingEnabled) {
308+
logger.debug('Billing disabled, skipping organization refresh')
309+
return
310+
}
311+
290312
const { activeOrganization } = get()
291313
if (!activeOrganization?.id) return
292314

@@ -318,6 +340,15 @@ export const useOrganizationStore = create<OrganizationStore>()(
318340

319341
// Organization management
320342
createOrganization: async (name: string, slug: string) => {
343+
if (!isBillingEnabled) {
344+
logger.debug('Billing disabled, skipping organization creation')
345+
set({
346+
error: 'Organizations are only available when billing is enabled',
347+
isCreatingOrg: false,
348+
})
349+
return
350+
}
351+
321352
set({ isCreatingOrg: true, error: null })
322353

323354
try {

0 commit comments

Comments
 (0)