Alessandro/web 1836 billing tab show x10 free guest (#2896)
* feat(workspaces): add label field to cost items * feat(workspaces): use label field to display cost items
This commit is contained in:
committed by
GitHub
parent
4896816506
commit
3fa2bcd4f3
@@ -5,10 +5,10 @@ import {
|
||||
import { Roles, throwUncoveredError } from '@speckle/shared'
|
||||
|
||||
type KnownWorkspaceCostItemNames =
|
||||
| 'workspace members'
|
||||
| 'free guests'
|
||||
| 'read/write guests'
|
||||
| 'read only guests'
|
||||
| 'workspace-members'
|
||||
| 'free-guests'
|
||||
| 'read-write-guests'
|
||||
| 'read-only-guests'
|
||||
|
||||
type KnownCurrencies = 'GBP'
|
||||
|
||||
@@ -17,6 +17,7 @@ type WorkspaceCostItem = {
|
||||
description: string
|
||||
count: number
|
||||
cost: number
|
||||
label: string
|
||||
}
|
||||
|
||||
const getWorkspaceCostItemCost = ({
|
||||
@@ -26,13 +27,13 @@ const getWorkspaceCostItemCost = ({
|
||||
currency?: KnownCurrencies
|
||||
}): number => {
|
||||
switch (name) {
|
||||
case 'workspace members':
|
||||
case 'workspace-members':
|
||||
return 49
|
||||
case 'free guests':
|
||||
case 'free-guests':
|
||||
return 0
|
||||
case 'read/write guests':
|
||||
case 'read-write-guests':
|
||||
return 15
|
||||
case 'read only guests':
|
||||
case 'read-only-guests':
|
||||
return 5
|
||||
default:
|
||||
throwUncoveredError(name)
|
||||
@@ -79,29 +80,40 @@ export const getWorkspaceCostItemsFactory =
|
||||
|
||||
const workspaceCostItems: WorkspaceCostItem[] = []
|
||||
|
||||
const workspaceMembersCount = adminCount + memberCount
|
||||
const freeGuestsCount = freeGuestsIds.length
|
||||
|
||||
workspaceCostItems.push({
|
||||
name: 'workspace members',
|
||||
name: 'workspace-members',
|
||||
description: 'General workspace member',
|
||||
count: adminCount + memberCount,
|
||||
cost: getWorkspaceCostItemCost({ name: 'workspace members' })
|
||||
count: workspaceMembersCount,
|
||||
cost: getWorkspaceCostItemCost({ name: 'workspace-members' }),
|
||||
label: `${workspaceMembersCount} workspace ${
|
||||
workspaceMembersCount === 1 ? 'member' : 'members'
|
||||
}`
|
||||
})
|
||||
workspaceCostItems.push({
|
||||
name: 'free guests',
|
||||
name: 'free-guests',
|
||||
description: 'The first 10 workspace guests are free',
|
||||
count: freeGuestsIds.length,
|
||||
cost: getWorkspaceCostItemCost({ name: 'free guests' })
|
||||
count: freeGuestsCount,
|
||||
cost: getWorkspaceCostItemCost({ name: 'free-guests' }),
|
||||
label: `${freeGuestsCount}/10 free ${freeGuestsCount === 1 ? 'guest' : 'guests'}`
|
||||
})
|
||||
workspaceCostItems.push({
|
||||
name: 'read/write guests',
|
||||
name: 'read-write-guests',
|
||||
description: 'Workspace guests with write access to minimum 1 workspace project',
|
||||
count: writeGuestCount,
|
||||
cost: getWorkspaceCostItemCost({ name: 'read/write guests' })
|
||||
cost: getWorkspaceCostItemCost({ name: 'read-write-guests' }),
|
||||
label: `${writeGuestCount} read/write ${
|
||||
writeGuestCount === 1 ? 'guest' : 'guests'
|
||||
}`
|
||||
})
|
||||
workspaceCostItems.push({
|
||||
name: 'read only guests',
|
||||
name: 'read-only-guests',
|
||||
description: 'Workspace guests with only read access to some workspace projects',
|
||||
count: readGuestCount,
|
||||
cost: getWorkspaceCostItemCost({ name: 'read only guests' })
|
||||
cost: getWorkspaceCostItemCost({ name: 'read-only-guests' }),
|
||||
label: `${readGuestCount} read only ${readGuestCount === 1 ? 'guest' : 'guests'}`
|
||||
})
|
||||
|
||||
return workspaceCostItems
|
||||
|
||||
@@ -44,6 +44,7 @@ export const workspaceBillingFragment = gql`
|
||||
count
|
||||
name
|
||||
cost
|
||||
label
|
||||
}
|
||||
discount {
|
||||
name
|
||||
|
||||
@@ -490,24 +490,28 @@ describe('Workspaces GQL CRUD', () => {
|
||||
expect(currency).to.equal('GBP')
|
||||
expect(items).to.deep.equal([
|
||||
{
|
||||
name: 'workspace members',
|
||||
name: 'workspace-members',
|
||||
count: 2,
|
||||
cost: 49
|
||||
cost: 49,
|
||||
label: '2 workspace members'
|
||||
},
|
||||
{
|
||||
name: 'free guests',
|
||||
name: 'free-guests',
|
||||
count: 10,
|
||||
cost: 0
|
||||
cost: 0,
|
||||
label: '10/10 free guests'
|
||||
},
|
||||
{
|
||||
name: 'read/write guests',
|
||||
name: 'read-write-guests',
|
||||
count: 1,
|
||||
cost: 15
|
||||
cost: 15,
|
||||
label: '1 read/write guest'
|
||||
},
|
||||
{
|
||||
name: 'read only guests',
|
||||
name: 'read-only-guests',
|
||||
count: 2,
|
||||
cost: 5
|
||||
cost: 5,
|
||||
label: '2 read only guests'
|
||||
}
|
||||
])
|
||||
expect(discount).to.deep.equal(null)
|
||||
|
||||
Reference in New Issue
Block a user