blob: 604549a42579b9871e4b20010cfe191f8b04630b [file] [log] [blame]
svishnev7c727c12018-05-24 13:20:51 +03001/*
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
17import React from 'react';
Arielka51eac02019-07-07 12:56:11 +030018import { Portal, Notification } from 'onap-ui-react';
svishnev7c727c12018-05-24 13:20:51 +030019import { connect } from 'react-redux';
svishnevfa538a12018-05-31 15:01:00 +030020import { notificationActions } from './NotificationsConstants.js';
svishnev7c727c12018-05-24 13:20:51 +030021import { CSSTransition, TransitionGroup } from 'react-transition-group';
22
23export const mapStateToProps = ({ popupNotifications = [] }) => {
24 return {
25 notifications: popupNotifications
26 };
27};
28
29const mapActionToProps = dispatch => {
30 return {
31 onClick: item => {
svishnevfa538a12018-05-31 15:01:00 +030032 dispatch(notificationActions.removeNotification(item));
svishnev7c727c12018-05-24 13:20:51 +030033 }
34 };
35};
36
37class 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
68export default connect(mapStateToProps, mapActionToProps, null)(Notifications);