Skip to content

Commit

Permalink
feat(notifications): reenable notifications (#1135)
Browse files Browse the repository at this point in the history
* feat(notifications): reenable notifications

* feat(notifications): add notifications for export & exportHtml actions

* fix(notifications): remove duplicate case
  • Loading branch information
JPSchellenberg committed Jan 7, 2021
1 parent 7cb1552 commit 1e95e3c
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 56 deletions.
11 changes: 10 additions & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@lumieducation/h5p-react": "0.1.1",
"@lumieducation/h5p-server": "6.2.0",
"@material-ui/core": "4.11.2",
"@material-ui/icons": "4.11.2",
"@sentry/browser": "5.29.2",
Expand All @@ -13,9 +15,8 @@
"@types/node": "12.19.12",
"@types/react": "17.0.0",
"@types/react-dom": "17.0.0",
"@lumieducation/h5p-server": "6.2.0",
"@lumieducation/h5p-react": "0.1.1",
"lodash": "4.17.20",
"notistack": "1.0.3",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-redux": "7.2.2",
Expand Down
14 changes: 10 additions & 4 deletions client/src/boot/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import Logger from '../helpers/Logger';
import CssBaseline from '@material-ui/core/CssBaseline';
import { ThemeProvider } from '@material-ui/styles';

// import { hot } from 'react-hot-loader/root';

// import { ConnectedRouter } from 'connected-react-router';
import { SnackbarProvider } from 'notistack';

import React from 'react';
import ReactDOM from 'react-dom';
Expand All @@ -34,7 +32,15 @@ function boot() {
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<App />
<SnackbarProvider
anchorOrigin={{
vertical: 'bottom',
horizontal: 'center'
}}
maxSnack={3}
>
<App />
</SnackbarProvider>
</ThemeProvider>
{/* </ConnectedRouter> */}
</Provider>,
Expand Down
87 changes: 84 additions & 3 deletions client/src/state/Notifications/NotificationsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,100 @@ import {
CLOSE_SNACKBAR,
ENQUEUE_SNACKBAR,
INotificationsState,
NotificationActionTypes,
REMOVE_SNACKBAR
REMOVE_SNACKBAR,
INotifyAction,
ICloseSnackbar,
IRemoveSnackbar
} from './NotificationsTypes';

import {
H5P_EXPORT_SUCCESS,
H5P_EXPORT_ERROR,
H5PEDITOR_EXPORTHTML_SUCCESS,
H5PEDITOR_EXPORTHTML_ERROR,
IH5PExportSuccessAction,
IH5PExportErrorAction,
IH5PEditorExportHtmlErrorAction,
IH5PEditorExportHtmlSuccessAction
} from '../H5PEditor/H5PEditorTypes';
import shortid from 'shortid';

export const initialState: INotificationsState = {
notifications: []
};

export default function notificationsReducer(
state: INotificationsState = initialState,
action: NotificationActionTypes
action:
| INotifyAction
| ICloseSnackbar
| IRemoveSnackbar
| IH5PExportSuccessAction
| IH5PExportErrorAction
| IH5PEditorExportHtmlErrorAction
| IH5PEditorExportHtmlSuccessAction
): INotificationsState {
switch (action.type) {
case H5P_EXPORT_SUCCESS:
return {
...state,
notifications: [
...state.notifications,
{
key: shortid(),
message: 'notification.export.success',
options: {
variant: 'success'
}
}
]
};

case H5P_EXPORT_ERROR:
return {
...state,
notifications: [
...state.notifications,
{
key: shortid(),
message: 'notification.export.error',
options: {
variant: 'error'
}
}
]
};

case H5PEDITOR_EXPORTHTML_SUCCESS:
return {
...state,
notifications: [
...state.notifications,
{
key: shortid(),
message: 'notification.exporthtml.success',
options: {
variant: 'success'
}
}
]
};

case H5PEDITOR_EXPORTHTML_ERROR:
return {
...state,
notifications: [
...state.notifications,
{
key: shortid(),
message: 'notification.exporthtml.error',
options: {
variant: 'error'
}
}
]
};

case ENQUEUE_SNACKBAR:
return {
...state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import {
REMOVE_SNACKBAR
} from '../NotificationsTypes';

import {
H5P_EXPORT_SUCCESS,
H5P_EXPORT_ERROR,
H5PEDITOR_EXPORTHTML_SUCCESS,
H5PEDITOR_EXPORTHTML_ERROR
} from '../../H5PEditor/H5PEditorTypes';

describe('initialState', () => {
it('returns the initial state', (done) => {
const state = reducer(undefined, { type: 'init' } as any);
Expand Down Expand Up @@ -90,3 +97,69 @@ describe('REMOVE_SNACKBAR', () => {
done();
});
});

describe('Notifications', () => {
it('shows a success notification on H5P_EXPORT_SUCCESS', (done) => {
const state = reducer(
{
notifications: []
},
{
payload: {} as any,
type: H5P_EXPORT_SUCCESS
}
);

expect(state.notifications.length).toBe(1);
expect(state.notifications[0].options.variant).toBe('success');
done();
});

it('shows a error notification on H5P_EXPORT_ERROR', (done) => {
const state = reducer(
{
notifications: []
},
{
payload: {} as any,
type: H5P_EXPORT_ERROR
}
);

expect(state.notifications.length).toBe(1);
expect(state.notifications[0].options.variant).toBe('error');
done();
});

it('shows a success notification on H5PEDITOR_EXPORTHTML_SUCCESS', (done) => {
const state = reducer(
{
notifications: []
},
{
payload: {} as any,
type: H5PEDITOR_EXPORTHTML_SUCCESS
}
);

expect(state.notifications.length).toBe(1);
expect(state.notifications[0].options.variant).toBe('success');
done();
});

it('shows a error notification on H5PEDITOR_EXPORTHTML_ERROR', (done) => {
const state = reducer(
{
notifications: []
},
{
payload: {} as any,
type: H5PEDITOR_EXPORTHTML_ERROR
}
);

expect(state.notifications.length).toBe(1);
expect(state.notifications[0].options.variant).toBe('error');
done();
});
});
Loading

0 comments on commit 1e95e3c

Please sign in to comment.