diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-11 16:54:01 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2019-04-11 16:54:01 +0200 |
commit | 47c1c99d893517efc679ab29d675cc0bf44be8be (patch) | |
tree | 9cab9697096bef0ce56d8ee8709bc1c2c3a42deb /src/features/workspaces/components/EditWorkspaceForm.js | |
parent | test package order (diff) | |
download | ferdium-app-47c1c99d893517efc679ab29d675cc0bf44be8be.tar.gz ferdium-app-47c1c99d893517efc679ab29d675cc0bf44be8be.tar.zst ferdium-app-47c1c99d893517efc679ab29d675cc0bf44be8be.zip |
feat(App): Added Workspaces for all your daily routines 🥳
* merge default and fetched feature configs
* ignore intellij project files
* basic setup for workspaces feature
* define workspaces as premium feature
* add workspaces menu item in settings dialog
* basic setup of workspaces settings screen
* fix eslint error
* assign react key prop to workspace items
* add styles for workspace table
* setup logic to display workspace edit page
* consolidate workspace feature for further development
* prepare basic workspace edit form
* add on enter key handler for form input component
* add form for creating workspaces
* small fixes
* adds flow for deleting workspaces
* stop tracking google analytics in components
* pin gulp-sass-variables version to 1.1.1
* fix merge conflict
* fix bug in form input library
* improve workspace form setup
* finish basic workspace settings
* finish workspaces mvp
* fix eslint issues
* remove dev logs
* detach service when underlying webview unmounts
* disable no-param-reassign eslint rule
* add workspace drawer
* change workspace switch shortcuts to start with zero
* add workspace drawer toggle menu item and shortcut
* improve workspace switching ux
* style add workspace icon in drawer like the sidebar icons
* improve workspace drawer layout
* add i18n messages for service loading and workspace switching
* small fixes
* add tooltip to add workspace button in drawer
* add workspaces count badge in settings navigation
* fix merge conflicts with latest develop
* refactor state management for workspace feature
* reset api requests when workspace feature is stopped
* hide workspace feature if it is disabled
* handle get workspaces request errors in the ui
* show infobox when updating workspaces
* indicate any server interaction with spinners and infoboxes
* add analytic events for workspace actions
* improve styling of workspace switch indicator
* add workspace premium notice to dashboard
* add workspace feature info in drawer for free users
* add workspace premium badge in settings nav
* fix premium workspace badge in settings menu for light theme
* fix active workspaces settings premium badge in light theme
* give upgrade account button a bit more padding
* add open last used workspace logic
* use mobx-localstorage directly in the store
* fix wrong workspace tooltip shortcut in sidebar
* fix bug in workspace feature initialization
* show workspaces intro in drawer when user has none yet
* fix issues for users that have workspace but downgraded to free
* border radius for premium intro in workspace settings
* close workspace drawer after clicking on a workspace
* add hover effect for drawer workspace items
* ensure drawer is open on workspace settings routes
* add small text label for adding new workspace to drawer
* make workspace settings list items taller
* refactor workspace table css away from legacy styles
* render workspace service list like services + toggle
* change plus icon in workspace drawer to settings icon
* autofocus create workspace input field
* add css transition to drawer workspace item hover
* fix drawer add workspace label styles
* refactors workspace theme vars into object structure
* improve contrast of workspace switching indicator
* added generic pro badge component for settings nav
* add premium badge to workspace drawer headline
* add context menu for workspace drawer items
* handle deleted services that are attached to workspaces
Diffstat (limited to 'src/features/workspaces/components/EditWorkspaceForm.js')
-rw-r--r-- | src/features/workspaces/components/EditWorkspaceForm.js | 189 |
1 files changed, 189 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..bba4485ff --- /dev/null +++ b/src/features/workspaces/components/EditWorkspaceForm.js | |||
@@ -0,0 +1,189 @@ | |||
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 | import injectSheet from 'react-jss'; | ||
8 | |||
9 | import Workspace from '../models/Workspace'; | ||
10 | import Service from '../../../models/Service'; | ||
11 | import Form from '../../../lib/Form'; | ||
12 | import { required } from '../../../helpers/validation-helpers'; | ||
13 | import WorkspaceServiceListItem from './WorkspaceServiceListItem'; | ||
14 | import Request from '../../../stores/lib/Request'; | ||
15 | import { gaEvent } from '../../../lib/analytics'; | ||
16 | import { GA_CATEGORY_WORKSPACES } from '../index'; | ||
17 | |||
18 | const messages = defineMessages({ | ||
19 | buttonDelete: { | ||
20 | id: 'settings.workspace.form.buttonDelete', | ||
21 | defaultMessage: '!!!Delete workspace', | ||
22 | }, | ||
23 | buttonSave: { | ||
24 | id: 'settings.workspace.form.buttonSave', | ||
25 | defaultMessage: '!!!Save workspace', | ||
26 | }, | ||
27 | name: { | ||
28 | id: 'settings.workspace.form.name', | ||
29 | defaultMessage: '!!!Name', | ||
30 | }, | ||
31 | yourWorkspaces: { | ||
32 | id: 'settings.workspace.form.yourWorkspaces', | ||
33 | defaultMessage: '!!!Your workspaces', | ||
34 | }, | ||
35 | servicesInWorkspaceHeadline: { | ||
36 | id: 'settings.workspace.form.servicesInWorkspaceHeadline', | ||
37 | defaultMessage: '!!!Services in this Workspace', | ||
38 | }, | ||
39 | }); | ||
40 | |||
41 | const styles = () => ({ | ||
42 | nameInput: { | ||
43 | height: 'auto', | ||
44 | }, | ||
45 | serviceList: { | ||
46 | height: 'auto', | ||
47 | }, | ||
48 | }); | ||
49 | |||
50 | @injectSheet(styles) @observer | ||
51 | class EditWorkspaceForm extends Component { | ||
52 | static contextTypes = { | ||
53 | intl: intlShape, | ||
54 | }; | ||
55 | |||
56 | static propTypes = { | ||
57 | classes: PropTypes.object.isRequired, | ||
58 | onDelete: PropTypes.func.isRequired, | ||
59 | onSave: PropTypes.func.isRequired, | ||
60 | services: PropTypes.arrayOf(PropTypes.instanceOf(Service)).isRequired, | ||
61 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
62 | updateWorkspaceRequest: PropTypes.instanceOf(Request).isRequired, | ||
63 | deleteWorkspaceRequest: PropTypes.instanceOf(Request).isRequired, | ||
64 | }; | ||
65 | |||
66 | form = this.prepareWorkspaceForm(this.props.workspace); | ||
67 | |||
68 | componentWillReceiveProps(nextProps) { | ||
69 | const { workspace } = this.props; | ||
70 | if (workspace.id !== nextProps.workspace.id) { | ||
71 | this.form = this.prepareWorkspaceForm(nextProps.workspace); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | prepareWorkspaceForm(workspace) { | ||
76 | const { intl } = this.context; | ||
77 | return new Form({ | ||
78 | fields: { | ||
79 | name: { | ||
80 | label: intl.formatMessage(messages.name), | ||
81 | placeholder: intl.formatMessage(messages.name), | ||
82 | value: workspace.name, | ||
83 | validators: [required], | ||
84 | }, | ||
85 | services: { | ||
86 | value: workspace.services.slice(), | ||
87 | }, | ||
88 | }, | ||
89 | }); | ||
90 | } | ||
91 | |||
92 | save(form) { | ||
93 | form.submit({ | ||
94 | onSuccess: async (f) => { | ||
95 | const { onSave } = this.props; | ||
96 | const values = f.values(); | ||
97 | onSave(values); | ||
98 | gaEvent(GA_CATEGORY_WORKSPACES, 'save'); | ||
99 | }, | ||
100 | onError: async () => {}, | ||
101 | }); | ||
102 | } | ||
103 | |||
104 | delete() { | ||
105 | const { onDelete } = this.props; | ||
106 | onDelete(); | ||
107 | gaEvent(GA_CATEGORY_WORKSPACES, 'delete'); | ||
108 | } | ||
109 | |||
110 | toggleService(service) { | ||
111 | const servicesField = this.form.$('services'); | ||
112 | const serviceIds = servicesField.value; | ||
113 | if (serviceIds.includes(service.id)) { | ||
114 | serviceIds.splice(serviceIds.indexOf(service.id), 1); | ||
115 | } else { | ||
116 | serviceIds.push(service.id); | ||
117 | } | ||
118 | servicesField.set(serviceIds); | ||
119 | } | ||
120 | |||
121 | render() { | ||
122 | const { intl } = this.context; | ||
123 | const { | ||
124 | classes, | ||
125 | workspace, | ||
126 | services, | ||
127 | deleteWorkspaceRequest, | ||
128 | updateWorkspaceRequest, | ||
129 | } = this.props; | ||
130 | const { form } = this; | ||
131 | const workspaceServices = form.$('services').value; | ||
132 | const isDeleting = deleteWorkspaceRequest.isExecuting; | ||
133 | const isSaving = updateWorkspaceRequest.isExecuting; | ||
134 | return ( | ||
135 | <div className="settings__main"> | ||
136 | <div className="settings__header"> | ||
137 | <span className="settings__header-item"> | ||
138 | <Link to="/settings/workspaces"> | ||
139 | {intl.formatMessage(messages.yourWorkspaces)} | ||
140 | </Link> | ||
141 | </span> | ||
142 | <span className="separator" /> | ||
143 | <span className="settings__header-item"> | ||
144 | {workspace.name} | ||
145 | </span> | ||
146 | </div> | ||
147 | <div className="settings__body"> | ||
148 | <div className={classes.nameInput}> | ||
149 | <Input {...form.$('name').bind()} /> | ||
150 | </div> | ||
151 | <h2>{intl.formatMessage(messages.servicesInWorkspaceHeadline)}</h2> | ||
152 | <div className={classes.serviceList}> | ||
153 | {services.map(s => ( | ||
154 | <WorkspaceServiceListItem | ||
155 | key={s.id} | ||
156 | service={s} | ||
157 | isInWorkspace={workspaceServices.includes(s.id)} | ||
158 | onToggle={() => this.toggleService(s)} | ||
159 | /> | ||
160 | ))} | ||
161 | </div> | ||
162 | </div> | ||
163 | <div className="settings__controls"> | ||
164 | {/* ===== Delete Button ===== */} | ||
165 | <Button | ||
166 | label={intl.formatMessage(messages.buttonDelete)} | ||
167 | loaded={false} | ||
168 | busy={isDeleting} | ||
169 | buttonType={isDeleting ? 'secondary' : 'danger'} | ||
170 | className="settings__delete-button" | ||
171 | disabled={isDeleting} | ||
172 | onClick={this.delete.bind(this)} | ||
173 | /> | ||
174 | {/* ===== Save Button ===== */} | ||
175 | <Button | ||
176 | type="submit" | ||
177 | label={intl.formatMessage(messages.buttonSave)} | ||
178 | busy={isSaving} | ||
179 | buttonType={isSaving ? 'secondary' : 'primary'} | ||
180 | onClick={this.save.bind(this, form)} | ||
181 | disabled={isSaving} | ||
182 | /> | ||
183 | </div> | ||
184 | </div> | ||
185 | ); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | export default EditWorkspaceForm; | ||