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 '@mui/material/';
8 import { CustomStyleRulesCallback } from 'common/custom-theme';
9 import { Button, CircularProgress } from '@mui/material';
10 import { WithStyles } from '@mui/styles';
11 import withStyles from '@mui/styles/withStyles';
12 import { WithDialogProps } from 'store/dialog/with-dialog';
14 type CssRules = "button" | "lastButton" | "form" | "formContainer" | "dialogTitle" | "progressIndicator" | "dialogActions";
16 const styles: CustomStyleRulesCallback<CssRules> = theme => ({
18 marginLeft: theme.spacing(1),
21 marginLeft: theme.spacing(1),
27 flexDirection: 'column',
32 flexDirection: "column",
36 paddingTop: theme.spacing(1),
37 paddingBottom: theme.spacing(1),
44 marginBottom: theme.spacing(1),
45 marginRight: theme.spacing(3),
49 interface DialogProjectDataProps {
52 formFields: React.ComponentType<InjectedFormProps<any> & WithDialogProps<any>>;
54 cancelCallback?: Function;
55 enableWhenPristine?: boolean;
56 doNotDisableCancel?: boolean;
59 type DialogProjectProps = DialogProjectDataProps & WithDialogProps<{}> & InjectedFormProps<any> & WithStyles<CssRules>;
61 export const FormDialog = withStyles(styles)((props: DialogProjectProps) => {
63 const handleClose = (ev, reason) => {
64 if (reason !== 'backdropClick') {
72 disableEscapeKeyDown={props.submitting}
76 <form data-cy='form-dialog' className={props.classes.form}>
77 <DialogTitle className={props.classes.dialogTitle}>
80 <DialogContent className={props.classes.formContainer}>
81 <props.formFields {...props} />
83 <DialogActions className={props.classes.dialogActions}>
85 data-cy='form-cancel-btn'
89 if (props.cancelCallback) {
90 props.cancelCallback();
95 className={props.classes.button}
97 disabled={props.doNotDisableCancel ? false : props.submitting}>
98 {props.cancelLabel || 'Cancel'}
101 data-cy='form-submit-btn'
103 onClick={props.handleSubmit}
104 className={props.classes.lastButton}
106 disabled={props.invalid || props.submitting || (props.pristine && !props.enableWhenPristine)}
108 {props.submitLabel || 'Submit'}
109 {props.submitting && <CircularProgress size={20} className={props.classes.progressIndicator} />}