Module Allotments
This package contains functions for retrieving module allotments from the server.
User Module Allotments
User module allotments are retrieved given a module name and a user GUID. All GET requests are cached for 30 days.
Getting User Module Allotments
User module allotments can be retrieved asynchronously using getUserModuleAllotments.
import { getUserModuleAllotments } from '@shared/module-allotments'
async function workWithAllotments() {
const userAllotments = await getUserModuleAllotments({
moduleName: 'meeting_intelligence',
userGuid: '752c884e-3b0f-413d-97b0-443e38f70aa7',
})
console.log(allotments[0])
}
Getting User Module Allotments in React
import { useUserModuleAllotments } from '@shared/module-allotments'
function Allotments() {
const { data, isLoading } = useUserModuleAllotments({
moduleName: 'meeting_intelligence',
userGuid: '752c884e-3b0f-413d-97b0-443e38f70aa7',
})
// ...
return <span>Is allotment enabled? {data[0].enabled ? 'Yes' : 'No'}</span>
}
Busting the Cache
We can bust the user module allotment cache across all module names and user GUIDs with invalidateUserModuleAllotments.
import { invalidateUserModuleAllotments } from '@shared/module-allotments'
// Bust the cache and wait to refetch until another allotment is asked for
invalidateUserModuleAllotments()
// Bust the cache and refetch immediately if anything is using module allotments
invalidateUserModuleAllotments({ refetch: true })
Creating a User Module Allotment
We can create a user module allotment using createUserModuleAllotment.
import { createUserModuleAllotment } from '@shared/module-allotments'
async function createAllotment() {
const newAllotment = await createUserModuleAllotment({
enabled: true,
moduleName: 'meeting_intelligence',
userGuid: '752c884e-3b0f-413d-97b0-443e38f70aa7',
})
console.log(newAllotment)
}
This function automatically busts the cache for the given module name / user GUID pair.
Updating a User Module Allotment
We can update a user module allotment using updateUserModuleAllotment.
import { updateUserModuleAllotment } from '@shared/module-allotments'
async function updateAllotment() {
const updatedAllotment = await updateUserModuleAllotment({
enabled: true,
id: 101,
moduleName: 'meeting_intelligence',
userGuid: '752c884e-3b0f-413d-97b0-443e38f70aa7',
})
console.log(updatedAllotment)
}
This function automatically busts the cache for the given module name / user GUID pair.
Team Module Allotments
Team module allotments are retrieved given a module name. No team module allotment requests are cached.
Getting Team Module Allotments
Team module allotments can be retrieved asynchronously using getTeamModuleAllotments.
import { getTeamModuleAllotments } from '@shared/module-allotments'
async function getTeamAllotments() {
const teamAllotments = await getTeamModuleAllotments({
moduleName: 'meeting_intelligence',
})
console.log(teamAllotments[0])
}