@@ -24,22 +24,39 @@ export const mutations = {
2424}
2525
2626export const actions = {
27- createEvent ( { commit } , event ) {
28- return EventService . postEvent ( event ) . then ( ( ) => {
29- commit ( 'ADD_EVENT' , event )
30- } )
27+ createEvent ( { commit, dispatch } , event ) {
28+ return EventService . postEvent ( event )
29+ . then ( ( ) => {
30+ commit ( 'ADD_EVENT' , event )
31+ const notification = {
32+ type : 'success' ,
33+ message : 'Your event has been created!'
34+ }
35+ dispatch ( 'notification/add' , notification , { root : true } )
36+ } )
37+ . catch ( error => {
38+ const notification = {
39+ type : 'error' ,
40+ message : 'There was a problem creating your event: ' + error . message
41+ }
42+ dispatch ( 'notification/add' , notification , { root : true } )
43+ } )
3144 } ,
32- fetchEvents ( { commit } , { perPage, page } ) {
45+ fetchEvents ( { commit, dispatch } , { perPage, page } ) {
3346 EventService . getEvents ( perPage , page )
3447 . then ( response => {
3548 commit ( 'SET_EVENTS_TOTAL' , parseInt ( response . headers [ 'x-total-count' ] ) )
3649 commit ( 'SET_EVENTS' , response . data )
3750 } )
3851 . catch ( error => {
39- console . log ( 'There was an error:' , error . response )
52+ const notification = {
53+ type : 'error' ,
54+ message : 'There was a problem fetching events: ' + error . message
55+ }
56+ dispatch ( 'notification/add' , notification , { root : true } )
4057 } )
4158 } ,
42- fetchEvent ( { commit, getters } , id ) {
59+ fetchEvent ( { commit, getters, dispatch } , id ) {
4360 var event = getters . getEventById ( id )
4461
4562 if ( event ) {
@@ -50,7 +67,11 @@ export const actions = {
5067 commit ( 'SET_EVENT' , response . data )
5168 } )
5269 . catch ( error => {
53- console . log ( 'There was an error:' , error . response )
70+ const notification = {
71+ type : 'error' ,
72+ message : 'There was a problem fetching event: ' + error . message
73+ }
74+ dispatch ( 'notification/add' , notification , { root : true } )
5475 } )
5576 }
5677 }
0 commit comments