06594bde8f
Close #2062
Squashed commit of the following:
commit a1a1d4fe74dd414f83477d972bc07062e2c890ab
Merge: 9535e109 84938c56
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Tue Sep 8 10:21:47 2020 +0300
Merge branch 'master' into fix/2062
commit 9535e10934c57c2592df234a030bad183c0086cd
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Mon Sep 7 13:59:57 2020 +0300
Fix translation
commit e6f912d1d2793fd008c22b4418681abcc54896d0
Author: ArtemBaskal <a.baskal@adguard.com>
Date: Mon Sep 7 12:03:45 2020 +0300
- client: Add link to 'update_failed' error toast
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import { handleActions } from 'redux-actions';
|
|
import { nanoid } from 'nanoid';
|
|
|
|
import {
|
|
addErrorToast, addNoticeToast, addSuccessToast,
|
|
} from '../actions/toasts';
|
|
import { removeToast } from '../actions';
|
|
import { TOAST_TYPES } from '../helpers/constants';
|
|
|
|
const toasts = handleActions({
|
|
[addErrorToast]: (state, { payload }) => {
|
|
const message = payload.error.toString();
|
|
console.error(payload.error);
|
|
|
|
const errorToast = {
|
|
id: nanoid(),
|
|
message,
|
|
options: payload.options,
|
|
type: TOAST_TYPES.ERROR,
|
|
};
|
|
|
|
const newState = { ...state, notices: [...state.notices, errorToast] };
|
|
return newState;
|
|
},
|
|
[addSuccessToast]: (state, { payload }) => {
|
|
const successToast = {
|
|
id: nanoid(),
|
|
message: payload,
|
|
type: TOAST_TYPES.SUCCESS,
|
|
};
|
|
|
|
const newState = { ...state, notices: [...state.notices, successToast] };
|
|
return newState;
|
|
},
|
|
[addNoticeToast]: (state, { payload }) => {
|
|
const noticeToast = {
|
|
id: nanoid(),
|
|
message: payload.error.toString(),
|
|
options: payload.options,
|
|
type: TOAST_TYPES.NOTICE,
|
|
};
|
|
|
|
const newState = { ...state, notices: [...state.notices, noticeToast] };
|
|
return newState;
|
|
},
|
|
[removeToast]: (state, { payload }) => {
|
|
const filtered = state.notices.filter((notice) => notice.id !== payload);
|
|
const newState = { ...state, notices: filtered };
|
|
return newState;
|
|
},
|
|
}, { notices: [] });
|
|
|
|
export default toasts;
|