Commit ff6acdf1 authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Implement discussion reply.

parent 905ad9cd
......@@ -17,6 +17,7 @@ export default {
return {
registerLink: '#',
signInLink: '#',
newNotePath: '',
isReplying: false,
};
},
......@@ -45,6 +46,9 @@ export default {
this.registerLink = registerLink.getAttribute('href');
this.signInLink = signInLink.getAttribute('href');
}
const newNotePath = document.querySelector('.js-main-target-form').getAttribute('action');
this.newNotePath = `${newNotePath}?full_data=1`;
},
methods: {
toggleDiscussion() {
......@@ -58,8 +62,21 @@ export default {
cancelReplyForm() {
this.isReplying = false;
},
saveReply() {
this.isReplying = false;
saveReply({ note }) {
const data = {
endpoint: this.newNotePath,
reply: {
in_reply_to_discussion_id: this.note.reply_id,
target_type: 'issue',
target_id: this.discussion.noteable_id,
note: { note },
},
};
this.$store.dispatch('replyToDiscussion', data)
.then(() => {
this.isReplying = false;
});
},
},
};
......
......@@ -10,4 +10,7 @@ export default {
deleteNote(endpoint) {
return Vue.http.delete(endpoint);
},
replyToDiscussion(endpoint, data) {
return Vue.http.post(endpoint, data, { emulateJSON: true });
},
};
......@@ -38,6 +38,11 @@ const mutations = {
}
}
},
addNewReplyToDiscussion(storeState, note) {
const noteObj = findNoteObjectById(storeState.notes, note.discussion_id);
noteObj.notes.push(note);
},
};
const actions = {
......@@ -62,6 +67,19 @@ const actions = {
new Flash('Something went wrong while deleting your note. Please try again.'); // eslint-disable-line
});
},
replyToDiscussion(context, data) {
const { endpoint, reply } = data;
return service
.replyToDiscussion(endpoint, reply)
.then((res) => res.json())
.then((res) => {
context.commit('addNewReplyToDiscussion', res);
})
.catch(() => {
new Flash('Something went wrong while adding your reply. Please try again.'); // eslint-disable-line
});
},
};
export default {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment