Refactor SystemVersionContainer and add dtos to types
parent
c5ba810605
commit
74a176b9aa
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
export type SystemVersionElement = {
|
||||
version: string;
|
||||
lastReleaseDate: string;
|
||||
};
|
||||
|
||||
export type SystemVersion = {
|
||||
api: SystemVersionElement;
|
||||
server: SystemVersionElement;
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
import * as models from "./models";
|
||||
import * as dtos from "./dtos";
|
||||
|
||||
export * from "./models";
|
||||
|
||||
export { models };
|
||||
export { models, dtos };
|
||||
|
|
|
@ -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`,
|
||||
|
|
Loading…
Reference in New Issue