diff options
author | 2019-04-11 12:00:07 +0200 | |
---|---|---|
committer | 2019-04-11 12:00:07 +0200 | |
commit | e43d6bd80b3d76aae627fa8174eea98c14016549 (patch) | |
tree | de1d0a3ba10100ce68d0cb1ed618095e362fe573 /src/features/workspaces/containers/EditWorkspaceScreen.js | |
parent | implements basic release announcement feature (diff) | |
parent | handle deleted services that are attached to workspaces (diff) | |
download | ferdium-app-e43d6bd80b3d76aae627fa8174eea98c14016549.tar.gz ferdium-app-e43d6bd80b3d76aae627fa8174eea98c14016549.tar.zst ferdium-app-e43d6bd80b3d76aae627fa8174eea98c14016549.zip |
merge-in workspace feature
Diffstat (limited to 'src/features/workspaces/containers/EditWorkspaceScreen.js')
-rw-r--r-- | src/features/workspaces/containers/EditWorkspaceScreen.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/features/workspaces/containers/EditWorkspaceScreen.js b/src/features/workspaces/containers/EditWorkspaceScreen.js new file mode 100644 index 000000000..248b40131 --- /dev/null +++ b/src/features/workspaces/containers/EditWorkspaceScreen.js | |||
@@ -0,0 +1,60 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import { inject, observer } from 'mobx-react'; | ||
3 | import PropTypes from 'prop-types'; | ||
4 | |||
5 | import ErrorBoundary from '../../../components/util/ErrorBoundary'; | ||
6 | import EditWorkspaceForm from '../components/EditWorkspaceForm'; | ||
7 | import ServicesStore from '../../../stores/ServicesStore'; | ||
8 | import Workspace from '../models/Workspace'; | ||
9 | import { workspaceStore } from '../index'; | ||
10 | import { deleteWorkspaceRequest, updateWorkspaceRequest } from '../api'; | ||
11 | |||
12 | @inject('stores', 'actions') @observer | ||
13 | class EditWorkspaceScreen extends Component { | ||
14 | static propTypes = { | ||
15 | actions: PropTypes.shape({ | ||
16 | workspace: PropTypes.shape({ | ||
17 | delete: PropTypes.func.isRequired, | ||
18 | }), | ||
19 | }).isRequired, | ||
20 | stores: PropTypes.shape({ | ||
21 | services: PropTypes.instanceOf(ServicesStore).isRequired, | ||
22 | }).isRequired, | ||
23 | }; | ||
24 | |||
25 | onDelete = () => { | ||
26 | const { workspaceBeingEdited } = workspaceStore; | ||
27 | const { actions } = this.props; | ||
28 | if (!workspaceBeingEdited) return null; | ||
29 | actions.workspaces.delete({ workspace: workspaceBeingEdited }); | ||
30 | }; | ||
31 | |||
32 | onSave = (values) => { | ||
33 | const { workspaceBeingEdited } = workspaceStore; | ||
34 | const { actions } = this.props; | ||
35 | const workspace = new Workspace( | ||
36 | Object.assign({}, workspaceBeingEdited, values), | ||
37 | ); | ||
38 | actions.workspaces.update({ workspace }); | ||
39 | }; | ||
40 | |||
41 | render() { | ||
42 | const { workspaceBeingEdited } = workspaceStore; | ||
43 | const { stores } = this.props; | ||
44 | if (!workspaceBeingEdited) return null; | ||
45 | return ( | ||
46 | <ErrorBoundary> | ||
47 | <EditWorkspaceForm | ||
48 | workspace={workspaceBeingEdited} | ||
49 | services={stores.services.all} | ||
50 | onDelete={this.onDelete} | ||
51 | onSave={this.onSave} | ||
52 | updateWorkspaceRequest={updateWorkspaceRequest} | ||
53 | deleteWorkspaceRequest={deleteWorkspaceRequest} | ||
54 | /> | ||
55 | </ErrorBoundary> | ||
56 | ); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | export default EditWorkspaceScreen; | ||