15685: Adds missing redux-form configs for immediate validation feedback.
[arvados.git] / src / views-components / ssh-keys-dialog / public-key-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 { compose } from 'redux';
7 import { withStyles, Dialog, DialogTitle, DialogContent, DialogActions, Button, StyleRulesCallback, WithStyles } from '@material-ui/core';
8 import { WithDialogProps, withDialog } from "~/store/dialog/with-dialog";
9 import { SSH_KEY_PUBLIC_KEY_DIALOG } from '~/store/auth/auth-action-ssh';
10 import { ArvadosTheme } from '~/common/custom-theme';
11 import { DefaultCodeSnippet } from '~/components/default-code-snippet/default-code-snippet';
12
13 type CssRules = 'codeSnippet';
14
15 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
16     codeSnippet: {
17         borderRadius: theme.spacing.unit * 0.5,
18         border: '1px solid',
19         borderColor: theme.palette.grey["400"],
20         '& pre': {
21             wordWrap: 'break-word',
22             whiteSpace: 'pre-wrap'
23         }
24     },
25 });
26
27 interface PublicKeyDialogDataProps {
28     name: string;
29     publicKey: string;
30 }
31
32 export const PublicKeyDialog = compose(
33     withDialog(SSH_KEY_PUBLIC_KEY_DIALOG),
34     withStyles(styles))(
35         ({ open, closeDialog, data, classes }: WithDialogProps<PublicKeyDialogDataProps> & WithStyles<CssRules>) =>
36             <Dialog open={open}
37                 onClose={closeDialog}
38                 fullWidth
39                 maxWidth='sm'>
40                 <DialogTitle>{data.name} - SSH Key</DialogTitle>
41                 <DialogContent>
42                     {data && data.publicKey && <DefaultCodeSnippet
43                         className={classes.codeSnippet}
44                         lines={data.publicKey.split(' ')} />}
45                 </DialogContent>
46                 <DialogActions>
47                     <Button
48                         variant='text'
49                         color='primary'
50                         onClick={closeDialog}>
51                         Close
52                     </Button>
53                 </DialogActions>
54             </Dialog>
55     );