mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
fix(organizations): remove org calls when billing is disabled (#1211)
This commit is contained in:
@@ -2,6 +2,7 @@ import { create } from 'zustand'
|
||||
import { devtools } from 'zustand/middleware'
|
||||
import { client } from '@/lib/auth-client'
|
||||
import { checkEnterprisePlan } from '@/lib/billing/subscriptions/utils'
|
||||
import { getEnv, isTruthy } from '@/lib/env'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import type {
|
||||
OrganizationStore,
|
||||
@@ -17,6 +18,8 @@ import {
|
||||
|
||||
const logger = createLogger('OrganizationStore')
|
||||
|
||||
const isBillingEnabled = isTruthy(getEnv('NEXT_PUBLIC_BILLING_ENABLED'))
|
||||
|
||||
const CACHE_DURATION = 30 * 1000
|
||||
|
||||
export const useOrganizationStore = create<OrganizationStore>()(
|
||||
@@ -49,6 +52,20 @@ export const useOrganizationStore = create<OrganizationStore>()(
|
||||
hasEnterprisePlan: false,
|
||||
|
||||
loadData: async () => {
|
||||
if (!isBillingEnabled) {
|
||||
logger.debug('Billing disabled, skipping organization data loading')
|
||||
set({
|
||||
organizations: [],
|
||||
activeOrganization: null,
|
||||
hasTeamPlan: false,
|
||||
hasEnterprisePlan: false,
|
||||
isLoading: false,
|
||||
error: null,
|
||||
lastFetched: Date.now(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const state = get()
|
||||
|
||||
if (state.lastFetched && Date.now() - state.lastFetched < CACHE_DURATION) {
|
||||
@@ -287,6 +304,11 @@ export const useOrganizationStore = create<OrganizationStore>()(
|
||||
},
|
||||
|
||||
refreshOrganization: async () => {
|
||||
if (!isBillingEnabled) {
|
||||
logger.debug('Billing disabled, skipping organization refresh')
|
||||
return
|
||||
}
|
||||
|
||||
const { activeOrganization } = get()
|
||||
if (!activeOrganization?.id) return
|
||||
|
||||
@@ -318,6 +340,15 @@ export const useOrganizationStore = create<OrganizationStore>()(
|
||||
|
||||
// Organization management
|
||||
createOrganization: async (name: string, slug: string) => {
|
||||
if (!isBillingEnabled) {
|
||||
logger.debug('Billing disabled, skipping organization creation')
|
||||
set({
|
||||
error: 'Organizations are only available when billing is enabled',
|
||||
isCreatingOrg: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
set({ isCreatingOrg: true, error: null })
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user