Skip to content

Commit fe94162

Browse files
committed
Clean up usage of backend billing cycle data
1 parent 7225561 commit fe94162

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

jsapp/js/account/subscriptionStore.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class SubscriptionStore {
1515
public planResponse: SubscriptionInfo[] = [];
1616
public addOnsResponse: SubscriptionInfo[] = [];
1717
public activeSubscriptions: SubscriptionInfo[] = [];
18+
public canceledPlans: SubscriptionInfo[] = [];
1819
public isPending = false;
1920
public isInitialised = false;
2021

@@ -50,6 +51,11 @@ class SubscriptionStore {
5051
this.activeSubscriptions = response.results.filter((sub) =>
5152
ACTIVE_STRIPE_STATUSES.includes(sub.status)
5253
);
54+
this.canceledPlans = response.results.filter(
55+
(sub) =>
56+
sub.items[0]?.price.product.metadata?.product_type == 'plan' &&
57+
sub.status === 'canceled'
58+
);
5359
// get any active plan subscriptions for the user
5460
this.planResponse = this.activeSubscriptions.filter(
5561
(sub) => sub.items[0]?.price.product.metadata?.product_type == 'plan'

jsapp/js/account/usage/usage.api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ export interface AssetWithUsage {
3535

3636
export interface UsageResponse {
3737
current_month_start: string;
38+
current_month_end: string;
3839
current_year_start: string;
39-
billing_period_end: string | null;
40+
current_year_end: string;
4041
total_submission_count: {
4142
current_month: number;
4243
current_year: number;

jsapp/js/account/usage/useUsage.hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const loadUsage = async (
5757
usage.total_nlp_usage[`mt_characters_current_${trackingPeriod}`],
5858
currentMonthStart: usage.current_month_start,
5959
currentYearStart: usage.current_year_start,
60-
billingPeriodEnd: usage.billing_period_end,
60+
billingPeriodEnd: usage[`current_${trackingPeriod}_end`],
6161
trackingPeriod,
6262
lastUpdated,
6363
};

jsapp/js/account/usage/yourPlan.component.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export const YourPlan = () => {
5151
let date;
5252
if (subscriptions.planResponse.length) {
5353
date = subscriptions.planResponse[0].start_date;
54+
} else if (subscriptions.canceledPlans.length){
55+
date =
56+
subscriptions.canceledPlans[subscriptions.canceledPlans.length - 1]
57+
.ended_at;
5458
} else {
5559
date = session.currentAccount.date_joined;
5660
}

0 commit comments

Comments
 (0)