mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-30 02:57:48 +01:00
Working
This commit is contained in:
28
app/composables/user-limits.ts
Normal file
28
app/composables/user-limits.ts
Normal 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user