124 lines
3.4 KiB
TypeScript
Raw Normal View History

2024-05-04 10:18:37 +02:00
import {
Tab,
TabList,
makeStyles,
typographyStyles,
} from "@fluentui/react-components";
import {
AppsListDetailFilled,
AppsListDetailRegular,
2024-05-04 10:18:37 +02:00
DesktopFilled,
DesktopRegular,
InfoFilled,
InfoRegular,
bundleIcon,
} from "@fluentui/react-icons";
import React from "react";
2024-11-30 10:26:14 +01:00
import { Rights, ServerApi } from "./api/ServerApi";
2024-05-04 10:34:59 +02:00
import { AuthRouteWidget } from "./routes/AuthRouteWidget";
import { AsyncWidget } from "./widgets/AsyncWidget";
import { MainMenu } from "./widgets/MainMenu";
import { SystemInfoWidget } from "./widgets/SystemInfoWidget";
import { VirtualMachinesWidget } from "./widgets/VirtualMachinesWidget";
import { GroupsWidget } from "./widgets/GroupsWidget";
2024-05-03 22:03:25 +02:00
const useStyles = makeStyles({
title: typographyStyles.title2,
});
2024-05-04 10:18:37 +02:00
const InfoIcon = bundleIcon(InfoFilled, InfoRegular);
const DesktopIcon = bundleIcon(DesktopFilled, DesktopRegular);
const AppListIcon = bundleIcon(AppsListDetailFilled, AppsListDetailRegular);
export function App() {
return (
<AsyncWidget
loadKey={1}
errMsg="Failed to load server configuration!"
load={ServerApi.LoadConfig}
loadingMessage="Loading server configuration..."
2024-05-02 22:14:20 +02:00
build={() => <AppInner />}
/>
);
}
2024-05-02 22:14:20 +02:00
function AppInner(): React.ReactElement {
2024-11-30 10:26:14 +01:00
if (!ServerApi.Config.authenticated && !ServerApi.Config.disable_auth)
return <AuthRouteWidget />;
return <AuthenticatedApp />;
}
function AuthenticatedApp(): React.ReactElement {
2024-05-03 22:03:25 +02:00
const styles = useStyles();
const [tab, setTab] = React.useState<"group" | "vm" | "info">("group");
2024-05-03 22:03:25 +02:00
2024-11-30 10:26:14 +01:00
const [rights, setRights] = React.useState<Rights | undefined>();
const load = async () => {
const rights = await ServerApi.GetRights();
setRights(rights);
if (rights!.groups.length > 0) setTab("group");
else if (rights!.vms.length > 0) setTab("vm");
else setTab("info");
2024-11-30 10:26:14 +01:00
};
2024-05-03 22:03:25 +02:00
return (
2024-11-30 10:26:14 +01:00
<AsyncWidget
loadKey={1}
load={load}
errMsg="Failed to retrieve application rights!"
build={() => {
return (
<div
style={{
width: "95%",
maxWidth: "1000px",
margin: "50px auto",
}}
>
<span className={styles.title}>VirtWebRemote</span>
<div
style={{
display: "flex",
justifyContent: "space-between",
marginTop: "30px",
}}
>
<TabList
selectedValue={tab}
onTabSelect={(_, d) => setTab(d.value as any)}
>
{rights!.groups.length > 0 && (
<Tab value="group" icon={<AppListIcon />}>
Groups
</Tab>
)}
{rights!.vms.length > 0 && (
<Tab value="vm" icon={<DesktopIcon />}>
Virtual machines
</Tab>
)}
{rights!.sys_info && (
<Tab value="info" icon={<InfoIcon />}>
System info
</Tab>
)}
2024-11-30 10:26:14 +01:00
</TabList>
<div>
<MainMenu />
</div>
</div>
{tab === "group" && <GroupsWidget rights={rights!} />}
2024-11-30 10:26:14 +01:00
{tab === "vm" && <VirtualMachinesWidget rights={rights!} />}
{tab === "info" && <SystemInfoWidget />}
</div>
);
2024-05-03 22:03:25 +02:00
}}
2024-11-30 10:26:14 +01:00
/>
2024-05-03 22:03:25 +02:00
);
2024-05-02 22:14:20 +02:00
}