diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-02-19 15:02:11 +0100 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-02-19 15:02:11 +0100 |
commit | a421ba151f40695f54a4890219c5ec8af0a24a45 (patch) | |
tree | f6ef23bae9c8f1fc5c055e67d4a1a9e52fd18a8e /src/features/workspaces/components | |
parent | consolidate workspace feature for further development (diff) | |
download | ferdium-app-a421ba151f40695f54a4890219c5ec8af0a24a45.tar.gz ferdium-app-a421ba151f40695f54a4890219c5ec8af0a24a45.tar.zst ferdium-app-a421ba151f40695f54a4890219c5ec8af0a24a45.zip |
prepare basic workspace edit form
Diffstat (limited to 'src/features/workspaces/components')
-rw-r--r-- | src/features/workspaces/components/EditWorkspaceForm.js | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/features/workspaces/components/EditWorkspaceForm.js b/src/features/workspaces/components/EditWorkspaceForm.js new file mode 100644 index 000000000..9e87b56dd --- /dev/null +++ b/src/features/workspaces/components/EditWorkspaceForm.js | |||
@@ -0,0 +1,142 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import { defineMessages, intlShape } from 'react-intl'; | ||
5 | import { Link } from 'react-router'; | ||
6 | import { Input, Button } from '@meetfranz/forms'; | ||
7 | |||
8 | import Form from '../../../lib/Form'; | ||
9 | import Workspace from '../models/Workspace'; | ||
10 | |||
11 | const messages = defineMessages({ | ||
12 | buttonDelete: { | ||
13 | id: 'settings.workspace.form.buttonDelete', | ||
14 | defaultMessage: '!!!Delete workspace', | ||
15 | }, | ||
16 | buttonSave: { | ||
17 | id: 'settings.workspace.form.buttonSave', | ||
18 | defaultMessage: '!!!Save workspace', | ||
19 | }, | ||
20 | name: { | ||
21 | id: 'settings.workspace.form.name', | ||
22 | defaultMessage: '!!!Name', | ||
23 | }, | ||
24 | yourWorkspaces: { | ||
25 | id: 'settings.workspace.form.yourWorkspaces', | ||
26 | defaultMessage: '!!!Your workspaces', | ||
27 | }, | ||
28 | }); | ||
29 | |||
30 | @observer | ||
31 | class EditWorkspaceForm extends Component { | ||
32 | static contextTypes = { | ||
33 | intl: intlShape, | ||
34 | }; | ||
35 | |||
36 | static propTypes = { | ||
37 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
38 | onSave: PropTypes.func.isRequired, | ||
39 | onDelete: PropTypes.func.isRequired, | ||
40 | isSaving: PropTypes.bool.isRequired, | ||
41 | isDeleting: PropTypes.bool.isRequired, | ||
42 | }; | ||
43 | |||
44 | prepareForm(workspace) { | ||
45 | const { intl } = this.context; | ||
46 | const config = { | ||
47 | fields: { | ||
48 | name: { | ||
49 | label: intl.formatMessage(messages.name), | ||
50 | placeholder: intl.formatMessage(messages.name), | ||
51 | value: workspace.name, | ||
52 | }, | ||
53 | }, | ||
54 | }; | ||
55 | return new Form(config); | ||
56 | } | ||
57 | |||
58 | submitForm(submitEvent, form) { | ||
59 | submitEvent.preventDefault(); | ||
60 | form.submit({ | ||
61 | onSuccess: async (f) => { | ||
62 | const { onSave } = this.props; | ||
63 | const values = f.values(); | ||
64 | onSave(values); | ||
65 | }, | ||
66 | onError: async () => {}, | ||
67 | }); | ||
68 | } | ||
69 | |||
70 | render() { | ||
71 | const { intl } = this.context; | ||
72 | const { | ||
73 | workspace, | ||
74 | isDeleting, | ||
75 | isSaving, | ||
76 | onDelete, | ||
77 | } = this.props; | ||
78 | if (!workspace) return null; | ||
79 | |||
80 | const form = this.prepareForm(workspace); | ||
81 | |||
82 | return ( | ||
83 | <div className="settings__main"> | ||
84 | <div className="settings__header"> | ||
85 | <span className="settings__header-item"> | ||
86 | <Link to="/settings/workspaces"> | ||
87 | {intl.formatMessage(messages.yourWorkspaces)} | ||
88 | </Link> | ||
89 | </span> | ||
90 | <span className="separator" /> | ||
91 | <span className="settings__header-item"> | ||
92 | {workspace.name} | ||
93 | </span> | ||
94 | </div> | ||
95 | <div className="settings__body"> | ||
96 | <form onSubmit={e => this.submitForm(e, form)} id="form"> | ||
97 | <div className="workspace-name"> | ||
98 | <Input {...form.$('name').bind()} /> | ||
99 | </div> | ||
100 | </form> | ||
101 | </div> | ||
102 | <div className="settings__controls"> | ||
103 | {/* ===== Delete Button ===== */} | ||
104 | {isDeleting ? ( | ||
105 | <Button | ||
106 | label={intl.formatMessage(messages.buttonDelete)} | ||
107 | loaded={false} | ||
108 | buttonType="secondary" | ||
109 | className="settings__delete-button" | ||
110 | disabled | ||
111 | /> | ||
112 | ) : ( | ||
113 | <Button | ||
114 | buttonType="danger" | ||
115 | label={intl.formatMessage(messages.buttonDelete)} | ||
116 | className="settings__delete-button" | ||
117 | onClick={onDelete} | ||
118 | /> | ||
119 | )} | ||
120 | {/* ===== Save Button ===== */} | ||
121 | {isSaving ? ( | ||
122 | <Button | ||
123 | type="submit" | ||
124 | label={intl.formatMessage(messages.buttonSave)} | ||
125 | loaded={!isSaving} | ||
126 | buttonType="secondary" | ||
127 | disabled | ||
128 | /> | ||
129 | ) : ( | ||
130 | <Button | ||
131 | type="submit" | ||
132 | label={intl.formatMessage(messages.buttonSave)} | ||
133 | htmlForm="form" | ||
134 | /> | ||
135 | )} | ||
136 | </div> | ||
137 | </div> | ||
138 | ); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | export default EditWorkspaceForm; | ||