alert dialog component

This commit is contained in:
muzam1l
2022-05-02 21:05:18 +05:30
parent e88720327e
commit 5e997044ed
7 changed files with 124 additions and 46 deletions

View File

@@ -0,0 +1,19 @@
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
const body = (_body && typeof _body === 'object') ? ref(_body) : _body
const confirmNode = (_confirmNode && typeof _confirmNode === 'object') ? ref(_confirmNode) : _confirmNode
const nwState = {
isOpen: true,
title,
body,
confirmNode,
...rest
}
Object.entries(nwState).forEach(([key, value]) => {
(alertState as any)[key] = value
})
}