18559: Add groups and admin tab to user profile, use for other users profile
[arvados-workbench2.git] / src / views-components / user-dialog / manage-dialog.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import { compose, Dispatch } from "redux";
7 import { connect } from "react-redux";
8 import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Typography } from "@material-ui/core";
9 import { WithDialogProps } from "store/dialog/with-dialog";
10 import { withDialog } from 'store/dialog/with-dialog';
11 import { WithStyles, withStyles } from '@material-ui/core/styles';
12 import { ArvadosTheme } from 'common/custom-theme';
13 import { USER_MANAGEMENT_DIALOG } from "store/users/users-actions";
14 import { openSetupShellAccount, loginAs } from 'store/users/users-actions';
15 import { getUserDisplayName } from "models/user";
16
17 type CssRules = 'spacing';
18
19 const styles = withStyles<CssRules>((theme: ArvadosTheme) => ({
20     spacing: {
21         paddingBottom: theme.spacing.unit * 2,
22         paddingTop: theme.spacing.unit * 2,
23     }
24 }));
25
26 interface UserManageDataProps {
27     data: any;
28 }
29
30 interface UserManageActionProps {
31     openSetupShellAccount: (uuid: string) => void;
32     loginAs: (uuid: string) => void;
33 }
34
35 const mapDispatchToProps = (dispatch: Dispatch) => ({
36     openSetupShellAccount: (uuid: string) => dispatch<any>(openSetupShellAccount(uuid)),
37     loginAs: (uuid: string) => dispatch<any>(loginAs(uuid))
38 });
39
40 type UserManageProps = UserManageDataProps & UserManageActionProps & WithStyles<CssRules>;
41
42 export const UserManageDialog = compose(
43     connect(null, mapDispatchToProps),
44     withDialog(USER_MANAGEMENT_DIALOG),
45     styles)(
46         (props: WithDialogProps<UserManageProps> & UserManageProps) =>
47             <Dialog open={props.open}
48                 onClose={props.closeDialog}
49                 fullWidth
50                 maxWidth="md">
51                 {props.data &&
52                     <span>
53                         <DialogTitle>{`Manage - ${getUserDisplayName(props.data)}`}</DialogTitle>
54                         <DialogContent>
55                             <Typography variant='body1' className={props.classes.spacing}>
56                                 As an admin, you can log in as this user. When you’ve finished, you will need to log out and log in again with your own account.
57                     </Typography>
58                             <Button variant="contained" color="primary" onClick={() => props.loginAs(props.data.uuid)}>
59                                 {`LOG IN AS ${getUserDisplayName(props.data)}`}
60                             </Button>
61                             <Typography variant='body1' className={props.classes.spacing}>
62                                 As an admin, you can setup a shell account for this user. The login name is automatically generated from the user's e-mail address.
63                     </Typography>
64                             <Button variant="contained" color="primary" onClick={() => props.openSetupShellAccount(props.data.uuid)}>
65                                 {`SETUP SHELL ACCOUNT FOR ${getUserDisplayName(props.data)}`}
66                             </Button>
67                         </DialogContent></span>}
68
69                 <DialogActions>
70                     <Button
71                         variant='text'
72                         color='primary'
73                         onClick={props.closeDialog}>
74                         Close
75                 </Button>
76                 </DialogActions>
77             </Dialog>
78     );