This commit is contained in:
2024-09-02 16:58:23 +02:00
parent c77503ed45
commit 1b0dc0f27d
52 changed files with 817 additions and 1379 deletions

View File

@@ -0,0 +1,28 @@
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
return userLimits.value.categories.length < MAX_CATEGORIES
}
function canCreateTabInCategory(categoryId: number): boolean {
if (hasPaidPlan.value)
return true
return userLimits.value.categories.find(category => category.id === categoryId).tabs.length < MAX_TABS_PER_CATEGORY
}
return {
hasPaidPlan,
canCreateCategory,
canCreateTabInCategory,
refreshUserLimits,
}
}