Skip to content

Commit 48810e0

Browse files
committed
feat(credits-admin): show explicit subscription state chip
The 'Entitled' badge collapsed two distinct states into 'not entitled': an account that never subscribed (no Subscription row) and one whose subscription lapsed (expired/revoked). Admins couldn't tell them apart from the top card. Replace the yes/no badge with a status chip driven by the data already sent: - no subscription row -> grey 'none' - entitled (trial/active/grace/billingRetry) -> green, raw effective status - lapsed (expired/revoked) -> red, raw effective status Client-only; the sub-block still shows stored vs effective status and periods.
1 parent 9a50bb4 commit 48810e0

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/api/v2/credits-admin/handlers/admin-page.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function buildHTML(nonce: string, creditsPerUsd: number): string {
5555
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
5656
.badge-yes { background: #d1f0d6; color: #14752a; }
5757
.badge-no { background: #f7d6d6; color: #a3151f; }
58+
.badge-none { background: #e8e8ed; color: #6e6e73; }
5859
table { width: 100%; border-collapse: collapse; font-size: 13px; }
5960
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #ececec; }
6061
th { color: #6e6e73; font-weight: 600; }
@@ -100,7 +101,7 @@ function buildHTML(nonce: string, creditsPerUsd: number): string {
100101
<h2>Account <span id="detail-id" style="font-weight:400;font-size:13px"></span></h2>
101102
<div class="balances">
102103
<div class="balance primary"><div class="k">Balance</div><div class="v" id="b-balance"></div></div>
103-
<div class="balance"><div class="k">Entitled</div><div class="v"><span id="b-entitled"></span></div></div>
104+
<div class="balance"><div class="k">Subscription</div><div class="v"><span id="b-substate"></span></div></div>
104105
</div>
105106
<div id="sub-block" style="margin-top:16px"></div>
106107
</div>
@@ -239,9 +240,14 @@ function buildHTML(nonce: string, creditsPerUsd: number): string {
239240
document.getElementById("detail").classList.remove("hidden");
240241
document.getElementById("detail-id").textContent = j.accountId;
241242
document.getElementById("b-balance").textContent = fmtCredits(j.balanceCredits);
242-
document.getElementById("b-entitled").innerHTML = j.isEntitled
243-
? '<span class="badge badge-yes">entitled</span>'
244-
: '<span class="badge badge-no">not entitled</span>';
243+
var subState = j.subscription ? j.subscription.effectiveStatus : "none";
244+
var subClass = !j.subscription
245+
? "badge-none"
246+
: j.isEntitled
247+
? "badge-yes"
248+
: "badge-no";
249+
document.getElementById("b-substate").innerHTML =
250+
'<span class="badge ' + subClass + '">' + esc(subState) + "</span>";
245251
var sb = document.getElementById("sub-block");
246252
if (j.subscription) {
247253
var s = j.subscription;

tests/credits-admin/admin-page.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,11 @@ describe("credits-admin page", () => {
4646
expect(res.text).toContain("Allotment");
4747
expect(res.text).toContain("perPeriodCredits");
4848
});
49+
50+
it("renders subscription state as a colored status chip (none/entitled/lapsed)", async () => {
51+
const res = await adminRequest(app, false).get("/api/v2/credits-admin/");
52+
expect(res.text).toContain('id="b-substate"');
53+
expect(res.text).toContain("badge-none");
54+
expect(res.text).toContain("effectiveStatus");
55+
});
4956
});

0 commit comments

Comments
 (0)