From e4329d6db16048d9bd98fcb111093ea55246de94 Mon Sep 17 00:00:00 2001 From: Johanna Szepanski <johanna.szepanski@softhouse.se> Date: Wed, 4 Dec 2024 14:16:19 +0100 Subject: [PATCH] changed to rtk and cleaned up details container --- src/views/IOC/IOCDetailsContainer.jsx | 59 +++++++-------------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/src/views/IOC/IOCDetailsContainer.jsx b/src/views/IOC/IOCDetailsContainer.jsx index c3bcf7c2..0cbda486 100644 --- a/src/views/IOC/IOCDetailsContainer.jsx +++ b/src/views/IOC/IOCDetailsContainer.jsx @@ -1,59 +1,28 @@ -import { useEffect, useContext, useState, useMemo } from "react"; import { LinearProgress } from "@mui/material"; -import { useAPIMethod } from "@ess-ics/ce-ui-common"; import { IOCDetailsView } from "./IOCDetailsView"; import { NotFoundView } from "../../components/navigation/NotFoundView/NotFoundView"; -import { onFetchEntityError } from "../../components/common/Helper"; -import { apiContext } from "../../api/DeployApi"; +import { useGetIocQuery } from "../../store/enhancedApi"; +import { ApiAlertError } from "../../components/common/Alerts/ApiAlertError"; -export function IOCDetailsContainer({ id }) { - const [error, setError] = useState(null); - - const client = useContext(apiContext); +const IOC_POLL_INTERVAL = 5000; - const params = useMemo( - () => ({ - ioc_id: id - }), - [id] +export function IOCDetailsContainer({ id }) { + const { data: ioc, error } = useGetIocQuery( + { iocId: id }, + { pollingInterval: IOC_POLL_INTERVAL } ); - const { - value: ioc, - wrapper: getIOC, - loading, - error: fetchError, - abort: abortGetIOC - } = useAPIMethod({ - fcn: client.apis.IOCs.getIoc, - params - }); - - useEffect(() => { - if (fetchError) { - onFetchEntityError(fetchError?.message, fetchError?.status, setError); - } - }, [fetchError]); - - if (error) { - return ( - <NotFoundView - message={error?.message} - status={error?.status} - /> - ); + if (error && "status" in error && error.status === 404) { + return <NotFoundView />; } - if (!ioc && !error) { - return <LinearProgress color="primary" />; + if (error) { + return <ApiAlertError error={error} />; } return ( - <IOCDetailsView - ioc={ioc} - getIOC={getIOC} - abortGetIOC={abortGetIOC} - loading={loading} - /> + <> + {ioc ? <IOCDetailsView ioc={ioc} /> : <LinearProgress color="primary" />} + </> ); } -- GitLab