Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/admin/registration-token-license-summary.tsx
5996 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020-2025 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { useEffect, useState } from "react";
7
8
import {
9
site_license_public_info,
10
trunc_license_id,
11
} from "@cocalc/frontend/site-licenses/util";
12
import { describe_quota } from "@cocalc/util/licenses/describe-quota";
13
14
interface Props {
15
licenseId?: string;
16
}
17
18
export default function LicenseSummary({ licenseId }: Props) {
19
const [summary, setSummary] = useState<string>("None");
20
21
useEffect(() => {
22
let isMounted = true;
23
if (!licenseId) {
24
setSummary("None");
25
return;
26
}
27
setSummary("Loading...");
28
(async () => {
29
try {
30
const info = await site_license_public_info(licenseId);
31
if (!isMounted) return;
32
if (!info) {
33
setSummary(`${trunc_license_id(licenseId)} (not found)`);
34
return;
35
}
36
const parts: string[] = [];
37
if (info.title) parts.push(info.title);
38
if (info.description) parts.push(info.description);
39
if (info.quota) {
40
const quotaDesc = describe_quota(info.quota);
41
if (quotaDesc) parts.push(quotaDesc);
42
}
43
const text = parts.filter(Boolean).join(" — ");
44
setSummary(text || trunc_license_id(licenseId));
45
} catch (err) {
46
if (isMounted) {
47
setSummary(`${trunc_license_id(licenseId)} (error loading)`);
48
}
49
}
50
})();
51
return () => {
52
isMounted = false;
53
};
54
}, [licenseId]);
55
56
if (!licenseId) return <span>None</span>;
57
return <span title={licenseId}>{summary}</span>;
58
}
59
60