fix(admin): show the cardless trial as a trial in the admin panel

The cardless trial writes trialEndsAt and nothing else, because there is no
Stripe subscription behind it to report trialing. subscriptionStatus stays
FREE, so every admin view reading that column alone showed a live trial as a
free account: On Trial sat at zero, Free Users counted the trials, the user
table badged them Free with an open-ended Active access, the Trialing filter
returned nobody and the growth scoreboard left them out of the paid accounts
table.

Access has always been resolved from the date (hasBillingAccess), so the
display now follows the same date through getEffectiveBillingStatus. Only FREE
is overridden: any other status means Stripe has an opinion worth showing.
This commit is contained in:
2026-08-18 18:55:41 +03:00
parent bf46860feb
commit 60c208b3b3
7 changed files with 282 additions and 22 deletions
+11 -2
View File
@@ -379,7 +379,14 @@ export async function getScoreboard(options?: { weeks?: number }): Promise<Score
SELECT u.id AS user_id,
u.name,
u.email,
u."subscriptionStatus"::text AS status,
-- A cardless trial has no Stripe subscription to carry the status,
-- so it sits at FREE with only a date to go on. Reported as the
-- trial it is, and matched by the WHERE below for the same reason.
CASE
WHEN u."subscriptionStatus"::text = 'FREE' AND u."trialEndsAt" > NOW()
THEN 'TRIALING'
ELSE u."subscriptionStatus"::text
END AS status,
ua.channel,
ua.self_reported,
COUNT(e.id) FILTER (WHERE e.occurred_at >= NOW() - INTERVAL '7 days')::int
@@ -393,7 +400,9 @@ export async function getScoreboard(options?: { weeks?: number }): Promise<Score
ON e.user_id = u.id
AND e.name::text = ANY(${[...VALUE_EVENT_NAMES]}::text[])
WHERE u."subscriptionStatus"::text IN ('ACTIVE', 'TRIALING')
GROUP BY u.id, u.name, u.email, u."subscriptionStatus", ua.channel, ua.self_reported
OR (u."subscriptionStatus"::text = 'FREE' AND u."trialEndsAt" > NOW())
GROUP BY u.id, u.name, u.email, u."subscriptionStatus", u."trialEndsAt", ua.channel,
ua.self_reported
ORDER BY MAX(e.occurred_at) ASC NULLS FIRST
LIMIT ${PAID_ACCOUNT_LIMIT + 1}
`,