diff options
Diffstat (limited to 'src/features')
-rw-r--r-- | src/features/workspaces/actions.js | 3 | ||||
-rw-r--r-- | src/features/workspaces/api.js | 18 | ||||
-rw-r--r-- | src/features/workspaces/containers/EditWorkspaceScreen.js | 14 | ||||
-rw-r--r-- | src/features/workspaces/containers/WorkspacesScreen.js | 6 | ||||
-rw-r--r-- | src/features/workspaces/store.js | 11 |
5 files changed, 42 insertions, 10 deletions
diff --git a/src/features/workspaces/actions.js b/src/features/workspaces/actions.js index 390af0696..83d3447c3 100644 --- a/src/features/workspaces/actions.js +++ b/src/features/workspaces/actions.js | |||
@@ -8,4 +8,7 @@ export default { | |||
8 | create: { | 8 | create: { |
9 | name: PropTypes.string.isRequired, | 9 | name: PropTypes.string.isRequired, |
10 | }, | 10 | }, |
11 | delete: { | ||
12 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
13 | }, | ||
11 | }; | 14 | }; |
diff --git a/src/features/workspaces/api.js b/src/features/workspaces/api.js index 65108a077..fabc12455 100644 --- a/src/features/workspaces/api.js +++ b/src/features/workspaces/api.js | |||
@@ -1,21 +1,27 @@ | |||
1 | import { prepareAuthRequest } from '../../api/utils/auth'; | 1 | import { sendAuthRequest } from '../../api/utils/auth'; |
2 | import { API, API_VERSION } from '../../environment'; | 2 | import { API, API_VERSION } from '../../environment'; |
3 | 3 | ||
4 | export default { | 4 | export default { |
5 | getUserWorkspaces: async () => { | 5 | getUserWorkspaces: async () => { |
6 | const url = `${API}/${API_VERSION}/workspace`; | 6 | const url = `${API}/${API_VERSION}/workspace`; |
7 | const request = await window.fetch(url, prepareAuthRequest({ | 7 | const request = await sendAuthRequest(url, { method: 'GET' }); |
8 | method: 'GET', | ||
9 | })); | ||
10 | if (!request.ok) throw request; | 8 | if (!request.ok) throw request; |
11 | return request.json(); | 9 | return request.json(); |
12 | }, | 10 | }, |
11 | |||
13 | createWorkspace: async (name) => { | 12 | createWorkspace: async (name) => { |
14 | const url = `${API}/${API_VERSION}/workspace`; | 13 | const url = `${API}/${API_VERSION}/workspace`; |
15 | const request = await window.fetch(url, prepareAuthRequest({ | 14 | const request = await sendAuthRequest(url, { |
16 | method: 'POST', | 15 | method: 'POST', |
17 | body: JSON.stringify({ name }), | 16 | body: JSON.stringify({ name }), |
18 | })); | 17 | }); |
18 | if (!request.ok) throw request; | ||
19 | return request.json(); | ||
20 | }, | ||
21 | |||
22 | deleteWorkspace: async (workspace) => { | ||
23 | const url = `${API}/${API_VERSION}/workspace/${workspace.id}`; | ||
24 | const request = await sendAuthRequest(url, { method: 'DELETE' }); | ||
19 | if (!request.ok) throw request; | 25 | if (!request.ok) throw request; |
20 | return request.json(); | 26 | return request.json(); |
21 | }, | 27 | }, |
diff --git a/src/features/workspaces/containers/EditWorkspaceScreen.js b/src/features/workspaces/containers/EditWorkspaceScreen.js index ed54b194e..87b6062fb 100644 --- a/src/features/workspaces/containers/EditWorkspaceScreen.js +++ b/src/features/workspaces/containers/EditWorkspaceScreen.js | |||
@@ -5,15 +5,27 @@ import ErrorBoundary from '../../../components/util/ErrorBoundary'; | |||
5 | import { gaPage } from '../../../lib/analytics'; | 5 | import { gaPage } from '../../../lib/analytics'; |
6 | import { state } from '../state'; | 6 | import { state } from '../state'; |
7 | import EditWorkspaceForm from '../components/EditWorkspaceForm'; | 7 | import EditWorkspaceForm from '../components/EditWorkspaceForm'; |
8 | import PropTypes from 'prop-types'; | ||
8 | 9 | ||
9 | @inject('stores', 'actions') @observer | 10 | @inject('stores', 'actions') @observer |
10 | class EditWorkspaceScreen extends Component { | 11 | class EditWorkspaceScreen extends Component { |
12 | static propTypes = { | ||
13 | actions: PropTypes.shape({ | ||
14 | workspace: PropTypes.shape({ | ||
15 | delete: PropTypes.func.isRequired, | ||
16 | }), | ||
17 | }).isRequired, | ||
18 | }; | ||
19 | |||
11 | componentDidMount() { | 20 | componentDidMount() { |
12 | gaPage('Settings/Workspace/Edit'); | 21 | gaPage('Settings/Workspace/Edit'); |
13 | } | 22 | } |
14 | 23 | ||
15 | onDelete = () => { | 24 | onDelete = () => { |
16 | console.log('delete workspace'); | 25 | const { workspaceBeingEdited } = state; |
26 | const { actions } = this.props; | ||
27 | if (!workspaceBeingEdited) return null; | ||
28 | actions.workspace.delete({ workspace: workspaceBeingEdited }); | ||
17 | }; | 29 | }; |
18 | 30 | ||
19 | onSave = (values) => { | 31 | onSave = (values) => { |
diff --git a/src/features/workspaces/containers/WorkspacesScreen.js b/src/features/workspaces/containers/WorkspacesScreen.js index eb3287952..a3876a01a 100644 --- a/src/features/workspaces/containers/WorkspacesScreen.js +++ b/src/features/workspaces/containers/WorkspacesScreen.js | |||
@@ -21,14 +21,14 @@ class WorkspacesScreen extends Component { | |||
21 | } | 21 | } |
22 | 22 | ||
23 | render() { | 23 | render() { |
24 | const { workspace } = this.props.actions; | 24 | const { actions } = this.props; |
25 | return ( | 25 | return ( |
26 | <ErrorBoundary> | 26 | <ErrorBoundary> |
27 | <WorkspacesDashboard | 27 | <WorkspacesDashboard |
28 | workspaces={state.workspaces} | 28 | workspaces={state.workspaces} |
29 | isLoading={state.isLoading} | 29 | isLoading={state.isLoading} |
30 | onCreateWorkspaceSubmit={data => workspace.create(data)} | 30 | onCreateWorkspaceSubmit={data => actions.workspace.create(data)} |
31 | onWorkspaceClick={w => workspace.edit({ workspace: w })} | 31 | onWorkspaceClick={w => actions.workspace.edit({ workspace: w })} |
32 | /> | 32 | /> |
33 | </ErrorBoundary> | 33 | </ErrorBoundary> |
34 | ); | 34 | ); |
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index d90f9caac..a9b93f904 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js | |||
@@ -50,6 +50,7 @@ export default class WorkspacesStore extends Store { | |||
50 | 50 | ||
51 | this.actions.workspace.edit.listen(this._edit); | 51 | this.actions.workspace.edit.listen(this._edit); |
52 | this.actions.workspace.create.listen(this._create); | 52 | this.actions.workspace.create.listen(this._create); |
53 | this.actions.workspace.delete.listen(this._delete); | ||
53 | } | 54 | } |
54 | 55 | ||
55 | _setWorkspaces = (workspaces) => { | 56 | _setWorkspaces = (workspaces) => { |
@@ -77,4 +78,14 @@ export default class WorkspacesStore extends Store { | |||
77 | throw error; | 78 | throw error; |
78 | } | 79 | } |
79 | }; | 80 | }; |
81 | |||
82 | _delete = async ({ workspace }) => { | ||
83 | try { | ||
84 | await this.api.deleteWorkspace(workspace); | ||
85 | this.state.workspaces.remove(workspace); | ||
86 | this.stores.router.push('/settings/workspaces'); | ||
87 | } catch (error) { | ||
88 | throw error; | ||
89 | } | ||
90 | }; | ||
80 | } | 91 | } |