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}
67 <form data-cy='form-dialog' className={props.classes.form}>
68 <DialogTitle className={props.classes.dialogTitle}>
71 <DialogContent className={props.classes.formContainer}>
72 <props.formFields {...props} />
74 <DialogActions className={props.classes.dialogActions}>
76 data-cy='form-cancel-btn'
80 if (props.cancelCallback) {
81 props.cancelCallback();
86 className={props.classes.button}
88 disabled={props.doNotDisableCancel ? false : props.submitting}>
89 {props.cancelLabel || 'Cancel'}
92 data-cy='form-submit-btn'
94 onClick={props.handleSubmit}
95 className={props.classes.lastButton}
97 disabled={props.invalid || props.submitting || (props.pristine && !props.enableWhenPristine)}
99 {props.submitLabel || 'Submit'}
100 {props.submitting && <CircularProgress size={20} className={props.classes.progressIndicator} />}