Skip to content

Show how many trial days are left on the GoDAM dashboard - #2378

Merged
rudrakshi-gupta merged 2 commits into
feat/one-connection-statusfrom
feat/trial-days-dashboard
Nov 18, 2026
Merged

rudrakshi-gupta merged 2 commits into
feat/one-connection-statusfrom
feat/trial-days-dashboard

Conversation

@rudrakshi-gupta

Copy link
Copy Markdown
Member

Summary

Shows how many trial days are left on the GoDAM dashboard, with a link to upgrade, for sites on a GoDAM trial.

Closes rtCamp/godam-plugin-wp#114 · Part of rtCamp/godam-plugin-wp#101

Base branch: feat/one-connection-status (rtCamp/gdam-plugin-wp#101). This PR uses the connection status, trial days and renewal URL that rtCamp/godam-plugin-wp#101 adds to the data the admin pages get. Merge rtCamp/godam-plugin-wp#101 first, or review this against it.

Why

rtCamp/godam-plugin-wp#101's status table says a trial is "Everything on, with days left". The rtCamp/godam-plugin-wp#101 branch shows the days left only as a notice in the Media Library. Trial sites manage their account from the GoDAM dashboard, so they should see it there too, with a way to upgrade before Pro features stop.

What changed

New: TrialDaysNotice (pages/shared/TrialDaysNotice.jsx)

  • Shows "Your GoDAM trial ends in N days.", or "Your GoDAM trial ends today." on the last day.
  • Includes an "Upgrade to keep transcoding and other Pro features ↗." link to the renewal URL. It uses the same ↗ arrow as the dashboard's other outbound links and opens in a new tab.
  • Blue (info) normally, yellow (warning) in the last 3 days.
  • Shows only when all of these are true:
    • the connection status is trial
    • the key works on this site (validApiKey), so a site Central refused gets no countdown
    • Central sent the trial's end date (trialDaysLeft is a number)
  • Reads its data from window.userData (connectionStatus, trialDaysLeft, renewalUrl, validApiKey), which rtgodam_get_user_data( true ) already sends on the rtCamp/godam-plugin-wp#101 branch. No PHP changes.
  • Accepts trialDaysLeft and validApiKey as strings, because wp_localize_script() sends every number as text ("5") and false as "".
  • Links only to http(s) URLs.
  • Uses the same strings as the Media Library trial notice (render_trial_notice()), so both share one translation.
  • It's a shared component, so it can be reused on other GoDAM screens (e.g. Settings) later.

Dashboard (pages/dashboard/Dashboard.js)

  • Renders <TrialDaysNotice area="dashboard" /> under the GoDAM header, above the Dashboard title.

Styles (pages/shared/trial-days-notice.scss)

  • Same box as the dashboard content (.dashboard-container): centred, at most 1440px wide, 1rem either side. Its edges line up with the cards at every screen width.
  • The arrow sits inline with the link text, so the arrow and the full stop wrap with the last word on narrow screens.

Screenshots

Desktop Mobile
1-desktop-5-days-info 4-mobile-5-days
5 days left (info) 2 days left (warning) Last day
1-desktop-5-days-info 2-desktop-2-days-warning 3-desktop-last-day

How to test

Central doesn't send trial_ends_at yet (rtCamp/godam-core#1957), so fake its answer with wp-cli on a site with a valid key, then open GoDAM → Dashboard.

The plugin re-checks the key about once an hour and overwrites this test value with connected. If the notice disappears mid-test, set the option again.

  1. 5 days left: a blue notice with the days and the upgrade link
    wp option update rtgodam-connection "{\"status\":\"trial\",\"trial_ends_at\":$(( $(date +%s) + 5*86400 )),\"organization\":\"acme\"}" --format=json
    
    • The link goes to https://app.godam.io/godam_upgrade?organization=acme&wp_return=… in a new tab.
    • The notice's left and right edges line up with the cards below.
  2. 2 days left: change 5*86400 to 2*86400. The notice turns yellow and says "2 days".
  3. Last day: change it to 0. The notice says "Your GoDAM trial ends today."
  4. Not on a trial: set "status":"connected" (or "expired"). No notice.
  5. No end date: remove trial_ends_at from the JSON. No notice.
  6. Narrow screen: resize to phone width. The notice still lines up with the cards, and "↗." stays on the same line as "features".
  7. Reset:
    wp option delete rtgodam-connection
    

Tests

  • pages/shared/TrialDaysNotice.test.js has 12 tests:
    • the message, the upgrade link, the arrow and the full stop
    • days left sent as strings, as wp_localize_script() sends them
    • singular "1 day" and "ends today"
    • info vs warning (last 3 days)
    • nothing shown for: a paid plan, an expired plan, a key this site can't use (as false and as ""), no end date (as null and as ""), no user data
    • http(s)-only links
  • Full JS suite passes, and ESLint and Stylelint are clean.

- Add a TrialDaysNotice shared component: "Your GoDAM trial ends in N days" (or
  "ends today") with an upgrade link ↗ to the renewal URL
- Show it only for a trial whose key works on this site and whose end date
  Central sent; switch to a warning in the last three days
- Read the days left whether wp_localize_script sends them as a number or as
  text, so the notice shows on real pages
- Match the dashboard content's width and side spacing so the notice lines up
  with the cards at every screen size
- Use the same wording as the Media Library trial notice so both share one
  translation
- Add unit tests for the notice

Refs rtCamp/godam-plugin-wp#114
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
13 0 13

⚠️ Warnings (13)

📁 readme.txt (1 warning)
📍 Line 🔖 Check 💬 Message
0 mismatched_plugin_name Plugin name "GoDAM - Video Hosting for LMS & Online Courses" is different from the name declared in plugin header "GoDAM".
📁 assets/build/pages/video-editor.min.js (1 warning)
📍 Line 🔖 Check 💬 Message
2 react_removed_api This file calls "ReactDOM.findDOMNode", which was removed in React 19 and stops working once WordPress upgrades React. Use a ref on the element instead.
📁 assets/build/css/main.css (1 warning)
📍 Line 🔖 Check 💬 Message
0 EnqueuedStylesScope This style is being loaded in all contexts.
📁 assets/src/libs/analytics.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/11/17/demo-post-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-page-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
📁 assets/build/js/main.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/11/17/demo-post-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-page-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@KMchaudhary

Copy link
Copy Markdown
Collaborator

Code review — correctness pass (medium effort)

Reviewed the diff. Solid, well-tested PR — no crashers. Four findings, most-severe first.

1. /^\d+$/ can silently hide the whole notice — pages/shared/TrialDaysNotice.jsx:52

daysLeft is null unless trialDaysLeft stringifies to a bare integer. If the server ever sends a fractional or formatted value ("4.5", a localized number, a stray space), the guard fails and a site genuinely on a trial sees no countdown at all, with no fallback. Consider Number() + Number.isFinite + Math.floor/Math.round so a near-expiry or imprecise value still renders.

2. Overlaps the existing TrialCountdownBanner — pages/godam/components/TrialCountdownBanner.jsx:47

This is a second trial-countdown component keyed off a different data model (connectionStatus/trialDaysLeft here vs active_plan === 'free' + end_date there). A site that satisfies both conditions would render the header strip and this notice at once — two "trial ends" messages. Worth confirming these signals are mutually exclusive, or consolidating onto one.

3. SCSS duplicates .dashboard-container metrics — pages/shared/trial-days-notice.scss:6

max-width: 1440px and padding: 0 1rem are hardcoded to mirror .dashboard-container (pages/dashboard/index.scss:66). If that box's width/gutter changes, the notice silently stops lining up with the cards — the file's stated goal. A shared SCSS variable or %placeholder keeps them in sync.

4. Warning window is 4 day-values, copy says "last 3 days" — pages/shared/TrialDaysNotice.jsx:62

daysLeft <= 3 styles the warning for 3, 2, 1, and 0 days left. The PR describes warning as the "last 3 days" (2/1/0). Minor, and the test locks in 3 → warning; flagging only because copy and code disagree on when urgency starts.

Review by Claude Code (correctness pass).

- Read days left from any number (strings, decimals) instead of digits only, counting a part day as a day
- Hide the notice while the header's Free plan banner (TrialCountdownBanner) shows, so the trial end isn't shown twice
- Share the content box's max width and gutter with .dashboard-container through a content-box partial
- Show the warning for the last 3 days (2, 1, 0 left), matching the description
- Add tests for days-left parsing, decimals and the banner overlap
@rudrakshi-gupta

Copy link
Copy Markdown
Member Author
  1. Fixed: parseDaysLeft() reads any number (string, decimal, padded), counting a part day as a day like the server does. Only empty, non-numeric or negative values hide it. Tests added.

  2. Good catch, they can overlap. TrialCountdownBanner’s check is now an exported getFreeTrialEnd(), and TrialDaysNotice stays quiet while the banner shows, so there’s only ever one message. If Central’s trial status turns out to be the same Free plan, I’d suggest merging the two into one component in a follow-up.

  3. Fixed: new pages/shared/_content-box.scss with $max-width and $gutter, used by both .dashboard-container and the notice.

  4. Fixed: the warning now starts at 2 days left (< 3), so it covers the last 3 days. The test checks that 3 days is info and 2 and 0 are warnings.

@subodhr258 subodhr258 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review at edbb176. I read the full diff and checked the fixes for the 4 points in @KMchaudhary's review comment. No new findings.

Point How checked Result
1. /^\d+$/ could hide the notice parseDaysLeft() uses Number() + Number.isFinite + Math.ceil, and returns null only for empty, non-numeric or negative values. The server (Connection::get_trial_days_left() on the base branch) always sends a whole number, so ceil changes nothing for real data. Fraction test added. Fixed
2. Overlap with TrialCountdownBanner The banner check is now the exported getFreeTrialEnd(), and the notice returns null when it is true. The Dashboard renders GodamHeader (which holds the banner), so only one message ever shows. Test added. Fixed
3. SCSS duplicating .dashboard-container pages/shared/_content-box.scss holds $max-width / $gutter, and both .dashboard-container and .godam-trial-days use them Fixed
4. Warning window vs "last 3 days" daysLeft < WARNING_DAYS (3), so the warning shows at 2, 1 and 0 days left. The test checks that 3 is info. Fixed

CI on the head: JS unit tests, PHPCS and Plugin Check pass.

Not tested: I did not run it on a site (the faked rtgodam-connection option steps). This review is from reading the code and the tests. The PR is based on feat/one-connection-status, so it can only merge after #2377.

@subodhr258 subodhr258 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving at edbb176. See the review above. Merge after #2377.

@rudrakshi-gupta
rudrakshi-gupta merged commit 2efdf9c into feat/one-connection-status Nov 18, 2026
3 checks passed
@rudrakshi-gupta
rudrakshi-gupta deleted the feat/trial-days-dashboard branch November 18, 2026 13:53
rudrakshi-gupta added a commit that referenced this pull request Nov 18, 2026
…d of signup (#2377)

* Read one connection status from GoDAM Central and show renewal instead of signup

- Add a Connection_Status enum (connected, trial, expired, unreachable, none)
  and a Connection helper that stores what verify_api_key returns:
  connection_status, trial_ends_at, organization and (when sent) expired_at
- Read those fields from Central's 200, 401 and 403 answers, only for the stored
  key or a new key being saved, so a mistyped key changes nothing
- On an older Central that doesn't send connection_status, work the status out
  from the key status as before
- Treat a 200 with "none" (subscription still being set up) as connected, and a
  403 that still says connected or trial (site not on the key's allowed sites)
  as no usable key, so neither shows the wrong screen
- Report "unreachable" while Central can't be reached and the last good answer
  is still trusted
- Show a renewal screen in the onboarding overlay when the plan has expired,
  instead of the signup screens: Renew plan, "I've renewed, check again",
  use a different license key, Contact support
- Show the onboarding overlay only for "none" and "expired"; never while Central
  is unreachable
- Build the renewal link from the organization:
  /godam_upgrade?organization=<org>&wp_return=<dashboard>, falling back to the
  Plans page when the organization isn't known
- Count trial days left by calendar date in the site's timezone, since Central
  sends the trial's last day as UTC midnight
- Show "Your GoDAM trial ends in N days" in the Media Library with an upgrade
  link; point the expired notice at renewal, and at Settings when Central
  refused the key for another reason
- Add connectionStatus, trialDaysLeft and renewalUrl to the data the admin
  pages get, for the Woo add-on and the dashboard to use
- Expose when the plan lapsed (Central's expired_at, otherwise the first time the
  site saw the key as expired) for the Woo grace period
- Clear the stored status when the API key is removed
- Add PHP tests for the status helper and for what verify_api_key stores, and
  JS tests for the renewal screen

Refs rtCamp/godam-plugin-wp#101

* Show renewal for a lapsed plan without blocking a key that still works

- Keep Central's connection_status as sent, including on the not-allowed-site
  403; it describes the plan, while the key status still decides features
- Show the renewal screen only when the plan has expired and the key stopped
  working; when the key still works, show a renewal notice instead
- Show the trial notice only when the key works, and point a refused key with a
  live plan to settings instead of renewal
- Update the connection status tests

* subscription-ended notice and licence-failed grace start

- Show a dismissible wp-admin notice when the subscription has ended but the
  licence still works: "Your GoDAM subscription has ended. Renew to keep Pro
  features." Never on the site, never a full screen
- Save the dismissal for the whole site, and show the notice again for the next
  lapse
- Replace get_expired_since() with get_licence_failed_since(): count Woo's grace
  period from the licence failing, not from connection_status saying expired
- Return nothing while the licence works; use Central's expired_at once sent,
  otherwise the first failed check; Central being unreachable never starts it
- Update the connection status tests

* Align with Central's final connection status contract

- Start Woo's grace period from the first failed key check, not Central's expired_at (the subscription can lapse while the licence still works)
- Use expired_at only when no failed check is on record
- Document what Central sends for 200, 401 and both 403 cases
- Add tests for every final Central answer and the grace start date

* Address review on the connection status

- "Check again" says GoDAM couldn't be reached when the refresh can't reach Central or the request fails, not "still expired"
- Back from the license key screen returns to renewal for a site with a lapsed plan
- Remove rtgodam-connection and the dismissed-notice option on uninstall
- Forget the previous key's answer, including its organization, when a different key is saved
- Read an older Central's 401 as a key it doesn't know (connect screens, not renewal)
- Match the key-check test answers to Central's shapes: subscription ended on a 200 with its date, an inactive licence on a 403 with no date

* Make the license key screen's Back tests pass in any order

- Clear WordPress's record of logged deprecations before each test, so the text field's size warning shows in every test, not only the first one run
- Expect the warning in both tests

* Show how many trial days are left on the GoDAM dashboard (#2378)

* Show how many trial days are left on the GoDAM dashboard

- Add a TrialDaysNotice shared component: "Your GoDAM trial ends in N days" (or
  "ends today") with an upgrade link ↗ to the renewal URL
- Show it only for a trial whose key works on this site and whose end date
  Central sent; switch to a warning in the last three days
- Read the days left whether wp_localize_script sends them as a number or as
  text, so the notice shows on real pages
- Match the dashboard content's width and side spacing so the notice lines up
  with the cards at every screen size
- Use the same wording as the Media Library trial notice so both share one
  translation
- Add unit tests for the notice

Refs rtCamp/godam-plugin-wp#114

* Address review on the dashboard trial notice

- Read days left from any number (strings, decimals) instead of digits only, counting a part day as a day
- Hide the notice while the header's Free plan banner (TrialCountdownBanner) shows, so the trial end isn't shown twice
- Share the content box's max width and gutter with .dashboard-container through a content-box partial
- Show the warning for the last 3 days (2, 1, 0 left), matching the description
- Add tests for days-left parsing, decimals and the banner overlap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants