Introduce Dialog.alert

Summary: Introduce `Dialog.alert` to show users a FYI message, and be able to wait for it to be handled, as utility around several `Modal` utilities.

Reviewed By: jknoxville

Differential Revision: D29875484

fbshipit-source-id: 5d2ea83e486631ac18a81800b467f97dfaac6d34
This commit is contained in:
Michel Weststrate
2021-08-10 13:23:05 -07:00
committed by Facebook GitHub Bot
parent 4b892e7373
commit 8d7caa9dd4
3 changed files with 32 additions and 4 deletions

View File

@@ -77,14 +77,33 @@ export const Dialog = {
confirm({
message,
onConfirm,
...rest
}: {
message: React.ReactNode;
onConfirm?: () => Promise<true>;
} & BaseDialogOptions): DialogResult<true> {
return Dialog.show<true>({
...rest,
children: message,
onConfirm: async () => true,
onConfirm: onConfirm ?? (async () => true),
});
},
alert({
message,
type,
...rest
}: {
message: React.ReactNode;
type: 'info' | 'error' | 'warning' | 'success';
} & BaseDialogOptions): Promise<void> {
return new Promise((resolve) => {
Modal[type]({
afterClose: resolve,
content: message,
...rest,
});
});
},