mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-31 05:31:10 -04:00 
			
		
		
		
	build version 400
This commit is contained in:
		
							
								
								
									
										91
									
								
								resources/assets/js/store/modules/custom-field/actions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								resources/assets/js/store/modules/custom-field/actions.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,91 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export const fetchCustomFields = ({ commit, dispatch, state }, params) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios | ||||
|       .get(`/api/v1/custom-fields`, { params }) | ||||
|       .then((response) => { | ||||
|         commit(types.SET_CUSTOM_FIELDS, response.data.customFields.data) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const fetchNoteCustomFields = ({ commit, dispatch, state }, params) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     if (state.isRequestOngoing) { | ||||
|       resolve({ requestOnGoing: true }) | ||||
|       return true | ||||
|     } | ||||
|     commit(types.SET_REQUEST_STATE, true) | ||||
|     window.axios | ||||
|       .get(`/api/v1/custom-fields`, { params }) | ||||
|       .then((response) => { | ||||
|         commit(types.SET_CUSTOM_FIELDS, response.data.customFields.data) | ||||
|         commit(types.SET_REQUEST_STATE, false) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         commit(types.SET_REQUEST_STATE, false) | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const fetchCustomField = ({ commit, dispatch }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios | ||||
|       .get(`/api/v1/custom-fields/${id}`) | ||||
|       .then((response) => { | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const addCustomField = ({ commit, dispatch, state }, params) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios | ||||
|       .post(`/api/v1/custom-fields`, params) | ||||
|       .then((response) => { | ||||
|         commit(types.ADD_CUSTOM_FIELDS, response.data.customField) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const updateCustomField = ({ commit, dispatch, state }, params) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios | ||||
|       .put(`/api/v1/custom-fields/${params.id}`, params) | ||||
|       .then((response) => { | ||||
|         commit(types.UPDATE_CUSTOM_FIELDS, params) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const deleteCustomFields = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios | ||||
|       .delete(`/api/v1/custom-fields/${id}`) | ||||
|       .then((response) => { | ||||
|         commit(types.DELETE_CUSTOM_FIELDS, id) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
| @ -0,0 +1 @@ | ||||
| export const getCustomFields = (state) => state.customFields | ||||
							
								
								
									
										20
									
								
								resources/assets/js/store/modules/custom-field/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								resources/assets/js/store/modules/custom-field/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| import mutations from './mutations' | ||||
| import * as actions from './actions' | ||||
| import * as getters from './getters' | ||||
|  | ||||
| const initialState = { | ||||
|   customFields: [], | ||||
|   isRequestOngoing: false, | ||||
| } | ||||
|  | ||||
| export default { | ||||
|   namespaced: true, | ||||
|  | ||||
|   state: initialState, | ||||
|  | ||||
|   getters: getters, | ||||
|  | ||||
|   actions: actions, | ||||
|  | ||||
|   mutations: mutations, | ||||
| } | ||||
| @ -0,0 +1,5 @@ | ||||
| export const SET_CUSTOM_FIELDS = 'SET_CUSTOM_FIELDS' | ||||
| export const ADD_CUSTOM_FIELDS = 'ADD_CUSTOM_FIELDS' | ||||
| export const UPDATE_CUSTOM_FIELDS = 'UPDATE_CUSTOM_FIELDS' | ||||
| export const DELETE_CUSTOM_FIELDS = 'DELETE_CUSTOM_FIELDS' | ||||
| export const SET_REQUEST_STATE = 'SET_REQUEST_STATE' | ||||
							
								
								
									
										42
									
								
								resources/assets/js/store/modules/custom-field/mutations.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								resources/assets/js/store/modules/custom-field/mutations.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export default { | ||||
|   [types.SET_CUSTOM_FIELDS](state, fields) { | ||||
|     state.customFields = fields | ||||
|   }, | ||||
|  | ||||
|   [types.ADD_CUSTOM_FIELDS](state, field) { | ||||
|     field = { | ||||
|       ...field, | ||||
|       options: field.options.map((option) => { | ||||
|         return { name: option ? option : '' } | ||||
|       }), | ||||
|     } | ||||
|  | ||||
|     state.customFields = [...state.customFields, field] | ||||
|   }, | ||||
|  | ||||
|   [types.UPDATE_CUSTOM_FIELDS](state, field) { | ||||
|     field = { | ||||
|       ...field, | ||||
|       options: field.options.map((option) => { | ||||
|         return { name: option ? option : '' } | ||||
|       }), | ||||
|     } | ||||
|  | ||||
|     let pos = state.customFields.findIndex((_f) => _f.id === field.id) | ||||
|  | ||||
|     if (state.customFields[pos]) { | ||||
|       state.customFields[pos] = field | ||||
|     } | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_CUSTOM_FIELDS](state, id) { | ||||
|     let index = state.customFields.findIndex((field) => field.id === id) | ||||
|     state.customFields.splice(index, 1) | ||||
|   }, | ||||
|  | ||||
|   [types.SET_REQUEST_STATE](state, flag) { | ||||
|     state.isRequestOngoing = flag | ||||
|   }, | ||||
| } | ||||
		Reference in New Issue
	
	Block a user