yusuketk 7 лет назад
Родитель
Сommit
e91e565c2c

+ 7 - 7
src/client/js/components/Page/EditTagModal.jsx

@@ -18,7 +18,7 @@ export default class EditTagModal extends React.Component {
       isOpenModal: false,
     };
 
-    this.addTag = this.addTag.bind(this);
+    this.addNewTag = this.addNewTag.bind(this);
     this.handleShowModal = this.handleShowModal.bind(this);
     this.handleCloseModal = this.handleCloseModal.bind(this);
     this.handleSubmit = this.handleSubmit.bind(this);
@@ -35,7 +35,8 @@ export default class EditTagModal extends React.Component {
     }
   }
 
-  addTag(newPageTags) {
+  // receive new tag from PageTagForm component
+  addNewTag(newPageTags) {
     this.setState({ newPageTags });
   }
 
@@ -47,10 +48,10 @@ export default class EditTagModal extends React.Component {
     this.setState({ isOpenModal: true });
   }
 
-  handleSubmit() {
+  async handleSubmit() {
     try {
-      this.props.crowi.apiPost('/pages.updateTags', { pageId: this.props.pageId, newPageTags: this.state.newPageTags });
-      this.setState({ currentPageTags: this.state.newPageTags, isOpenModal: false });
+      const res = await this.props.crowi.apiPost('/pages.updateTags', { pageId: this.props.pageId, newPageTags: this.state.newPageTags });
+      this.setState({ currentPageTags: res.nextTags, isOpenModal: false });
       toastr.success(undefined, 'Updated tags successfully', {
         closeButton: true,
         progressBar: true,
@@ -71,7 +72,6 @@ export default class EditTagModal extends React.Component {
         timeOut: '3000',
       });
     }
-
   }
 
   render() {
@@ -100,7 +100,7 @@ export default class EditTagModal extends React.Component {
             <Modal.Title className="text-white">ページタグ</Modal.Title>
           </Modal.Header>
           <Modal.Body>
-            <PageTagForm crowi={this.props.crowi} currentPageTags={this.state.currentPageTags} addTag={this.addTag} />
+            <PageTagForm crowi={this.props.crowi} currentPageTags={this.state.currentPageTags} addNewTag={this.addNewTag} />
           </Modal.Body>
           <Modal.Footer>
             <Button variant="primary" onClick={this.handleSubmit}>

+ 2 - 0
src/server/models/page.js

@@ -321,6 +321,8 @@ module.exports = function(crowi) {
       const setTag = await Tag.findOrCreate(tag);
       PageTagRelation.createIfNotExist(page._id, setTag._id);
     });
+
+    return newTags;
   };
 
 

+ 5 - 2
src/server/routes/page.js

@@ -681,14 +681,17 @@ module.exports = function(crowi, app) {
   api.updateTags = async function(req, res) {
     const pageId = req.body.pageId;
     const newPageTags = req.body.newPageTags;
+    const result = {};
     try {
       const page = await Page.findOne({ _id: pageId });
       // update page tag
-      await page.updateTags(newPageTags);
+      result.nextTags = await page.updateTags(newPageTags);
     }
     catch (err) {
-      throw new Error('Error occured on updating tags');
+      return res.json(ApiResponse.error(err));
     }
+
+    return res.json(ApiResponse.success(result));
   };
 
   /**