Skip to content

Commit

Permalink
Optimize some code
Browse files Browse the repository at this point in the history
Signed-off-by: gaobinlong <gbinlong@amazon.com>
  • Loading branch information
gaobinlong committed Apr 3, 2024
1 parent accfda0 commit 5b38942
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ export const WorkspaceCreator = () => {
let result;
try {
result = await workspaceClient.create(data);
if (result?.success) {
notifications?.toasts.addSuccess({
title: i18n.translate('workspace.create.success', {
defaultMessage: 'Create workspace successfully',
}),
});
if (application && http) {
const newWorkspaceId = result.result.id;
// Redirect page after one second, leave one second time to show create successful toast.
window.setTimeout(() => {
window.location.href = formatUrlWithWorkspaceId(
application.getUrlForApp(WORKSPACE_OVERVIEW_APP_ID, {
absolute: true,
}),
newWorkspaceId,
http.basePath
);
}, 1000);
}
return;
} else {
throw new Error(result?.error ? result?.error : 'create workspace failed');
}
} catch (error) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.create.failed', {
Expand All @@ -31,33 +54,6 @@ export const WorkspaceCreator = () => {
});
return;
}
if (result?.success) {
notifications?.toasts.addSuccess({
title: i18n.translate('workspace.create.success', {
defaultMessage: 'Create workspace successfully',
}),
});
if (application && http) {
const newWorkspaceId = result.result.id;
// Redirect page after one second, leave one second time to show create successful toast.
window.setTimeout(() => {
window.location.href = formatUrlWithWorkspaceId(
application.getUrlForApp(WORKSPACE_OVERVIEW_APP_ID, {
absolute: true,
}),
newWorkspaceId,
http.basePath
);
}, 1000);
}
return;
}
notifications?.toasts.addDanger({
title: i18n.translate('workspace.create.failed', {
defaultMessage: 'Failed to create workspace',
}),
text: result?.error,
});
},
[notifications?.toasts, http, application, workspaceClient]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ export const WorkspaceUpdater = () => {
try {
const { ...attributes } = data;
result = await workspaceClient.update(currentWorkspace.id, attributes);
if (result?.success) {
notifications?.toasts.addSuccess({
title: i18n.translate('workspace.update.success', {
defaultMessage: 'Update workspace successfully',
}),
});
if (application && http) {
// Redirect page after one second, leave one second time to show update successful toast.
window.setTimeout(() => {
window.location.href = formatUrlWithWorkspaceId(
application.getUrlForApp(WORKSPACE_OVERVIEW_APP_ID, {
absolute: true,
}),
currentWorkspace.id,
http.basePath
);
}, 1000);
}
return;
} else {
throw new Error(result?.error ? result?.error : 'update workspace failed');
}
} catch (error) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.update.failed', {
Expand All @@ -60,32 +82,6 @@ export const WorkspaceUpdater = () => {
});
return;
}
if (result?.success) {
notifications?.toasts.addSuccess({
title: i18n.translate('workspace.update.success', {
defaultMessage: 'Update workspace successfully',
}),
});
if (application && http) {
// Redirect page after one second, leave one second time to show update successful toast.
window.setTimeout(() => {
window.location.href = formatUrlWithWorkspaceId(
application.getUrlForApp(WORKSPACE_OVERVIEW_APP_ID, {
absolute: true,
}),
currentWorkspace.id,
http.basePath
);
}, 1000);
}
return;
}
notifications?.toasts.addDanger({
title: i18n.translate('workspace.update.failed', {
defaultMessage: 'Failed to update workspace',
}),
text: result?.error,
});
},
[notifications?.toasts, currentWorkspace, http, application, workspaceClient]
);
Expand Down

0 comments on commit 5b38942

Please sign in to comment.