mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
re-structure to monorepo.
This commit is contained in:
47
packages/webapp/src/store/settings/settings.actions.tsx
Normal file
47
packages/webapp/src/store/settings/settings.actions.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
// @ts-nocheck
|
||||
import ApiService from '@/services/ApiService';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const submitOptions = ({ form }) => {
|
||||
return (dispatch) => {
|
||||
return ApiService.post('settings', form).then((response) => {
|
||||
dispatch({
|
||||
type: t.SETTING_SET,
|
||||
options: form.options,
|
||||
});
|
||||
return response;
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const FetchOptions = ({ form }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.get('settings')
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.SETTING_SET,
|
||||
options: response.data.settings,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const setSettings = (settings) => {
|
||||
return {
|
||||
type: t.SETTING_SET,
|
||||
options: settings,
|
||||
};
|
||||
}
|
||||
|
||||
export const addSettings = (group, key, value) => {
|
||||
return {
|
||||
type: t.SETTING_ADD,
|
||||
payload: { group, key, value }
|
||||
};
|
||||
}
|
||||
115
packages/webapp/src/store/settings/settings.reducer.tsx
Normal file
115
packages/webapp/src/store/settings/settings.reducer.tsx
Normal file
@@ -0,0 +1,115 @@
|
||||
// @ts-nocheck
|
||||
import { camelCase } from 'lodash';
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
|
||||
import t from '@/store/types';
|
||||
|
||||
const initialState = {
|
||||
data: {
|
||||
organization: {
|
||||
name: 'Bigcapital, LLC',
|
||||
},
|
||||
manualJournals: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
bills: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
billPayments: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
paymentReceives: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
salesEstimates: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
items: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
salesInvoices: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
salesReceipts: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
expenses: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
customers: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
vendors: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
accounts: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
cashflowAccounts: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
cashflowTransactions: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
creditNote: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
vendorCredit: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
warehouseTransfer: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
projectTasks: {
|
||||
tableSize: 'small',
|
||||
},
|
||||
projectTasks: {
|
||||
tableSize: 'medium',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:settings';
|
||||
|
||||
const PRESIST_CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: ['data'],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
[t.SETTING_SET]: (state, action) => {
|
||||
const { options } = action;
|
||||
const _data = {
|
||||
...state.data,
|
||||
};
|
||||
options.forEach((option) => {
|
||||
const { key, group, value } = option;
|
||||
const _group = camelCase(group);
|
||||
const _key = camelCase(key);
|
||||
|
||||
if (!_data[_group]) {
|
||||
_data[_group] = {};
|
||||
}
|
||||
_data[_group][_key] = value;
|
||||
});
|
||||
state.data = _data;
|
||||
},
|
||||
|
||||
[t.SETTING_ADD]: (state, action) => {
|
||||
const { group, key, value } = action.payload;
|
||||
|
||||
const newData = {
|
||||
...state.data,
|
||||
[group]: {
|
||||
...state.data[group],
|
||||
[key]: value,
|
||||
},
|
||||
};
|
||||
state.data = newData;
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(PRESIST_CONFIG, reducerInstance);
|
||||
7
packages/webapp/src/store/settings/settings.type.tsx
Normal file
7
packages/webapp/src/store/settings/settings.type.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
SETTING_LIST_SET: 'SETTING_LIST_SET',
|
||||
CLEAR_OPTIONS_FORM_ERRORS: 'CLEAR_OPTIONS_FORM_ERRORS',
|
||||
SETTING_SET: 'SETTING_SET',
|
||||
SETTING_ADD: 'SETTING_ADD',
|
||||
};
|
||||
Reference in New Issue
Block a user