Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/store/run-limit.tsx
6028 views
1
/*
2
* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Divider, Form } from "antd";
7
import { useRouter } from "next/router";
8
9
import { unreachable } from "@cocalc/util/misc";
10
import A from "components/misc/A";
11
import IntegerSlider from "components/misc/integer-slider";
12
13
import type { LicenseSource } from "@cocalc/util/upgrades/shopping";
14
15
export const MAX_ALLOWED_RUN_LIMIT = 10000;
16
17
interface RunLimitProps {
18
showExplanations: boolean;
19
form: any;
20
onChange: () => void;
21
disabled?: boolean;
22
boost?: boolean;
23
source: LicenseSource;
24
}
25
26
export function RunLimit({
27
showExplanations,
28
form,
29
onChange,
30
disabled = false,
31
boost = false,
32
source,
33
}: RunLimitProps) {
34
const router = useRouter();
35
36
function extra() {
37
if (!showExplanations) return;
38
39
switch (source) {
40
case "site-license":
41
return (
42
<div style={{ marginTop: "5px" }}>
43
{boost ? (
44
<div style={{ fontWeight: "bold" }}>
45
It's not necessary to match the run limit of the license you
46
want to boost!
47
</div>
48
) : undefined}
49
Simultaneously run this many projects using this license. You, and
50
anyone you share the license code with, can apply the license to an
51
unlimited number of projects, but it will only be used up to the run
52
limit. When{" "}
53
<A href="https://doc.cocalc.com/teaching-instructors.html">
54
teaching a course
55
</A>
56
,{" "}
57
<b>
58
<i>
59
the run limit is typically 2 more than the number of students
60
(one for each student, one for the shared project and one for
61
the instructor project)
62
</i>
63
</b>
64
.
65
</div>
66
);
67
case "course":
68
return (
69
<div style={{ marginTop: "5px" }}>
70
If you consider creating a shared project for your course, you
71
should select one more seat than the number of students. One for
72
each student, and one for the shared project. Regarding your
73
instructor project, you need one additional seat or purchase a
74
regular{" "}
75
<a onClick={() => router.push("/store/site-license")}>
76
site license
77
</a>{" "}
78
to cover it.
79
</div>
80
);
81
82
default:
83
unreachable(source);
84
}
85
}
86
87
switch (source) {
88
case "site-license":
89
return (
90
<>
91
<Divider plain>Simultaneous Project Upgrades</Divider>
92
<Form.Item
93
label="Run Limit"
94
name="run_limit"
95
initialValue={1}
96
extra={extra()}
97
>
98
<EditRunLimit
99
source={source}
100
disabled={disabled}
101
onChange={(run_limit) => {
102
form.setFieldsValue({ run_limit });
103
onChange();
104
}}
105
/>
106
</Form.Item>
107
</>
108
);
109
110
case "course":
111
return (
112
<>
113
<Divider plain>Size of Course</Divider>
114
<Form.Item
115
label="Students"
116
name="run_limit"
117
initialValue={25}
118
extra={extra()}
119
>
120
<EditRunLimit
121
source={source}
122
disabled={disabled}
123
onChange={(run_limit) => {
124
form.setFieldsValue({ run_limit });
125
onChange();
126
}}
127
/>
128
</Form.Item>
129
</>
130
);
131
132
default:
133
unreachable(source);
134
}
135
}
136
137
function EditRunLimit({
138
value,
139
onChange,
140
disabled,
141
source,
142
}: {
143
value?: number;
144
onChange: (run_limit: number) => void;
145
disabled?: boolean;
146
source: LicenseSource;
147
}) {
148
return (
149
<IntegerSlider
150
value={value}
151
min={1}
152
disabled={disabled}
153
max={300}
154
maxText={MAX_ALLOWED_RUN_LIMIT}
155
onChange={onChange}
156
units={source === "course" ? "students" : "projects"}
157
presets={
158
source === "course"
159
? [10, 25, 50, 75, 100, 125, 150, 200]
160
: [1, 2, 10, 50, 100, 250, 500]
161
}
162
/>
163
);
164
}
165
166