mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-31 05:31:10 -04:00 
			
		
		
		
	init crater
This commit is contained in:
		
							
								
								
									
										95
									
								
								resources/assets/js/store/modules/customer/actions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								resources/assets/js/store/modules/customer/actions.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,95 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export const fetchCustomers = ({ commit, dispatch, state }, params) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/customers`, {params}).then((response) => { | ||||
|       commit(types.BOOTSTRAP_CUSTOMERS, response.data.customers.data) | ||||
|       commit(types.SET_TOTAL_CUSTOMERS, response.data.customers.total) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const fetchCustomer = ({ commit, dispatch }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/customers/${id}/edit`).then((response) => { | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const addCustomer = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post('/api/customers', data).then((response) => { | ||||
|       commit(types.ADD_CUSTOMER, response.data) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const updateCustomer = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.put(`/api/customers/${data.id}`, data).then((response) => { | ||||
|       commit(types.UPDATE_CUSTOMER, response.data) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const deleteCustomer = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.delete(`/api/customers/${id}`).then((response) => { | ||||
|       commit(types.DELETE_CUSTOMER, id) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const deleteMultipleCustomers = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/customers/delete`, {'id': state.selectedCustomers}).then((response) => { | ||||
|       commit(types.DELETE_MULTIPLE_CUSTOMERS, state.selectedCustomers) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const setSelectAllState = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.SET_SELECT_ALL_STATE, data) | ||||
| } | ||||
|  | ||||
| export const selectAllCustomers = ({ commit, dispatch, state }) => { | ||||
|   if (state.selectedCustomers.length === state.customers.length) { | ||||
|     commit(types.SET_SELECTED_CUSTOMERS, []) | ||||
|     commit(types.SET_SELECT_ALL_STATE, false) | ||||
|   } else { | ||||
|     let allCustomerIds = state.customers.map(cust => cust.id) | ||||
|     commit(types.SET_SELECTED_CUSTOMERS, allCustomerIds) | ||||
|     commit(types.SET_SELECT_ALL_STATE, true) | ||||
|   } | ||||
| } | ||||
|  | ||||
| export const selectCustomer = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.SET_SELECTED_CUSTOMERS, data) | ||||
|   if (state.selectedCustomers.length === state.customers.length) { | ||||
|     commit(types.SET_SELECT_ALL_STATE, true) | ||||
|   } else { | ||||
|     commit(types.SET_SELECT_ALL_STATE, false) | ||||
|   } | ||||
| } | ||||
|  | ||||
| export const resetSelectedCustomer = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.RESET_SELECTED_CUSTOMER) | ||||
| } | ||||
							
								
								
									
										4
									
								
								resources/assets/js/store/modules/customer/getters.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								resources/assets/js/store/modules/customer/getters.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| export const customers = (state) => state.customers | ||||
| export const selectAllField = (state) => state.selectAllField | ||||
| export const selectedCustomers = (state) => state.selectedCustomers | ||||
| export const totalCustomers = (state) => state.totalCustomers | ||||
							
								
								
									
										22
									
								
								resources/assets/js/store/modules/customer/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								resources/assets/js/store/modules/customer/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| import mutations from './mutations' | ||||
| import * as actions from './actions' | ||||
| import * as getters from './getters' | ||||
|  | ||||
| const initialState = { | ||||
|   customers: [], | ||||
|   totalCustomers: 0, | ||||
|   selectAllField: false, | ||||
|   selectedCustomers: [] | ||||
| } | ||||
|  | ||||
| export default { | ||||
|   namespaced: true, | ||||
|  | ||||
|   state: initialState, | ||||
|  | ||||
|   getters: getters, | ||||
|  | ||||
|   actions: actions, | ||||
|  | ||||
|   mutations: mutations | ||||
| } | ||||
| @ -0,0 +1,9 @@ | ||||
| export const BOOTSTRAP_CUSTOMERS = 'BOOTSTRAP_CUSTOMERS' | ||||
| export const ADD_CUSTOMER = 'ADD_CUSTOMER' | ||||
| export const UPDATE_CUSTOMER = 'UPDATE_CUSTOMER' | ||||
| export const DELETE_CUSTOMER = 'DELETE_CUSTOMER' | ||||
| export const DELETE_MULTIPLE_CUSTOMERS = 'DELETE_MULTIPLE_CUSTOMERS' | ||||
| export const SET_SELECTED_CUSTOMERS = 'SET_SELECTED_CUSTOMERS' | ||||
| export const SET_TOTAL_CUSTOMERS = 'SET_TOTAL_CUSTOMERS' | ||||
| export const RESET_SELECTED_CUSTOMER = 'RESET_SELECTED_CUSTOMER' | ||||
| export const SET_SELECT_ALL_STATE = 'SET_SELECT_ALL_STATE' | ||||
							
								
								
									
										48
									
								
								resources/assets/js/store/modules/customer/mutations.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								resources/assets/js/store/modules/customer/mutations.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export default { | ||||
|   [types.BOOTSTRAP_CUSTOMERS] (state, customers) { | ||||
|     state.customers = customers | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TOTAL_CUSTOMERS] (state, totalCustomers) { | ||||
|     state.totalCustomers = totalCustomers | ||||
|   }, | ||||
|  | ||||
|   [types.ADD_CUSTOMER] (state, data) { | ||||
|     state.customers.push(data.customer) | ||||
|   }, | ||||
|  | ||||
|   [types.UPDATE_CUSTOMER] (state, data) { | ||||
|     let pos = state.customers.findIndex(customer => customer.id === data.customer.id) | ||||
|  | ||||
|     state.customers[pos] = data.customer | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_CUSTOMER] (state, id) { | ||||
|     let index = state.customers.findIndex(customer => customer.id === id) | ||||
|     state.customers.splice(index, 1) | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_MULTIPLE_CUSTOMERS] (state, selectedCustomers) { | ||||
|     selectedCustomers.forEach((customer) => { | ||||
|       let index = state.customers.findIndex(_cust => _cust.id === customer.id) | ||||
|       state.customers.splice(index, 1) | ||||
|     }) | ||||
|  | ||||
|     state.selectedCustomers = [] | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECTED_CUSTOMERS] (state, data) { | ||||
|     state.selectedCustomers = data | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_SELECTED_CUSTOMER] (state, data) { | ||||
|     state.selectedCustomer = null | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECT_ALL_STATE] (state, data) { | ||||
|     state.selectAllField = data | ||||
|   } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user