diff --git a/src/packages/frontend/customize.tsx b/src/packages/frontend/customize.tsx index 622413b7cc..d9bb69be86 100644 --- a/src/packages/frontend/customize.tsx +++ b/src/packages/frontend/customize.tsx @@ -127,6 +127,7 @@ export interface CustomizeState { max_upgrades: TypedMap>; nonfree_countries?: List; limit_free_project_uptime: number; // minutes + require_license_to_create_project?: boolean; onprem_quota_heading: string; organization_email: string; organization_name: string; diff --git a/src/packages/frontend/projects/create-project.tsx b/src/packages/frontend/projects/create-project.tsx index dee3ae9d4a..9727e8b0ef 100644 --- a/src/packages/frontend/projects/create-project.tsx +++ b/src/packages/frontend/projects/create-project.tsx @@ -9,7 +9,7 @@ Create a new project import { Button, Card, Col, Form, Input, Row } from "antd"; import { delay } from "awaiting"; - +import { BuyLicenseForProject } from "@cocalc/frontend/site-licenses/purchase/buy-license-for-project"; import { Alert, Well } from "@cocalc/frontend/antd-bootstrap"; import { CSS, @@ -61,7 +61,6 @@ export const NewProjectCreator: React.FC = ({ const [title_text, set_title_text] = useState(default_value ?? ""); const [error, set_error] = useState(""); const [show_advanced, set_show_advanced] = useState(false); - const [show_add_license, set_show_add_license] = useState(false); const [title_prefill, set_title_prefill] = useState(false); const [license_id, set_license_id] = useState(""); const [warnBoost, setWarnBoost] = useState(false); @@ -73,6 +72,12 @@ export const NewProjectCreator: React.FC = ({ const is_anonymous = useTypedRedux("account", "is_anonymous"); const customize_kucalc = useTypedRedux("customize", "kucalc"); + const requireLicense = !!useTypedRedux( + "customize", + "require_license_to_create_project", + ); + const [show_add_license, set_show_add_license] = + useState(requireLicense); // onprem and cocalc.com use licenses to adjust quota configs – but only cocalc.com has custom software images const show = useMemo( @@ -80,8 +85,6 @@ export const NewProjectCreator: React.FC = ({ [customize_kucalc], ); - //const requireLicense = customize_kucalc == KUCALC_COCALC_COM; - const [form] = Form.useForm(); useEffect(() => { @@ -113,7 +116,7 @@ export const NewProjectCreator: React.FC = ({ set_error(""); set_custom_software({}); set_show_advanced(false); - set_show_add_license(false); + set_show_add_license(requireLicense); set_title_prefill(true); set_license_id(""); } @@ -227,7 +230,10 @@ export const NewProjectCreator: React.FC = ({ ); } - function create_disabled() { + function isDisabled() { + if (requireLicense && !license_id) { + return true; + } return ( // no name of new project !title_text?.trim() || @@ -286,8 +292,20 @@ export const NewProjectCreator: React.FC = ({ function render_add_license() { if (!show_add_license) return; return ( - + +
+ +
+ Select License + + } + style={CARD_STYLE} + > @@ -325,6 +343,7 @@ export const NewProjectCreator: React.FC = ({ return (
); } @@ -419,12 +438,12 @@ export const NewProjectCreator: React.FC = ({ Cancel diff --git a/src/packages/frontend/site-licenses/input.tsx b/src/packages/frontend/site-licenses/input.tsx index 0d09534797..5fe352ff7b 100644 --- a/src/packages/frontend/site-licenses/input.tsx +++ b/src/packages/frontend/site-licenses/input.tsx @@ -34,6 +34,7 @@ interface Props { style?: CSS; extra?: React.ReactNode; extraButtons?: React.ReactNode; + requireValid?: boolean; } export const SiteLicenseInput: React.FC = (props: Props) => { @@ -46,6 +47,7 @@ export const SiteLicenseInput: React.FC = (props: Props) => { confirmLabel = "Apply License", extra, extraButtons, + requireValid, } = props; const managedLicenses = useManagedLicenses(); @@ -63,6 +65,7 @@ export const SiteLicenseInput: React.FC = (props: Props) => { style={style} extra={extra} extraButtons={extraButtons} + requireValid={requireValid} /> ); }; diff --git a/src/packages/frontend/site-licenses/select-license.tsx b/src/packages/frontend/site-licenses/select-license.tsx index f7cb0bd645..d90529c945 100644 --- a/src/packages/frontend/site-licenses/select-license.tsx +++ b/src/packages/frontend/site-licenses/select-license.tsx @@ -35,6 +35,7 @@ interface Props { style?: CSS; extra?: ReactNode; // plain-text node is ok extraButtons?: ReactNode; + requireValid?: boolean; } export default function SelectLicense(props: Props) { @@ -49,6 +50,7 @@ export default function SelectLicense(props: Props) { style, extra, extraButtons, + requireValid, } = props; const isBlurredRef = useRef(true); const [licenseId, setLicenseId] = useState(defaultLicenseId ?? ""); @@ -154,24 +156,30 @@ export default function SelectLicense(props: Props) { style={{ width: "100%", ...style }} >
- {(showAll || licenseIds.length < len(managedLicenses)) && ( - setShowAll(!showAll)} - > - Show expired - - )}{" "} + {!requireValid && + (showAll || licenseIds.length < len(managedLicenses)) && ( + setShowAll(!showAll)} + > + Show expired + + )}{" "}