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",
34 marginBottom: theme.spacing.unit * 3
38 interface DialogProjectDataProps {
41 formFields: React.ComponentType<InjectedFormProps<any> & WithDialogProps<any>>;
45 type DialogProjectProps = DialogProjectDataProps & WithDialogProps<{}> & InjectedFormProps<any> & WithStyles<CssRules>;
47 export const FormDialog = withStyles(styles)((props: DialogProjectProps) =>
50 onClose={props.closeDialog}
52 disableEscapeKeyDown={props.submitting}
56 <DialogTitle className={props.classes.dialogTitle}>
59 <DialogContent className={props.classes.formContainer}>
60 <props.formFields {...props} />
62 <DialogActions className={props.classes.dialogActions}>
64 onClick={props.closeDialog}
65 className={props.classes.button}
67 disabled={props.submitting}>
68 {props.cancelLabel || 'Cancel'}
72 onClick={props.handleSubmit}
73 className={props.classes.lastButton}
75 disabled={props.invalid || props.submitting || props.pristine}
77 {props.submitLabel || 'Submit'}
78 {props.submitting && <CircularProgress size={20} className={props.classes.progressIndicator} />}