diff --git a/src/views/IOC/IOCDetailsContainer.jsx b/src/views/IOC/IOCDetailsContainer.jsx index c3bcf7c23332f5b97a27d2768b0fbf86ab960add..0cbda486d8b30981bbfd5008656812272b672fde 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" />} + </> ); }