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",
38 interface DialogProjectProps {
41 formFields: React.ComponentType<InjectedFormProps<any> & WithDialogProps<any>>;
45 export const FormDialog = withStyles(styles)((props: DialogProjectProps & WithDialogProps<{}> & InjectedFormProps<any> & WithStyles<CssRules>) =>
48 onClose={props.closeDialog}
49 disableBackdropClick={props.submitting}
50 disableEscapeKeyDown={props.submitting}
54 <DialogTitle className={props.classes.dialogTitle}>
57 <DialogContent className={props.classes.formContainer}>
58 <props.formFields {...props} />
60 <DialogActions className={props.classes.dialogActions}>
62 onClick={props.closeDialog}
63 className={props.classes.button}
65 disabled={props.submitting}>
66 {props.cancelLabel || 'Cancel'}
69 onClick={props.handleSubmit}
70 className={props.classes.lastButton}
72 disabled={props.invalid || props.submitting || props.pristine}
74 {props.submitLabel || 'Submit'}
75 {props.submitting && <CircularProgress size={20} className={props.classes.progressIndicator} />}