18559: Add uuid with copy and action menu to user profile panel
[arvados-workbench2.git] / src / views / user-profile-panel / user-profile-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { RootState } from 'store/store';
6 import { compose, Dispatch } from 'redux';
7 import { reduxForm, isPristine, isValid } from 'redux-form';
8 import { connect } from 'react-redux';
9 import { UserResource } from 'models/user';
10 import { saveEditedUser } from 'store/user-profile/user-profile-actions';
11 import { UserProfilePanelRoot, UserProfilePanelRootDataProps } from 'views/user-profile-panel/user-profile-panel-root';
12 import { openSetupDialog, openDeactivateDialog, USER_PROFILE_FORM } from "store/user-profile/user-profile-actions";
13 import { matchUserProfileRoute } from 'routes/routes';
14 import { loginAs } from 'store/users/users-actions';
15 import { openUserContextMenu } from 'store/context-menu/context-menu-actions';
16
17 const mapStateToProps = (state: RootState): UserProfilePanelRootDataProps => {
18   const pathname = state.router.location ? state.router.location.pathname : '';
19   const match = matchUserProfileRoute(pathname);
20   const uuid = match ? match.params.id : state.auth.user?.uuid || '';
21
22   return {
23     isAdmin: state.auth.user!.isAdmin,
24     isSelf: state.auth.user!.uuid === uuid,
25     isPristine: isPristine(USER_PROFILE_FORM)(state),
26     isValid: isValid(USER_PROFILE_FORM)(state),
27     localCluster: state.auth.localCluster,
28     userUuid: uuid,
29     resources: state.resources,
30 }};
31
32 const mapDispatchToProps = (dispatch: Dispatch) => ({
33     openSetupDialog: (uuid: string) => dispatch<any>(openSetupDialog(uuid)),
34     loginAs: (uuid: string) => dispatch<any>(loginAs(uuid)),
35     openDeactivateDialog: (uuid: string) => dispatch<any>(openDeactivateDialog(uuid)),
36     handleContextMenu: (event, resource: UserResource) => dispatch<any>(openUserContextMenu(event, resource)),
37 });
38
39 export const UserProfilePanel = compose(
40     connect(mapStateToProps, mapDispatchToProps),
41     reduxForm({
42         form: USER_PROFILE_FORM,
43         onSubmit: (data, dispatch) => {
44             dispatch(saveEditedUser(data));
45         }
46     }))(UserProfilePanelRoot);