Skip to content

fix(trials): Fix missing and negative day-count in product trial alerts and tags#119118

Open
souredoutlook wants to merge 2 commits into
masterfrom
fix/logging-trial-negative-days-left
Open

fix(trials): Fix missing and negative day-count in product trial alerts and tags#119118
souredoutlook wants to merge 2 commits into
masterfrom
fix/logging-trial-negative-days-left

Conversation

@souredoutlook

@souredoutlook souredoutlook commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Two related bugs in the logging trial UI when a trial's endDate is today or yesterday.

Bug 1 — ProductTrialTag shows "-1 days left" instead of "Trial ended"

When endDate has a late-day time component (e.g. 2026-07-05T23:00:00), the old "Trial ended" guard used an exact timestamp check: moment(endDate).add(1, 'days').isBefore(now). If endDate + 1 day hasn't passed in clock time, the guard doesn't fire. But getDaysSinceDate normalizes to start-of-day before diffing, so it returns 1 for a trial that ended yesterday regardless of time — producing daysLeft = -1 and rendering "-1 days left".

Fix: compute daysLeft first via getDaysSinceDate (the single source of truth), then branch on daysLeft < 0 for the "Trial ended" state.

Bug 2 — ProductTrialAlert renders nothing when daysLeft === 0

When the trial ends today (daysLeft === 0 and trial.isStarted === true), none of the four conditional branches in ProductTrialAlert matched:

  • daysLeft >= 0 && !isStarted — false (trial is started)
  • daysLeft > 7 — false
  • daysLeft > 0 && daysLeft <= 7 — false (0 > 0 is false)
  • daysLeft < 0 — false

So alertHeader, alertText, alertButton all stayed null and the alert rendered invisible — no notice shown at all.

Fix: change daysLeft > 0 && daysLeft <= 7 to daysLeft >= 0 && daysLeft <= 7 to include the last-day case in the 0–7 days remaining branch.

…oduct trial expires

Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jul 7, 2026
@souredoutlook souredoutlook marked this pull request as ready for review July 7, 2026 16:02
@souredoutlook souredoutlook requested a review from a team as a code owner July 7, 2026 16:02
When daysLeft === 0 (trial ends today), ProductTrialAlert fell through
all conditional branches without matching any, leaving alertHeader and
alertText null and rendering an empty invisible alert.

Include daysLeft === 0 in the 0-7 days remaining branch by changing
the condition from daysLeft > 0 to daysLeft >= 0.

Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
@souredoutlook souredoutlook changed the title fix(trials): Show 'Trial ended' instead of negative days left when product trial expires fix(trials): Fix missing and negative day-count in product trial alerts and tags Jul 7, 2026
showTrialEnded = false,
}: ProductTrialTagProps) {
const now = moment();
const daysLeft = -1 * getDaysSinceDate(trial.endDate ?? '');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: When trial.endDate is null or undefined, the component incorrectly calculates the days remaining as NaN and renders "NaN days left" to the user.
Severity: MEDIUM

Suggested Fix

Add a guard clause at the beginning of the component to handle cases where trial.endDate is null or undefined. If endDate is not present, return null early to prevent the getDaysSinceDate calculation from executing with invalid input and producing NaN.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: static/gsApp/components/productTrial/productTrialTag.tsx#L22

Potential issue: The `ProductTrial` type definition allows the `endDate` field to be
optional. When `trial.endDate` is `null` or `undefined`, the code passes an empty string
to `getDaysSinceDate` due to the `?? ''` nullish coalescing operator. The
`getDaysSinceDate` function, when called with an empty string, uses `moment('')` which
results in an invalid date, causing the function to return `NaN`. Consequently, the
`daysLeft` variable becomes `NaN`. All subsequent conditional checks on `daysLeft`
(e.g., `daysLeft < 0`) evaluate to false, leading the component to render the
user-facing text "NaN days left". This bug is introduced by the pull request's
refactoring, which moves the calculation before the necessary safety checks.

Also affects:

  • static/app/utils/getDaysSinceDate.tsx
  • static/gsApp/types/index.tsx:268
  • static/gsApp/components/productTrial/productTrialAlert.tsx:57

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants