mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
WIP Items module.
This commit is contained in:
@@ -3,6 +3,8 @@ import Vuex from 'vuex';
|
||||
import vuexI18n from 'vuex-i18n';
|
||||
import sidebar from '@/store/modules/sidebar';
|
||||
import app from '@/store/modules/app';
|
||||
import items from '@/store/modules/items';
|
||||
import customers from '@/store/modules/customers';
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
@@ -12,6 +14,8 @@ const store = new Vuex.Store({
|
||||
modules: {
|
||||
app,
|
||||
sidebar,
|
||||
items,
|
||||
customers,
|
||||
},
|
||||
strict: debug,
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import ApiService from '~/plugins/api-service';
|
||||
import ApiService from '@/plugins/api-service';
|
||||
|
||||
let state = {
|
||||
const state = {
|
||||
token: localStorage.getItem('token') || '',
|
||||
errors: {},
|
||||
role: {}
|
||||
role: {},
|
||||
};
|
||||
|
||||
const getters = {
|
||||
@@ -14,9 +14,9 @@ const getters = {
|
||||
|
||||
const actions = {
|
||||
/**
|
||||
* User login authentication request.
|
||||
* User login login authentication request.
|
||||
*/
|
||||
async authRequest({ commit }, { form }) {
|
||||
async login({ commit }, { form }) {
|
||||
const response = await ApiService.post('auth/login', form);
|
||||
const { data } = response;
|
||||
|
||||
@@ -27,32 +27,29 @@ const actions = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Send reset password email or SMS.
|
||||
* Send reset password via email or SMS.
|
||||
*/
|
||||
sendResetPassword({}, { email }) {
|
||||
return ApiService.post('auth/send_reset_password', { email });
|
||||
},
|
||||
|
||||
/**
|
||||
* Verify reset password verification code.
|
||||
*/
|
||||
verifyResetPasswordToken({ commit, dispatch }, { token }) {
|
||||
return ApiService.post(`reset/${token}`);
|
||||
}
|
||||
newPassword(, { form }) {
|
||||
return ApiService.post('auth/new_password', form);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
const mutations = {
|
||||
|
||||
setToken(state, token) {
|
||||
|
||||
setToken(s, token) {
|
||||
localStorage.setItem('token', token);
|
||||
state.token = token;
|
||||
s.token = token;
|
||||
},
|
||||
|
||||
removeToken(state) {
|
||||
removeToken(s) {
|
||||
localStorage.removeItem('token');
|
||||
state.token = '';
|
||||
s.token = '';
|
||||
},
|
||||
};
|
||||
|
||||
export default {state, actions, mutations, getters};
|
||||
export default { state, actions, mutations, getters };
|
||||
|
||||
|
||||
77
client/src/store/modules/customers.js
Normal file
77
client/src/store/modules/customers.js
Normal file
@@ -0,0 +1,77 @@
|
||||
import ApiService from '@/plugins/api-service';
|
||||
|
||||
const state = {
|
||||
list: {},
|
||||
details: [],
|
||||
};
|
||||
|
||||
const getters = {
|
||||
getCustomers: s => s.list,
|
||||
getCustomer: s => id => s.details.find(i => i.id === id),
|
||||
};
|
||||
|
||||
const actions = {
|
||||
/**
|
||||
* Fetches customers with current page.
|
||||
*/
|
||||
async fetchCustomers({ commit }, { query } = {}) {
|
||||
const response = await ApiService.post('customers', { params: query });
|
||||
const { data } = response;
|
||||
const { count } = data.pagination;
|
||||
|
||||
commit('setItems', data);
|
||||
|
||||
if (count) {
|
||||
commit('setSidebarItemCount', {
|
||||
name: 'customers', count,
|
||||
});
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch the given customer details.
|
||||
*/
|
||||
async fetchCustomer({ commit }, { id }) {
|
||||
const response = await ApiService.get(`customers/${id}`);
|
||||
const { data } = response;
|
||||
|
||||
commit('setItem', data);
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete the given customer.
|
||||
*/
|
||||
async deleteCustomer({}, { id }) {
|
||||
return ApiService.delete(`customers/${id}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* Submit the new customer.
|
||||
*/
|
||||
async newCustomer({}, { form }) {
|
||||
return ApiService.post('customers', form);
|
||||
},
|
||||
|
||||
/**
|
||||
* Update details the given customer.
|
||||
*/
|
||||
async updateCustomer({}, { form, id }) {
|
||||
return ApiService.post(`customers/${id}`, form);
|
||||
},
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
|
||||
setCustomers(s, items) {
|
||||
s.list = items;
|
||||
},
|
||||
|
||||
setCustomer(s, item) {
|
||||
s.details = s.details.filter(i => i.id !== item.id);
|
||||
s.details.push(item);
|
||||
},
|
||||
};
|
||||
|
||||
export default { state, actions, mutations, getters };
|
||||
71
client/src/store/modules/items.js
Normal file
71
client/src/store/modules/items.js
Normal file
@@ -0,0 +1,71 @@
|
||||
import ApiService from '@/plugins/api-service';
|
||||
|
||||
const state = {
|
||||
list: {},
|
||||
details: [],
|
||||
};
|
||||
|
||||
const getters = {
|
||||
getItems: s => s.list,
|
||||
getItem: s => id => s.details.find(i => i.id === id),
|
||||
};
|
||||
|
||||
const actions = {
|
||||
/**
|
||||
* Fetches the products/services list.
|
||||
*/
|
||||
async fetchItems({ commit }, { query } = {}) {
|
||||
const response = await ApiService.post('items', { params: query });
|
||||
const { data } = response;
|
||||
const { count } = data.pagination;
|
||||
|
||||
commit('setItems', data);
|
||||
|
||||
if (count) {
|
||||
commit('setSidebarItemCount', {
|
||||
name: 'items', count,
|
||||
});
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch the given product/service details.
|
||||
*/
|
||||
async fetchItem({ commit }, { id }) {
|
||||
const response = await ApiService.get(`${id}`);
|
||||
const { data } = response;
|
||||
|
||||
commit('setItem', data);
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete the given product/service.
|
||||
*/
|
||||
async deleteItem({ commit }, { id }) {
|
||||
return ApiService.delete(`items/${id}`);
|
||||
},
|
||||
|
||||
async newItem({}, { form }) {
|
||||
return ApiService.post('items', form);
|
||||
},
|
||||
|
||||
async updateItem({}, { form, id }) {
|
||||
return ApiService.post(`items/${id}`, form);
|
||||
},
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
|
||||
setItems(s, items) {
|
||||
s.list = items;
|
||||
},
|
||||
|
||||
setItem(s, item) {
|
||||
s.details = s.details.filter(i => i.id !== item.id);
|
||||
s.details.push(item);
|
||||
},
|
||||
};
|
||||
|
||||
export default { state, actions, mutations, getters };
|
||||
@@ -37,12 +37,15 @@ const actions = {
|
||||
* Set count to the given sidebar item.
|
||||
*/
|
||||
setSidebarItemCount(s, { name, count }) {
|
||||
s.items.forEach((item) => {
|
||||
s.items = s.items.map((item) => {
|
||||
const mapped = { ...item };
|
||||
|
||||
if (item.name === name) {
|
||||
item.count = count;
|
||||
mapped.count = count;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return mapped;
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default { state, getters, actions };
|
||||
|
||||
Reference in New Issue
Block a user