From 82d7926c830c3e89e14055df5a18bac2a66f3d64 Mon Sep 17 00:00:00 2001 From: Max Frederiksen <maxfrederiksen@Maxs-MacBook-Air.local> Date: Fri, 30 Aug 2024 15:22:39 +0200 Subject: [PATCH] remove stopJob extra hook and rename variables --- src/components/IOC/IOCService/IOCService.js | 65 +++++++++------------ 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/src/components/IOC/IOCService/IOCService.js b/src/components/IOC/IOCService/IOCService.js index 34698fb0..8d0425e4 100644 --- a/src/components/IOC/IOCService/IOCService.js +++ b/src/components/IOC/IOCService/IOCService.js @@ -13,6 +13,7 @@ import AccessControl from "../../auth/AccessControl"; import { useNavigate } from "react-router-dom"; import { useStartOperationMutation } from "../../../store/deployApi"; import { getErrorMessage } from "../../common/Alerts/ApiAlertError"; +import useCustomSnackbar from "../../common/snackbar"; export function IOCService({ ioc, @@ -22,37 +23,35 @@ export function IOCService({ setButtonDisabled, jobLazyParams }) { - const [error, setError] = useState(); const navigate = useNavigate(); + const showWarning = useCustomSnackbar(); + const [error, setError] = useState(); const [inProgress, setInProgress] = useState(false); const [startModalOpen, setStartModalOpen] = useState(false); const [stopModalOpen, setStopModalOpen] = useState(false); const [command, setCommand] = useState(null); - const [startIOC, { error: startJobError, data: startJob }] = - useStartOperationMutation(); - const [stopIOC, { error: stopJobError, data: stopJob }] = + const [startOperation, { error: jobError, data: jobData }] = useStartOperationMutation(); useEffect(() => { - setError(startJobError); - }, [startJobError]); - - useEffect(() => { - setError(stopJobError); - }, [stopJobError]); + setError(jobError); + }, [jobError]); useEffect(() => { - if (startJob && (!command || command.id !== startJob.id)) { - navigate(`/jobs/${startJob.id}`); - setCommand(startJob); - } else if (stopJob && (!command || command.id !== stopJob.id)) { - navigate(`/jobs/${stopJob.id}`); - setCommand(stopJob); + if (jobData && (!command || command.id !== jobData.id)) { + navigate(`/jobs/${jobData.id}`); + setCommand(jobData); } else if (currentCommand) { setCommand(currentCommand); } - }, [startJob, stopJob, command, currentCommand, navigate]); + }, [jobData, command, currentCommand, navigate]); + + useEffect(() => { + if (jobError) { + showWarning(getErrorMessage(jobError)); + } + }, [jobError]); const resetUI = useCallback(() => { setCommand(null); @@ -64,16 +63,12 @@ export function IOCService({ setInProgress(true); setButtonDisabled(true); - startIOC( - { - ioc_id: ioc.id - }, - { - requestBody: { - type: "START" - } + startOperation({ + iocId: ioc.id, + createJobRequest: { + type: "START" } - ); + }); let requestParams = initRequestParams(jobLazyParams); @@ -85,7 +80,7 @@ export function IOCService({ jobLazyParams, resetUI, setButtonDisabled, - startIOC + startOperation ]); const stop = useCallback(() => { @@ -93,16 +88,12 @@ export function IOCService({ setInProgress(true); setButtonDisabled(true); - stopIOC( - { - ioc_id: ioc.id - }, - { - requestBody: { - type: "STOP" - } + startOperation({ + iocId: ioc.id, + createJobRequest: { + type: "STOP" } - ); + }); let requestParams = initRequestParams(jobLazyParams); @@ -114,7 +105,7 @@ export function IOCService({ jobLazyParams, resetUI, setButtonDisabled, - stopIOC + startOperation ]); const onStartModalClose = useCallback(() => { -- GitLab