@@ -9,7 +9,7 @@ Create a new project
9
9
10
10
import { Button , Card , Col , Form , Input , Row } from "antd" ;
11
11
import { delay } from "awaiting" ;
12
-
12
+ import { BuyLicenseForProject } from "@cocalc/frontend/site-licenses/purchase/buy-license-for-project" ;
13
13
import { Alert , Well } from "@cocalc/frontend/antd-bootstrap" ;
14
14
import {
15
15
CSS ,
@@ -61,7 +61,6 @@ export const NewProjectCreator: React.FC<Props> = ({
61
61
const [ title_text , set_title_text ] = useState < string > ( default_value ?? "" ) ;
62
62
const [ error , set_error ] = useState < string > ( "" ) ;
63
63
const [ show_advanced , set_show_advanced ] = useState < boolean > ( false ) ;
64
- const [ show_add_license , set_show_add_license ] = useState < boolean > ( false ) ;
65
64
const [ title_prefill , set_title_prefill ] = useState < boolean > ( false ) ;
66
65
const [ license_id , set_license_id ] = useState < string > ( "" ) ;
67
66
const [ warnBoost , setWarnBoost ] = useState < boolean > ( false ) ;
@@ -73,15 +72,19 @@ export const NewProjectCreator: React.FC<Props> = ({
73
72
74
73
const is_anonymous = useTypedRedux ( "account" , "is_anonymous" ) ;
75
74
const customize_kucalc = useTypedRedux ( "customize" , "kucalc" ) ;
75
+ const requireLicense = ! ! useTypedRedux (
76
+ "customize" ,
77
+ "require_license_to_create_project" ,
78
+ ) ;
79
+ const [ show_add_license , set_show_add_license ] =
80
+ useState < boolean > ( requireLicense ) ;
76
81
77
82
// onprem and cocalc.com use licenses to adjust quota configs – but only cocalc.com has custom software images
78
83
const show = useMemo (
79
84
( ) => [ KUCALC_COCALC_COM , KUCALC_ON_PREMISES ] . includes ( customize_kucalc ) ,
80
85
[ customize_kucalc ] ,
81
86
) ;
82
87
83
- //const requireLicense = customize_kucalc == KUCALC_COCALC_COM;
84
-
85
88
const [ form ] = Form . useForm ( ) ;
86
89
87
90
useEffect ( ( ) => {
@@ -113,7 +116,7 @@ export const NewProjectCreator: React.FC<Props> = ({
113
116
set_error ( "" ) ;
114
117
set_custom_software ( { } ) ;
115
118
set_show_advanced ( false ) ;
116
- set_show_add_license ( false ) ;
119
+ set_show_add_license ( requireLicense ) ;
117
120
set_title_prefill ( true ) ;
118
121
set_license_id ( "" ) ;
119
122
}
@@ -227,7 +230,10 @@ export const NewProjectCreator: React.FC<Props> = ({
227
230
) ;
228
231
}
229
232
230
- function create_disabled ( ) {
233
+ function isDisabled ( ) {
234
+ if ( requireLicense && ! license_id ) {
235
+ return true ;
236
+ }
231
237
return (
232
238
// no name of new project
233
239
! title_text ?. trim ( ) ||
@@ -286,8 +292,20 @@ export const NewProjectCreator: React.FC<Props> = ({
286
292
function render_add_license ( ) {
287
293
if ( ! show_add_license ) return ;
288
294
return (
289
- < Card size = "small" title = "Select license" style = { CARD_STYLE } >
295
+ < Card
296
+ size = "small"
297
+ title = {
298
+ < >
299
+ < div style = { { float : "right" } } >
300
+ < BuyLicenseForProject size = "small" />
301
+ </ div >
302
+ < Icon name = "key" /> Select License
303
+ </ >
304
+ }
305
+ style = { CARD_STYLE }
306
+ >
290
307
< SiteLicenseInput
308
+ requireValid
291
309
confirmLabel = { "Add this license" }
292
310
onChange = { addSiteLicense }
293
311
/>
@@ -325,6 +343,7 @@ export const NewProjectCreator: React.FC<Props> = ({
325
343
return (
326
344
< div style = { TOGGLE_STYLE } >
327
345
< Button
346
+ disabled = { requireLicense }
328
347
onClick = { ( ) => set_show_add_license ( true ) }
329
348
type = "link"
330
349
style = { TOGGLE_BUTTON_STYLE }
@@ -348,7 +367,7 @@ export const NewProjectCreator: React.FC<Props> = ({
348
367
>
349
368
add/remove licenses
350
369
</ A > { " " }
351
- in the project settings later on .
370
+ in project settings later.
352
371
</ div >
353
372
) ;
354
373
}
@@ -419,12 +438,12 @@ export const NewProjectCreator: React.FC<Props> = ({
419
438
Cancel
420
439
</ Button >
421
440
< Button
422
- disabled = { create_disabled ( ) }
441
+ disabled = { isDisabled ( ) }
423
442
onClick = { ( ) => create_project ( ) }
424
443
type = "primary"
425
444
>
426
445
Create Project
427
- { create_disabled ( ) ? " (enter a title above!)" : "" }
446
+ { requireLicense && ! license_id && < > (select license above) </ > }
428
447
</ Button >
429
448
</ Col >
430
449
</ Row >
0 commit comments