State Management
Uses Zustand. All stores are in libs/console-core/src/stores/.
useUserStore
const { user, fetchUser, clearUser, isAdmin } = useUserStore()
| Field/Method | Description |
|---|
user | User 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/Method | Description |
|---|
subscription | Current subscription list |
lifetime | Lifetime deal list |
credits | Credits { 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/Method | Description |
|---|
tenants | All orgs the user belongs to |
current | Currently 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()
| Field | Description |
|---|
config.subscription | Subscription config (enabled, packages, has_lifetime) |
config.credit | Credit config (enabled, min_credits, packages) |
config.tenant | Tenant config (roles) |
config.app_mode | App 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>
)
}