Skip to content

Commit

Permalink
Modify soonToExpire license notification
Browse files Browse the repository at this point in the history
  • Loading branch information
jvorcak committed Oct 29, 2024
1 parent 1e3c63a commit 89207c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/license/LicenseNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { License_Type } from '../../protogen/redpanda/api/console/v1alpha1/licen

export const LicenseNotification = observer(() => {
const location = useLocation();
const visibleExpiredLicenses = api.licenses.filter(licenseIsExpired).filter(license => license.type !== License_Type.TRIAL) ?? [];
const visibleExpiredLicenses = api.licenses.filter(licenseIsExpired).filter(license => license.type === License_Type.ENTERPRISE) ?? [];
const soonToExpireLicenses = api.licenses
.filter(licenseSoonToExpire)
.filter(licenseCanExpire)
.filter(license => licenseSoonToExpire(license))
.filter(license => licenseCanExpire(license))
?? [];

const showSomeLicenseExpirationInfo = visibleExpiredLicenses.length || soonToExpireLicenses.length;
Expand Down
17 changes: 14 additions & 3 deletions frontend/src/components/license/licenseUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@ export const licenseIsExpired = (license: License): boolean => license.type !==
* The function returns `true` if the license is set to expire within the offset period from the current date.
*
* @param {License} license - The license object to check.
* @param {number} [offsetInDays=30] - The number of days to check before the license expires. Defaults to 30 days.
* @param {Partial<Record<License_Type, number>>} [offsetInDays] - An optional mapping of license types
* to the number of days before expiration to consider for each license type. Defaults to 15 days
* for `TRIAL` licenses and 30 days for `ENTERPRISE` licenses.
* @returns {boolean} - Returns `true` if the license will expire within the specified number of days, otherwise `false`.
*/
export const licenseSoonToExpire = (license: License, offsetInDays: number = 30): boolean => {
export const licenseSoonToExpire = (license: License, offsetInDays: Partial<Record<License_Type, number>> = {
[License_Type.TRIAL]: 15,
[License_Type.ENTERPRISE]: 30,
}): boolean => {
const daysToExpire: number | undefined = offsetInDays[license.type]

if(daysToExpire === undefined) {
return false
}

const millisecondsInADay = 24 * 60 * 60 * 1000; // Number of milliseconds in a day
const offsetInMilliseconds = offsetInDays * millisecondsInADay;
const offsetInMilliseconds = daysToExpire * millisecondsInADay;

const timeToExpiration = getTimeToExpiration(license);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/admin/AdminPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class AdminPage extends PageComponent {
: <div>
<Alert status="error">
<AlertIcon />
You do not have the neccesary permissions to view this page.
You do not have the necessary permissions to view this page.
</Alert>
</div>
}
Expand Down

0 comments on commit 89207c2

Please sign in to comment.