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

CE-2103: Convert useDeteleIoc hook

parent 930b8cb2
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!378CE-2103: Convert useDeteleIoc hook
Pipeline #161489 passed
......@@ -341,22 +341,6 @@ export function useAllowedGitProjects() {
return useAsync({ fcn: method, call: false, init: [] });
}
export function useDeleteIOC(id, onError) {
const api = useContext(apiContext);
const method = useCallAndUnpack(
api.apis.IOCs.deleteIoc,
unpackDeleteIocResponse
);
const boundMethod = useCallback(method.bind(null, { ioc_id: id }), [id]);
return useAsync({ fcn: boundMethod, call: false, onError: onError });
}
export function unpackDeleteIocResponse(_, status) {
if (status === 204) {
return "Successful delete";
}
}
export function useUpdateIoc(id, onError) {
const api = useContext(apiContext);
const method = useCallAndUnpack(
......
import React, { useState, useEffect, useCallback } from "react";
import React, {
useState,
useEffect,
useCallback,
useContext,
useMemo
} from "react";
import { useNavigate } from "react-router-dom";
import { Button, Typography, Grid, Tooltip } from "@mui/material";
import { useDeleteIOC } from "../../../api/SwaggerApi";
import { SimpleAccordion, ConfirmationDialog } from "@ess-ics/ce-ui-common";
import Alert from "@mui/material/Alert";
import AccessControl from "../../auth/AccessControl";
import { apiContext } from "../../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
export default function IOCDelete({ ioc, buttonDisabled }) {
const navigate = useNavigate();
function onError(message) {
setError(message);
}
// for the dialog
const [error, setError] = useState();
const [open, setOpen] = useState(false);
const [response, deleteIOC] = useDeleteIOC(ioc.id, onError);
const client = useContext(apiContext);
const params = useMemo(
() => ({
ioc_id: ioc?.id
}),
[ioc]
);
const {
wrapper: deleteIOC,
dataReady: dataready,
error: errorResponse
} = useAPIMethod({
fcn: client.apis.IOCs.deleteIoc,
call: false,
params
});
useEffect(() => {
if (errorResponse) {
setError(errorResponse?.message);
}
}, [errorResponse, setError]);
useEffect(() => {
if (response && !error) {
if (dataready && !error) {
navigate(-1);
}
}, [response, navigate, error]);
}, [dataready, navigate, error]);
let disabledButtonTitle = "";
......
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