Skip to content

Commit f904ff1

Browse files
committed
more fixes to student pay fix 86522f2
1 parent ea4029b commit f904ff1

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/packages/frontend/course/configuration/student-pay.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import { compute_cost } from "@cocalc/util/licenses/purchase/compute-cost";
2222
import { DEFAULT_PURCHASE_INFO } from "@cocalc/util/licenses/purchase/student-pay";
2323
import type { PurchaseInfo } from "@cocalc/util/licenses/purchase/types";
2424
import { currency } from "@cocalc/util/misc";
25+
import ShowError from "@cocalc/frontend/components/error";
2526

2627
export default function StudentPay({ actions, settings }) {
2728
const intl = useIntl();
2829

30+
const [error, setError] = useState<string>("");
2931
const [minPayment, setMinPayment] = useState<number | undefined>(undefined);
3032
const updateMinPayment = () => {
3133
(async () => {
@@ -37,20 +39,24 @@ export default function StudentPay({ actions, settings }) {
3739
}, []);
3840

3941
const [info, setInfo] = useState<PurchaseInfo>(() => {
40-
const cur = settings.get("payInfo")?.toJS();
42+
let cur = settings.get("payInfo")?.toJS();
43+
let info: PurchaseInfo;
4144
if (cur != null) {
42-
return cur;
45+
info = { ...DEFAULT_PURCHASE_INFO, ...cur };
46+
} else {
47+
info = {
48+
...DEFAULT_PURCHASE_INFO,
49+
// @ts-ignore
50+
start: new Date(),
51+
end: dayjs().add(3, "month").toDate(),
52+
};
4353
}
44-
const info = {
45-
...DEFAULT_PURCHASE_INFO,
46-
start: new Date(),
47-
end: dayjs().add(3, "month").toDate(),
48-
} as PurchaseInfo;
4954
setTimeout(() => {
5055
// React requirement: this must happen in different render loop, because
5156
// it causes an update to the UI.
5257
actions.configuration.setStudentPay({ info, cost });
5358
}, 1);
59+
console.log(info);
5460
return info;
5561
});
5662

@@ -74,7 +80,8 @@ export default function StudentPay({ actions, settings }) {
7480
const cost = useMemo(() => {
7581
try {
7682
return compute_cost(info).cost;
77-
} catch (_) {
83+
} catch (err) {
84+
setError(`${err}`);
7885
return null;
7986
}
8087
}, [info]);
@@ -149,6 +156,7 @@ export default function StudentPay({ actions, settings }) {
149156
</>
150157
}
151158
>
159+
<ShowError error={error} setError={setError} />
152160
{cost != null && !showStudentPay && !!settings?.get("student_pay") && (
153161
<div style={{ float: "right" }}>
154162
<MoneyStatistic title="Cost Per Student" value={cost} />

src/packages/frontend/course/store.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type {
2727
CopyConfigurationOptions,
2828
CopyConfigurationTargets,
2929
} from "./configuration/configuration-copying";
30+
import { DEFAULT_PURCHASE_INFO } from "@cocalc/util/licenses/purchase/student-pay";
3031

3132
export const PARALLEL_DEFAULT = 5;
3233
export const MAX_COPY_PARALLEL = 25;
@@ -287,7 +288,11 @@ export class CourseStore extends Store<CourseState> {
287288
if (settings == null || !settings.get("student_pay")) return null;
288289
const payInfo = settings.get("payInfo")?.toJS();
289290
if (!payInfo) return null;
290-
return payInfo;
291+
// merge in defaults for backward compat if e.g., no version set
292+
return {
293+
...DEFAULT_PURCHASE_INFO,
294+
...payInfo,
295+
};
291296
}
292297

293298
public get_datastore(): Datastore {

src/packages/frontend/course/student-projects/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ export class StudentProjectsActions {
833833
await this.course_actions.shared_project.configure();
834834
await this.set_all_student_project_course_info();
835835
} catch (err) {
836+
console.warn(err);
836837
this.course_actions.set_error(
837838
`Error configuring student projects - ${err}`,
838839
);

src/packages/util/licenses/purchase/consts.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { CustomUpgrades, Subscription, User } from "./types";
77

88
import costVersions from "./cost-versions";
99

10-
1110
export const CURRENT_VERSION = "3";
1211

1312
// Another gamble implicit in this is that pre's are available. When they
@@ -83,6 +82,10 @@ interface CostsStructure {
8382
}
8483

8584
export function getCosts(version: string): CostsStructure {
85+
const x = costVersions[version];
86+
if (x == null) {
87+
throw Error(`Unknown cost version '${version}'`);
88+
}
8689
const {
8790
SUB_DISCOUNT,
8891
GCE_COSTS,

0 commit comments

Comments
 (0)