Browse Source

$store.dispatch > $toasted 토스트 메세지 알림

김보경 5 years ago
parent
commit
94bee04dce
2 changed files with 24 additions and 3 deletions
  1. 10 2
      pages/instructor/course/_id/manage.vue
  2. 14 1
      store/instructor/course.js

+ 10 - 2
pages/instructor/course/_id/manage.vue

@@ -6,7 +6,7 @@
       <template #actionMenu>
         <div class="full-page-takeover-header-button">
           <button
-            @click="() => {}"
+            @click="updateCourse"
             class="button is-primary is-inverted is-medium is-outlined">
             Save
           </button>
@@ -120,7 +120,15 @@ export default {
   methods: {
     handleCourseUpdate({value, field}){
       this.$store.dispatch('instructor/course/updateCourseValue', {field, value})
-    }
+    },
+    async updateCourse() {
+      try{
+        await this.$store.dispatch('instructor/course/updateCourse')
+        this.$toasted.success('Course has been succefuly updated!', {duration: 3000})
+      }catch(error){
+        this.$toasted.error('Course cannot be updated!'), {duration: 3000}
+      }
+    },
   }
 }
 </script>

+ 14 - 1
store/instructor/course.js

@@ -46,7 +46,20 @@ export const actions = {
   },
   updateCourseValue({commit}, {value, field}) {
     commit('setCourseValue', {value, field})
-  }
+  },
+  async updateCourse({state, commit}) {
+    try {
+      console.log('instructor/course.js actions updateCourse call axios.$patch->course')
+      const course = await this.$axios.$patch(`/api/v1/products/${state.item._id}`, state.item)
+      console.log('instructor/course.js actions updateCourse done axios.$patch->course')
+      console.log('courses.js mutations call setCourse')
+      commit('setCourse', course)
+      console.log('courses.js mutations done setCourse')
+      return state.item
+    } catch (error) {
+      return error
+    }
+  },
 }
 
 export const mutations = {