mango-ui-v3/utils/notifications.tsx

36 lines
855 B
TypeScript
Raw Normal View History

2021-04-11 21:17:23 -07:00
import useMangoStore from '../stores/useMangoStore'
2021-12-09 09:23:19 -08:00
export type Notification = {
type: 'success' | 'info' | 'error' | 'confirm'
title: string
description?: null | string
txid?: string
show: boolean
id: number
}
2021-04-11 21:17:23 -07:00
export function notify(newNotification: {
2021-12-09 09:23:19 -08:00
type?: 'success' | 'info' | 'error' | 'confirm'
title: string
2021-04-11 21:17:23 -07:00
description?: string
txid?: string
}) {
const setMangoStore = useMangoStore.getState().set
const notifications = useMangoStore.getState().notifications
const lastId = useMangoStore.getState().notificationIdCounter
const newId = lastId + 1
2021-04-11 21:17:23 -07:00
2021-12-09 09:23:19 -08:00
const newNotif: Notification = {
id: newId,
type: 'success',
show: true,
description: null,
...newNotification,
}
2021-04-11 21:17:23 -07:00
setMangoStore((state) => {
state.notificationIdCounter = newId
2021-12-09 09:23:19 -08:00
state.notifications = [...notifications, newNotif]
2021-04-11 21:17:23 -07:00
})
2021-04-02 11:26:21 -07:00
}