mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-30 21:21:09 -04:00 
			
		
		
		
	Add New SweetAlert & Notification Components
This commit is contained in:
		
				
					committed by
					
						 Mohit Panjwani
						Mohit Panjwani
					
				
			
			
				
	
			
			
			
						parent
						
							3f7db2793f
						
					
				
				
					commit
					c3d3e5e35f
				
			| @ -13,7 +13,6 @@ export const login = ({ commit }, data) => { | ||||
|           commit('user/' + userTypes.RESET_CURRENT_USER, null, { root: true }) | ||||
|           commit(rootTypes.UPDATE_APP_LOADING_STATUS, false, { root: true }) | ||||
|  | ||||
|           window.toastr['success']('Login Successful') | ||||
|           resolve(response) | ||||
|         }) | ||||
|         .catch((err) => { | ||||
| @ -28,7 +27,7 @@ export const setLogoutFalse = ({ state, commit }) => { | ||||
|   commit(types.SET_LOGOUT, false) | ||||
| } | ||||
|  | ||||
| export const logout = ({ state, commit }) => { | ||||
| export const logout = ({ state, commit, dispatch }) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     if (state.isLoggedOut) { | ||||
|       resolve() | ||||
| @ -40,7 +39,14 @@ export const logout = ({ state, commit }) => { | ||||
|       .get('/auth/logout') | ||||
|       .then(() => { | ||||
|         router.push('/login') | ||||
|         window.toastr['success']('Logged out!', 'Success') | ||||
|         dispatch( | ||||
|           'notification/showNotification', | ||||
|           { | ||||
|             type: 'success', | ||||
|             message: 'Logged out successfully.', | ||||
|           }, | ||||
|           { root: true } | ||||
|         ) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         router.push('/login') | ||||
|  | ||||
							
								
								
									
										27
									
								
								resources/assets/js/store/modules/notification/actions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								resources/assets/js/store/modules/notification/actions.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export const showNotification = ({ commit, dispatch, state }, payload) => { | ||||
|   commit(types.SHOW_NOTIFICATION, true) | ||||
|  | ||||
|   if (payload.type) { | ||||
|     commit(types.SET_NOTIFICATION_TYPE, payload.type) | ||||
|   } | ||||
|   if (payload.title) { | ||||
|     commit(types.SET_TITLE, payload.title) | ||||
|   } | ||||
|   if (payload.autoHide) { | ||||
|     commit(types.SET_AUTO_HIDE, payload.autoHide) | ||||
|   } | ||||
|   if (payload.message) { | ||||
|     commit(types.SET_MESSAGE, payload.message) | ||||
|   } | ||||
| } | ||||
|  | ||||
| export const hideNotification = ({ commit, dispatch, state }) => { | ||||
|   commit(types.RESET_DATA) | ||||
|   commit(types.HIDE_NOTIFICATION, false) | ||||
| } | ||||
|  | ||||
| export const resetNotificationData = ({ commit, dispatch, state }) => { | ||||
|   commit(types.RESET_DATA) | ||||
| } | ||||
| @ -0,0 +1,5 @@ | ||||
| export const notificationActive = (state) => state.active | ||||
| export const notificationTitle = (state) => state.title | ||||
| export const notificationMessage = (state) => state.message | ||||
| export const notificationAutoHide = (state) => state.autoHide | ||||
| export const notificationType = (state) => state.type | ||||
							
								
								
									
										23
									
								
								resources/assets/js/store/modules/notification/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								resources/assets/js/store/modules/notification/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | ||||
| import mutations from './mutations' | ||||
| import * as actions from './actions' | ||||
| import * as getters from './getters' | ||||
|  | ||||
| const initialState = { | ||||
|   active: false, | ||||
|   autoHide: true, | ||||
|   title: '', | ||||
|   message: '', | ||||
|   type: '', | ||||
| } | ||||
|  | ||||
| export default { | ||||
|   namespaced: true, | ||||
|  | ||||
|   state: initialState, | ||||
|  | ||||
|   getters: getters, | ||||
|  | ||||
|   actions: actions, | ||||
|  | ||||
|   mutations: mutations, | ||||
| } | ||||
| @ -0,0 +1,7 @@ | ||||
| export const SHOW_NOTIFICATION = 'SHOW_NOTIFICATION' | ||||
| export const HIDE_NOTIFICATION = 'HIDE_NOTIFICATION' | ||||
| export const SET_TITLE = 'SET_TITLE' | ||||
| export const SET_AUTO_HIDE = 'SET_AUTO_HIDE' | ||||
| export const SET_MESSAGE = 'SET_MESSAGE' | ||||
| export const SET_NOTIFICATION_TYPE = 'SET_NOTIFICATION_TYPE' | ||||
| export const RESET_DATA = 'RESET_DATA' | ||||
							
								
								
									
										33
									
								
								resources/assets/js/store/modules/notification/mutations.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								resources/assets/js/store/modules/notification/mutations.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export default { | ||||
|   [types.SHOW_NOTIFICATION](state, data) { | ||||
|     state.active = data | ||||
|   }, | ||||
|  | ||||
|   [types.HIDE_NOTIFICATION](state, data) { | ||||
|     state.active = data | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TITLE](state, data) { | ||||
|     state.title = data | ||||
|   }, | ||||
|  | ||||
|   [types.SET_AUTO_HIDE](state, data) { | ||||
|     state.autoHide = data | ||||
|   }, | ||||
|  | ||||
|   [types.SET_MESSAGE](state, data) { | ||||
|     state.message = data | ||||
|   }, | ||||
|  | ||||
|   [types.SET_NOTIFICATION_TYPE](state, data) { | ||||
|     state.type = data | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_DATA](state) { | ||||
|     state.active = false | ||||
|     state.description = '' | ||||
|     state.title = '' | ||||
|   }, | ||||
| } | ||||
		Reference in New Issue
	
	Block a user