diff options
Diffstat (limited to 'src/features/workspaces/containers/EditWorkspaceScreen.tsx')
-rw-r--r-- | src/features/workspaces/containers/EditWorkspaceScreen.tsx | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/features/workspaces/containers/EditWorkspaceScreen.tsx b/src/features/workspaces/containers/EditWorkspaceScreen.tsx new file mode 100644 index 000000000..8e8f8179d --- /dev/null +++ b/src/features/workspaces/containers/EditWorkspaceScreen.tsx | |||
@@ -0,0 +1,61 @@ | |||
1 | import { Component } from 'react'; | ||
2 | import { inject, observer } from 'mobx-react'; | ||
3 | |||
4 | import ErrorBoundary from '../../../components/util/ErrorBoundary'; | ||
5 | import EditWorkspaceForm from '../components/EditWorkspaceForm'; | ||
6 | import Workspace from '../models/Workspace'; | ||
7 | import { workspaceStore } from '../index'; | ||
8 | import { deleteWorkspaceRequest, updateWorkspaceRequest } from '../api'; | ||
9 | import { ServicesStore, WorkspacesStore } from '../../../stores.types'; | ||
10 | |||
11 | type Props = { | ||
12 | actions: { | ||
13 | workspaces: WorkspacesStore; | ||
14 | }; | ||
15 | stores: { | ||
16 | services: ServicesStore; | ||
17 | }; | ||
18 | }; | ||
19 | |||
20 | @inject('stores', 'actions') | ||
21 | @observer | ||
22 | class EditWorkspaceScreen extends Component<Props> { | ||
23 | // @ts-expect-error Not all code paths return a value. | ||
24 | onDelete = () => { | ||
25 | const { workspaceBeingEdited } = workspaceStore; | ||
26 | const { actions } = this.props; | ||
27 | if (!workspaceBeingEdited) return null; | ||
28 | actions.workspaces.delete({ workspace: workspaceBeingEdited }); | ||
29 | }; | ||
30 | |||
31 | onSave = values => { | ||
32 | const { workspaceBeingEdited } = workspaceStore; | ||
33 | const { actions } = this.props; | ||
34 | const workspace = new Workspace({ | ||
35 | saving: true, | ||
36 | ...workspaceBeingEdited, | ||
37 | ...values, | ||
38 | }); | ||
39 | actions.workspaces.update({ workspace }); | ||
40 | }; | ||
41 | |||
42 | render() { | ||
43 | const { workspaceBeingEdited } = workspaceStore; | ||
44 | const { stores } = this.props; | ||
45 | if (!workspaceBeingEdited) return null; | ||
46 | return ( | ||
47 | <ErrorBoundary> | ||
48 | <EditWorkspaceForm | ||
49 | workspace={workspaceBeingEdited} | ||
50 | services={stores.services.all} | ||
51 | onDelete={this.onDelete} | ||
52 | onSave={this.onSave} | ||
53 | updateWorkspaceRequest={updateWorkspaceRequest} | ||
54 | deleteWorkspaceRequest={deleteWorkspaceRequest} | ||
55 | /> | ||
56 | </ErrorBoundary> | ||
57 | ); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | export default EditWorkspaceScreen; | ||