aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/components/CreateWorkspaceForm.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/workspaces/components/CreateWorkspaceForm.js')
-rw-r--r--src/features/workspaces/components/CreateWorkspaceForm.js94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/features/workspaces/components/CreateWorkspaceForm.js b/src/features/workspaces/components/CreateWorkspaceForm.js
new file mode 100644
index 000000000..d440b9bae
--- /dev/null
+++ b/src/features/workspaces/components/CreateWorkspaceForm.js
@@ -0,0 +1,94 @@
1import React, { Component } from 'react';
2import PropTypes from 'prop-types';
3import { observer } from 'mobx-react';
4import { defineMessages, intlShape } from 'react-intl';
5import { Input, Button } from '@meetfranz/forms';
6import injectSheet from 'react-jss';
7
8import Form from '../../../lib/Form';
9
10const messages = defineMessages({
11 submitButton: {
12 id: 'settings.workspace.add.form.submitButton',
13 defaultMessage: '!!!Save workspace',
14 },
15 name: {
16 id: 'settings.workspace.add.form.name',
17 defaultMessage: '!!!Name',
18 },
19});
20
21const styles = () => ({
22 form: {
23 display: 'flex',
24 },
25 input: {
26 flexGrow: 1,
27 marginRight: '10px',
28 },
29 submitButton: {
30 height: 'inherit',
31 marginTop: '17px',
32 },
33});
34
35@observer @injectSheet(styles)
36class CreateWorkspaceForm extends Component {
37 static contextTypes = {
38 intl: intlShape,
39 };
40
41 static propTypes = {
42 classes: PropTypes.object.isRequired,
43 onSubmit: PropTypes.func.isRequired,
44 };
45
46 prepareForm() {
47 const { intl } = this.context;
48 const config = {
49 fields: {
50 name: {
51 label: intl.formatMessage(messages.name),
52 placeholder: intl.formatMessage(messages.name),
53 value: '',
54 },
55 },
56 };
57 return new Form(config);
58 }
59
60 submitForm(form) {
61 form.submit({
62 onSuccess: async (f) => {
63 const { onSubmit } = this.props;
64 const values = f.values();
65 onSubmit(values);
66 },
67 onError: async () => {},
68 });
69 }
70
71 render() {
72 const { intl } = this.context;
73 const { classes } = this.props;
74 const form = this.prepareForm();
75
76 return (
77 <div className={classes.form}>
78 <Input
79 className={classes.input}
80 {...form.$('name').bind()}
81 onEnterKey={this.submitForm.bind(this, form)}
82 />
83 <Button
84 className={classes.submitButton}
85 type="button"
86 label={intl.formatMessage(messages.submitButton)}
87 onClick={this.submitForm.bind(this, form)}
88 />
89 </div>
90 );
91 }
92}
93
94export default CreateWorkspaceForm;