1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import 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" | "form" | "formContainer" | "dialogTitle" | "progressIndicator" | "dialogActions";
13 const styles: StyleRulesCallback<CssRules> = theme => ({
15 marginLeft: theme.spacing.unit
18 marginLeft: theme.spacing.unit,
24 flexDirection: 'column',
29 flexDirection: "column",
33 paddingTop: theme.spacing.unit,
34 paddingBottom: theme.spacing.unit,
41 marginBottom: theme.spacing.unit,
42 marginRight: theme.spacing.unit * 3,
46 interface DialogProjectDataProps {
49 formFields: React.ComponentType<InjectedFormProps<any> & WithDialogProps<any>>;
51 cancelCallback?: Function;
52 enableWhenPristine?: boolean;
53 doNotDisableCancel?: boolean;
56 type DialogProjectProps = DialogProjectDataProps & WithDialogProps<{}> & InjectedFormProps<any> & WithStyles<CssRules>;
58 export const FormDialog = withStyles(styles)((props: DialogProjectProps) =>
61 onClose={props.closeDialog}
63 disableEscapeKeyDown={props.submitting}
66 <form data-cy='form-dialog' className={props.classes.form}>
67 <DialogTitle className={props.classes.dialogTitle}>
70 <DialogContent className={props.classes.formContainer}>
71 <props.formFields {...props} />
73 <DialogActions className={props.classes.dialogActions}>
75 data-cy='form-cancel-btn'
79 if (props.cancelCallback) {
80 props.cancelCallback();
85 className={props.classes.button}
87 disabled={props.doNotDisableCancel ? false : props.submitting}>
88 {props.cancelLabel || 'Cancel'}
91 data-cy='form-submit-btn'
93 onClick={props.handleSubmit}
94 className={props.classes.lastButton}
96 disabled={props.invalid || props.submitting || (props.pristine && !props.enableWhenPristine)}
98 {props.submitLabel || 'Submit'}
99 {props.submitting && <CircularProgress size={20} className={props.classes.progressIndicator} />}