Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(subscriptionStore): move planName TASK-987 #5306

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion jsapp/js/account/subscriptionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {makeAutoObservable} from 'mobx';
import {handleApiFail, fetchGet} from 'js/api';
import {ACTIVE_STRIPE_STATUSES, ROOT_URL} from 'js/constants';
import type {PaginatedResponse} from 'js/dataInterface';
import type {Product, SubscriptionInfo} from 'js/account/stripe.types';
import {PlanNames, type Product, type SubscriptionInfo} from 'js/account/stripe.types';
import envStore from 'js/envStore';

const PRODUCTS_URL = '/api/v2/stripe/products/';

Expand Down Expand Up @@ -43,6 +44,22 @@ class SubscriptionStore {
});
}

/*
* The plan name displayed to the user. This will display, in order of precedence:
* * The user's active plan subscription
* * The FREE_TIER_DISPLAY["name"] setting (if the user registered before FREE_TIER_CUTOFF_DATE
* * The free plan
*/
public get planName() {
if (
this.planResponse.length &&
this.planResponse[0].items.length
) {
return this.planResponse[0].items[0].price.product.name;
}
return envStore.data?.free_tier_display?.name || PlanNames.FREE;
}

private onFetchSubscriptionInfoDone(
response: PaginatedResponse<SubscriptionInfo>
) {
Expand Down
13 changes: 1 addition & 12 deletions jsapp/js/account/usage/yourPlan.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,7 @@ export const YourPlan = () => {
const [session] = useState(() => sessionStore);
const [productsContext] = useContext(ProductsContext);

/*
* The plan name displayed to the user. This will display, in order of precedence:
* * The user's active plan subscription
* * The FREE_TIER_DISPLAY["name"] setting (if the user registered before FREE_TIER_CUTOFF_DATE
* * The free plan
*/
const planName = useMemo(() => {
if (subscriptions.planResponse.length) {
return subscriptions.planResponse[0].items[0].price.product.name;
}
return env.data?.free_tier_display?.name || PlanNames.FREE;
}, [env.isReady, subscriptions.isInitialised]);
const planName = subscriptions.planName;

// The start date of the user's plan. Defaults to the account creation date if the user doesn't have a subscription.
const startDate = useMemo(() => {
Expand Down