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 | |
| 17 | import React from 'react'; |
Arielk | a51eac0 | 2019-07-07 12:56:11 +0300 | [diff] [blame] | 18 | import { Portal, Notification } from 'onap-ui-react'; |
svishnev | 7c727c1 | 2018-05-24 13:20:51 +0300 | [diff] [blame] | 19 | import { connect } from 'react-redux'; |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 20 | import { notificationActions } from './NotificationsConstants.js'; |
svishnev | 7c727c1 | 2018-05-24 13:20:51 +0300 | [diff] [blame] | 21 | import { CSSTransition, TransitionGroup } from 'react-transition-group'; |
| 22 | |
| 23 | export const mapStateToProps = ({ popupNotifications = [] }) => { |
| 24 | return { |
| 25 | notifications: popupNotifications |
| 26 | }; |
| 27 | }; |
| 28 | |
| 29 | const mapActionToProps = dispatch => { |
| 30 | return { |
| 31 | onClick: item => { |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 32 | dispatch(notificationActions.removeNotification(item)); |
svishnev | 7c727c1 | 2018-05-24 13:20:51 +0300 | [diff] [blame] | 33 | } |
| 34 | }; |
| 35 | }; |
| 36 | |
| 37 | class Notifications extends React.Component { |
| 38 | render() { |
| 39 | const { notifications, onClick } = this.props; |
| 40 | |
| 41 | return ( |
| 42 | <Portal> |
| 43 | <div className="onboarding-notifications-container position-top-right"> |
| 44 | <TransitionGroup> |
| 45 | {notifications.map(item => ( |
| 46 | <CSSTransition |
| 47 | in={true} |
| 48 | timeout={500} |
| 49 | unmountOnExit |
| 50 | classNames="react-transition" |
| 51 | key={`notification-transition-${item.id}`}> |
| 52 | <Notification |
| 53 | key={item.id} |
| 54 | type={item.type} |
| 55 | title={item.title} |
| 56 | message={item.message} |
| 57 | onClick={() => onClick(item)} |
| 58 | /> |
| 59 | </CSSTransition> |
| 60 | ))} |
| 61 | </TransitionGroup> |
| 62 | </div> |
| 63 | </Portal> |
| 64 | ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | export default connect(mapStateToProps, mapActionToProps, null)(Notifications); |