mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-27 18:00:26 +01:00
working
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user