1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { InjectedFormProps } from 'redux-form';
7 import { Dialog, DialogActions, DialogContent, DialogTitle } from '@material-ui/core/';
8 import { Button, StyleRulesCallback, WithStyles, withStyles, CircularProgress } from '@material-ui/core';
9 import { WithDialogProps } from '~/store/dialog/with-dialog';
11 type CssRules = "button" | "lastButton" | "formContainer" | "dialogTitle" | "progressIndicator" | "dialogActions";
13 const styles: StyleRulesCallback<CssRules> = theme => ({
15 marginLeft: theme.spacing.unit
18 marginLeft: theme.spacing.unit,
23 flexDirection: "column",
27 paddingTop: theme.spacing.unit,
28 paddingBottom: theme.spacing.unit,
35 marginBottom: theme.spacing.unit,
36 marginRight: theme.spacing.unit * 3,
40 interface DialogProjectDataProps {
43 formFields: React.ComponentType<InjectedFormProps<any> & WithDialogProps<any>>;
47 type DialogProjectProps = DialogProjectDataProps & WithDialogProps<{}> & InjectedFormProps<any> & WithStyles<CssRules>;
49 export const FormDialog = withStyles(styles)((props: DialogProjectProps) =>
52 onClose={props.closeDialog}
54 disableEscapeKeyDown={props.submitting}
57 <form data-cy='form-dialog'>
58 <DialogTitle className={props.classes.dialogTitle}>
61 <DialogContent className={props.classes.formContainer}>
62 <props.formFields {...props} />
64 <DialogActions className={props.classes.dialogActions}>
66 data-cy='form-cancel-btn'
67 onClick={props.closeDialog}
68 className={props.classes.button}
70 disabled={props.submitting}>
71 {props.cancelLabel || 'Cancel'}
74 data-cy='form-submit-btn'
76 onClick={props.handleSubmit}
77 className={props.classes.lastButton}
79 disabled={props.invalid || props.submitting || props.pristine}
81 {props.submitLabel || 'Submit'}
82 {props.submitting && <CircularProgress size={20} className={props.classes.progressIndicator} />}