Skip to content

Make trial banner informational at start of trial #2667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2025
Merged
Changes from 2 commits
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
39 changes: 30 additions & 9 deletions frontend/src/features/org/org-status-banner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { localized, msg, str } from "@lit/localize";
import type { SlAlert } from "@shoelace-style/shoelace";
import type { SlAlert, SlIcon } from "@shoelace-style/shoelace";
import { differenceInHours } from "date-fns/fp";
import { html, type TemplateResult } from "lit";
import { customElement } from "lit/decorators.js";
Expand All @@ -18,6 +18,26 @@ type Alert = {
};
};

const iconForVariant = (
variant: SlAlert["variant"],
): NonNullable<SlIcon["name"]> => {
switch (variant) {
case "danger":
return "exclamation-triangle";
case "success":
return "check2-circle";
case "warning":
return "exclamation-diamond";
default:
return "info-circle";
}
};

// show banner if <= this many days of trial is left
const TRIAL_DAYS_SHOW_BANNER = 7;
// show banner as warning if <= this many days of trial is left
const TRIAL_DAYS_SHOW_WARNING = 4;

@customElement("btrix-org-status-banner")
@localized()
export class OrgStatusBanner extends BtrixElement {
Expand All @@ -29,12 +49,13 @@ export class OrgStatusBanner extends BtrixElement {
if (!alert) return;

const content = alert.content();
const variant = alert.variant || "danger";

return html`
<div id="banner" class="border-b bg-slate-100 py-5">
<div class="mx-auto box-border w-full max-w-screen-desktop px-3">
<sl-alert variant=${alert.variant || "danger"} open>
<sl-icon slot="icon" name="exclamation-triangle-fill"></sl-icon>
<sl-alert variant=${variant} open>
<sl-icon slot="icon" name=${iconForVariant(variant)}></sl-icon>
<strong class="block font-semibold">${content.title}</strong>
${content.detail}
</sl-alert>
Expand Down Expand Up @@ -89,9 +110,6 @@ export class OrgStatusBanner extends BtrixElement {
const isTrial =
subscription?.status === SubscriptionStatus.Trialing || isCancelingTrial;

// show banner if < this many days of trial is left
const MAX_TRIAL_DAYS_SHOW_BANNER = 8;

return [
{
test: () =>
Expand Down Expand Up @@ -127,9 +145,12 @@ export class OrgStatusBanner extends BtrixElement {
!readOnly &&
!readOnlyOnCancel &&
!!futureCancelDate &&
((isTrial && daysDiff < MAX_TRIAL_DAYS_SHOW_BANNER) ||
isCancelingTrial),
variant: isCancelingTrial ? "danger" : "warning",
((isTrial && daysDiff <= TRIAL_DAYS_SHOW_BANNER) || isCancelingTrial),
variant: isCancelingTrial
? "danger"
: isTrial && daysDiff <= TRIAL_DAYS_SHOW_WARNING
? "warning"
: "primary",
content: () => {
return {
title:
Expand Down
Loading