From f1a91512cc1c712cd755e8b5fadb0164507c7293 Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Tue, 8 Aug 2023 13:34:03 -0400 Subject: [PATCH] :bug: Cleanup wizard state on cancel / submit Signed-off-by: ibolton336 --- .../analysis-wizard/analysis-wizard.tsx | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx index 696a2ab446..e57226f6df 100644 --- a/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx +++ b/client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx @@ -102,12 +102,6 @@ export const AnalysisWizard: React.FC = ({ const [stepIdReached, setStepIdReached] = React.useState(1); const isMutating = useIsMutating(); - React.useEffect(() => { - if (!currentTaskgroup) { - createTaskgroup(defaultTaskgroup); - } - }, []); - const onCreateTaskgroupSuccess = (data: Taskgroup) => { setCurrentTaskgroup(data); }; @@ -287,12 +281,22 @@ export const AnalysisWizard: React.FC = ({ const isModeValid = applications.every((app) => isModeSupported(app, mode)); + const handleCancel = () => { + if (currentTaskgroup && currentTaskgroup.id) { + deleteTaskgroup(currentTaskgroup.id); + } + setCurrentTaskgroup(null); + reset(); + onClose(); + }; + const onSubmit = (fieldValues: AnalysisWizardFormValues) => { if (currentTaskgroup) { const taskgroup = setupTaskgroup(currentTaskgroup, fieldValues); - submitTaskgroup(taskgroup); } + setCurrentTaskgroup(null); + reset(); onClose(); }; @@ -301,13 +305,11 @@ export const AnalysisWizard: React.FC = ({ { prevId, prevName } ) => { if (id && stepIdReached < (id as number)) setStepIdReached(id as number); - }; - - const handleClose = () => { - reset(); - if (currentTaskgroup && currentTaskgroup.id) - deleteTaskgroup(currentTaskgroup.id); - onClose(); + if (id === StepId.SetTargets) { + if (!currentTaskgroup) { + createTaskgroup(defaultTaskgroup); + } + } }; const analyzableApplications = useAnalyzableApplications(applications, mode); @@ -410,7 +412,7 @@ export const AnalysisWizard: React.FC = ({ onBack={onMove} onSave={handleSubmit(onSubmit)} onClose={() => { - handleClose(); + handleCancel(); }} />