blob: 3b6d62bc154194365d94052b5ce74d3501453725 [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
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020017import { connect } from 'react-redux';
talig8e9c0652017-12-20 14:30:43 +020018import PermissionsManager from './PermissionsManager.jsx';
19import PermissionsActionHelper from './PermissionsActionHelper.js';
20
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020021export const mapStateToProps = ({
22 versionsPage,
23 users: { usersList, userInfo }
24}) => {
25 let { permissions } = versionsPage;
talig8e9c0652017-12-20 14:30:43 +020026
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020027 return {
28 users: usersList,
29 userInfo,
30 owner: permissions.owner,
31 itemUsers: permissions.contributors
32 };
talig8e9c0652017-12-20 14:30:43 +020033};
34
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020035const mapActionsToProps = dispatch => {
36 return {
37 onCancel: () =>
38 PermissionsActionHelper.closePermissionManager(dispatch),
39 onSubmit: ({
40 itemId,
41 addedUsersIds,
42 removedUsersIds,
43 allUsers,
44 newOwnerId
45 }) => {
46 return PermissionsActionHelper.saveItemUsers(dispatch, {
47 itemId,
48 addedUsersIds,
49 removedUsersIds,
50 allUsers
51 })
52 .then(() => {
53 return newOwnerId
54 ? PermissionsActionHelper.changeOwner(dispatch, {
55 itemId,
56 newOwnerId,
57 allUsers
58 })
59 : Promise.resolve();
60 })
61 .then(() =>
62 PermissionsActionHelper.closePermissionManager(dispatch)
63 );
64 }
65 };
talig8e9c0652017-12-20 14:30:43 +020066};
67
68export default connect(mapStateToProps, mapActionsToProps)(PermissionsManager);