1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 18:23:31 +00:00
Files
browser/libs/common/src/billing/models/view/self-hosted-organization-subscription.view.ts
Shane Melton bcda04ee86 [AC-358] SelfHosted update subscription page (#5101)
* [AC-358] Add selfHostSubscriptionExpiration property to organization-subscription.response.ts

* [AC-358] Update selfHost org subscription template

- Replace "Subscription" with "SubscriptionExpiration"
- Add question mark help link
- Add helper text for grace period
- Add support for graceful fallback in case of missing grace period in subscription response

* Update libs/common/src/billing/models/response/organization-subscription.response.ts

Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>

* [AC-358] Remove unnecessary hypen

Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>

* [AC-358] Introduce SelfHostedOrganizationSubscription view
- Encapsulate expiration/grace period logic in the new view object.
- Remove API response getters from the angular component
- Replace the API response object with the new view

* [AC-358] Clarify name for new expiration without grace period field

* [AC-358] Update constructor parameter name

* [AC-358] Simplify new selfhost subscription view

- Make expiration date properties public
- Remove obsolete expiration date getters
- Update the component to use new properties
- Add helper to component for determining if the subscription should be rendered as expired (red text)

* [AC-358] Rename isExpired to isExpiredAndOutsideGracePeriod to be more explicit

---------

Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
2023-05-15 07:38:53 -07:00

62 lines
2.0 KiB
TypeScript

import { View } from "../../../models/view/view";
import { OrganizationSubscriptionResponse } from "../response/organization-subscription.response";
export class SelfHostedOrganizationSubscriptionView implements View {
planName: string;
/**
* Date the subscription expires, including the grace period.
*/
expirationWithGracePeriod?: Date;
/**
* Date the subscription expires, excluding the grace period.
* This will be `null` for older (< v12) license files because they do not include this date.
* In this case, you have to rely on the `expirationWithGracePeriod` instead.
*/
expirationWithoutGracePeriod?: Date;
constructor(response: OrganizationSubscriptionResponse) {
if (response == null) {
return;
}
this.planName = response.plan.name;
this.expirationWithGracePeriod =
response.expiration != null ? new Date(response.expiration) : null;
this.expirationWithoutGracePeriod =
response.expirationWithoutGracePeriod != null
? new Date(response.expirationWithoutGracePeriod)
: null;
}
/**
* The subscription has separate expiration dates for the subscription and the end of grace period.
*/
get hasSeparateGracePeriod() {
return this.expirationWithGracePeriod != null && this.expirationWithoutGracePeriod != null;
}
/**
* True if the subscription has an expiration date.
*/
get hasExpiration() {
return this.expirationWithGracePeriod != null;
}
/**
* True if the subscription has an expiration date that has past, but may still be within the grace period.
* For older licenses (< v12), this will always be false because they do not include the `expirationWithoutGracePeriod`.
*/
get isExpiredWithoutGracePeriod() {
return this.hasSeparateGracePeriod && this.expirationWithoutGracePeriod < new Date();
}
/**
* True if the subscription has an expiration date that has past, including the grace period.
*/
get isExpiredAndOutsideGracePeriod() {
return this.hasExpiration && this.expirationWithGracePeriod < new Date();
}
}