Skip to content
Snippets Groups Projects
Commit 0ae04924 authored by Imre Toth's avatar Imre Toth
Browse files

Merge branch 'CE-2104_Convert_useUpdateIoc' into 'develop'

CE-2104: Convert useUpdateIoc hook

See merge request !381
parents 077b0399 b509dc9b
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!381CE-2104: Convert useUpdateIoc hook
Pipeline #161887 passed
...@@ -283,20 +283,6 @@ export function unpackGitProject(project) { ...@@ -283,20 +283,6 @@ export function unpackGitProject(project) {
return { ...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) { export function unpackUpdateActiveDeploymentHost(ioc) {
return { ...ioc }; return { ...ioc };
} }
...@@ -13,7 +13,6 @@ import { ...@@ -13,7 +13,6 @@ import {
Autocomplete, Autocomplete,
Alert Alert
} from "@mui/material"; } from "@mui/material";
import { useUpdateIoc } from "../../../api/SwaggerApi";
import { useTypingTimer } from "../../common/SearchBoxFilter/TypingTimer"; import { useTypingTimer } from "../../common/SearchBoxFilter/TypingTimer";
import AccessControl from "../../auth/AccessControl"; import AccessControl from "../../auth/AccessControl";
import { apiContext } from "../../../api/DeployApi"; import { apiContext } from "../../../api/DeployApi";
...@@ -37,10 +36,6 @@ export default function IOCDetailAdmin({ ...@@ -37,10 +36,6 @@ export default function IOCDetailAdmin({
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [error, setError] = useState(); const [error, setError] = useState();
function onError(message) {
setError(message);
}
const client = useContext(apiContext); const client = useContext(apiContext);
const { const {
...@@ -63,6 +58,21 @@ export default function IOCDetailAdmin({ ...@@ -63,6 +58,21 @@ export default function IOCDetailAdmin({
call: false 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 requiredDataMissing = useCallback(() => !gitId || !name, [gitId, name]);
const noModification = useCallback( const noModification = useCallback(
...@@ -74,8 +84,6 @@ export default function IOCDetailAdmin({ ...@@ -74,8 +84,6 @@ export default function IOCDetailAdmin({
[gitId, name, ioc] [gitId, name, ioc]
); );
const [uioc, actionUpdateIoc] = useUpdateIoc(ioc.id, onError);
useEffect(() => { useEffect(() => {
getAllowedGitProjects(); getAllowedGitProjects();
}, [getAllowedGitProjects]); }, [getAllowedGitProjects]);
...@@ -95,11 +103,16 @@ export default function IOCDetailAdmin({ ...@@ -95,11 +103,16 @@ export default function IOCDetailAdmin({
}, [setOpen]); }, [setOpen]);
const onConfirm = useCallback(() => { const onConfirm = useCallback(() => {
actionUpdateIoc({ actionUpdateIoc(
gitProjectId: gitId, { ioc_id: ioc?.id },
namingUuid: name ? name.uuid : null {
}); requestBody: {
}, [actionUpdateIoc, gitId, name]); gitProjectId: gitId,
namingUuid: name ? name.uuid : null
}
}
);
}, [actionUpdateIoc, ioc, name, gitId]);
useEffect(() => { useEffect(() => {
if (uioc) { if (uioc) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment