mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
Migrate from Vue to React framework.
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
import Vue from 'vue';
|
||||
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';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
app,
|
||||
sidebar,
|
||||
items,
|
||||
customers,
|
||||
},
|
||||
strict: debug,
|
||||
});
|
||||
|
||||
Vue.use(vuexI18n.plugin, store);
|
||||
|
||||
export default store;
|
||||
@@ -1,41 +0,0 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
|
||||
const state = {
|
||||
appName: 'Ratteb',
|
||||
appVersion: '1.0.0',
|
||||
appBuild: '1000',
|
||||
|
||||
pageTitle: 'Welcome',
|
||||
actions: [],
|
||||
|
||||
contentState: 0,
|
||||
sidebarOpened: true,
|
||||
};
|
||||
|
||||
const getters = {
|
||||
getAppName: s => s.appName,
|
||||
getAppVersion: s => s.appVersion,
|
||||
getAppBuild: s => s.appBuild,
|
||||
getPageTitle: s => s.pageTitle,
|
||||
};
|
||||
|
||||
const actions = {
|
||||
|
||||
setPageTitle(s, title) {
|
||||
s.title = title;
|
||||
},
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
toggleSidebar() {
|
||||
state.sidebarOpened = !state.sidebarOpened;
|
||||
|
||||
if (state.sidebarOpened) {
|
||||
localStorage.set('sidebarStatus', 1)
|
||||
} else {
|
||||
localStorage.set('sidebarStatus', 0)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default { state, actions, mutations, getters };
|
||||
@@ -1,55 +0,0 @@
|
||||
import ApiService from '@/plugins/api-service';
|
||||
|
||||
const state = {
|
||||
token: localStorage.getItem('token') || '',
|
||||
errors: {},
|
||||
role: {},
|
||||
};
|
||||
|
||||
const getters = {
|
||||
authCheck: s => s.token,
|
||||
authToken: s => s.token,
|
||||
authorizedUserRole: s => s.role,
|
||||
};
|
||||
|
||||
const actions = {
|
||||
/**
|
||||
* User login login authentication request.
|
||||
*/
|
||||
async login({ commit }, { form }) {
|
||||
const response = await ApiService.post('auth/login', form);
|
||||
const { data } = response;
|
||||
|
||||
if (data.token) {
|
||||
commit('setToken', data.token);
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Send reset password via email or SMS.
|
||||
*/
|
||||
sendResetPassword({}, { email }) {
|
||||
return ApiService.post('auth/send_reset_password', { email });
|
||||
},
|
||||
|
||||
newPassword({}, { form }) {
|
||||
return ApiService.post('auth/new_password', form);
|
||||
},
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
|
||||
setToken(s, token) {
|
||||
localStorage.setItem('token', token);
|
||||
s.token = token;
|
||||
},
|
||||
|
||||
removeToken(s) {
|
||||
localStorage.removeItem('token');
|
||||
s.token = '';
|
||||
},
|
||||
};
|
||||
|
||||
export default { state, actions, mutations, getters };
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
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 };
|
||||
@@ -1,28 +0,0 @@
|
||||
const state = {
|
||||
logs: [],
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
ADD_ERROR_LOG: (s, log) => {
|
||||
s.logs.push(log);
|
||||
},
|
||||
CLEAR_ERROR_LOG: (s) => {
|
||||
s.logs.splice(0);
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
addErrorLog({ commit }, log) {
|
||||
commit('ADD_ERROR_LOG', log);
|
||||
},
|
||||
clearErrorLog({ commit }) {
|
||||
commit('CLEAR_ERROR_LOG');
|
||||
},
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions,
|
||||
};
|
||||
@@ -1,119 +0,0 @@
|
||||
import ApiService from '@/plugins/api-service';
|
||||
|
||||
const state = {
|
||||
list: {},
|
||||
details: [],
|
||||
categories: {},
|
||||
categoriesDetails: [],
|
||||
};
|
||||
|
||||
const getters = {
|
||||
getItems: s => s.list,
|
||||
getItem: s => id => s.details.find(i => i.id === id),
|
||||
getItemsCategories: s => s.categories,
|
||||
getItemCategory: s => id => s.categoriesDetails.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);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetches items categories paged list.
|
||||
*/
|
||||
async fetchItemsCategories({}, { query }) {
|
||||
return ApiService.get('/items_categories', { params: query });
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch details of the given item category.
|
||||
*/
|
||||
async fetchItemCategory({}, { id }) {
|
||||
return ApiService.get(`/item/${id}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete the given item category.
|
||||
*/
|
||||
async deleteItemCategory({}, { id }) {
|
||||
return ApiService.delete(`/items_categories/${id}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* Post a new item category.
|
||||
*/
|
||||
async newItemCategory({}, { form }) {
|
||||
return ApiService.post('/items_categories', form);
|
||||
},
|
||||
|
||||
/**
|
||||
* Update details of the given item category.
|
||||
*/
|
||||
async updateItemCategory({}, { id, form }) {
|
||||
return ApiService.post(`/items_categories/${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);
|
||||
},
|
||||
|
||||
setItemCategories(s, categories) {
|
||||
s.categories = categories;
|
||||
},
|
||||
|
||||
setItemCategory(s, category) {
|
||||
s.categoriesDetails = s.categoriesDetails.filter(i => i.id !== category.id);
|
||||
s.categoriesDetails.push(category);
|
||||
},
|
||||
};
|
||||
|
||||
export default { state, actions, mutations, getters };
|
||||
@@ -1,93 +0,0 @@
|
||||
|
||||
const state = {
|
||||
items: [
|
||||
{
|
||||
name: 'Home',
|
||||
to: 'dashboard.home',
|
||||
icon: 'home',
|
||||
count: null,
|
||||
},
|
||||
{
|
||||
name: 'Products',
|
||||
to: 'dashboard.items.list',
|
||||
},
|
||||
{
|
||||
name: 'Customers',
|
||||
to: 'dashboard.home',
|
||||
},
|
||||
{
|
||||
name: 'Suppliers',
|
||||
to: 'dashboard.home',
|
||||
},
|
||||
{
|
||||
name: 'Reports',
|
||||
to: 'dashboard.home',
|
||||
},
|
||||
{
|
||||
name: 'Users',
|
||||
to: 'dashboard.users.list',
|
||||
children: {
|
||||
name: 'New User',
|
||||
to: 'dashboard.user.new',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Accounting',
|
||||
to: 'dashboard.accounts.list',
|
||||
},
|
||||
],
|
||||
|
||||
quickActions: [
|
||||
{
|
||||
route: 'dashboard.items.list',
|
||||
actions: [
|
||||
{
|
||||
dialog: 'global-search',
|
||||
label: 'Search',
|
||||
icon: 'search',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
route: 'dashboard.items.list',
|
||||
actions: [
|
||||
{
|
||||
dialog: 'test',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const getters = {
|
||||
getSidebarItems: s => s.items,
|
||||
getSidebarItem: s => name => s.items.find(item => item.name === name),
|
||||
|
||||
getAllQuickActions: s => s.quickActions,
|
||||
getQuickActions: s => (route) => {
|
||||
const foundDefault = s.quickActions.find(q => q.default === true);
|
||||
const found = s.quickActions.find(q => q.route === route);
|
||||
const defaultActions = foundDefault ? foundDefault.actions : [];
|
||||
|
||||
return found ? [...defaultActions, found.actions] : defaultActions;
|
||||
},
|
||||
};
|
||||
|
||||
const actions = {
|
||||
|
||||
/**
|
||||
* Set count to the given sidebar item.
|
||||
*/
|
||||
setSidebarItemCount(s, { name, count }) {
|
||||
s.items = s.items.map((item) => {
|
||||
const mapped = { ...item };
|
||||
|
||||
if (item.name === name) {
|
||||
mapped.count = count;
|
||||
}
|
||||
return mapped;
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default { state, getters, actions };
|
||||
Reference in New Issue
Block a user