17782: Fixes almost all tests (4 left) mostly by fixing namespace-type imports.
[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, openSetupShellAccount, loginAs } from "store/users/users-actions";
14 import { getUserDisplayName } from "models/user";
15
16 type CssRules = 'spacing';
17
18 const styles = withStyles<CssRules>((theme: ArvadosTheme) => ({
19     spacing: {
20         paddingBottom: theme.spacing.unit * 2,
21         paddingTop: theme.spacing.unit * 2,
22     }
23 }));
24
25 interface UserManageDataProps {
26     data: any;
27 }
28
29 interface UserManageActionProps {
30     openSetupShellAccount: (uuid: string) => void;
31     loginAs: (uuid: string) => void;
32 }
33
34 const mapDispatchToProps = (dispatch: Dispatch) => ({
35     openSetupShellAccount: (uuid: string) => dispatch<any>(openSetupShellAccount(uuid)),
36     loginAs: (uuid: string) => dispatch<any>(loginAs(uuid))
37 });
38
39 type UserManageProps = UserManageDataProps & UserManageActionProps & WithStyles<CssRules>;
40
41 export const UserManageDialog = compose(
42     connect(null, mapDispatchToProps),
43     withDialog(USER_MANAGEMENT_DIALOG),
44     styles)(
45         (props: WithDialogProps<UserManageProps> & UserManageProps) =>
46             <Dialog open={props.open}
47                 onClose={props.closeDialog}
48                 fullWidth
49                 maxWidth="md">
50                 {props.data &&
51                     <span>
52                         <DialogTitle>{`Manage - ${getUserDisplayName(props.data)}`}</DialogTitle>
53                         <DialogContent>
54                             <Typography variant='body1' className={props.classes.spacing}>
55                                 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.
56                     </Typography>
57                             <Button variant="contained" color="primary" onClick={() => props.loginAs(props.data.uuid)}>
58                                 {`LOG IN AS ${getUserDisplayName(props.data)}`}
59                             </Button>
60                             <Typography variant='body1' className={props.classes.spacing}>
61                                 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.
62                     </Typography>
63                             <Button variant="contained" color="primary" onClick={() => props.openSetupShellAccount(props.data.uuid)}>
64                                 {`SETUP SHELL ACCOUNT FOR ${getUserDisplayName(props.data)}`}
65                             </Button>
66                         </DialogContent></span>}
67
68                 <DialogActions>
69                     <Button
70                         variant='text'
71                         color='primary'
72                         onClick={props.closeDialog}>
73                         Close
74                 </Button>
75                 </DialogActions>
76             </Dialog>
77     );