Skip to content

Commit

Permalink
Improvement: Add a resolve value for promise function to confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaa77770 committed Dec 18, 2020
1 parent 08345f2 commit 11bd20f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/app/containers/Settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ class Settings extends PureComponent {
// Workspace
config: {
restoreDefaults: async () => {
await confirm({
const confirmed = await confirm({
title: i18n._('Reset All User Settings'),
body: i18n._('Are you sure you want to restore the default settings?')
});
if (!confirmed) {
return;
}
await this.props.resetAllUserSettings();
window.location.reload();
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/lib/confirm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ export default (options) => new Promise((resolve) => {
const props = {
...options,
onConfirm: () => {
resolve();
resolve(true);
},
onCancel: () => {
resolve(false);
},
container: container
};
Expand Down
10 changes: 8 additions & 2 deletions src/app/views/PrintingManager/PrintingManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,12 @@ class PrintingManager extends PureComponent {
onRemoveManagerDefinition: async (managerDisplayType) => {
if (managerDisplayType === PRINTING_MANAGER_TYPE_MATERIAL) {
const definition = this.state.materialDefinitionForManager;
await confirm({
const confirmed = await confirm({
body: `Are you sure to remove profile "${definition.name}"?`
});
if (!confirmed) {
return;
}

await this.props.removeMaterialDefinition(definition);

Expand All @@ -312,9 +315,12 @@ class PrintingManager extends PureComponent {
} else if (managerDisplayType === PRINTING_MANAGER_TYPE_QUALITY) {
const definition = this.state.qualityDefinitionForManager;

await confirm({
const confirmed = await confirm({
body: `Are you sure to remove profile "${definition.name}"?`
});
if (!confirmed) {
return;
}

await this.props.removeQualityDefinition(definition);

Expand Down

0 comments on commit 11bd20f

Please sign in to comment.