caac3e8cd4abca9511dfc423755457484a7eafe5
[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 { saveEditedUser } from 'store/user-profile/user-profile-actions';
10 import { UserProfilePanelRoot, UserProfilePanelRootDataProps } from 'views/user-profile-panel/user-profile-panel-root';
11 import { openDeactivateDialog, USER_PROFILE_FORM } from "store/user-profile/user-profile-actions";
12 import { matchUserProfileRoute } from 'routes/routes';
13 import { UserResource } from 'models/user';
14 import { getResource } from 'store/resources/resources';
15 import { openSetupShellAccount, loginAs } from 'store/users/users-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   // get user resource
22   const user = getResource<UserResource>(uuid)(state.resources);
23   // const subprocesses = getSubprocesses(uuid)(resources);
24
25   return {
26
27     isPristine: isPristine(USER_PROFILE_FORM)(state),
28     isValid: isValid(USER_PROFILE_FORM)(state),
29     initialValues: user,
30     localCluster: state.auth.localCluster
31 }};
32
33 const mapDispatchToProps = (dispatch: Dispatch) => ({
34     openSetupShellAccount: (uuid: string) => dispatch<any>(openSetupShellAccount(uuid)),
35     loginAs: (uuid: string) => dispatch<any>(loginAs(uuid)),
36     openDeactivateDialog: (uuid: string) => dispatch<any>(openDeactivateDialog(uuid)),
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);