Merge branch 'master' into 14604-ui-improvements
[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 * as React from "react";
6 import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Typography } from "@material-ui/core";
7 import { WithDialogProps } from "~/store/dialog/with-dialog";
8 import { withDialog } from '~/store/dialog/with-dialog';
9 import { WithStyles, withStyles } from '@material-ui/core/styles';
10 import { ArvadosTheme } from '~/common/custom-theme';
11 import { compose, Dispatch } from "redux";
12 import { USER_MANAGEMENT_DIALOG, openSetupShellAccount, loginAs } from "~/store/users/users-actions";
13 import { connect } from "react-redux";
14
15 type CssRules = 'spacing';
16
17 const styles = withStyles<CssRules>((theme: ArvadosTheme) => ({
18     spacing: {
19         paddingBottom: theme.spacing.unit * 2,
20         paddingTop: theme.spacing.unit * 2,
21     }
22 }));
23
24 interface UserManageDataProps {
25     data: any;
26 }
27
28 interface UserManageActionProps {
29     openSetupShellAccount: (uuid: string) => void;
30     loginAs: (uuid: string) => void;
31 }
32
33 const mapDispatchToProps = (dispatch: Dispatch) => ({
34     openSetupShellAccount: (uuid: string) => dispatch<any>(openSetupShellAccount(uuid)),
35     loginAs: (uuid: string) => dispatch<any>(loginAs(uuid))
36 });
37
38 type UserManageProps = UserManageDataProps & UserManageActionProps & WithStyles<CssRules>;
39
40 export const UserManageDialog = compose(
41     connect(null, mapDispatchToProps),
42     withDialog(USER_MANAGEMENT_DIALOG),
43     styles)(
44         (props: WithDialogProps<UserManageProps> & UserManageProps) =>
45             <Dialog open={props.open}
46                 onClose={props.closeDialog}
47                 fullWidth
48                 maxWidth="md">
49                 {props.data &&
50                     <span>
51                         <DialogTitle>{`Manage - ${props.data.firstName} ${props.data.lastName}`}</DialogTitle>
52                         <DialogContent>
53                             <Typography variant='body1' className={props.classes.spacing}>
54                                 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.
55                     </Typography>
56                             <Button variant="contained" color="primary" onClick={() => props.loginAs(props.data.uuid)}>
57                                 {`LOG IN AS ${props.data.firstName} ${props.data.lastName}`}
58                             </Button>
59                             <Typography variant='body1' className={props.classes.spacing}>
60                                 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.
61                     </Typography>
62                             <Button variant="contained" color="primary" onClick={() => props.openSetupShellAccount(props.data.uuid)}>
63                                 {`SETUP SHELL ACCOUNT FOR ${props.data.firstName} ${props.data.lastName}`}
64                             </Button>
65                         </DialogContent></span>}
66
67                 <DialogActions>
68                     <Button
69                         variant='text'
70                         color='primary'
71                         onClick={props.closeDialog}>
72                         Close
73                 </Button>
74                 </DialogActions>
75             </Dialog>
76     );