talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | /*! |
| 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 Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 17 | import { connect } from 'react-redux'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 18 | import PermissionsManager from './PermissionsManager.jsx'; |
| 19 | import PermissionsActionHelper from './PermissionsActionHelper.js'; |
| 20 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 21 | export const mapStateToProps = ({ |
| 22 | versionsPage, |
| 23 | users: { usersList, userInfo } |
| 24 | }) => { |
| 25 | let { permissions } = versionsPage; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 26 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 27 | return { |
| 28 | users: usersList, |
| 29 | userInfo, |
| 30 | owner: permissions.owner, |
| 31 | itemUsers: permissions.contributors |
| 32 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 33 | }; |
| 34 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 35 | const 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 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | export default connect(mapStateToProps, mapActionsToProps)(PermissionsManager); |