Skip to content

Commit 8a58ef4

Browse files
committed
implement way to test legacy upgrades UI
- it sucks wasting time on this!!!
1 parent 0f4771a commit 8a58ef4

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/packages/frontend/account/store.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
import { List, Map } from "immutable";
77
import { reduce } from "lodash";
8-
98
import { store as customizeStore } from "@cocalc/frontend/customize";
109
import { make_valid_name } from "@cocalc/util/misc";
1110
import { Store } from "@cocalc/util/redux/Store";
1211
import { get_total_upgrades } from "@cocalc/util/upgrades";
1312
import { AccountState } from "./types";
1413

14+
declare var DEBUG: boolean;
15+
1516
// Define account store
1617
export class AccountStore extends Store<AccountState> {
1718
// User type
@@ -104,13 +105,19 @@ export class AccountStore extends Store<AccountState> {
104105
return this.getIn(["other_settings", "confirm_close"]);
105106
}
106107

107-
// Total ugprades this user is paying for (sum of all upgrades from subscriptions)
108+
// Total upgrades this user is paying for (sum of all upgrades from subscriptions)
108109
get_total_upgrades(): { [key: string]: number } | undefined {
109110
const stripe_data = this.getIn([
110111
"stripe_customer",
111112
"subscriptions",
112113
"data",
113114
]);
115+
// to fake having upgrades, type this in the console
116+
// cc.redux.getStore('account').fake_upgrades = true
117+
if (DEBUG && (this as any).fake_upgrades && !stripe_data) {
118+
// fake debugging data
119+
return get_total_upgrades({}, true);
120+
}
114121
return stripe_data && get_total_upgrades(stripe_data.toJS());
115122
}
116123

src/packages/frontend/account/upgrades/upgrades-page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Footer, PolicyPricingPageUrl, SiteName } from "../../customize";
2121
import "./project-upgrades-table";
2222
import { ProjectUpgradesTable } from "./project-upgrades-table";
2323
export { tmp as UpgradesPage };
24+
declare var DEBUG: boolean;
2425

2526
interface reduxProps {
2627
stripe_customer?: Map<string, any>;
@@ -178,7 +179,7 @@ class UpgradesPage extends Component<reduxProps> {
178179
redux.getActions("projects").load_all_projects();
179180
return <Loading theme={"medium"} />;
180181
}
181-
if (!this.props.stripe_customer?.getIn(["subscriptions", "total_count"])) {
182+
if (!DEBUG && !this.props.stripe_customer?.getIn(["subscriptions", "total_count"])) {
182183
return this.render_no_upgrades();
183184
} else {
184185
return (

src/packages/util/upgrades.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ const misc = require("./misc");
1010
// This is used by the frontend in r_account. It's also used by the backend
1111
// to double check the claims of the frontend.
1212
// stripe_subscriptions_data = stripe_customer?.subscriptions?.data
13-
function get_total_upgrades(stripe_subscriptions_data) {
13+
function get_total_upgrades(stripe_subscriptions_data, DEBUG = false) {
14+
if (DEBUG) {
15+
return PROJECT_UPGRADES.subscription.professional.benefits;
16+
}
17+
1418
const subs = stripe_subscriptions_data;
1519
if (subs == null) {
1620
return {};
@@ -92,7 +96,7 @@ exports.available_upgrades = available_upgrades;
9296
function upgrade_maxes(stripe_subscriptions_data, projects, project_id) {
9397
const { available, excess } = available_upgrades(
9498
stripe_subscriptions_data,
95-
projects
99+
projects,
96100
);
97101
const allocated = projects[project_id];
98102
const maxes = {};

0 commit comments

Comments
 (0)