1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
import { Component, ReactElement } from 'react';
import { observer } from 'mobx-react';
import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';
import withStyles, { WithStylesProps } from 'react-jss';
import Input from '../../../components/ui/input/index';
import Button from '../../../components/ui/button';
import Form from '../../../lib/Form';
import { required } from '../../../helpers/validation-helpers';
import { workspaceStore } from '../index';
const messages = defineMessages({
submitButton: {
id: 'settings.workspace.add.form.submitButton',
defaultMessage: 'Create workspace',
},
name: {
id: 'settings.workspace.add.form.name',
defaultMessage: 'Name',
},
});
const styles = {
form: {
display: 'flex',
},
input: {
flexGrow: 1,
marginRight: '10px',
},
submitButton: {
height: 'inherit',
},
};
interface IProps extends WithStylesProps<typeof styles>, WrappedComponentProps {
isSubmitting: boolean;
onSubmit: (...args: any[]) => void;
}
@observer
class CreateWorkspaceForm extends Component<IProps> {
form: Form;
constructor(props: IProps) {
super(props);
this.form = new Form({
fields: {
name: {
label: this.props.intl.formatMessage(messages.name),
placeholder: this.props.intl.formatMessage(messages.name),
value: '',
validators: [required],
},
},
});
}
submitForm(): void {
this.form.submit({
onSuccess: async form => {
const { onSubmit } = this.props;
const values = form.values();
onSubmit(values);
},
});
}
render(): ReactElement {
const { classes, isSubmitting, intl } = this.props;
const { form } = this;
return (
<div className={classes.form}>
<Input
{...form.$('name').bind()}
className={classes.input}
showLabel={false}
// @ts-expect-error Expected 1 arguments, but got 2.
onEnterKey={this.submitForm.bind(this, form)}
focus={workspaceStore.isUserAllowedToUseFeature}
/>
<Button
className={`${classes.submitButton} franz-form__button`}
type="submit"
label={intl.formatMessage(messages.submitButton)}
// @ts-expect-error Expected 1 arguments, but got 2.
onClick={this.submitForm.bind(this, form)}
busy={isSubmitting}
buttonType={isSubmitting ? 'secondary' : 'primary'}
/>
</div>
);
}
}
export default injectIntl(
withStyles(styles, { injectTheme: true })(CreateWorkspaceForm),
);
|