blob: 23acd5033423e79a37f9f8e3db9968c9e0d67c59 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
16
17import React from 'react';
18import PropTypes from 'prop-types';
19import enhanceWithClickOutside from 'react-click-outside';
20import classnames from 'classnames';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020021import { connect } from 'react-redux';
Arielka51eac02019-07-07 12:56:11 +030022import { SVGIcon } from 'onap-ui-react';
talig8e9c0652017-12-20 14:30:43 +020023import Overlay from 'nfvo-components/overlay/Overlay.jsx';
24import UserNotifications from 'sdc-app/onboarding/userNotifications/UserNotifications.jsx';
25import UserNotificationsActionHelper from 'sdc-app/onboarding/userNotifications/UserNotificationsActionHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020026import { actionTypes } from './UserNotificationsConstants.js';
talig8e9c0652017-12-20 14:30:43 +020027import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js';
28
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020029const mapStateToProps = ({
30 currentScreen,
31 notifications,
32 users: { usersList }
33}) => {
34 return { currentScreen, notifications, usersList };
talig8e9c0652017-12-20 14:30:43 +020035};
36
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020037const mapActionToProps = dispatch => {
38 return {
39 resetNewNotifications: notificationId =>
40 UserNotificationsActionHelper.updateLastSeenNotification(dispatch, {
41 notificationId
42 }),
43 toggleOverlay: ({ showNotificationsOverlay }) =>
44 dispatch({
45 type: actionTypes.TOGGLE_OVERLAY,
46 showNotificationsOverlay
47 }),
48 onLoadPrevNotifications: (lastScanned, endOfPage) =>
49 UserNotificationsActionHelper.loadPreviousNotifications(dispatch, {
50 lastScanned,
51 endOfPage
52 }),
53 onSync: ({ itemId, itemName, versionId, versionName, currentScreen }) =>
54 UserNotificationsActionHelper.syncItem(dispatch, {
55 itemId,
56 itemName,
57 versionId,
58 versionName,
59 currentScreen
60 }),
61 updateNotification: notificationForUpdate =>
62 UserNotificationsActionHelper.updateNotification(dispatch, {
63 notificationForUpdate
64 }),
65 onLoadItemsLists: () => OnboardingActionHelper.loadItemsLists(dispatch)
66 };
talig8e9c0652017-12-20 14:30:43 +020067};
68
talig8e9c0652017-12-20 14:30:43 +020069class NotificationsView extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020070 static propTypes = {
71 currentScreen: PropTypes.object,
72 notifications: PropTypes.object,
73 resetNewNotifications: PropTypes.func,
74 toggleOverlay: PropTypes.func,
75 onLoadPrevNotifications: PropTypes.func,
76 onSync: PropTypes.func,
77 updateNotification: PropTypes.func,
78 onLoadItemsLists: PropTypes.func
79 };
talig8e9c0652017-12-20 14:30:43 +020080
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020081 render() {
82 const {
83 usersList,
84 notifications,
85 onLoadPrevNotifications,
86 onSync,
87 updateNotification,
88 onLoadItemsLists,
89 currentScreen
90 } = this.props;
91 const {
92 notificationsList,
93 numOfNotSeenNotifications,
94 showNotificationsOverlay,
95 lastScanned,
96 endOfPage
97 } = notifications;
talig8e9c0652017-12-20 14:30:43 +020098
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020099 return (
100 <div className="onboarding-notifications">
101 <div
102 className="notifications-icon"
103 onClick={() => this.onNotificationIconClick()}>
104 <SVGIcon
105 name={
106 numOfNotSeenNotifications > 0
107 ? 'notificationFullBell'
108 : 'notificationBell'
109 }
110 color={numOfNotSeenNotifications > 0 ? 'primary' : ''}
111 />
112 <div
113 className={classnames('notifications-count', {
114 'hidden-count': numOfNotSeenNotifications === 0
115 })}>
116 {numOfNotSeenNotifications}
117 </div>
118 </div>
119 {showNotificationsOverlay && (
120 <Overlay>
121 <UserNotifications
122 notificationsList={notificationsList}
123 usersList={usersList}
124 lastScanned={lastScanned}
125 endOfPage={endOfPage}
126 onLoadPrevNotifications={onLoadPrevNotifications}
127 onSync={onSync}
128 updateNotification={updateNotification}
129 onLoadItemsLists={onLoadItemsLists}
130 currentScreen={currentScreen}
131 />
132 </Overlay>
133 )}
134 </div>
135 );
136 }
talig8e9c0652017-12-20 14:30:43 +0200137
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200138 handleClickOutside() {
139 const { notifications: { showNotificationsOverlay } } = this.props;
140 if (showNotificationsOverlay) {
141 this.onCloseOverlay();
142 }
143 }
talig8e9c0652017-12-20 14:30:43 +0200144
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200145 onNotificationIconClick() {
146 const {
147 notifications: { showNotificationsOverlay },
148 toggleOverlay
149 } = this.props;
150 if (showNotificationsOverlay) {
151 this.onCloseOverlay();
152 } else {
153 toggleOverlay({ showNotificationsOverlay: true });
154 }
155 }
talig8e9c0652017-12-20 14:30:43 +0200156
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200157 onCloseOverlay() {
158 const {
159 notifications: { numOfNotSeenNotifications, lastScanned },
160 resetNewNotifications,
161 toggleOverlay
162 } = this.props;
163 if (numOfNotSeenNotifications) {
164 resetNewNotifications(lastScanned);
165 }
166 toggleOverlay({ showNotificationsOverlay: false });
167 }
talig8e9c0652017-12-20 14:30:43 +0200168}
169
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200170export default connect(mapStateToProps, mapActionToProps)(
171 enhanceWithClickOutside(NotificationsView)
172);