Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/components/misc/select-site-license.tsx
Views: 687
/*1Select a site license, either by pasting one in, or2from a list of all of the licenses the signed in user3is a manager of.4*/5import { useMemo } from "react";6import { Alert } from "antd";7import SelectLicense, {8License,9} from "@cocalc/frontend/site-licenses/select-license";10import useQuery from "lib/hooks/database";11import Loading from "components/share/loading";1213interface Props {14onChange: (licenseId: string | undefined) => void; // called with undefined if user doesn't want to select a license15defaultLicenseId?: string;16}1718export default function SelectSiteLicense({19onChange,20defaultLicenseId,21}: Props) {22const { error, value, loading } = useQuery({23manager_site_licenses: [24{ id: null, expires: null, title: null, quota: null },25],26});27const managedLicenses: { [id: string]: License } = useMemo(() => {28const x: { [id: string]: License } = {};29if (!value) return x;30const { manager_site_licenses } = value;31for (const license of manager_site_licenses) {32if (license.expires) {33// comes back from database as ISO string.34license.expires = new Date(license.expires);35}36x[license.id] = license;37}38return x;39}, [value]);4041if (loading || value == null) {42return <Loading />;43}44if (error) {45return <Alert type="error" message={error} />;46}47return (48<SelectLicense49onChange={onChange}50defaultLicenseId={defaultLicenseId}51managedLicenses={managedLicenses}52/>53);54}555657