@@ -9,7 +9,7 @@ Create a new project
99
1010import { Button , Card , Col , Form , Input , Row } from "antd" ;
1111import { delay } from "awaiting" ;
12-
12+ import { BuyLicenseForProject } from "@cocalc/frontend/site-licenses/purchase/buy-license-for-project" ;
1313import { Alert , Well } from "@cocalc/frontend/antd-bootstrap" ;
1414import {
1515 CSS ,
@@ -61,7 +61,6 @@ export const NewProjectCreator: React.FC<Props> = ({
6161 const [ title_text , set_title_text ] = useState < string > ( default_value ?? "" ) ;
6262 const [ error , set_error ] = useState < string > ( "" ) ;
6363 const [ show_advanced , set_show_advanced ] = useState < boolean > ( false ) ;
64- const [ show_add_license , set_show_add_license ] = useState < boolean > ( false ) ;
6564 const [ title_prefill , set_title_prefill ] = useState < boolean > ( false ) ;
6665 const [ license_id , set_license_id ] = useState < string > ( "" ) ;
6766 const [ warnBoost , setWarnBoost ] = useState < boolean > ( false ) ;
@@ -73,15 +72,19 @@ export const NewProjectCreator: React.FC<Props> = ({
7372
7473 const is_anonymous = useTypedRedux ( "account" , "is_anonymous" ) ;
7574 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 ) ;
7681
7782 // onprem and cocalc.com use licenses to adjust quota configs – but only cocalc.com has custom software images
7883 const show = useMemo (
7984 ( ) => [ KUCALC_COCALC_COM , KUCALC_ON_PREMISES ] . includes ( customize_kucalc ) ,
8085 [ customize_kucalc ] ,
8186 ) ;
8287
83- //const requireLicense = customize_kucalc == KUCALC_COCALC_COM;
84-
8588 const [ form ] = Form . useForm ( ) ;
8689
8790 useEffect ( ( ) => {
@@ -113,7 +116,7 @@ export const NewProjectCreator: React.FC<Props> = ({
113116 set_error ( "" ) ;
114117 set_custom_software ( { } ) ;
115118 set_show_advanced ( false ) ;
116- set_show_add_license ( false ) ;
119+ set_show_add_license ( requireLicense ) ;
117120 set_title_prefill ( true ) ;
118121 set_license_id ( "" ) ;
119122 }
@@ -227,7 +230,10 @@ export const NewProjectCreator: React.FC<Props> = ({
227230 ) ;
228231 }
229232
230- function create_disabled ( ) {
233+ function isDisabled ( ) {
234+ if ( requireLicense && ! license_id ) {
235+ return true ;
236+ }
231237 return (
232238 // no name of new project
233239 ! title_text ?. trim ( ) ||
@@ -286,8 +292,20 @@ export const NewProjectCreator: React.FC<Props> = ({
286292 function render_add_license ( ) {
287293 if ( ! show_add_license ) return ;
288294 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+ >
290307 < SiteLicenseInput
308+ requireValid
291309 confirmLabel = { "Add this license" }
292310 onChange = { addSiteLicense }
293311 />
@@ -325,6 +343,7 @@ export const NewProjectCreator: React.FC<Props> = ({
325343 return (
326344 < div style = { TOGGLE_STYLE } >
327345 < Button
346+ disabled = { requireLicense }
328347 onClick = { ( ) => set_show_add_license ( true ) }
329348 type = "link"
330349 style = { TOGGLE_BUTTON_STYLE }
@@ -348,7 +367,7 @@ export const NewProjectCreator: React.FC<Props> = ({
348367 >
349368 add/remove licenses
350369 </ A > { " " }
351- in the project settings later on .
370+ in project settings later.
352371 </ div >
353372 ) ;
354373 }
@@ -419,12 +438,12 @@ export const NewProjectCreator: React.FC<Props> = ({
419438 Cancel
420439 </ Button >
421440 < Button
422- disabled = { create_disabled ( ) }
441+ disabled = { isDisabled ( ) }
423442 onClick = { ( ) => create_project ( ) }
424443 type = "primary"
425444 >
426445 Create Project
427- { create_disabled ( ) ? " (enter a title above!)" : "" }
446+ { requireLicense && ! license_id && < > (select license above) </ > }
428447 </ Button >
429448 </ Col >
430449 </ Row >
0 commit comments