Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
sorting licenses; add expiration badge
  • Loading branch information
Kira-Pilot committed May 25, 2023
commit a5b2e3255ff4ba4ead195db903b28976ece79f68
46 changes: 34 additions & 12 deletions site/src/components/LicenseCard/LicenseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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"

type LicenseCardProps = {
license: License
Expand Down Expand Up @@ -67,29 +69,46 @@ export const LicenseCard = ({
flex: 1,
}}
>
<Stack direction="column" spacing={0}>
<Stack direction="column" spacing={0} alignItems="center">
<span className={styles.secondaryMaincolor}>Users</span>
<span className={styles.userLimit}>
{userLimitActual} {` / ${userLimitLimit || "Unlimited"}`}
</span>
</Stack>

<Stack direction="column" spacing={0}>
<span className={styles.secondaryMaincolor}>Valid Until</span>
<Stack
direction="column"
spacing={0}
alignItems="center"
width="134px" // standardize width of date column
>
{compareAsc(
new Date(license.claims.license_expires * 1000),
new Date(),
) < 1 ? (
<Pill
className={styles.expiredBadge}
text="Expired"
type="error"
/>
) : (
<span className={styles.secondaryMaincolor}>Valid Until</span>
)}
<span className={styles.licenseExpires}>
{dayjs
.unix(license.claims.license_expires)
.format("MMMM D, YYYY")}
</span>
</Stack>
<Button
className={styles.removeButton}
variant="text"
size="small"
onClick={() => setLicenseIDMarkedForRemoval(license.id)}
>
Remove
</Button>
<Stack spacing={2}>
<Button
className={styles.removeButton}
variant="text"
size="small"
onClick={() => setLicenseIDMarkedForRemoval(license.id)}
>
Remove
</Button>
</Stack>
</Stack>
</Stack>
</Paper>
Expand Down Expand Up @@ -119,6 +138,9 @@ const useStyles = makeStyles((theme) => ({
licenseExpires: {
color: theme.palette.text.secondary,
},
expiredBadge: {
marginBottom: theme.spacing(0.5),
},
secondaryMaincolor: {
color: theme.palette.text.secondary,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,22 @@ const LicensesSettingsPageView: FC<Props> = ({

{!isLoading && licenses && licenses?.length > 0 && (
<Stack spacing={4}>
{licenses?.map((license) => (
<LicenseCard
key={license.id}
license={license}
userLimitActual={userLimitActual}
userLimitLimit={userLimitLimit}
isRemoving={isRemovingLicense}
onRemove={removeLicense}
/>
))}
{licenses
?.sort(
(a, b) =>
new Date(b.claims.license_expires as number).valueOf() -
new Date(a.claims.license_expires as number).valueOf(),
)
.map((license) => (
<LicenseCard
key={license.id}
license={license}
userLimitActual={userLimitActual}
userLimitLimit={userLimitLimit}
isRemoving={isRemovingLicense}
onRemove={removeLicense}
/>
))}
</Stack>
)}

Expand Down