diff --git a/src/store/modules/lists.js b/src/store/modules/lists.js index 21d6d076c..abce934ac 100644 --- a/src/store/modules/lists.js +++ b/src/store/modules/lists.js @@ -52,5 +52,19 @@ export default { return Promise.reject(e) }) }, + createList(ctx, list) { + const listService = new ListService() + + return listService.create(list) + .then(r => { + r.namespaceId = list.namespaceId + ctx.commit('namespaces/addListToNamespace', r, {root: true}) + ctx.commit('addList', r) + return Promise.resolve(r) + }) + .catch(e => { + return Promise.reject(e) + }) + }, }, } \ No newline at end of file diff --git a/src/views/list/NewList.vue b/src/views/list/NewList.vue index 3a132f4ab..d0889857c 100644 --- a/src/views/list/NewList.vue +++ b/src/views/list/NewList.vue @@ -64,12 +64,10 @@ export default { this.showError = false this.list.namespaceId = this.$route.params.id - this.listService.create(this.list) - .then(response => { - response.namespaceId = this.list.namespaceId - this.$store.commit('namespaces/addListToNamespace', response) + this.$store.dispatch('lists/createList', this.list) + .then(r => { this.success({message: 'The list was successfully created.'}, this) - router.push({name: 'list.index', params: {listId: response.id}}) + router.push({name: 'list.index', params: {listId: r.id}}) }) .catch(e => { this.error(e, this)