This commit is contained in:
2024-08-30 18:15:07 +02:00
parent 8cadaf08a0
commit c77503ed45
17 changed files with 273 additions and 149 deletions

View File

@@ -1,22 +1,26 @@
export function useUserLimit() {
function hasUserFreePlan() {
return true
export async function useUserLimit() {
const { user } = useUserSession()
const { categories } = await useCategories()
const { tabs } = await useTabs()
const hasPaidPlan = computed(() => user.value.subscription !== 'free')
function canCreateCategory() {
if (hasPaidPlan.value)
return true
return categories.value.length < 3
}
function getRemainingCategories() {
if (!hasUserFreePlan())
return -1
return 3
}
function getRemainingTabs(category_id: number) {
if (!hasUserFreePlan())
return -1
return category_id * 3
function canCreateTabInCategory(categoryId: number): boolean {
if (hasPaidPlan.value)
return true
return tabs.filter(tab => tab.categoryId === categoryId).length < 5
}
return {
getRemainingCategories,
getRemainingTabs,
hasPaidPlan,
userLimits,
canCreateCategory,
canCreateTabInCategory,
}
}