Skip to content

Commit

Permalink
[frontend] fixed workbench creation pop-up in case of error (#8265)
Browse files Browse the repository at this point in the history
Signed-off-by: stefan1anuby <[email protected]>
  • Loading branch information
stefan1anuby authored Sep 26, 2024
1 parent d507f71 commit 1aa3e4b
Showing 1 changed file with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
const classes = useStyles();
const [commitWorkbench] = useApiMutation<WorkbenchFileCreatorMutation>(
workbenchFileCreatorMutation,
undefined,
{
errorMessage: 'An error occurred while creating the workbench.',
},
);
const entityId = entity?.id;
const onSubmitCreate: FormikConfig<WorkbenchFileCreatorFormValues>['onSubmit'] = (values, { setSubmitting, resetForm }) => {
Expand All @@ -101,6 +105,20 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
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) {
Expand All @@ -125,10 +143,10 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
commitWorkbench({
variables: { file, labels: finalLabels, entityId },
onCompleted: () => {
setSubmitting(false);
resetForm();
handleCloseCreate();
onCompleted?.();
handleCompleted();
},
onError: () => {
handleError();
},
});
});
Expand All @@ -142,10 +160,10 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
commitWorkbench({
variables: { file, labels: finalLabels, entityId },
onCompleted: () => {
setSubmitting(false);
resetForm();
handleCloseCreate();
onCompleted?.();
handleCompleted();
},
onError: () => {
handleError();
},
});
}
Expand Down

0 comments on commit 1aa3e4b

Please sign in to comment.