Replace native alerts
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user