mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(site): display correct user_limit on license ui (#8118)
This commit is contained in:
+1
-1
@@ -1006,7 +1006,7 @@ export const getWorkspaceBuildParameters = async (
|
||||
return response.data
|
||||
}
|
||||
type Claims = {
|
||||
license_expires?: number
|
||||
license_expires: number
|
||||
account_type?: string
|
||||
account_id?: string
|
||||
trial: boolean
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { screen } from "@testing-library/react"
|
||||
import { render } from "../../testHelpers/renderHelpers"
|
||||
import { LicenseCard } from "./LicenseCard"
|
||||
import { MockLicenseResponse } from "testHelpers/entities"
|
||||
|
||||
describe("LicenseCard", () => {
|
||||
it("renders (smoke test)", async () => {
|
||||
// When
|
||||
render(
|
||||
<LicenseCard
|
||||
license={MockLicenseResponse[0]}
|
||||
userLimitActual={1}
|
||||
userLimitLimit={10}
|
||||
onRemove={() => null}
|
||||
isRemoving={false}
|
||||
/>,
|
||||
)
|
||||
|
||||
// Then
|
||||
await screen.findByText("#1")
|
||||
await screen.findByText("1 / 10")
|
||||
await screen.findByText("Enterprise")
|
||||
})
|
||||
|
||||
it("renders userLimit as unlimited if there is not user limit", async () => {
|
||||
// When
|
||||
render(
|
||||
<LicenseCard
|
||||
license={MockLicenseResponse[0]}
|
||||
userLimitActual={1}
|
||||
userLimitLimit={undefined}
|
||||
onRemove={() => null}
|
||||
isRemoving={false}
|
||||
/>,
|
||||
)
|
||||
|
||||
// Then
|
||||
await screen.findByText("#1")
|
||||
await screen.findByText("1 / Unlimited")
|
||||
await screen.findByText("Enterprise")
|
||||
})
|
||||
|
||||
it("renders license's user_limit when it is available instead of using the default", async () => {
|
||||
const licenseUserLimit = 3
|
||||
const license = {
|
||||
...MockLicenseResponse[0],
|
||||
claims: {
|
||||
...MockLicenseResponse[0].claims,
|
||||
features: {
|
||||
...MockLicenseResponse[0].claims.features,
|
||||
user_limit: licenseUserLimit,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// When
|
||||
render(
|
||||
<LicenseCard
|
||||
license={license}
|
||||
userLimitActual={1}
|
||||
userLimitLimit={100} // This should not be used
|
||||
onRemove={() => null}
|
||||
isRemoving={false}
|
||||
/>,
|
||||
)
|
||||
|
||||
// Then
|
||||
await screen.findByText("1 / 3")
|
||||
})
|
||||
})
|
||||
@@ -1,16 +1,16 @@
|
||||
import Button from "@mui/material/Button"
|
||||
import Paper from "@mui/material/Paper"
|
||||
import { makeStyles } from "@mui/styles"
|
||||
import { License } from "api/typesGenerated"
|
||||
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
|
||||
import { Stack } from "components/Stack/Stack"
|
||||
import dayjs from "dayjs"
|
||||
import { useState } from "react"
|
||||
import { Pill } from "components/Pill/Pill"
|
||||
import { compareAsc } from "date-fns"
|
||||
import { GetLicensesResponse } from "api/api"
|
||||
|
||||
type LicenseCardProps = {
|
||||
license: License
|
||||
license: GetLicensesResponse
|
||||
userLimitActual?: number
|
||||
userLimitLimit?: number
|
||||
onRemove: (licenseId: number) => void
|
||||
@@ -30,6 +30,9 @@ export const LicenseCard = ({
|
||||
number | undefined
|
||||
>(undefined)
|
||||
|
||||
const currentUserLimit =
|
||||
license.claims.features["user_limit"] || userLimitLimit
|
||||
|
||||
return (
|
||||
<Paper key={license.id} elevation={2} className={styles.licenseCard}>
|
||||
<ConfirmDialog
|
||||
@@ -72,7 +75,7 @@ export const LicenseCard = ({
|
||||
<Stack direction="column" spacing={0} alignItems="center">
|
||||
<span className={styles.secondaryMaincolor}>Users</span>
|
||||
<span className={styles.userLimit}>
|
||||
{userLimitActual} {` / ${userLimitLimit || "Unlimited"}`}
|
||||
{userLimitActual} {` / ${currentUserLimit || "Unlimited"}`}
|
||||
</span>
|
||||
</Stack>
|
||||
<Stack
|
||||
|
||||
@@ -71,8 +71,8 @@ const LicensesSettingsPageView: FC<Props> = ({
|
||||
{licenses
|
||||
?.sort(
|
||||
(a, b) =>
|
||||
new Date(b.claims.license_expires as number).valueOf() -
|
||||
new Date(a.claims.license_expires as number).valueOf(),
|
||||
new Date(b.claims.license_expires).valueOf() -
|
||||
new Date(a.claims.license_expires).valueOf(),
|
||||
)
|
||||
.map((license) => (
|
||||
<LicenseCard
|
||||
|
||||
Reference in New Issue
Block a user