Skip to content

Commit c594f02

Browse files
authored
fix(site): display correct user_limit on license ui (#8118)
1 parent 797e91d commit c594f02

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed

site/src/api/api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ export const getWorkspaceBuildParameters = async (
10061006
return response.data
10071007
}
10081008
type Claims = {
1009-
license_expires?: number
1009+
license_expires: number
10101010
account_type?: string
10111011
account_id?: string
10121012
trial: boolean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { screen } from "@testing-library/react"
2+
import { render } from "../../testHelpers/renderHelpers"
3+
import { LicenseCard } from "./LicenseCard"
4+
import { MockLicenseResponse } from "testHelpers/entities"
5+
6+
describe("LicenseCard", () => {
7+
it("renders (smoke test)", async () => {
8+
// When
9+
render(
10+
<LicenseCard
11+
license={MockLicenseResponse[0]}
12+
userLimitActual={1}
13+
userLimitLimit={10}
14+
onRemove={() => null}
15+
isRemoving={false}
16+
/>,
17+
)
18+
19+
// Then
20+
await screen.findByText("#1")
21+
await screen.findByText("1 / 10")
22+
await screen.findByText("Enterprise")
23+
})
24+
25+
it("renders userLimit as unlimited if there is not user limit", async () => {
26+
// When
27+
render(
28+
<LicenseCard
29+
license={MockLicenseResponse[0]}
30+
userLimitActual={1}
31+
userLimitLimit={undefined}
32+
onRemove={() => null}
33+
isRemoving={false}
34+
/>,
35+
)
36+
37+
// Then
38+
await screen.findByText("#1")
39+
await screen.findByText("1 / Unlimited")
40+
await screen.findByText("Enterprise")
41+
})
42+
43+
it("renders license's user_limit when it is available instead of using the default", async () => {
44+
const licenseUserLimit = 3
45+
const license = {
46+
...MockLicenseResponse[0],
47+
claims: {
48+
...MockLicenseResponse[0].claims,
49+
features: {
50+
...MockLicenseResponse[0].claims.features,
51+
user_limit: licenseUserLimit,
52+
},
53+
},
54+
}
55+
56+
// When
57+
render(
58+
<LicenseCard
59+
license={license}
60+
userLimitActual={1}
61+
userLimitLimit={100} // This should not be used
62+
onRemove={() => null}
63+
isRemoving={false}
64+
/>,
65+
)
66+
67+
// Then
68+
await screen.findByText("1 / 3")
69+
})
70+
})

site/src/components/LicenseCard/LicenseCard.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import Button from "@mui/material/Button"
22
import Paper from "@mui/material/Paper"
33
import { makeStyles } from "@mui/styles"
4-
import { License } from "api/typesGenerated"
54
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
65
import { Stack } from "components/Stack/Stack"
76
import dayjs from "dayjs"
87
import { useState } from "react"
98
import { Pill } from "components/Pill/Pill"
109
import { compareAsc } from "date-fns"
10+
import { GetLicensesResponse } from "api/api"
1111

1212
type LicenseCardProps = {
13-
license: License
13+
license: GetLicensesResponse
1414
userLimitActual?: number
1515
userLimitLimit?: number
1616
onRemove: (licenseId: number) => void
@@ -30,6 +30,9 @@ export const LicenseCard = ({
3030
number | undefined
3131
>(undefined)
3232

33+
const currentUserLimit =
34+
license.claims.features["user_limit"] || userLimitLimit
35+
3336
return (
3437
<Paper key={license.id} elevation={2} className={styles.licenseCard}>
3538
<ConfirmDialog
@@ -72,7 +75,7 @@ export const LicenseCard = ({
7275
<Stack direction="column" spacing={0} alignItems="center">
7376
<span className={styles.secondaryMaincolor}>Users</span>
7477
<span className={styles.userLimit}>
75-
{userLimitActual} {` / ${userLimitLimit || "Unlimited"}`}
78+
{userLimitActual} {` / ${currentUserLimit || "Unlimited"}`}
7679
</span>
7780
</Stack>
7881
<Stack

site/src/pages/DeploySettingsPage/LicensesSettingsPage/LicensesSettingsPageView.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ const LicensesSettingsPageView: FC<Props> = ({
7171
{licenses
7272
?.sort(
7373
(a, b) =>
74-
new Date(b.claims.license_expires as number).valueOf() -
75-
new Date(a.claims.license_expires as number).valueOf(),
74+
new Date(b.claims.license_expires).valueOf() -
75+
new Date(a.claims.license_expires).valueOf(),
7676
)
7777
.map((license) => (
7878
<LicenseCard

0 commit comments

Comments
 (0)