import { INIT_PAYMENTS_CUSTOMERS, SELECT_PAYMENTS_CUSTOMER, SELECT_CUSTOMER_INVOICES, FILTER_PAYMENTS_CUSTOMERS, RESET_CUSTOMERS } from '@/constants/actionTypes' import { SET_CUSTOMERS, SET_LOADING_CUSTOMERS, SET_SELECTED_CUSTOMER, SET_FILTER_PAYMENTS_CUSTOMERS } from '@/constants/mutationTypes' const initialState = { customers: [], filterCustomers: [], selectedCustomer: null, loadingCustomers: false, } const state = { customers: initialState.customers, loadingCustomers: !initialState.loadingCustomers, selectedCustomer: initialState.selectedCustomer, filterCustomers: initialState.filterCustomers } const getters = { /** * [customers description] * @param {[type]} state [description] * @return {[type]} [description] */ customers(state) { return state.customers }, /** * [loadingcustomers description] * @param {[type]} state [description] * @return {[type]} [description] */ loadingCustomers(state) { return state.loadingCustomers }, /** * [selectedCustomer description] * @param {[type]} state [description] * @return {[type]} [description] */ selectedCustomer(state) { return state.selectedCustomer }, customerVisible (state) { return state.filterCustomers.length === 0 ? state.customers : state.filterCustomers } } const mutations = { /** * [actions description] * @param {[type]} state [description] * @param {[type]} payload [description] */ [SET_CUSTOMERS] (state, payload) { state.customers = payload }, /** * [loadingcustomers description] * @param {[type]} state [description] * @param {[type]} payload [description] */ [SET_LOADING_CUSTOMERS] (state, payload) { state.loadingCustomers = !payload }, /** * [selectedCustomer description] * @param {[type]} state [description] * @param {[type]} payload [description] */ [SET_SELECTED_CUSTOMER] (state, payload) { state.selectedCustomer = payload }, [SET_FILTER_PAYMENTS_CUSTOMERS] (state, payload) { state.filterCustomers = payload } } const actions = { /** * * @param {*} param0 * @param {*} payload */ [INIT_PAYMENTS_CUSTOMERS] ({commit}, payload) { commit(SET_CUSTOMERS, payload) commit(SET_LOADING_CUSTOMERS, payload) }, /** * @param {*} param0 * @param {*} payload */ [SELECT_PAYMENTS_CUSTOMER] ({ commit, dispatch }, payload ) { commit(SET_SELECTED_CUSTOMER, payload) dispatch(SELECT_CUSTOMER_INVOICES, payload.invoices) }, /** * @param {*} param0 * @param {*} payload * */ [FILTER_PAYMENTS_CUSTOMERS] ({ commit }, payload) { commit(SET_FILTER_PAYMENTS_CUSTOMERS, payload) }, /** * [RESET_CUSTOMERS] * @param {*} param0 */ [RESET_CUSTOMERS] ({ commit }) { commit(SET_CUSTOMERS, []) commit(SET_SELECTED_CUSTOMER, null) commit(SET_FILTER_PAYMENTS_CUSTOMERS, []) commit(SET_LOADING_CUSTOMERS, true) } } export default { state, getters, mutations, actions }