1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
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 || '';
22 const user = getResource<UserResource>(uuid)(state.resources);
23 // const subprocesses = getSubprocesses(uuid)(resources);
26 isAdmin: state.auth.user!.isAdmin,
27 isSelf: state.auth.user!.uuid === uuid,
28 isPristine: isPristine(USER_PROFILE_FORM)(state),
29 isValid: isValid(USER_PROFILE_FORM)(state),
31 localCluster: state.auth.localCluster
34 const mapDispatchToProps = (dispatch: Dispatch) => ({
35 openSetupShellAccount: (uuid: string) => dispatch<any>(openSetupShellAccount(uuid)),
36 loginAs: (uuid: string) => dispatch<any>(loginAs(uuid)),
37 openDeactivateDialog: (uuid: string) => dispatch<any>(openDeactivateDialog(uuid)),
40 export const UserProfilePanel = compose(
41 connect(mapStateToProps, mapDispatchToProps),
43 form: USER_PROFILE_FORM,
44 onSubmit: (data, dispatch) => {
45 dispatch(saveEditedUser(data));
47 }))(UserProfilePanelRoot);