Merge branch 'master' into 14565-admin-managing-user
[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_MANAGE_DIALOG, openSetupShellAccount } from "~/store/users/users-actions";
13 import { UserResource } from "~/models/user";
14 import { connect } from "react-redux";
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: UserResource;
27 }
28
29 interface UserManageActionProps {
30     openSetupShellAccount: (uuid: string) => void;
31 }
32
33 const mapDispatchToProps = (dispatch: Dispatch) => ({
34     openSetupShellAccount: (uuid: string) => dispatch<any>(openSetupShellAccount(uuid))
35 });
36
37 type UserManageProps = UserManageDataProps & UserManageActionProps & WithStyles<CssRules>;
38
39 export const UserManageDialog = compose(
40     connect(null, mapDispatchToProps),
41     withDialog(USER_MANAGE_DIALOG),
42     styles)(
43         (props: WithDialogProps<UserManageProps> & UserManageProps) =>
44             <Dialog open={props.open}
45                 onClose={props.closeDialog}
46                 fullWidth
47                 maxWidth="md">
48                 <DialogTitle>{`Manage - ${props.data.firstName} ${props.data.lastName}`}</DialogTitle>
49                 <DialogContent>
50                     <Typography variant="body2" className={props.classes.spacing}>
51                         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.
52                     </Typography>
53                     <Button variant="contained" color="primary">
54                         {`LOG IN AS ${props.data.firstName} ${props.data.lastName}`}
55                     </Button>
56                     <Typography variant="body2" className={props.classes.spacing}>
57                         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.
58                     </Typography>
59                     <Button variant="contained" color="primary" onClick={() => props.openSetupShellAccount(props.data.uuid)}>
60                         {`SETUP SHELL ACCOUNT FOR ${props.data.firstName} ${props.data.lastName}`}
61                     </Button>
62                 </DialogContent>
63                 <DialogActions>
64                     <Button
65                         variant='flat'
66                         color='primary'
67                         onClick={props.closeDialog}>
68                         Close
69                 </Button>
70                 </DialogActions>
71             </Dialog>
72     );