From 1aa3e4b79efcf299a055fa3c590b80d4122f03bb Mon Sep 17 00:00:00 2001 From: Popa Stefan-Eduard <38299145+stefan1anuby@users.noreply.github.com> Date: Thu, 26 Sep 2024 12:20:44 +0300 Subject: [PATCH] [frontend] fixed workbench creation pop-up in case of error (#8265) Signed-off-by: stefan1anuby --- .../files/workbench/WorkbenchFileCreator.tsx | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileCreator.tsx b/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileCreator.tsx index cde40710d21c..fe10ad606ca6 100644 --- a/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileCreator.tsx +++ b/opencti-platform/opencti-front/src/private/components/common/files/workbench/WorkbenchFileCreator.tsx @@ -93,6 +93,10 @@ const WorkbenchFileCreator: FunctionComponent = ({ const classes = useStyles(); const [commitWorkbench] = useApiMutation( workbenchFileCreatorMutation, + undefined, + { + errorMessage: 'An error occurred while creating the workbench.', + }, ); const entityId = entity?.id; const onSubmitCreate: FormikConfig['onSubmit'] = (values, { setSubmitting, resetForm }) => { @@ -101,6 +105,20 @@ const WorkbenchFileCreator: FunctionComponent = ({ if (!name.endsWith('.json')) { name += '.json'; } + + const handleCompleted = () => { + setSubmitting(false); + resetForm(); + handleCloseCreate(); + onCompleted?.(); + }; + + const handleError = () => { + setSubmitting(false); + resetForm(); + handleCloseCreate(); + }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const objects: any = []; if (entityId) { @@ -125,10 +143,10 @@ const WorkbenchFileCreator: FunctionComponent = ({ commitWorkbench({ variables: { file, labels: finalLabels, entityId }, onCompleted: () => { - setSubmitting(false); - resetForm(); - handleCloseCreate(); - onCompleted?.(); + handleCompleted(); + }, + onError: () => { + handleError(); }, }); }); @@ -142,10 +160,10 @@ const WorkbenchFileCreator: FunctionComponent = ({ commitWorkbench({ variables: { file, labels: finalLabels, entityId }, onCompleted: () => { - setSubmitting(false); - resetForm(); - handleCloseCreate(); - onCompleted?.(); + handleCompleted(); + }, + onError: () => { + handleError(); }, }); }