diff --git a/src/api/SwaggerApi.js b/src/api/SwaggerApi.js index f7a60437aaab7cb428356e1d2b84a4de9d0f852f..ff25b530964b5f4bf1550c3edb39edeb72855a06 100644 --- a/src/api/SwaggerApi.js +++ b/src/api/SwaggerApi.js @@ -283,20 +283,6 @@ export function unpackGitProject(project) { return { ...project }; } -export function useUpdateIoc(id, onError) { - const api = useContext(apiContext); - const method = useCallAndUnpack( - (body) => api.apis.IOCs.updateIoc({ ioc_id: id }, { requestBody: body }), - unpackUpdateIoc - ); - return useAsync({ fcn: method, call: false, onError: onError }); -} - -export function unpackUpdateIoc(updateIoc) { - const d = { ...updateIoc }; - return d; -} - export function unpackUpdateActiveDeploymentHost(ioc) { return { ...ioc }; } diff --git a/src/components/IOC/IOCDetailAdmin/IOCDetailAdmin.js b/src/components/IOC/IOCDetailAdmin/IOCDetailAdmin.js index fd1310fa8af7421363daae9031d29eef82816190..9d07405d3ed1183fc2e62b0be2bc2aef30a1fd4a 100644 --- a/src/components/IOC/IOCDetailAdmin/IOCDetailAdmin.js +++ b/src/components/IOC/IOCDetailAdmin/IOCDetailAdmin.js @@ -13,7 +13,6 @@ import { Autocomplete, Alert } from "@mui/material"; -import { useUpdateIoc } from "../../../api/SwaggerApi"; import { useTypingTimer } from "../../common/SearchBoxFilter/TypingTimer"; import AccessControl from "../../auth/AccessControl"; import { apiContext } from "../../../api/DeployApi"; @@ -37,10 +36,6 @@ export default function IOCDetailAdmin({ const [open, setOpen] = useState(false); const [error, setError] = useState(); - function onError(message) { - setError(message); - } - const client = useContext(apiContext); const { @@ -63,6 +58,21 @@ export default function IOCDetailAdmin({ call: false }); + const { + value: uioc, + wrapper: actionUpdateIoc, + error: updateError + } = useAPIMethod({ + fcn: client.apis.IOCs.updateIoc, + call: false + }); + + useEffect(() => { + if (updateError) { + setError(updateError?.message); + } + }, [updateError, setError]); + const requiredDataMissing = useCallback(() => !gitId || !name, [gitId, name]); const noModification = useCallback( @@ -74,8 +84,6 @@ export default function IOCDetailAdmin({ [gitId, name, ioc] ); - const [uioc, actionUpdateIoc] = useUpdateIoc(ioc.id, onError); - useEffect(() => { getAllowedGitProjects(); }, [getAllowedGitProjects]); @@ -95,11 +103,16 @@ export default function IOCDetailAdmin({ }, [setOpen]); const onConfirm = useCallback(() => { - actionUpdateIoc({ - gitProjectId: gitId, - namingUuid: name ? name.uuid : null - }); - }, [actionUpdateIoc, gitId, name]); + actionUpdateIoc( + { ioc_id: ioc?.id }, + { + requestBody: { + gitProjectId: gitId, + namingUuid: name ? name.uuid : null + } + } + ); + }, [actionUpdateIoc, ioc, name, gitId]); useEffect(() => { if (uioc) {