|
@@ -1,10 +1,10 @@
|
1
|
1
|
import React from 'react'
|
2
|
2
|
import {
|
3
|
|
- CardPopupCreateContent
|
|
3
|
+ CardPopupCreateContent, handleFetchResult
|
4
|
4
|
} from 'tracim_lib'
|
5
|
|
-import { FETCH_CONFIG } from '../helper.js'
|
|
5
|
+import { postHtmlDocContent } from '../action.async.js'
|
6
|
6
|
|
7
|
|
-const debug = {
|
|
7
|
+const debug = { // outdated
|
8
|
8
|
config: {
|
9
|
9
|
label: 'Text Document',
|
10
|
10
|
slug: 'html-documents',
|
|
@@ -43,7 +43,6 @@ class PopupCreateHtmlDocument extends React.Component {
|
43
|
43
|
idFolder: props.data ? props.data.idFolder : debug.idFolder,
|
44
|
44
|
newContentName: ''
|
45
|
45
|
}
|
46
|
|
- this.handleValidate = this.handleValidate.bind(this)
|
47
|
46
|
}
|
48
|
47
|
|
49
|
48
|
handleChangeNewContentName = e => this.setState({newContentName: e.target.value})
|
|
@@ -55,31 +54,26 @@ class PopupCreateHtmlDocument extends React.Component {
|
55
|
54
|
}
|
56
|
55
|
})
|
57
|
56
|
|
58
|
|
- async handleValidate () {
|
59
|
|
- const fetchSaveNewHtmlDoc = await fetch(`${this.state.config.apiUrl}/workspaces/${this.state.idWorkspace}/contents`, {
|
60
|
|
- ...FETCH_CONFIG,
|
61
|
|
- method: 'POST',
|
62
|
|
- body: JSON.stringify({
|
63
|
|
- parent_id: this.state.idFolder,
|
64
|
|
- content_type: this.state.config.slug,
|
65
|
|
- label: this.state.newContentName
|
66
|
|
- })
|
67
|
|
- })
|
|
57
|
+ handleValidate = async () => {
|
|
58
|
+ const { config, appName, idWorkspace, idFolder, newContentName } = this.state
|
68
|
59
|
|
69
|
|
- if (fetchSaveNewHtmlDoc.status === 200) {
|
70
|
|
- const jsonSaveNewHtmlDoc = await fetchSaveNewHtmlDoc.json()
|
|
60
|
+ const fetchSaveNewHtmlDoc = postHtmlDocContent(config.apiUrl, idWorkspace, idFolder, config.slug, newContentName)
|
71
|
61
|
|
72
|
|
- this.handleClose()
|
|
62
|
+ handleFetchResult(await fetchSaveNewHtmlDoc)
|
|
63
|
+ .then(resSave => {
|
|
64
|
+ if (resSave.apiResponse.status === 200) {
|
|
65
|
+ this.handleClose()
|
73
|
66
|
|
74
|
|
- GLOBAL_dispatchEvent({
|
75
|
|
- type: 'openContentUrl', // handled by tracim_front:src/container/WorkspaceContent.jsx
|
76
|
|
- data: {
|
77
|
|
- idWorkspace: jsonSaveNewHtmlDoc.workspace_id,
|
78
|
|
- contentType: this.state.appName,
|
79
|
|
- idContent: jsonSaveNewHtmlDoc.id
|
|
67
|
+ GLOBAL_dispatchEvent({
|
|
68
|
+ type: 'openContentUrl', // handled by tracim_front:src/container/WorkspaceContent.jsx
|
|
69
|
+ data: {
|
|
70
|
+ idWorkspace: resSave.body.workspace_id,
|
|
71
|
+ contentType: appName,
|
|
72
|
+ idContent: resSave.body.content_id
|
|
73
|
+ }
|
|
74
|
+ })
|
80
|
75
|
}
|
81
|
76
|
})
|
82
|
|
- }
|
83
|
77
|
}
|
84
|
78
|
|
85
|
79
|
render () {
|