Account Tiers
A shared package that contains queries and types for tiers.
Usage
This package is available to be imported into your module.
import { AccountTier } from '@shared/account-tiers'
General remarks
When working with Tiers, it's important to be aware that tiers can be inactive. Although inactive tiers are valid and can be set as an Account's tier, they mostly should't be available for users to pick. This package provides functions that make it easier to guard this behavior.
The query results are by default cached for duration of the DEFAULT_CACHE_DURATION const.
Exported Types
| Type | Description |
|---|---|
AccountTier | AccountTier resource returned by our public and private API |
Exported Utils
tiersFixtures
Fixtures of tiers and its requests for testing purposes.
import { tiersFixtures } from '@shared/account-tiers'
const tiersFromApi = tiersFixtures.tiersListResponse
nock(/localhost/)
.get('/v2/account_tiers')
.query({ sort_by: 'order', sort_direction: 'asc' })
.reply(200, tiersFromApi)
Private API
Usage
import { privateAccountTiersApi } from '@shared/account-tiers'
Exported Private Queries
Account Tiers - useActiveAccountTiersQuery
Fetches the complete list of account tiers from the private API account_tiers endpoint and selects only active ones.
Given only active tiers should be available to set as the value of an Account's Tier, this query is recommended to be used over useAccountTiersQuery.
import { privateAccountTiersApi } from '@shared/account-tiers'
const { data: activeAccountTiers = [], isInitialLoading } = privateAccountTiersApi.queries.useActiveAccountTiersQuery()
Account Tiers - useAccountTiersQuery
Note: Before using it in the application, ensure that inactive values should be available in the given place. Otherwise, consider using useActiveAccountTiersQuery
This function behaves similarly to useActiveAccountTiersQuery with one difference - it returns all tiers (inactive + active).
import { privateAccountTiersApi } from '@shared/account-tiers'
const { data: accountTiers = [], isInitialLoading } = privateAccountTiersApi.queries.useAccountTiersQuery()
Exported Hooks
Account Tiers - useActiveAccountTiersForDropdown
Retrieve list of AccountTiers for the purpose of using them as option list in a dropdown.
The list will include:
- all active tiers
- current tier (regardless if it's active or inactive)
This hook handles the case when the current tier value is inactive, which otherwise wouldn't be included in the list of active tiers.
import { privateAccountTiersApi } from '@shared/account-tiers'
const { data: tiersForDropdown = [], isLoading: isLoadingActiveTiers } =
privateAccountTiersApi.hooks.useActiveAccountTiersForDropdown({
accountTierId: account?.account_tier_id,
enabled: Boolean(account),
})