Skip to content

Commit 8cd1e7c

Browse files
committed
course: put constraint on student pay deadline (3 weeks)
1 parent 700c334 commit 8cd1e7c

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

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

+35-27
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,32 @@ export default function StudentPay({ actions, settings }) {
102102
return <Spin />;
103103
}
104104

105+
const buttons = showStudentPay ? (
106+
<Space style={{ margin: "10px 0", float: "right" }}>
107+
<Button
108+
onClick={() => {
109+
setShowStudentPay(false);
110+
reset();
111+
}}
112+
>
113+
Cancel
114+
</Button>
115+
<Button
116+
disabled={
117+
isEqual(info, settings.get("payInfo")?.toJS()) &&
118+
when.isSame(dayjs(settings.get("pay")))
119+
}
120+
type="primary"
121+
onClick={() => {
122+
actions.configuration.setStudentPay({ info, when, cost });
123+
setShowStudentPay(false);
124+
}}
125+
>
126+
Save Changes
127+
</Button>
128+
</Space>
129+
) : undefined;
130+
105131
return (
106132
<Card
107133
style={!paySelected ? { background: "#fcf8e3" } : undefined}
@@ -135,6 +161,7 @@ export default function StudentPay({ actions, settings }) {
135161
</Checkbox>
136162
{settings?.get("student_pay") && (
137163
<div>
164+
{buttons}
138165
<Space style={{ margin: "10px 0" }}>
139166
<Button
140167
disabled={showStudentPay}
@@ -144,31 +171,6 @@ export default function StudentPay({ actions, settings }) {
144171
>
145172
<Icon name="credit-card" /> Start and end dates and upgrades...
146173
</Button>
147-
{showStudentPay && (
148-
<>
149-
<Button
150-
onClick={() => {
151-
setShowStudentPay(false);
152-
reset();
153-
}}
154-
>
155-
Cancel
156-
</Button>
157-
<Button
158-
disabled={
159-
isEqual(info, settings.get("payInfo")?.toJS()) &&
160-
when.isSame(dayjs(settings.get("pay")))
161-
}
162-
type="primary"
163-
onClick={() => {
164-
actions.configuration.setStudentPay({ info, when, cost });
165-
setShowStudentPay(false);
166-
}}
167-
>
168-
Save Changes
169-
</Button>
170-
</>
171-
)}
172174
</Space>
173175
<div>
174176
{showStudentPay && (
@@ -214,8 +216,10 @@ export default function StudentPay({ actions, settings }) {
214216
setWhen={setWhen}
215217
cost={cost}
216218
minPayment={minPayment}
219+
info={info}
217220
/>
218221
)}
222+
{buttons}
219223
</div>
220224
}
221225
/>
@@ -252,15 +256,19 @@ function StudentPayCheckboxLabel({ settings, when }) {
252256
}
253257
}
254258

255-
function RequireStudentsPayWhen({ when, setWhen, cost, minPayment }) {
259+
function RequireStudentsPayWhen({ when, setWhen, cost, minPayment, info }) {
260+
const start = dayjs(info.start);
256261
return (
257262
<div style={{ marginBottom: "15px" }}>
258263
<div style={{ textAlign: "center", marginBottom: "15px" }}>
259264
<DatePicker
260265
changeOnBlur
261266
showToday
262267
allowClear={false}
263-
disabledDate={(current) => current < dayjs().subtract(1, "day")}
268+
disabledDate={(current) =>
269+
current < start.subtract(1, "day") ||
270+
current >= start.add(21, "day")
271+
}
264272
defaultValue={when}
265273
onChange={(date) => {
266274
setWhen(date ?? dayjs());

0 commit comments

Comments
 (0)