2023-02-26 21:26:01 +00:00
|
|
|
import { ConfirmationAlertOptions, InputAlertProps } from "@types";
|
|
|
|
import { findByProps } from "@metro/filters";
|
|
|
|
import InputAlert from "@ui/components/InputAlert";
|
|
|
|
|
|
|
|
const Alerts = findByProps("openLazy", "close");
|
|
|
|
|
2023-02-26 22:56:36 +00:00
|
|
|
interface InternalConfirmationAlertOptions extends Omit<ConfirmationAlertOptions, "content"> {
|
2023-04-22 23:09:04 +00:00
|
|
|
content?: ConfirmationAlertOptions["content"];
|
|
|
|
body?: ConfirmationAlertOptions["content"];
|
2023-02-26 21:26:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function showConfirmationAlert(options: ConfirmationAlertOptions) {
|
|
|
|
const internalOptions = options as InternalConfirmationAlertOptions;
|
|
|
|
|
2023-04-22 23:09:04 +00:00
|
|
|
internalOptions.body = options.content;
|
2023-02-26 21:26:01 +00:00
|
|
|
delete internalOptions.content;
|
2023-04-22 23:09:04 +00:00
|
|
|
|
|
|
|
internalOptions.isDismissable ??= true;
|
|
|
|
|
2023-02-26 21:26:01 +00:00
|
|
|
return Alerts.show(internalOptions);
|
|
|
|
};
|
|
|
|
|
2023-02-26 22:56:36 +00:00
|
|
|
export const showCustomAlert = (component: React.ComponentType, props: any) => Alerts.openLazy({
|
|
|
|
importer: async () => () => React.createElement(component, props),
|
|
|
|
});
|
2023-02-26 21:26:01 +00:00
|
|
|
|
2023-04-22 23:09:04 +00:00
|
|
|
export const showInputAlert = (options: InputAlertProps) => showCustomAlert(InputAlert as React.ComponentType, options);
|