fix(gatekeeper): fix subscription upgrades (#4411)
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
import { WorkspacePlans } from '@speckle/shared'
|
||||
import { z } from 'zod'
|
||||
|
||||
const WorkspacePlansUpgradeMapping = z.union([
|
||||
z.object({
|
||||
current: z.literal('free'),
|
||||
upgrade: z.union([z.literal('team'), z.literal('pro')])
|
||||
}),
|
||||
z.object({
|
||||
current: z.literal('team'),
|
||||
upgrade: z.union([z.literal('team'), z.literal('pro')])
|
||||
}),
|
||||
z.object({
|
||||
current: z.literal('pro'),
|
||||
upgrade: z.literal('pro')
|
||||
})
|
||||
])
|
||||
const WorkspacePlansUpgradeMapping: Record<WorkspacePlans, WorkspacePlans[]> = {
|
||||
academia: [],
|
||||
unlimited: [],
|
||||
business: [],
|
||||
businessInvoiced: [],
|
||||
plus: [],
|
||||
plusInvoiced: [],
|
||||
starter: [],
|
||||
starterInvoiced: [],
|
||||
free: ['team', 'teamUnlimited', 'pro', 'proUnlimited'],
|
||||
team: ['team', 'teamUnlimited', 'pro', 'proUnlimited'],
|
||||
teamUnlimited: ['teamUnlimited', 'pro', 'proUnlimited'],
|
||||
teamUnlimitedInvoiced: [],
|
||||
pro: ['pro', 'proUnlimited'],
|
||||
proUnlimited: ['proUnlimited'],
|
||||
proUnlimitedInvoiced: []
|
||||
}
|
||||
|
||||
export const isUpgradeWorkspacePlanValid = ({
|
||||
current,
|
||||
@@ -23,5 +25,5 @@ export const isUpgradeWorkspacePlanValid = ({
|
||||
current: WorkspacePlans
|
||||
upgrade: WorkspacePlans
|
||||
}): boolean => {
|
||||
return WorkspacePlansUpgradeMapping.safeParse({ current, upgrade }).success
|
||||
return WorkspacePlansUpgradeMapping[current].includes(upgrade)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user