svishnev | 7c727c1 | 2018-05-24 13:20:51 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | import UUID from 'uuid-js'; |
| 17 | |
| 18 | export const actionTypes = { |
svishnev | bacc715 | 2018-11-05 12:11:30 +0200 | [diff] [blame^] | 19 | ADD_NOTIFICATION: 'notifications/ADD_NOTIFICATION', |
| 20 | REMOVE_NOTIFICATION: 'notifications/REMOVE_NOTIFICATION' |
svishnev | 7c727c1 | 2018-05-24 13:20:51 +0300 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | export const notificationActions = { |
| 24 | showNotification: item => ({ |
| 25 | type: actionTypes.ADD_NOTIFICATION, |
| 26 | payload: { |
| 27 | ...item, |
| 28 | id: UUID.create().toString() |
| 29 | } |
| 30 | }), |
| 31 | |
| 32 | showSuccess: ({ title, message, timeout }) => |
| 33 | notificationActions.showNotification({ |
| 34 | title, |
| 35 | message, |
| 36 | timeout, |
| 37 | type: 'success' |
| 38 | }), |
| 39 | showInfo: ({ title, message, timeout }) => |
| 40 | notificationActions.showNotification({ |
| 41 | title, |
| 42 | message, |
| 43 | timeout, |
| 44 | type: 'info' |
| 45 | }), |
| 46 | showWarning: ({ title, message, timeout }) => |
| 47 | notificationActions.showNotification({ |
| 48 | title, |
| 49 | message, |
| 50 | timeout, |
| 51 | type: 'warning' |
| 52 | }), |
| 53 | showError: ({ title, message, timeout }) => |
| 54 | notificationActions.showNotification({ |
| 55 | title, |
| 56 | message, |
| 57 | timeout, |
| 58 | type: 'error' |
| 59 | }), |
| 60 | removeNotification: item => ({ |
| 61 | type: actionTypes.REMOVE_NOTIFICATION, |
| 62 | payload: item |
| 63 | }) |
| 64 | }; |
| 65 | |
| 66 | export const notificationTimeout = 4000; |