fix: More accurate rounded days in subscription end message (#2193)

Resolves https://github.com/webrecorder/browsertrix/issues/2192

## Changes

- Displays more accurate subscription/trial end message when
subscription ends between 1-2 days
- Shows timezone for end date

---------
Co-authored-by: SuaYoo <SuaYoo@users.noreply.github.com>
This commit is contained in:
sua yoo 2024-12-05 14:22:27 -08:00 committed by GitHub
parent 17459dc8cd
commit 9736297c49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 25 deletions

View File

@ -1,5 +1,5 @@
import { localized, msg, str } from "@lit/localize"; import { localized, msg, str } from "@lit/localize";
import { differenceInDays } from "date-fns/fp"; import { differenceInHours } from "date-fns/fp";
import { html, type TemplateResult } from "lit"; import { html, type TemplateResult } from "lit";
import { customElement } from "lit/decorators.js"; import { customElement } from "lit/decorators.js";
@ -62,18 +62,21 @@ export class OrgStatusBanner extends BtrixElement {
execMinutesQuotaReached, execMinutesQuotaReached,
} = this.org; } = this.org;
let hoursDiff = 0;
let daysDiff = 0; let daysDiff = 0;
let dateStr = ""; let dateStr = "";
const futureCancelDate = subscription?.futureCancelDate || null; const futureCancelDate = subscription?.futureCancelDate || null;
if (futureCancelDate) { if (futureCancelDate) {
daysDiff = differenceInDays(new Date(), new Date(futureCancelDate)); hoursDiff = differenceInHours(new Date(), new Date(futureCancelDate));
daysDiff = Math.trunc(hoursDiff / 24);
dateStr = this.localize.date(futureCancelDate, { dateStr = this.localize.date(futureCancelDate, {
month: "long", month: "long",
day: "numeric", day: "numeric",
year: "numeric", year: "numeric",
hour: "numeric", hour: "numeric",
timeZoneName: "short",
}); });
} }
@ -90,12 +93,11 @@ export class OrgStatusBanner extends BtrixElement {
content: () => { content: () => {
return { return {
title: title:
daysDiff > 1 hoursDiff < 24
? msg( ? msg("Your org will be deleted within one day")
str`Your org will be deleted in : daysDiff === 1
${daysDiff} days`, ? msg("Your org will be deleted in one day.")
) : msg(str`Your org will be deleted in ${daysDiff} days`),
: `Your org will be deleted within one day`,
detail: html` detail: html`
<p> <p>
${msg( ${msg(
@ -124,11 +126,13 @@ export class OrgStatusBanner extends BtrixElement {
content: () => { content: () => {
return { return {
title: title:
daysDiff > 1 hoursDiff < 24
? msg( ? msg("Your trial ends within one day")
str`You have ${daysDiff} days left of your Browsertrix trial`, : daysDiff === 1
) ? msg("You have one day left of your Browsertrix trial")
: msg(`Your trial ends within one day`), : msg(
str`You have ${daysDiff} days left of your Browsertrix trial`,
),
detail: html` detail: html`
<p> <p>

View File

@ -2935,10 +2935,6 @@
<trans-unit id="sc154fb69dffcdef9"> <trans-unit id="sc154fb69dffcdef9">
<source>billing settings</source> <source>billing settings</source>
</trans-unit> </trans-unit>
<trans-unit id="s71c5c2d34bb2c4c2">
<source>Your org will be deleted in
<x equiv-text="${daysDiff}" id="0"/> days</source>
</trans-unit>
<trans-unit id="s7fa0d24b94690373"> <trans-unit id="s7fa0d24b94690373">
<source>Your subscription ends on <x equiv-text="${dateStr}" id="0"/>. Your user account, org, and all associated data will be deleted.</source> <source>Your subscription ends on <x equiv-text="${dateStr}" id="0"/>. Your user account, org, and all associated data will be deleted.</source>
</trans-unit> </trans-unit>
@ -3835,17 +3831,30 @@
<trans-unit id="sab5061cf8c519285"> <trans-unit id="sab5061cf8c519285">
<source><x equiv-text="${storageBytesText}" id="0"/> of disk space</source> <source><x equiv-text="${storageBytesText}" id="0"/> of disk space</source>
</trans-unit> </trans-unit>
<trans-unit id="saecba9c0445090e6"> <trans-unit id="s8be75efeafa7ffe1">
<source>Choose a Browsertrix Crawler release channel. If available, other versions may provide new/experimental crawling features.</source> <source>Your org will be deleted within one day</source>
</trans-unit> </trans-unit>
<trans-unit id="s22cec6a3e464a4e9"> <trans-unit id="sfa1778ba000b56f5">
<source>Gracefully stop archiving after the specified amount of time has elapsed.</source> <source>Your org will be deleted in one day.</source>
</trans-unit> </trans-unit>
<trans-unit id="s2823887bf8a836da"> <trans-unit id="se392e1f811076a30">
<source>Gracefully stop archiving after the specified amount of data has been captured.</source> <source>Your org will be deleted in <x equiv-text="${daysDiff}" id="0"/> days</source>
</trans-unit> </trans-unit>
<trans-unit id="s9aa0dfb832cb7f69"> <trans-unit id="se1037ae4d9adb08a">
<source>View error logs</source> <source>You have one day left of your Browsertrix trial</source>
<trans-unit id="saecba9c0445090e6">
<source>Choose a Browsertrix Crawler release channel. If available, other versions may provide new/experimental crawling features.</source>
</trans-unit>
<trans-unit id="s22cec6a3e464a4e9">
<source>Gracefully stop archiving after the specified amount of time has elapsed.</source>
</trans-unit>
<trans-unit id="s2823887bf8a836da">
<source>Gracefully stop archiving after the specified amount of data has been captured.</source>
</trans-unit>
<trans-unit id="s9aa0dfb832cb7f69">
<source>View error logs</source>
</trans-unit>
<source>You have one day left of your Browsertrix trial</source>
</trans-unit> </trans-unit>
</body> </body>
</file> </file>