diff --git a/cmd/ui/src/ducks/global/types.ts b/cmd/ui/src/ducks/global/types.ts index 5af656331..d2c50089d 100644 --- a/cmd/ui/src/ducks/global/types.ts +++ b/cmd/ui/src/ducks/global/types.ts @@ -13,7 +13,8 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -import { OptionsObject, SnackbarKey } from 'notistack'; +import { SnackbarKey } from 'notistack'; +import { Notification } from 'bh-shared-ui'; const GLOBAL_ADD_SNACKBAR = 'app/global/ADDSNACKBAR'; const GLOBAL_CLOSE_SNACKBAR = 'app/global/CLOSESNACKBAR'; @@ -44,13 +45,6 @@ export interface GlobalViewState { darkMode: boolean; } -export interface Notification { - message: string; - key: string; - dismissed: boolean; - options: OptionsObject; -} - export interface GlobalOptionsState { domain: Domain | null; assetGroups: any[]; @@ -74,7 +68,7 @@ interface RemoveSnackbarAction { interface CloseSnackbarAction { type: typeof GLOBAL_CLOSE_SNACKBAR; - key: string; + key: SnackbarKey; } export interface SetDarkModeAction { diff --git a/packages/javascript/bh-shared-ui/src/providers/NotificationProvider/actions.ts b/packages/javascript/bh-shared-ui/src/providers/NotificationProvider/actions.ts index 94d59d9ea..76a5047bb 100644 --- a/packages/javascript/bh-shared-ui/src/providers/NotificationProvider/actions.ts +++ b/packages/javascript/bh-shared-ui/src/providers/NotificationProvider/actions.ts @@ -14,6 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 +import { OptionsObject } from 'notistack'; import { Notification } from './model'; export enum ActionType { @@ -27,7 +28,7 @@ export type Dismiss = { type: ActionType.Dismiss; key?: string }; export type Remove = { type: ActionType.Remove; key?: string }; export type NotificationAction = Add | Dismiss | Remove; -export const addNotification = (notification: string, key?: string, options: any = {}): Add => { +export const addNotification = (notification: string, key?: string, options: OptionsObject = {}): Add => { return { type: ActionType.Add, value: { diff --git a/packages/javascript/bh-shared-ui/src/providers/NotificationProvider/hooks.ts b/packages/javascript/bh-shared-ui/src/providers/NotificationProvider/hooks.ts index e820c0ac1..8d4a41961 100644 --- a/packages/javascript/bh-shared-ui/src/providers/NotificationProvider/hooks.ts +++ b/packages/javascript/bh-shared-ui/src/providers/NotificationProvider/hooks.ts @@ -15,6 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 import { useContext } from 'react'; +import { OptionsObject } from 'notistack'; import { addNotification, dismissNotification, removeNotification } from './actions'; import { NotificationsContext, NotificationsDispatchContext } from './NotificationsProvider'; @@ -24,9 +25,9 @@ export const useNotifications = () => { return { notifications, - addNotification: (notification: string, key?: string, options: any = {}) => - dispatch!(addNotification(notification, key, options)), - dismissNotification: (key?: string) => dispatch!(dismissNotification(key)), - removeNotification: (key?: string) => dispatch!(removeNotification(key)), + addNotification: (notification: string, key?: string, options: OptionsObject = {}) => + dispatch && dispatch(addNotification(notification, key, options)), + dismissNotification: (key?: string) => dispatch && dispatch(dismissNotification(key)), + removeNotification: (key?: string) => dispatch && dispatch(removeNotification(key)), }; };