Skip to content

Commit

Permalink
[frontend] extracted duplicated code (#8265)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan1anuby committed Sep 8, 2024
1 parent 00bd589 commit 51d7e4b
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,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 @@ -129,15 +143,10 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
commitWorkbench({
variables: { file, labels: finalLabels, entityId },
onCompleted: () => {
setSubmitting(false);
resetForm();
handleCloseCreate();
onCompleted?.();
handleCompleted();
},
onError: () => {
setSubmitting(false);
resetForm();
handleCloseCreate();
handleError();
},
});
});
Expand All @@ -151,15 +160,10 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
commitWorkbench({
variables: { file, labels: finalLabels, entityId },
onCompleted: () => {
setSubmitting(false);
resetForm();
handleCloseCreate();
onCompleted?.();
handleCompleted();
},
onError: () => {
setSubmitting(false);
resetForm();
handleCloseCreate();
handleError();
},
});
}
Expand Down

0 comments on commit 51d7e4b

Please sign in to comment.