Refactor SystemVersionContainer and add dtos to types

master^2
Tudor Stanciu 2024-11-10 02:05:32 +02:00
parent c5ba810605
commit 74a176b9aa
4 changed files with 17 additions and 15 deletions

View File

@ -1,26 +1,19 @@
import React, { useState, useEffect } from "react";
import React from "react";
import SystemVersionComponent from "./SystemVersionComponent";
import { routes, get, endpoints } from "../../../utils/api";
import { endpoints } from "../../../utils/api";
import useSWR from "swr";
import { fetcher } from "utils/swr";
import { blip } from "utils";
import { dtos } from "types";
const SystemVersionContainer: React.FC = () => {
const { data: namespaces } = useSWR<any[], Error>(endpoints.system.version, fetcher, {
const { data, isLoading } = useSWR<dtos.SystemVersion, Error>(endpoints.system.version, fetcher, {
revalidateOnFocus: false,
onError: err => blip.error(err.message)
});
const [state, setState] = useState({ data: {}, loaded: false });
useEffect(() => {
if (state.loaded) return;
get(routes.systemVersion, {
onCompleted: (data: any) => setState({ data, loaded: true })
});
}, [state.loaded]);
return <>{state.loaded && <SystemVersionComponent data={state.data} />}</>;
if (isLoading || !data) return null;
return <SystemVersionComponent data={data} />;
};
export default SystemVersionContainer;

View File

@ -0,0 +1,9 @@
export type SystemVersionElement = {
version: string;
lastReleaseDate: string;
};
export type SystemVersion = {
api: SystemVersionElement;
server: SystemVersionElement;
};

View File

@ -1,5 +1,6 @@
import * as models from "./models";
import * as dtos from "./dtos";
export * from "./models";
export { models };
export { models, dtos };

View File

@ -11,7 +11,6 @@ const securityRoute = `${apiHost}/security`;
const routes = {
permissions: `${securityRoute}/permissions`,
systemVersion: `${systemRoute}/version`,
releaseNotes: `${systemRoute}/release-notes`,
resetCache: `${systemRoute}/reset-cache`,
machines: `${networkRoute}/machines`,