From 51d7e4b66d3d406b72bb761a476ed8e099cc6aa2 Mon Sep 17 00:00:00 2001 From: stefan1anuby Date: Sun, 8 Sep 2024 20:14:37 +0300 Subject: [PATCH] [frontend] extracted duplicated code (#8265) --- .../files/workbench/WorkbenchFileCreator.tsx | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 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 3368b63035a79..fe10ad606ca6e 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 @@ -105,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) { @@ -129,15 +143,10 @@ const WorkbenchFileCreator: FunctionComponent = ({ commitWorkbench({ variables: { file, labels: finalLabels, entityId }, onCompleted: () => { - setSubmitting(false); - resetForm(); - handleCloseCreate(); - onCompleted?.(); + handleCompleted(); }, onError: () => { - setSubmitting(false); - resetForm(); - handleCloseCreate(); + handleError(); }, }); }); @@ -151,15 +160,10 @@ const WorkbenchFileCreator: FunctionComponent = ({ commitWorkbench({ variables: { file, labels: finalLabels, entityId }, onCompleted: () => { - setSubmitting(false); - resetForm(); - handleCloseCreate(); - onCompleted?.(); + handleCompleted(); }, onError: () => { - setSubmitting(false); - resetForm(); - handleCloseCreate(); + handleError(); }, }); }