@@ -41,21 +41,17 @@ function getTimezoneFromDate(
41
41
) ;
42
42
}
43
43
44
- export function UsageAndDuration ( props : Props ) {
45
- const {
46
- showExplanations = false ,
47
- form,
48
- onChange,
49
- disabled = false ,
50
- showUsage = true ,
51
- discount = true ,
52
- extraDuration,
53
- source,
54
- } = props ;
55
-
56
- //const duration: Duration = type === "license" ? "all" : "range";
57
- const duration = props . duration || "all" ;
58
-
44
+ export function UsageAndDuration ( {
45
+ showExplanations = false ,
46
+ form,
47
+ onChange,
48
+ disabled = false ,
49
+ showUsage = true ,
50
+ discount = true ,
51
+ extraDuration,
52
+ source,
53
+ duration = "all" ,
54
+ } : Props ) {
59
55
const profile = useProfile ( ) ;
60
56
61
57
function renderUsageExplanation ( ) {
@@ -138,17 +134,16 @@ export function UsageAndDuration(props: Props) {
138
134
139
135
function renderRangeSelector ( getFieldValue ) {
140
136
const period = getFieldValue ( "period" ) ;
141
- if ( period !== "range" ) {
142
- return ;
143
- }
137
+
138
+ // ensure range is valid even if we aren't going to render this range selector visibly:
139
+ // see https://github.com/sagemathinc/cocalc/issues/8461
144
140
let range = getFieldValue ( "range" ) ;
145
141
let invalidRange = range ?. [ 0 ] == null || range ?. [ 1 ] == null ;
146
142
if ( invalidRange ) {
147
143
// Check if we're during initial load and URL has range parameters
148
144
// If so, don't override with default dates
149
145
const urlParams = new URLSearchParams ( window . location . search ) ;
150
- const hasRangeInUrl = urlParams . has ( 'range' ) ;
151
-
146
+ const hasRangeInUrl = urlParams . has ( "range" ) ;
152
147
if ( ! hasRangeInUrl ) {
153
148
const start = new Date ( ) ;
154
149
const dayMs = 1000 * 60 * 60 * 24 ;
@@ -159,6 +154,11 @@ export function UsageAndDuration(props: Props) {
159
154
onChange ( ) ;
160
155
}
161
156
}
157
+
158
+ if ( period !== "range" ) {
159
+ return ;
160
+ }
161
+
162
162
let suffix ;
163
163
try {
164
164
if ( ! invalidRange ) {
@@ -188,7 +188,9 @@ export function UsageAndDuration(props: Props) {
188
188
extra = { source === "course" ? renderDurationExplanation ( ) : undefined }
189
189
>
190
190
< DateRange
191
- key = { range ? `${ range [ 0 ] ?. getTime ( ) } _${ range [ 1 ] ?. getTime ( ) } ` : 'no-range' }
191
+ key = {
192
+ range ? `${ range [ 0 ] ?. getTime ( ) } _${ range [ 1 ] ?. getTime ( ) } ` : "no-range"
193
+ }
192
194
disabled = { disabled }
193
195
noPast
194
196
maxDaysInFuture = { 365 * 4 }
@@ -287,8 +289,8 @@ export function UsageAndDuration(props: Props) {
287
289
source === "course"
288
290
? "range"
289
291
: duration === "range"
290
- ? "range"
291
- : "monthly" ;
292
+ ? "range"
293
+ : "monthly" ;
292
294
293
295
switch ( source ) {
294
296
case "course" :
0 commit comments