From 74a176b9aac13446dce1bf148dd3f9e0f7535b5c Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 10 Nov 2024 02:05:32 +0200 Subject: [PATCH] Refactor SystemVersionContainer and add dtos to types --- .../about/system/SystemVersionContainer.tsx | 19 ++++++------------- frontend/src/types/dtos.ts | 9 +++++++++ frontend/src/types/index.ts | 3 ++- frontend/src/utils/api.js | 1 - 4 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 frontend/src/types/dtos.ts diff --git a/frontend/src/features/about/system/SystemVersionContainer.tsx b/frontend/src/features/about/system/SystemVersionContainer.tsx index 46aaa75..8c3204c 100644 --- a/frontend/src/features/about/system/SystemVersionContainer.tsx +++ b/frontend/src/features/about/system/SystemVersionContainer.tsx @@ -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(endpoints.system.version, fetcher, { + const { data, isLoading } = useSWR(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 && }; + if (isLoading || !data) return null; + return ; }; export default SystemVersionContainer; diff --git a/frontend/src/types/dtos.ts b/frontend/src/types/dtos.ts new file mode 100644 index 0000000..6b90b65 --- /dev/null +++ b/frontend/src/types/dtos.ts @@ -0,0 +1,9 @@ +export type SystemVersionElement = { + version: string; + lastReleaseDate: string; +}; + +export type SystemVersion = { + api: SystemVersionElement; + server: SystemVersionElement; +}; diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts index b471b7f..05ad3f9 100644 --- a/frontend/src/types/index.ts +++ b/frontend/src/types/index.ts @@ -1,5 +1,6 @@ import * as models from "./models"; +import * as dtos from "./dtos"; export * from "./models"; -export { models }; +export { models, dtos }; diff --git a/frontend/src/utils/api.js b/frontend/src/utils/api.js index 6b9e85f..ded593a 100644 --- a/frontend/src/utils/api.js +++ b/frontend/src/utils/api.js @@ -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`,