State Management

Uses Zustand. All stores are in libs/console-core/src/stores/.

useUserStore

const { user, fetchUser, clearUser, isAdmin } = useUserStore()
Field/MethodDescription
userUser info { id, email, role, tenant: { role } }
fetchUser()Calls /v1/users/info, returns success status
clearUser()Clears user state
isAdmin()Whether system admin (user.role === 'owner')

useBillingStore

const { subscription, lifetime, credits, fetchAll, clear, getTotalCredits, hasSubscription } = useBillingStore()
Field/MethodDescription
subscriptionCurrent subscription list
lifetimeLifetime deal list
creditsCredits { all: [], total: number }
fetchAll()Load subscriptions, lifetime, credits in parallel
clear()Clear all billing data
getTotalCredits()Get total available credits
hasSubscription(planId?)Whether there is an active subscription
hasLifetime(planId?)Whether there is a lifetime deal

useTenantStore

const { tenants, current, fetchTenants, setCurrent, clearTenants } = useTenantStore()
Field/MethodDescription
tenantsAll orgs the user belongs to
currentCurrently selected org
fetchTenants()Fetch org list, auto-restore last selection
setCurrent(tenant)Switch org (saved to localStorage)
clearTenants()Clear org state and localStorage

current includes a member_role field indicating the user’s role in the current org.

useWebsiteStore

const { config, fetchConfig } = useWebsiteStore()
FieldDescription
config.subscriptionSubscription config (enabled, packages, has_lifetime)
config.creditCredit config (enabled, min_credits, packages)
config.tenantTenant config (roles)
config.app_modeApp mode

Usage Example

import { useUserStore, useBillingStore, useTenantStore } from '@readystart/console-core'

function MyComponent() {
  const { user } = useUserStore()
  const { credits } = useBillingStore()
  const { current } = useTenantStore()

  return (
    <div>
      <p>User: {user?.email}</p>
      <p>Org: {current?.name}</p>
      <p>Credits: {credits?.total}</p>
    </div>
  )
}