mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-14 12:14:33 +01:00
33 lines
984 B
TypeScript
33 lines
984 B
TypeScript
const MAX_CATEGORIES = 3
|
|
const MAX_TABS_PER_CATEGORY = 6
|
|
|
|
export async function useUserLimits() {
|
|
const { user } = useUserSession()
|
|
const { data: userLimits, refresh: refreshUserLimits } = await useFetch('/api/users/limits')
|
|
|
|
const hasPaidPlan = computed(() => user.value.subscription !== 'free')
|
|
|
|
function canCreateCategory() {
|
|
if (hasPaidPlan.value)
|
|
return true
|
|
if (!userLimits.value.categories)
|
|
return false
|
|
return userLimits.value.categories.length < MAX_CATEGORIES
|
|
}
|
|
|
|
function canCreateTabInCategory(categoryId: number): boolean {
|
|
if (hasPaidPlan.value)
|
|
return true
|
|
if (!userLimits.value.categories || !userLimits.value.categories.find(category => category.id === categoryId))
|
|
return false
|
|
return userLimits.value.categories.find(category => category.id === categoryId).tabs.length < MAX_TABS_PER_CATEGORY
|
|
}
|
|
|
|
return {
|
|
hasPaidPlan,
|
|
canCreateCategory,
|
|
canCreateTabInCategory,
|
|
refreshUserLimits,
|
|
}
|
|
}
|