diff --git a/src/store/customers.js b/src/store/customers.js new file mode 100644 index 0000000..2f6e978 --- /dev/null +++ b/src/store/customers.js @@ -0,0 +1,74 @@ +export default { + namespaced: true, + state: { + loading: false, + customers: [], + }, + mutations: { + setCustomers(state, customers) { + state.customers = customers; + state.loaded = true; + }, + toggleLoading(state) { + state.loading = !state.loading; + }, + }, + actions: { + fetchCustomers({ commit }, opts = {}) { + commit('toggleLoading'); + + // TODO: fetch customers from server + const options = Object.assign({ + page: 0, + count: 10, + }, opts); + + return new Promise((resolve) => { + const customers = [{ + firstname: 'Peter', + lastname: 'Amaya', + email: 'PeterPAmaya@teleworm.us', + city: 'Greensboro', + state: 'NC', + }, { + firstname: 'Derrick', + lastname: 'Duplantis', + email: 'DerrickCDuplantis@dayrep.com', + city: 'Freeport', + state: 'NY', + }, { + firstname: 'Andrea', + lastname: 'Hernandez', + email: 'AndreaRHernandez@armyspy.com', + city: 'Maumee', + state: 'OH', + }, { + firstname: 'Daniel', + lastname: 'Hurt', + email: 'DanielGHurt@teleworm.us', + city: 'Cedar Rapids', + state: 'IA', + }, { + firstname: 'Milagros', + lastname: 'Anderson', + email: 'MilagrosCAnderson@jourrapide.com', + city: 'Kansas City', + state: 'KS', + }, { + firstname: 'An', + lastname: 'K\'ung', + email: 'AnKung@dayrep.com', + city: 'Benton Harbor', + state: 'MI', + }]; + + setTimeout(() => { + const results = customers.slice(options.page, options.count); + commit('setCustomers', results); + commit('toggleLoading'); + resolve(); + }, 2000) + }); + }, + }, +}; diff --git a/src/store/index.js b/src/store/index.js index aae0936..51da63c 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -4,6 +4,7 @@ import createPersistedState from 'vuex-persistedstate'; import lz from 'lz-string'; import authentication from './authentication'; +import customers from './customers'; Vue.use(Vuex); @@ -12,6 +13,7 @@ const store = new Vuex.Store({ }, modules: { authentication, + customers, }, plugins: [ createPersistedState({