VirtWeb/virtweb_frontend/src/App.tsx

98 lines
3.4 KiB
TypeScript
Raw Normal View History

2023-09-04 12:11:56 +00:00
import React from "react";
import {
Route,
RouterProvider,
createBrowserRouter,
createRoutesFromElements,
} from "react-router-dom";
import "./App.css";
2023-09-04 12:11:56 +00:00
import { AuthApi } from "./api/AuthApi";
2023-09-08 07:04:48 +00:00
import { ServerApi } from "./api/ServerApi";
import {
CreateNetworkRoute,
EditNetworkRoute,
} from "./routes/EditNetworkRoute";
import { CreateVMRoute, EditVMRoute } from "./routes/EditVMRoute";
import { IsoFilesRoute } from "./routes/IsoFilesRoute";
import { NetworksListRoute } from "./routes/NetworksListRoute";
import { NotFoundRoute } from "./routes/NotFound";
2023-09-08 07:45:41 +00:00
import { SysInfoRoute } from "./routes/SysInfoRoute";
2023-10-17 16:11:31 +00:00
import { VMListRoute } from "./routes/VMListRoute";
import { VMRoute } from "./routes/VMRoute";
2023-10-18 16:00:25 +00:00
import { VNCRoute } from "./routes/VNCRoute";
import { LoginRoute } from "./routes/auth/LoginRoute";
import { OIDCCbRoute } from "./routes/auth/OIDCCbRoute";
import { BaseAuthenticatedPage } from "./widgets/BaseAuthenticatedPage";
import { BaseLoginPage } from "./widgets/BaseLoginPage";
import { ViewNetworkRoute } from "./routes/ViewNetworkRoute";
2023-12-12 00:32:18 +00:00
import { HomeRoute } from "./routes/HomeRoute";
2024-01-03 13:50:59 +00:00
import { NetworkFiltersListRoute } from "./routes/NetworkFiltersListRoute";
import { ViewNWFilterRoute } from "./routes/ViewNWFilterRoute";
import {
CreateNWFilterRoute,
EditNWFilterRoute,
} from "./routes/EditNWFilterRoute";
2023-09-04 12:11:56 +00:00
interface AuthContext {
signedIn: boolean;
setSignedIn: (signedIn: boolean) => void;
}
const AuthContextK = React.createContext<AuthContext | null>(null);
export function App() {
const [signedIn, setSignedIn] = React.useState(AuthApi.SignedIn);
const context: AuthContext = {
signedIn: signedIn,
setSignedIn: (s) => setSignedIn(s),
};
const router = createBrowserRouter(
createRoutesFromElements(
2023-09-08 07:04:48 +00:00
signedIn || ServerApi.Config.auth_disabled ? (
2023-09-04 12:11:56 +00:00
<Route path="*" element={<BaseAuthenticatedPage />}>
2023-12-12 00:32:18 +00:00
<Route path="" element={<HomeRoute />} />
2023-09-05 11:19:25 +00:00
<Route path="iso" element={<IsoFilesRoute />} />
2023-10-16 17:00:15 +00:00
2023-10-17 16:11:31 +00:00
<Route path="vms" element={<VMListRoute />} />
2023-10-16 17:00:15 +00:00
<Route path="vms/new" element={<CreateVMRoute />} />
2023-10-17 16:11:31 +00:00
<Route path="vm/:uuid" element={<VMRoute />} />
2023-10-16 17:22:15 +00:00
<Route path="vm/:uuid/edit" element={<EditVMRoute />} />
2023-10-18 16:00:25 +00:00
<Route path="vm/:uuid/vnc" element={<VNCRoute />} />
2023-10-16 17:00:15 +00:00
2023-10-31 14:55:15 +00:00
<Route path="net" element={<NetworksListRoute />} />
<Route path="net/new" element={<CreateNetworkRoute />} />
<Route path="net/:uuid" element={<ViewNetworkRoute />} />
<Route path="net/:uuid/edit" element={<EditNetworkRoute />} />
2023-10-31 14:55:15 +00:00
2024-01-03 13:50:59 +00:00
<Route path="nwfilter" element={<NetworkFiltersListRoute />} />
<Route path="nwfilter/new" element={<CreateNWFilterRoute />} />
<Route path="nwfilter/:uuid" element={<ViewNWFilterRoute />} />
<Route path="nwfilter/:uuid/edit" element={<EditNWFilterRoute />} />
2024-01-03 13:50:59 +00:00
2023-09-08 07:45:41 +00:00
<Route path="sysinfo" element={<SysInfoRoute />} />
2023-09-04 12:11:56 +00:00
<Route path="*" element={<NotFoundRoute />} />
</Route>
) : (
<Route path="*" element={<BaseLoginPage />}>
<Route path="" element={<LoginRoute />} />
<Route path="oidc_cb" element={<OIDCCbRoute />} />
<Route path="*" element={<NotFoundRoute />} />
</Route>
)
)
);
return (
<AuthContextK.Provider value={context}>
<RouterProvider router={router} />
</AuthContextK.Provider>
);
}
export function useAuth(): AuthContext {
return React.useContext(AuthContextK)!;
}