Skip to content

Commit

Permalink
chore: more notification typing
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 committed Oct 16, 2024
1 parent e8bf0e2 commit e700e51
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
12 changes: 3 additions & 9 deletions cmd/ui/src/ducks/global/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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[];
Expand All @@ -74,7 +68,7 @@ interface RemoveSnackbarAction {

interface CloseSnackbarAction {
type: typeof GLOBAL_CLOSE_SNACKBAR;
key: string;
key: SnackbarKey;
}

export interface SetDarkModeAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//
// SPDX-License-Identifier: Apache-2.0

import { OptionsObject } from 'notistack';
import { Notification } from './model';

export enum ActionType {
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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)),
};
};

0 comments on commit e700e51

Please sign in to comment.