mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Notify user of error if confirmation dialog rejects promise (#3179)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
02320a5d2c
commit
2893ad956d
@ -28,6 +28,7 @@ import { cssNames, noop, prevDefault } from "../../utils";
|
|||||||
import { Button, ButtonProps } from "../button";
|
import { Button, ButtonProps } from "../button";
|
||||||
import { Dialog, DialogProps } from "../dialog";
|
import { Dialog, DialogProps } from "../dialog";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
|
import { Notifications } from "../notifications";
|
||||||
|
|
||||||
export interface ConfirmDialogProps extends Partial<DialogProps> {
|
export interface ConfirmDialogProps extends Partial<DialogProps> {
|
||||||
}
|
}
|
||||||
@ -90,7 +91,14 @@ export class ConfirmDialog extends React.Component<ConfirmDialogProps> {
|
|||||||
ok = async () => {
|
ok = async () => {
|
||||||
try {
|
try {
|
||||||
this.isSaving = true;
|
this.isSaving = true;
|
||||||
await Promise.resolve(this.params.ok()).catch(noop);
|
await (async () => this.params.ok())();
|
||||||
|
} catch (error) {
|
||||||
|
Notifications.error(
|
||||||
|
<>
|
||||||
|
<p>Confirmation action failed:</p>
|
||||||
|
<p>{error?.message ?? error?.toString?.() ?? "Unknown error"}</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
this.isSaving = false;
|
this.isSaving = false;
|
||||||
dialogState.isOpen = false;
|
dialogState.isOpen = false;
|
||||||
@ -103,7 +111,14 @@ export class ConfirmDialog extends React.Component<ConfirmDialogProps> {
|
|||||||
|
|
||||||
close = async () => {
|
close = async () => {
|
||||||
try {
|
try {
|
||||||
await Promise.resolve(this.params.cancel()).catch(noop);
|
await Promise.resolve(this.params.cancel());
|
||||||
|
} catch (error) {
|
||||||
|
Notifications.error(
|
||||||
|
<>
|
||||||
|
<p>Cancelling action failed:</p>
|
||||||
|
<p>{error?.message ?? error?.toString?.() ?? "Unknown error"}</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
this.isSaving = false;
|
this.isSaving = false;
|
||||||
dialogState.isOpen = false;
|
dialogState.isOpen = false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user