Files
speckle-server/packages/frontend-2/lib/workspaces/composables/limits.ts
T
Kristaps Fabians Geikins 596312ab0e feat(frontend): personal project limit disclaimers & prompts (#4822)
* ProjectsAdd wrapper

* WorkspaceMoveProject wrapper added

* move wrapper finalized

* passing through location

* more cleanup

* model add wrapper

* permissions cleanup

* add invite wrapper

* vue-tippy bugfix

* ViewerLimitsDialog prep

* upgrade limit alert prep

* limit alerts

* movemanager fix

* new add flow

* slug update fix

* add model flow

* invites?

* some extra fixes

* move unmount fix?

* more fixes

* vue-tsc update

* style: remove h-32 for smaller screens

* vue-tsc parser fix

* prep for new viewer limits dialog

* updated viewer dialogs

* comment variant cleanup

* CR comments

---------

Co-authored-by: michalspeckle <michal@speckle.systems>
2025-05-28 12:12:18 +03:00

73 lines
1.8 KiB
TypeScript

import { graphql } from '~/lib/common/generated/gql/gql'
import { useQuery } from '@vue/apollo-composable'
import { workspaceLimitsQuery } from '~/lib/workspaces/graphql/queries'
import { WorkspacePlanConfigs, type MaybeNullOrUndefined } from '@speckle/shared'
import type { WorkspacePlanLimits_WorkspaceFragment } from '~/lib/common/generated/gql/graphql'
graphql(`
fragment WorkspacePlanLimits_Workspace on Workspace {
id
slug
plan {
name
}
}
`)
export const useWorkspaceLimits = (params: {
slug: MaybeRef<MaybeNullOrUndefined<string>>
workspace?: MaybeRef<MaybeNullOrUndefined<WorkspacePlanLimits_WorkspaceFragment>>
}) => {
const { slug } = params
const { result } = useQuery(
workspaceLimitsQuery,
() => ({
slug: unref(slug) || ''
}),
() => ({
enabled: !!unref(slug)?.length
})
)
const workspace = computed(
() => unref(params.workspace) || result.value?.workspaceBySlug
)
// Plan limits
const limits = computed(() => {
const planName = workspace.value?.plan?.name
if (!planName)
return {
projectCount: 0,
modelCount: 0,
versionsHistory: null,
commentHistory: null
}
const planConfig = WorkspacePlanConfigs[planName]
return planConfig?.limits
})
const versionLimitFormatted = computed(() => {
const versionsHistory = limits.value?.versionsHistory
if (!versionsHistory) return 'Unlimited'
const { value, unit } = versionsHistory
return `${value} ${unit}`
})
const commentLimitFormatted = computed(() => {
const commentHistory = limits.value?.commentHistory
if (!commentHistory) return 'Unlimited'
const { value, unit } = commentHistory
return `${value} ${unit}`
})
return {
limits,
versionLimitFormatted,
commentLimitFormatted
}
}