Replace native alerts

This commit is contained in:
muzam1l
2022-05-04 14:38:59 +05:30
parent 5e997044ed
commit d18c893025
7 changed files with 40 additions and 32 deletions

View File

@@ -1,17 +1,21 @@
import { ref } from 'valtio';
import { AlertState, alertState } from "../../components/AlertDialog";
export const showAlert = (title: string, opts: Partial<AlertState> = {}) => {
const { body: _body, confirmNode: _confirmNode, ...rest } = opts
export const showAlert = (title: string, opts: Omit<Partial<AlertState>, 'title' | 'isOpen'> = {}) => {
const { body: _body, confirmPrefix: _confirmPrefix, ...rest } = opts
const body = (_body && typeof _body === 'object') ? ref(_body) : _body
const confirmNode = (_confirmNode && typeof _confirmNode === 'object') ? ref(_confirmNode) : _confirmNode
const confirmPrefix = (_confirmPrefix && typeof _confirmPrefix === 'object') ? ref(_confirmPrefix) : _confirmPrefix
const nwState = {
const nwState: AlertState = {
isOpen: true,
title,
body,
confirmNode,
...rest
confirmPrefix,
cancelText: undefined,
confirmText: undefined,
onCancel: undefined,
onConfirm: undefined,
...rest,
}
Object.entries(nwState).forEach(([key, value]) => {
(alertState as any)[key] = value