mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-05-12 22:05:01 +00:00
re-structure to monorepo.
This commit is contained in:
16
packages/webapp/src/store/Bills/bills.actions.tsx
Normal file
16
packages/webapp/src/store/Bills/bills.actions.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setBillsTableState = (queries) => {
|
||||
return {
|
||||
type: t.BILLS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetBillsTableState = () => {
|
||||
return {
|
||||
type: t.BILLS_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
|
||||
35
packages/webapp/src/store/Bills/bills.reducer.tsx
Normal file
35
packages/webapp/src/store/Bills/bills.reducer.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:bills';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('BILLS', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
26
packages/webapp/src/store/Bills/bills.selectors.tsx
Normal file
26
packages/webapp/src/store/Bills/bills.selectors.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQuery } from './bills.reducer';
|
||||
|
||||
const billsTableStateSelector = (state) => state.bills.tableState;
|
||||
|
||||
// Get bills table state marged with location query.
|
||||
export const getBillsTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
billsTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const billsTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(billsTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
6
packages/webapp/src/store/Bills/bills.type.tsx
Normal file
6
packages/webapp/src/store/Bills/bills.type.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export default {
|
||||
BILLS_TABLE_STATE_SET: 'BILLS/TABLE_STATE_SET',
|
||||
BILLS_TABLE_STATE_RESET: 'BILLS/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
/**
|
||||
* Sets the cashflow accounts table state.
|
||||
*/
|
||||
export const setCashflowAccountsTableState = (queries) => {
|
||||
return {
|
||||
type: t.CASHFLOW_ACCOUNTS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets the cashflow accounts table state.
|
||||
*/
|
||||
export const resetCashflowAccountsTableState = () => {
|
||||
return {
|
||||
type: t.CASHFLOW_ACCOUNTS_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
filterRoles: [],
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:cashflow_accounts';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('CASHFLOW_ACCOUNTS', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
@@ -0,0 +1,20 @@
|
||||
// @ts-nocheck
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
|
||||
// Accounts table state selector
|
||||
const cashflowAccountsTableStateSelector = (state, props) =>
|
||||
state.cashflowAccounts.tableState;
|
||||
|
||||
// Get accounts table state marged with location query.
|
||||
export const getCashflowAccountsTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
cashflowAccountsTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,6 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export default {
|
||||
CASHFLOW_ACCOUNTS_TABLE_STATE_SET: 'CASHFLOW_ACCOUNTS/TABLE_STATE_SET',
|
||||
CASHFLOW_ACCOUNTS_TABLE_STATE_RESET: 'CASHFLOW_ACCOUNTS/TABLE_STATE_RESET',
|
||||
};
|
||||
17
packages/webapp/src/store/CreditNote/creditNote.actions.tsx
Normal file
17
packages/webapp/src/store/CreditNote/creditNote.actions.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setCreditNoteTableState = (queries) => {
|
||||
return {
|
||||
type: t.CREDIT_NOTES_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetCreditNoteTableState = () => {
|
||||
return {
|
||||
type: t.CREDIT_NOTES_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
|
||||
export const setSelectedRowsItems = () => {};
|
||||
35
packages/webapp/src/store/CreditNote/creditNote.reducer.tsx
Normal file
35
packages/webapp/src/store/CreditNote/creditNote.reducer.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:credit_notes';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('CREDIT_NOTES', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
30
packages/webapp/src/store/CreditNote/creditNote.selector.tsx
Normal file
30
packages/webapp/src/store/CreditNote/creditNote.selector.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQuery } from './creditNote.reducer';
|
||||
|
||||
const creditsTableStateSelector = (state) => state.creditNotes.tableState;
|
||||
|
||||
/**
|
||||
* Retrieve credit notes table state.
|
||||
*/
|
||||
export const getCreditNotesTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
creditsTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve credit notes table state.
|
||||
*/
|
||||
export const isCreditNotesTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(creditsTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
5
packages/webapp/src/store/CreditNote/creditNote.type.tsx
Normal file
5
packages/webapp/src/store/CreditNote/creditNote.type.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
CREDIT_NOTES_TABLE_STATE_SET: 'CREDIT_NOTES/TABLE_STATE_SET',
|
||||
CREDIT_NOTES_TABLE_STATE_RESET: 'CREDIT_NOTE/TABLE_STATE_RESET',
|
||||
};
|
||||
15
packages/webapp/src/store/Estimate/estimates.actions.tsx
Normal file
15
packages/webapp/src/store/Estimate/estimates.actions.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setEstimatesTableState = (queries) => {
|
||||
return {
|
||||
type: t.ESTIMATES_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetEstimatesTableState = () => {
|
||||
return {
|
||||
type: t.ESTIMATES_TABLE_STATE_RESET,
|
||||
};
|
||||
}
|
||||
35
packages/webapp/src/store/Estimate/estimates.reducer.tsx
Normal file
35
packages/webapp/src/store/Estimate/estimates.reducer.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:estimates';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('ESTIMATES', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
25
packages/webapp/src/store/Estimate/estimates.selectors.tsx
Normal file
25
packages/webapp/src/store/Estimate/estimates.selectors.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { defaultTableQuery } from './estimates.reducer';
|
||||
|
||||
const estimatesTableState = (state) => state.salesEstimates.tableState;
|
||||
|
||||
// Retrieve estimates table query.
|
||||
export const getEstimatesTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
estimatesTableState,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const isEstimatesTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(estimatesTableState, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
5
packages/webapp/src/store/Estimate/estimates.types.tsx
Normal file
5
packages/webapp/src/store/Estimate/estimates.types.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
ESTIMATES_TABLE_STATE_SET: 'ESTIMATES/TABLE_STATE_SET',
|
||||
ESTIMATES_TABLE_STATE_RESET: 'ESTIMATES/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setExchangeRateTableState = (queries) => {
|
||||
return {
|
||||
type: t.EXCHANGE_RATES_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
14
packages/webapp/src/store/ExchangeRate/exchange.reducer.tsx
Normal file
14
packages/webapp/src/store/ExchangeRate/exchange.reducer.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
|
||||
const initialState = {
|
||||
tableState: {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
...createTableStateReducers('EXCHANGE_RATES'),
|
||||
});
|
||||
19
packages/webapp/src/store/ExchangeRate/exchange.selector.tsx
Normal file
19
packages/webapp/src/store/ExchangeRate/exchange.selector.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
// @ts-nocheck
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
|
||||
const exchangeRateTableState = (state) => {
|
||||
return state.exchangeRates.tableState;
|
||||
};
|
||||
|
||||
export const getExchangeRatesTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
exchangeRateTableState,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
4
packages/webapp/src/store/ExchangeRate/exchange.type.tsx
Normal file
4
packages/webapp/src/store/ExchangeRate/exchange.type.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
EXCHANGE_RATES_TABLE_STATE_SET: 'EXCHANGE_RATES/TABLE_STATE_SET',
|
||||
};
|
||||
17
packages/webapp/src/store/Invoice/invoices.actions.tsx
Normal file
17
packages/webapp/src/store/Invoice/invoices.actions.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setInvoicesTableState = (queries) => {
|
||||
return {
|
||||
type: t.INVOICES_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetInvoicesTableState= () => {
|
||||
return {
|
||||
type: t.INVOICES_TABLE_STATE_RESET,
|
||||
};
|
||||
}
|
||||
|
||||
export const setSelectedRowsItems = () => {};
|
||||
35
packages/webapp/src/store/Invoice/invoices.reducer.tsx
Normal file
35
packages/webapp/src/store/Invoice/invoices.reducer.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:invoices';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('INVOICES', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
33
packages/webapp/src/store/Invoice/invoices.selector.tsx
Normal file
33
packages/webapp/src/store/Invoice/invoices.selector.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQuery } from './invoices.reducer';
|
||||
|
||||
const invoicesTableStateSelector = (state) => state.salesInvoices.tableState;
|
||||
|
||||
/**
|
||||
* Retrieve invoices table state.
|
||||
*/
|
||||
export const getInvoicesTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
invoicesTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve invoices table state.
|
||||
*/
|
||||
export const isInvoicesTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
invoicesTableStateSelector,
|
||||
(tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
},
|
||||
);
|
||||
6
packages/webapp/src/store/Invoice/invoices.types.tsx
Normal file
6
packages/webapp/src/store/Invoice/invoices.types.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export default {
|
||||
INVOICES_TABLE_STATE_SET: 'INVOICES/TABLE_STATE_SET',
|
||||
INVOICES_TABLE_STATE_RESET: 'INVOICES/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setPaymentMadesTableState = (queries) => {
|
||||
return {
|
||||
type: t.PAYMENT_MADES_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetPaymentMadesTableState = (queries) => {
|
||||
return {
|
||||
type: t.PAYMENT_MADES_TABLE_STATE_RESET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
sortBy: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:paymentMades';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('PAYMENT_MADES', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
@@ -0,0 +1,26 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQuery } from './paymentMades.reducer';
|
||||
|
||||
const paymentMadesTableStateSelector = (state) => state.paymentMades.tableState;
|
||||
|
||||
// Get payment mades table state marged with location query.
|
||||
export const getPaymentMadesTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
paymentMadesTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const paymentsTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(paymentMadesTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
PAYMENT_MADES_TABLE_STATE_SET: 'PAYMENT_MADES/TABLE_STATE_SET',
|
||||
PAYMENT_MADES_TABLE_STATE_RESET: 'PAYMENT_MADES/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setPaymentReceivesTableState = (queries) => {
|
||||
return {
|
||||
type: t.PAYMENT_RECEIVES_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetPaymentReceivesTableState = () => {
|
||||
return {
|
||||
type: t.PAYMENT_RECEIVES_TABLE_STATE_RESET
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:paymentReceives';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('PAYMENT_RECEIVES', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
@@ -0,0 +1,27 @@
|
||||
// @ts-nocheck
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import {
|
||||
paginationLocationQuery,
|
||||
} from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQuery } from './paymentReceives.reducer';
|
||||
|
||||
const paymentReceiveTableState = (state) => state.paymentReceives.tableState;
|
||||
|
||||
// Retrieve payment receives table fetch query.
|
||||
export const getPaymentReceiveTableStateFactory = () => createSelector(
|
||||
paginationLocationQuery,
|
||||
paymentReceiveTableState,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
export const paymentsTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(paymentReceiveTableState, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
PAYMENT_RECEIVES_TABLE_STATE_SET: 'PAYMENT_RECEIVES/TABLE_STATE_SET',
|
||||
PAYMENT_RECEIVES_TABLE_STATE_RESET: 'PAYMENT_RECEIVES/TABLE_STATE_RESET',
|
||||
};
|
||||
15
packages/webapp/src/store/Project/projects.actions.ts
Normal file
15
packages/webapp/src/store/Project/projects.actions.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setProjectsTableState = (queries) => {
|
||||
return {
|
||||
type: t.PROJECTS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetProjectsTableState = () => {
|
||||
return {
|
||||
type: t.PROJECTS_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
34
packages/webapp/src/store/Project/projects.reducer.ts
Normal file
34
packages/webapp/src/store/Project/projects.reducer.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:projects';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('PROJECTS', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
25
packages/webapp/src/store/Project/projects.selectors.ts
Normal file
25
packages/webapp/src/store/Project/projects.selectors.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { defaultTableQuery } from './projects.reducer';
|
||||
|
||||
const projectsTableState = (state) => state.projects.tableState;
|
||||
|
||||
// Retrieve projects table query.
|
||||
export const getProjectsTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
projectsTableState,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const isProjectsTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(projectsTableState, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
5
packages/webapp/src/store/Project/projects.type.ts
Normal file
5
packages/webapp/src/store/Project/projects.type.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
PROJECTS_TABLE_STATE_SET: 'PROJECTS/TABLE_STATE_SET',
|
||||
PROJECTS_TABLE_STATE_RESET: 'PROJECTS/TABLE_STATE_RESET',
|
||||
};
|
||||
14
packages/webapp/src/store/ResetMiddleware.tsx
Normal file
14
packages/webapp/src/store/ResetMiddleware.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
export default (next) => (reducer, initialState, enhancer) => {
|
||||
let resetType = 'RESET'
|
||||
let resetData = 'state'
|
||||
|
||||
const enhanceReducer = (state, action) => {
|
||||
if (action.type === resetType) {
|
||||
state = action[resetData]
|
||||
}
|
||||
return reducer(state, action)
|
||||
}
|
||||
|
||||
return next(enhanceReducer, initialState, enhancer)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:vendor_credits';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('VENDOR_CREDITS', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
@@ -0,0 +1,17 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setVendorCreditTableState = (queries) => {
|
||||
return {
|
||||
type: t.VENDOR_CREDITS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetVendorCreditTableState = () => {
|
||||
return {
|
||||
type: t.VENDOR_CREDITS_NOTES_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
|
||||
export const setSelectedRowsItems = () => {};
|
||||
@@ -0,0 +1,32 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQuery } from './VendorCredit.reducer';
|
||||
|
||||
const vendorCreditsTableStateSelector = (state) => {
|
||||
return state.vendorCredit.tableState;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve vendor credit table state.
|
||||
*/
|
||||
export const getVendorCreditTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
vendorCreditsTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve vendor credit table state.
|
||||
*/
|
||||
export const isVendorCreditTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(vendorCreditsTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
VENDOR_CREDITS_TABLE_STATE_SET: 'VENDOR_CREDITS/TABLE_STATE_SET',
|
||||
VENDOR_CREDITS_NOTES_TABLE_STATE_RESET: 'VENDOR_CREDITS/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setWarehouseTransferTableState = (queries) => {
|
||||
return {
|
||||
type: t.WAREHOUSE_TRANSFERS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetWarehouseTransferTableState = () => {
|
||||
return {
|
||||
type: t.WAREHOUSE_TRANSFERS_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:warehouse_transfers';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('WAREHOUSE_TRANSFERS', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
@@ -0,0 +1,34 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQuery } from './warehouseTransfer.reducer';
|
||||
|
||||
const warehouseTransfersTableStateSelector = (state) =>
|
||||
state.warehouseTransfers.tableState;
|
||||
|
||||
/**
|
||||
* Retrieve warehouse transfers table state.
|
||||
*/
|
||||
export const getWarehouseTransfersTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
warehouseTransfersTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve warehouse transfers table state.
|
||||
*/
|
||||
export const isWarehouseTransferTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
warehouseTransfersTableStateSelector,
|
||||
(tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
WAREHOUSE_TRANSFERS_TABLE_STATE_SET: 'WAREHOUSE_TRANSFERS/TABLE_STATE_SET',
|
||||
WAREHOUSE_TRANSFERS_TABLE_STATE_RESET: 'WAREHOUSE_TRANSFERS/TABLE_STATE_RESET',
|
||||
};
|
||||
18
packages/webapp/src/store/accounts/accounts.actions.tsx
Normal file
18
packages/webapp/src/store/accounts/accounts.actions.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setAccountsTableState = (queries) => {
|
||||
return {
|
||||
type: t.ACCOUNTS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets the accounts table state.
|
||||
*/
|
||||
export const resetAccountsTableState = () => {
|
||||
return {
|
||||
type: t.ACCOUNTS_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
34
packages/webapp/src/store/accounts/accounts.reducer.tsx
Normal file
34
packages/webapp/src/store/accounts/accounts.reducer.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:accounts';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('ACCOUNTS', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
27
packages/webapp/src/store/accounts/accounts.selectors.tsx
Normal file
27
packages/webapp/src/store/accounts/accounts.selectors.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQuery } from './accounts.reducer';
|
||||
|
||||
// Accounts table state selector
|
||||
const accountsTableStateSelector = (state, props) => state.accounts.tableState;
|
||||
|
||||
// Get accounts table state marged with location query.
|
||||
export const getAccountsTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
accountsTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const accountsTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(accountsTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
6
packages/webapp/src/store/accounts/accounts.types.tsx
Normal file
6
packages/webapp/src/store/accounts/accounts.types.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export default {
|
||||
ACCOUNTS_TABLE_STATE_SET: 'ACCOUNTS/TABLE_STATE_SET',
|
||||
ACCOUNTS_TABLE_STATE_RESET: 'ACCOUNTS/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setLogin = () => ({ type: t.LOGIN_SUCCESS });
|
||||
export const setLogout = () => ({ type: t.LOGOUT });
|
||||
export const setStoreReset = () => ({ type: t.RESET });
|
||||
@@ -0,0 +1,51 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer } from 'redux-persist';
|
||||
import purgeStoredState from 'redux-persist/es/purgeStoredState';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { getCookie } from '@/utils';
|
||||
import t from '@/store/types';
|
||||
|
||||
// Read stored data in cookies and merge it with the initial state.
|
||||
const initialState = {
|
||||
token: getCookie('token'),
|
||||
organizationId: getCookie('organization_id'),
|
||||
tenantId: getCookie('tenant_id'),
|
||||
userId: getCookie('authenticated_user_id'),
|
||||
locale: getCookie('locale'),
|
||||
errors: [],
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:authentication';
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
[t.LOGIN_FAILURE]: (state, action) => {
|
||||
state.errors = action.errors;
|
||||
},
|
||||
|
||||
[t.LOGIN_CLEAR_ERRORS]: (state) => {
|
||||
state.errors = [];
|
||||
},
|
||||
|
||||
[t.RESET]: (state) => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
|
||||
export const isAuthenticated = (state) => !!state.authentication.token;
|
||||
export const hasErrorType = (state, errorType) => {
|
||||
return state.authentication.errors.find((e) => e.type === errorType);
|
||||
};
|
||||
|
||||
export const isTenantSeeded = (state) => !!state.tenant.seeded_at;
|
||||
export const isTenantBuilt = (state) => !!state.tenant.initialized_at;
|
||||
|
||||
export const isTenantHasSubscription = () => false;
|
||||
export const isTenantSubscriptionExpired = () => false;
|
||||
@@ -0,0 +1,25 @@
|
||||
// @ts-nocheck
|
||||
import { defaultTo } from 'lodash';
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
const getCurrentOrganizationId = (state) => state.authentication.organizationId;
|
||||
const getCurrentTenantId = (state) => state.authentication.tenantId;
|
||||
const getOrganizationsMap = (state) => state.organizations.data;
|
||||
|
||||
// Retrieve organization tenant id.
|
||||
export const getOrganizationTenantIdFactory = () =>
|
||||
createSelector(getCurrentTenantId, (tenantId) => tenantId);
|
||||
|
||||
// Retrieve organization id.
|
||||
export const getOrganizationIdFactory = () =>
|
||||
createSelector(getCurrentOrganizationId, (tenantId) => tenantId);
|
||||
|
||||
// Retrieve current organization meta object.
|
||||
export const getCurrentOrganizationFactory = () =>
|
||||
createSelector(
|
||||
getCurrentTenantId,
|
||||
getOrganizationsMap,
|
||||
(tenantId, organizationsMap) => {
|
||||
return defaultTo(organizationsMap[tenantId], {});
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,10 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export default {
|
||||
LOGIN_REQUEST: 'LOGIN_REQUEST',
|
||||
LOGIN_SUCCESS: 'LOGIN_SUCCESS',
|
||||
LOGIN_FAILURE: 'LOGIN_FAILURE',
|
||||
LOGOUT: 'LOGOUT',
|
||||
LOGIN_CLEAR_ERRORS: 'LOGIN_CLEAR_ERRORS',
|
||||
RESET: 'RESET',
|
||||
};
|
||||
19
packages/webapp/src/store/billing/Billing.action.tsx
Normal file
19
packages/webapp/src/store/billing/Billing.action.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
// @ts-nocheck
|
||||
import ApiService from '@/services/ApiService';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const submitBilling = ({ form }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post('subscription/license/payment', form)
|
||||
.then((response) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
|
||||
reject(data?.errors);
|
||||
});
|
||||
});
|
||||
};
|
||||
53
packages/webapp/src/store/createStore.tsx
Normal file
53
packages/webapp/src/store/createStore.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
// @ts-nocheck
|
||||
import {
|
||||
createStore as createReduxStore,
|
||||
applyMiddleware,
|
||||
compose,
|
||||
} from 'redux';
|
||||
import thunkMiddleware from 'redux-thunk';
|
||||
import { persistStore } from 'redux-persist';
|
||||
import monitorReducerEnhancer from '@/store/enhancers/monitorReducer';
|
||||
import loggerMiddleware from '@/store/logger.middleware';
|
||||
import rootReducer from '@/store/reducers';
|
||||
import ResetMiddleware from './ResetMiddleware';
|
||||
|
||||
|
||||
const createStoreFactory = (initialState = {}) => {
|
||||
/**
|
||||
|--------------------------------------------------
|
||||
| Middleware Configuration
|
||||
|--------------------------------------------------
|
||||
*/
|
||||
const middleware = [thunkMiddleware, loggerMiddleware];
|
||||
|
||||
/**
|
||||
|--------------------------------------------------
|
||||
| Store Enhancers
|
||||
|--------------------------------------------------
|
||||
*/
|
||||
const enhancers = [monitorReducerEnhancer, ResetMiddleware];
|
||||
let composeEnhancers = compose;
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ === 'function') {
|
||||
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|--------------------------------------------------
|
||||
| Store Instantiation and HMR Setup
|
||||
|--------------------------------------------------
|
||||
*/
|
||||
const store = createReduxStore(
|
||||
rootReducer,
|
||||
initialState,
|
||||
composeEnhancers(applyMiddleware(...middleware), ...enhancers),
|
||||
);
|
||||
store.asyncReducers = {};
|
||||
return store;
|
||||
};
|
||||
|
||||
export const createStore = createStoreFactory;
|
||||
export const store = createStoreFactory();
|
||||
export const persistor = persistStore(store);
|
||||
70
packages/webapp/src/store/currencies/currencies.actions.tsx
Normal file
70
packages/webapp/src/store/currencies/currencies.actions.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
// @ts-nocheck
|
||||
import ApiService from '@/services/ApiService';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const submitCurrencies = ({ form }) => {
|
||||
return (dispatch) => {
|
||||
return ApiService.post('currencies', form);
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteCurrency = ({ currency_code }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.delete(`currencies/${currency_code}`)
|
||||
.then((response) => {
|
||||
dispatch({ type: t.CURRENCY_CODE_DELETE, currency_code });
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error.response.data.errors || []);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const editCurrency = ({ id, form }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post(`currencies/${id}`, form)
|
||||
.then((response) => {
|
||||
dispatch({ type: t.CLEAR_CURRENCY_FORM_ERRORS });
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
const { errors } = data;
|
||||
|
||||
dispatch({ type: t.CLEAR_CURRENCY_FORM_ERRORS });
|
||||
if (errors) {
|
||||
dispatch({ type: t.CLEAR_CURRENCY_FORM_ERRORS, errors });
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchCurrencies = () => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
dispatch({
|
||||
type: t.CURRENCIES_TABLE_LOADING,
|
||||
loading: true,
|
||||
});
|
||||
ApiService.get('currencies')
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.CURRENCIES_REGISTERED_SET,
|
||||
currencies: response.data.currencies,
|
||||
});
|
||||
dispatch({
|
||||
type: t.CURRENCIES_TABLE_LOADING,
|
||||
loading: false,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
30
packages/webapp/src/store/currencies/currencies.reducer.tsx
Normal file
30
packages/webapp/src/store/currencies/currencies.reducer.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import t from '@/store/types';
|
||||
|
||||
const initialState = {
|
||||
data: {},
|
||||
loading: false,
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.CURRENCIES_REGISTERED_SET]: (state, action) => {
|
||||
const _currencies = {};
|
||||
|
||||
action.currencies.forEach((currency) => {
|
||||
_currencies[currency.currency_code] = currency;
|
||||
});
|
||||
state.data = {
|
||||
...state.data,
|
||||
..._currencies,
|
||||
};
|
||||
},
|
||||
[t.CURRENCIES_TABLE_LOADING]: (state, action) => {
|
||||
state.loading = action.loading;
|
||||
},
|
||||
[t.CURRENCY_CODE_DELETE]: (state, action) => {
|
||||
if (typeof state.data[action.currency_code] !== 'undefined') {
|
||||
delete state.data[action.currency_code];
|
||||
}
|
||||
},
|
||||
});
|
||||
23
packages/webapp/src/store/currencies/currencies.selector.tsx
Normal file
23
packages/webapp/src/store/currencies/currencies.selector.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
// @ts-nocheck
|
||||
// @flow
|
||||
import { createSelector } from 'reselect';
|
||||
import { getItemById } from '@/store/selectors';
|
||||
|
||||
const currenciesItemsSelector = (state) => state.currencies.data;
|
||||
const currenciesCodePropSelector = (state, props) => props.currencyId;
|
||||
|
||||
export const getCurrenciesList = createSelector(
|
||||
currenciesItemsSelector,
|
||||
(currencies) => {
|
||||
return Object.values(currencies);
|
||||
},
|
||||
);
|
||||
|
||||
export const getCurrencyByCode = createSelector(
|
||||
currenciesItemsSelector,
|
||||
currenciesCodePropSelector,
|
||||
(currencies, currencyCode) => {
|
||||
return getItemById(currencies, currencyCode);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
CURRENCIES_REGISTERED_SET: 'CURRENCIES_REGISTERED_SET',
|
||||
CLEAR_CURRENCY_FORM_ERRORS: 'CLEAR_CURRENCY_FORM_ERRORS',
|
||||
CURRENCIES_TABLE_LOADING: 'CURRENCIES_TABLE_LOADING',
|
||||
CURRENCY_CODE_DELETE: 'CURRENCY_CODE_DELETE',
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
// @ts-nocheck
|
||||
import ApiService from '@/services/ApiService';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const fetchResourceFields = ({ resourceSlug }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`fields/resource/${resourceSlug}`).then((response) => {
|
||||
dispatch({
|
||||
type: t.CUSTOM_FIELDS_RESOURCE_SET,
|
||||
resourceSlug: resourceSlug,
|
||||
fields: response.data.fields,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// @ts-nocheck
|
||||
import {createReducer} from '@reduxjs/toolkit';
|
||||
import t from '@/store/types';
|
||||
|
||||
const initialState = {
|
||||
custom_fields: {
|
||||
accounts: [{
|
||||
label_name: 'Label',
|
||||
predefined: true,
|
||||
data_type: 'text',
|
||||
help_text: '123sdasd',
|
||||
active: true,
|
||||
}]
|
||||
},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.CUSTOM_FIELDS_RESOURCE_SET]: (state, action) => {
|
||||
state.fields.custom_fields[action.resource_slug] = action.custom_field;
|
||||
}
|
||||
});
|
||||
|
||||
export const getCustomFieldsByResource = (state, resourceSlug) => {
|
||||
return state.fields.custom_fields[resourceSlug];
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export default {
|
||||
CUSTOM_FIELDS_RESOURCE_SET: 'CUSTOM_FIELDS_RESOURCE_SET',
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
// @ts-nocheck
|
||||
import ApiService from "services/ApiService";
|
||||
import t from '@/store/types';
|
||||
|
||||
export const submitView = ({ form }) => {
|
||||
return (dispatch) => ApiService.post('views', form);
|
||||
};
|
||||
|
||||
export const editView = ({ id, form }) => {
|
||||
return (dispatch) => ApiService.post(`views/${id}`, form);
|
||||
};
|
||||
|
||||
export const deleteView = ({ id }) => {
|
||||
return (dispatch) => ApiService.delete(`views/${id}`);
|
||||
};
|
||||
|
||||
export const fetchView = ({ id }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`views/${id}`).then((response) => {
|
||||
dispatch({
|
||||
type: t.VIEW_META_SET,
|
||||
view: response.data.view,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchResourceViews = ({ resourceSlug }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`views/resource/${resourceSlug}`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.RESOURCE_VIEWS_SET,
|
||||
resource: resourceSlug,
|
||||
views: response.data.views,
|
||||
});
|
||||
dispatch({
|
||||
type: t.VIEW_ITEMS_SET,
|
||||
views: response.data.views,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchViewResource = ({ id }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`views/${id}/resource`).then((response) => {
|
||||
dispatch({
|
||||
type: t.RESOURCE_COLUMNS_SET,
|
||||
columns: response.data.resource_columns,
|
||||
resource_slug: response.data.resource_slug
|
||||
});
|
||||
dispatch({
|
||||
type: t.RESOURCE_FIELDS_SET,
|
||||
fields: response.data.resource_fields,
|
||||
resource_slug: response.data.resource_slug,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from "@reduxjs/toolkit";
|
||||
import t from '@/store/types';
|
||||
|
||||
const initialState = {
|
||||
views: {},
|
||||
resourceViews: {
|
||||
'accounts': [],
|
||||
'expenses': [],
|
||||
},
|
||||
viewsMeta: {},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.VIEW_META_SET]: (state, action) => {
|
||||
state.viewsMeta[action.view.id] = action.view;
|
||||
},
|
||||
|
||||
[t.RESOURCE_VIEWS_SET]: (state, action) => {
|
||||
state.resourceViews[action.resource] = action.views.map(v => v.id);
|
||||
},
|
||||
|
||||
[t.VIEW_ITEMS_SET]: (state, action) => {
|
||||
const _views = {};
|
||||
|
||||
action.views.forEach((view) => {
|
||||
_views[view.id] = view;
|
||||
});
|
||||
state.views = { ...state.views, ..._views };
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
// @ts-nocheck
|
||||
import { createSelector } from 'reselect';
|
||||
import { pickItemsFromIds } from '@/store/selectors';
|
||||
import { getResourceColumn } from '@/store/resources/resources.reducer';
|
||||
|
||||
const resourceViewsIdsSelector = (state, props, resourceName) =>
|
||||
state.views.resourceViews[resourceName];
|
||||
|
||||
const viewsSelector = (state) => state.views.views;
|
||||
const viewByIdSelector = (state, props) => state.views.views[props.viewId];
|
||||
|
||||
const viewColumnsSelector = (state, props) => {
|
||||
};
|
||||
|
||||
export const getResourceViews = createSelector(
|
||||
resourceViewsIdsSelector,
|
||||
viewsSelector,
|
||||
(resourceViewsIds, views) => {
|
||||
return pickItemsFromIds(views, resourceViewsIds);
|
||||
},
|
||||
);
|
||||
|
||||
export const getViewMetaFactory = () => createSelector(
|
||||
viewByIdSelector,
|
||||
// viewColumnsSelector,
|
||||
(view, viewColumns) => {
|
||||
return view;
|
||||
}
|
||||
);
|
||||
|
||||
export const getViewItemFactory = () => createSelector(
|
||||
viewByIdSelector,
|
||||
// viewColumnsSelector,
|
||||
(view, viewColumns) => {
|
||||
return view;
|
||||
}
|
||||
);
|
||||
|
||||
export const getViewPages = (resourceViews, viewId) => {
|
||||
return typeof resourceViews[viewId] === 'undefined'
|
||||
? {}
|
||||
: resourceViews[viewId].pages;
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export default {
|
||||
VIEW_META_SET: 'VIEW_META_SET',
|
||||
VIEW_ITEMS_SET: 'VIEW_ITEMS_SET',
|
||||
RESOURCE_VIEWS_SET: 'RESOURCE_VIEWS_SET',
|
||||
};
|
||||
18
packages/webapp/src/store/customers/customers.actions.tsx
Normal file
18
packages/webapp/src/store/customers/customers.actions.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
/**
|
||||
* Sets the customers table state.
|
||||
*/
|
||||
export const setCustomersTableState = (queries) => {
|
||||
return {
|
||||
type: t.CUSTOMERS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetCustomersTableState = () => {
|
||||
return {
|
||||
type: t.CUSTOMERS_TABLE_STATE_RESET,
|
||||
};
|
||||
}
|
||||
34
packages/webapp/src/store/customers/customers.reducer.tsx
Normal file
34
packages/webapp/src/store/customers/customers.reducer.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
|
||||
// Default table query state.
|
||||
export const defaultTableQueryState = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
inactiveMode: false,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
// initial data.
|
||||
const initialState = {
|
||||
tableState: defaultTableQueryState,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('CUSTOMERS', defaultTableQueryState),
|
||||
});
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:estimates';
|
||||
|
||||
export default persistReducer(
|
||||
{
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
},
|
||||
reducerInstance,
|
||||
);
|
||||
26
packages/webapp/src/store/customers/customers.selectors.tsx
Normal file
26
packages/webapp/src/store/customers/customers.selectors.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQueryState } from './customers.reducer';
|
||||
|
||||
const customerTableStateSelector = (state) => state.customers.tableState;
|
||||
|
||||
export const getCustomersTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
customerTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const customersTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(customerTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQueryState);
|
||||
});
|
||||
|
||||
5
packages/webapp/src/store/customers/customers.type.tsx
Normal file
5
packages/webapp/src/store/customers/customers.type.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
CUSTOMERS_TABLE_STATE_SET: 'CUSTOMERS/TABLE_STATE_SET',
|
||||
CUSTOMERS_TABLE_STATE_RESET: 'CUSTOMERS/TABLE_STATE_RESET'
|
||||
};
|
||||
127
packages/webapp/src/store/dashboard/dashboard.actions.tsx
Normal file
127
packages/webapp/src/store/dashboard/dashboard.actions.tsx
Normal file
@@ -0,0 +1,127 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export function dashboardPageTitle(pageTitle) {
|
||||
return {
|
||||
type: t.CHANGE_DASHBOARD_PAGE_TITLE,
|
||||
pageTitle,
|
||||
};
|
||||
}
|
||||
|
||||
export function dashboardPageHint(pageHint) {
|
||||
return {
|
||||
type: t.CHANGE_DASHBOARD_PAGE_HINT,
|
||||
pageHint,
|
||||
};
|
||||
}
|
||||
|
||||
export function openDialog(name, payload) {
|
||||
return {
|
||||
type: t.OPEN_DIALOG,
|
||||
name: name,
|
||||
payload: payload,
|
||||
};
|
||||
}
|
||||
|
||||
export function closeDialog(name, payload) {
|
||||
return {
|
||||
type: t.CLOSE_DIALOG,
|
||||
name: name,
|
||||
payload: payload,
|
||||
};
|
||||
}
|
||||
|
||||
export function openAlert(name, payload) {
|
||||
return {
|
||||
type: t.OPEN_ALERT,
|
||||
name,
|
||||
payload,
|
||||
};
|
||||
}
|
||||
|
||||
export function closeAlert(name, payload) {
|
||||
return {
|
||||
type: t.CLOSE_ALERT,
|
||||
name,
|
||||
payload,
|
||||
};
|
||||
}
|
||||
|
||||
export function openDrawer(name, payload) {
|
||||
return {
|
||||
type: t.OPEN_DRAWER,
|
||||
name,
|
||||
payload,
|
||||
};
|
||||
}
|
||||
export function closeDrawer(name, payload) {
|
||||
return {
|
||||
type: t.CLOSE_DRAWER,
|
||||
name,
|
||||
payload,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the sidebar expend.
|
||||
*/
|
||||
export function toggleExpendSidebar(toggle) {
|
||||
return {
|
||||
type: t.SIDEBAR_EXPEND_TOGGLE,
|
||||
payload: { toggle },
|
||||
};
|
||||
}
|
||||
|
||||
export function appIsLoading(toggle) {
|
||||
return {
|
||||
type: t.APP_IS_LOADING,
|
||||
payload: { isLoading: toggle },
|
||||
};
|
||||
}
|
||||
|
||||
export function appIntlIsLoading(toggle) {
|
||||
return {
|
||||
type: t.APP_INTL_IS_LOADING,
|
||||
payload: { isLoading: toggle },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Splash start loading.
|
||||
*/
|
||||
export function splashStartLoading() {
|
||||
return {
|
||||
type: t.SPLASH_START_LOADING,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Splash stop loading.
|
||||
*/
|
||||
export function splashStopLoading() {
|
||||
return {
|
||||
type: t.SPLASH_STOP_LOADING,
|
||||
};
|
||||
}
|
||||
|
||||
export const setFeatureDashboardMeta = ({ features }) => {
|
||||
return {
|
||||
type: t.SET_FEATURE_DASHBOARD_META,
|
||||
payload: {
|
||||
features,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export function openSidebarSubmenu({ submenuId }) {
|
||||
return {
|
||||
type: t.SIDEBAR_SUBMENU_OPEN,
|
||||
payload: { submenuId },
|
||||
};
|
||||
}
|
||||
|
||||
export function closeSidebarSubmenu() {
|
||||
return {
|
||||
type: t.SIDEBAR_SUBMENU_CLOSE,
|
||||
};
|
||||
}
|
||||
158
packages/webapp/src/store/dashboard/dashboard.reducer.tsx
Normal file
158
packages/webapp/src/store/dashboard/dashboard.reducer.tsx
Normal file
@@ -0,0 +1,158 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { isUndefined, isNumber } from 'lodash';
|
||||
import t from '@/store/types';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
|
||||
|
||||
const initialState = {
|
||||
pageTitle: '',
|
||||
pageSubtitle: '',
|
||||
pageHint: '',
|
||||
preferencesPageTitle: '',
|
||||
sidebarExpended: true,
|
||||
dialogs: {},
|
||||
alerts: {},
|
||||
drawers: {},
|
||||
topbarEditViewId: null,
|
||||
requestsLoading: 0,
|
||||
backLink: false,
|
||||
splashScreenLoading: null,
|
||||
appIsLoading: true,
|
||||
appIntlIsLoading: true,
|
||||
sidebarSubmenu: { isOpen: false, submenuId: null },
|
||||
features: {},
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:dashboard';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
[t.CHANGE_DASHBOARD_PAGE_TITLE]: (state, action) => {
|
||||
state.pageTitle = action.pageTitle;
|
||||
},
|
||||
|
||||
[t.ALTER_DASHBOARD_PAGE_SUBTITLE]: (state, action) => {
|
||||
state.pageSubtitle = action.pageSubtitle;
|
||||
},
|
||||
|
||||
[t.CHANGE_DASHBOARD_PAGE_HINT]: (state, action) => {
|
||||
state.pageHint = action.payload.pageHint;
|
||||
},
|
||||
|
||||
[t.CHANGE_PREFERENCES_PAGE_TITLE]: (state, action) => {
|
||||
state.preferencesPageTitle = action.pageTitle;
|
||||
},
|
||||
|
||||
[t.OPEN_DIALOG]: (state, action) => {
|
||||
state.dialogs[action.name] = {
|
||||
isOpen: true,
|
||||
payload: action.payload || {},
|
||||
};
|
||||
},
|
||||
|
||||
[t.CLOSE_DIALOG]: (state, action) => {
|
||||
state.dialogs[action.name] = {
|
||||
...state.dialogs[action.name],
|
||||
isOpen: false,
|
||||
};
|
||||
},
|
||||
|
||||
[t.OPEN_ALERT]: (state, action) => {
|
||||
state.alerts[action.name] = {
|
||||
isOpen: true,
|
||||
payload: action.payload || {},
|
||||
};
|
||||
},
|
||||
|
||||
[t.CLOSE_ALERT]: (state, action) => {
|
||||
state.alerts[action.name] = {
|
||||
...state.alerts[action.name],
|
||||
isOpen: false,
|
||||
};
|
||||
},
|
||||
[t.OPEN_DRAWER]: (state, action) => {
|
||||
state.drawers[action.name] = {
|
||||
isOpen: true,
|
||||
payload: action.payload || {},
|
||||
};
|
||||
},
|
||||
[t.CLOSE_DRAWER]: (state, action) => {
|
||||
state.drawers[action.name] = {
|
||||
...state.drawers[action.name],
|
||||
isOpen: false,
|
||||
};
|
||||
},
|
||||
[t.CLOSE_ALL_DIALOGS]: (state, action) => {},
|
||||
|
||||
[t.SET_TOPBAR_EDIT_VIEW]: (state, action) => {
|
||||
state.topbarEditViewId = action.id;
|
||||
},
|
||||
|
||||
[t.SIDEBAR_EXPEND_TOGGLE]: (state, action) => {
|
||||
const { toggle } = action.payload;
|
||||
state.sidebarExpended = isUndefined(toggle)
|
||||
? !state.sidebarExpended
|
||||
: !!toggle;
|
||||
},
|
||||
|
||||
[t.SET_DASHBOARD_BACK_LINK]: (state, action) => {
|
||||
const { backLink } = action.payload;
|
||||
state.backLink = backLink;
|
||||
},
|
||||
|
||||
[t.SPLASH_START_LOADING]: (state) => {
|
||||
if (isNumber(state.splashScreenLoading)) {
|
||||
state.splashScreenLoading += 1;
|
||||
} else {
|
||||
state.splashScreenLoading = 1;
|
||||
}
|
||||
},
|
||||
|
||||
[t.SET_FEATURE_DASHBOARD_META]: (state, action) => {
|
||||
const { features } = action.payload;
|
||||
const _data = {};
|
||||
|
||||
features.forEach((feature) => {
|
||||
_data[feature.name] = feature.is_accessible;
|
||||
});
|
||||
state.features = _data;
|
||||
},
|
||||
|
||||
[t.SPLASH_STOP_LOADING]: (state) => {
|
||||
state.splashScreenLoading -= 1;
|
||||
state.splashScreenLoading = Math.max(state.splashScreenLoading, 0);
|
||||
},
|
||||
|
||||
[t.SIDEBAR_SUBMENU_OPEN]: (state, action) => {
|
||||
state.sidebarSubmenu.isOpen = true;
|
||||
state.sidebarSubmenu.submenuId = action.payload.submenuId;
|
||||
},
|
||||
|
||||
[t.SIDEBAR_SUBMENU_CLOSE]: (state, action) => {
|
||||
state.sidebarSubmenu.isOpen = false;
|
||||
state.sidebarSubmenu.submenuId = null;
|
||||
},
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
|
||||
export const getDialogPayload = (state, dialogName) => {
|
||||
return typeof state.dashboard.dialogs[dialogName] !== 'undefined'
|
||||
? state.dashboard.dialogs[dialogName].payload
|
||||
: {};
|
||||
};
|
||||
|
||||
export const getDialogActiveStatus = (state, dialogName) => {
|
||||
return true;
|
||||
};
|
||||
50
packages/webapp/src/store/dashboard/dashboard.selectors.tsx
Normal file
50
packages/webapp/src/store/dashboard/dashboard.selectors.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
// @ts-nocheck
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
const dialogByNameSelector = (state, props) =>
|
||||
state.dashboard.dialogs?.[props.dialogName];
|
||||
|
||||
export const isDialogOpenFactory = () =>
|
||||
createSelector(dialogByNameSelector, (dialog) => {
|
||||
return dialog && dialog.isOpen;
|
||||
});
|
||||
|
||||
export const getDialogPayloadFactory = () =>
|
||||
createSelector(dialogByNameSelector, (dialog) => {
|
||||
return { ...dialog?.payload };
|
||||
});
|
||||
|
||||
const alertByNameSelector = (state, props) =>
|
||||
state.dashboard.alerts?.[props.name];
|
||||
|
||||
export const isAlertOpenFactory = () =>
|
||||
createSelector(alertByNameSelector, (alert) => {
|
||||
return alert && alert.isOpen;
|
||||
});
|
||||
|
||||
export const getAlertPayloadFactory = () =>
|
||||
createSelector(alertByNameSelector, (alert) => {
|
||||
return { ...alert?.payload };
|
||||
});
|
||||
|
||||
const drawerByNameSelector = (state, props) =>
|
||||
state.dashboard.drawers?.[props.name];
|
||||
|
||||
export const isDrawerOpenFactory = () =>
|
||||
createSelector(drawerByNameSelector, (drawer) => {
|
||||
return drawer && drawer.isOpen;
|
||||
});
|
||||
|
||||
export const getDrawerPayloadFactory = () =>
|
||||
createSelector(drawerByNameSelector, (drawer) => {
|
||||
return { ...drawer?.payload };
|
||||
});
|
||||
|
||||
const featuresSelector = (state, props) => {
|
||||
return state.dashboard.features;
|
||||
};
|
||||
|
||||
export const getDashboardFeaturesSelector = () =>
|
||||
createSelector(featuresSelector, (features) => {
|
||||
return features;
|
||||
});
|
||||
24
packages/webapp/src/store/dashboard/dashboard.types.tsx
Normal file
24
packages/webapp/src/store/dashboard/dashboard.types.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
OPEN_DIALOG: 'OPEN_DIALOG',
|
||||
CLOSE_DIALOG: 'CLOSE_DIALOG',
|
||||
OPEN_ALERT: 'OPEN_ALERT',
|
||||
CLOSE_ALERT: 'CLOSE_ALERT',
|
||||
CLOSE_ALL_DIALOGS: 'CLOSE_ALL_DIALOGS',
|
||||
CLOSE_ALL_ALERTS: 'CLOSE_ALL_ALERTS',
|
||||
OPEN_DRAWER: 'OPEN_DRAWER',
|
||||
CLOSE_DRAWER: 'CLOSE_DRAWER',
|
||||
CHANGE_DASHBOARD_PAGE_TITLE: 'CHANGE_DASHBOARD_PAGE_TITLE',
|
||||
CHANGE_DASHBOARD_PAGE_HINT: 'CHANGE_DASHBOARD_PAGE_HINT',
|
||||
CHANGE_PREFERENCES_PAGE_TITLE: 'CHANGE_PREFERENCES_PAGE_TITLE',
|
||||
ALTER_DASHBOARD_PAGE_SUBTITLE: 'ALTER_DASHBOARD_PAGE_SUBTITLE',
|
||||
SET_TOPBAR_EDIT_VIEW: 'SET_TOPBAR_EDIT_VIEW',
|
||||
SIDEBAR_EXPEND_TOGGLE: 'SIDEBAR_EXPEND_TOGGLE',
|
||||
SIDEBAR_SUBMENU_OPEN: 'SIDEBAR_SUBMENU_OPEN',
|
||||
SIDEBAR_SUBMENU_CLOSE: 'SIDEBAR_SUBMENU_CLOSE',
|
||||
SIDEBAR_SUBMENU_TOGGLE: 'SIDEBAR_SUBMENU_TOGGLE',
|
||||
SET_DASHBOARD_BACK_LINK: 'SET_DASHBOARD_BACK_LINK',
|
||||
SPLASH_START_LOADING: 'SPLASH_START_LOADING',
|
||||
SPLASH_STOP_LOADING: 'SPLASH_STOP_LOADING',
|
||||
SET_FEATURE_DASHBOARD_META: 'SET_FEATURE_DASHBOARD_META',
|
||||
};
|
||||
18
packages/webapp/src/store/enhancers/monitorReducer.tsx
Normal file
18
packages/webapp/src/store/enhancers/monitorReducer.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
// @ts-nocheck
|
||||
const round = number => Math.round(number * 100) / 100
|
||||
const monitorReducerEnhancer = createStore => (
|
||||
reducer,
|
||||
initialState,
|
||||
enhancer
|
||||
) => {
|
||||
const monitoredReducer = (state, action) => {
|
||||
const start = performance.now()
|
||||
const newState = reducer(state, action)
|
||||
const end = performance.now()
|
||||
const diff = round(end - start)
|
||||
console.log('reducer process time:', diff)
|
||||
return newState
|
||||
}
|
||||
return createStore(monitoredReducer, initialState, enhancer)
|
||||
}
|
||||
export default monitorReducerEnhancer
|
||||
20
packages/webapp/src/store/expenses/expenses.actions.tsx
Normal file
20
packages/webapp/src/store/expenses/expenses.actions.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
/**
|
||||
* Sets global table state of the table.
|
||||
* @param {object} queries
|
||||
*/
|
||||
export const setExpensesTableState = (queries) => {
|
||||
return {
|
||||
type: t.EXPENSES_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetExpensesTableState = () => {
|
||||
return {
|
||||
type: t.EXPENSES_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
|
||||
37
packages/webapp/src/store/expenses/expenses.reducer.tsx
Normal file
37
packages/webapp/src/store/expenses/expenses.reducer.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
// Default table query.
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
// Initial state.
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:expenses';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('EXPENSES', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
27
packages/webapp/src/store/expenses/expenses.selectors.tsx
Normal file
27
packages/webapp/src/store/expenses/expenses.selectors.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { defaultTableQuery } from './expenses.reducer';
|
||||
|
||||
// Items table state selectors.
|
||||
const expensesTableStateSelector = (state) => state.expenses.tableState;
|
||||
|
||||
// Retrive expenses table query.
|
||||
export const getExpensesTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
expensesTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const expensesTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(expensesTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
4
packages/webapp/src/store/expenses/expenses.types.tsx
Normal file
4
packages/webapp/src/store/expenses/expenses.types.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
export default {
|
||||
EXPENSES_TABLE_STATE_SET: 'EXPENSES/TABLE_STATE_SET',
|
||||
EXPENSES_TABLE_STATE_RESET: 'EXPENSES/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -0,0 +1,246 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
/**
|
||||
* Toggles display of the balance sheet filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleBalanceSheetFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.BALANCE_SHEET}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the trial balance sheet filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleTrialBalanceSheetFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.TRIAL_BALANCE_SHEET}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the journal sheet filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleJournalSheeetFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.JOURNAL}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the profit/loss filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleProfitLossFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.PROFIT_LOSS}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the general ledger filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleGeneralLedgerFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.GENERAL_LEDGER}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the AR aging summary filter drawer.
|
||||
* @param {boolean} toggle -
|
||||
*/
|
||||
export function toggleARAgingSummaryFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.AR_AGING_SUMMARY}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the AP aging summary filter drawer.
|
||||
* @param {boolean} toggle -
|
||||
*/
|
||||
export function toggleAPAgingSummaryFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.AP_AGING_SUMMARY}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the purchases by items filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function togglePurchasesByItemsFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.PURCHASES_BY_ITEMS}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the sells by items filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleSalesByItemsFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.SALES_BY_ITEMS}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Toggles display of the inventory valuation filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleInventoryValuationFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.INVENTORY_VALUATION}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the customers balance summary filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleCustomersBalanceSummaryFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.CUSTOMERS_BALANCE_SUMMARY}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Toggles display of the vendors balance summary filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleVendorsBalanceSummaryFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.VENDORS_BALANCE_SUMMARY}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Toggles display of the customers transactions filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleCustomersTransactionsFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.CUSTOMERS_TRANSACTIONS}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the vendors transactions filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleVendorsTransactionsFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.VENDORS_TRANSACTIONS}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle display of the cash flow statement filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleCashFlowStatementFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.CASH_FLOW_STATEMENT}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles display of the inventory item details filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleInventoryItemDetailsFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.INVENTORY_ITEM_DETAILS}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle display of the Realized Gain or Loss filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleRealizedGainOrLossFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.REALIZED_GAIN_OR_LOSS}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle display of the Unrealized Gain or Loss filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleUnrealizedGainOrLossFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.UNREALIZED_GAIN_OR_LOSS}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle display of the project Profitability summary filter drawer.
|
||||
* @param {boolean} toggle
|
||||
*/
|
||||
export function toggleProjectProfitabilitySummaryFilterDrawer(toggle) {
|
||||
return {
|
||||
type: `${t.PROJECT_PROFITABILITY_SUMMARY}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`,
|
||||
payload: {
|
||||
toggle,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
// @ts-nocheck
|
||||
import { omit, chain } from 'lodash';
|
||||
import moment from 'moment';
|
||||
|
||||
export const mapBalanceSheetToTableRows = (accounts) => {
|
||||
return accounts.map((account) => {
|
||||
return {
|
||||
...account,
|
||||
children: mapBalanceSheetToTableRows([
|
||||
...(account.children ? account.children : []),
|
||||
...(account.total && account.children && account.children.length > 0
|
||||
? [
|
||||
{
|
||||
name: `Total ${account.name}`,
|
||||
row_types: ['total-row', account.section_type],
|
||||
total: { ...account.total },
|
||||
...(account.total_periods && {
|
||||
total_periods: account.total_periods,
|
||||
}),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
]),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
export const profitLossToTableRowsMapper = () => {};
|
||||
|
||||
export const journalToTableRowsMapper = (journal) => {
|
||||
const TYPES = {
|
||||
ENTRY: 'ENTRY',
|
||||
TOTAL_ENTRIES: 'TOTAL_ENTRIES',
|
||||
EMPTY_ROW: 'EMPTY_ROW',
|
||||
};
|
||||
|
||||
const entriesMapper = (transaction) => {
|
||||
return transaction.entries.map((entry, index) => ({
|
||||
...(index === 0
|
||||
? {
|
||||
date: transaction.date,
|
||||
reference_type: transaction.reference_type,
|
||||
reference_id: transaction.reference_id,
|
||||
reference_type_formatted: transaction.reference_type_formatted,
|
||||
}
|
||||
: {}),
|
||||
rowType: TYPES.ENTRY,
|
||||
...entry,
|
||||
}));
|
||||
};
|
||||
|
||||
return chain(journal)
|
||||
.map((transaction) => {
|
||||
const entries = entriesMapper(transaction);
|
||||
|
||||
return [
|
||||
...entries,
|
||||
{
|
||||
rowType: TYPES.TOTAL_ENTRIES,
|
||||
currency_code: transaction.currency_code,
|
||||
credit: transaction.credit,
|
||||
debit: transaction.debit,
|
||||
formatted_credit: transaction.formatted_credit,
|
||||
formatted_debit: transaction.formatted_debit,
|
||||
},
|
||||
{
|
||||
rowType: TYPES.EMPTY_ROW,
|
||||
},
|
||||
];
|
||||
})
|
||||
.flatten()
|
||||
.value();
|
||||
};
|
||||
|
||||
export const generalLedgerToTableRows = (accounts) => {
|
||||
return chain(accounts)
|
||||
.map((account) => {
|
||||
return {
|
||||
name: '',
|
||||
code: account.code,
|
||||
rowType: 'ACCOUNT_ROW',
|
||||
date: account.name,
|
||||
children: [
|
||||
{
|
||||
...account.opening_balance,
|
||||
name: 'Opening balance',
|
||||
rowType: 'OPENING_BALANCE',
|
||||
},
|
||||
...account.transactions.map((transaction) => ({
|
||||
...transaction,
|
||||
name: account.name,
|
||||
code: account.code,
|
||||
date: moment(transaction.date).format('DD MMM YYYY'),
|
||||
})),
|
||||
{
|
||||
...account.closing_balance,
|
||||
name: 'Closing balance',
|
||||
rowType: 'CLOSING_BALANCE',
|
||||
},
|
||||
],
|
||||
};
|
||||
})
|
||||
.value();
|
||||
};
|
||||
|
||||
export const ARAgingSummaryTableRowsMapper = (sheet, total) => {
|
||||
const rows = [];
|
||||
|
||||
const mapAging = (agingPeriods) => {
|
||||
return agingPeriods.reduce((acc, aging, index) => {
|
||||
acc[`aging-${index}`] = aging.total.formatted_amount;
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
sheet.customers.forEach((customer) => {
|
||||
const agingRow = mapAging(customer.aging);
|
||||
|
||||
rows.push({
|
||||
rowType: 'customer',
|
||||
name: customer.customer_name,
|
||||
...agingRow,
|
||||
current: customer.current.formatted_amount,
|
||||
total: customer.total.formatted_amount,
|
||||
});
|
||||
});
|
||||
if (rows.length <= 0) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
...rows,
|
||||
{
|
||||
name: '',
|
||||
rowType: 'total',
|
||||
current: sheet.total.current.formatted_amount,
|
||||
...mapAging(sheet.total.aging),
|
||||
total: sheet.total.total.formatted_amount,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
export const APAgingSummaryTableRowsMapper = (sheet, total) => {
|
||||
const rows = [];
|
||||
|
||||
const mapAging = (agingPeriods) => {
|
||||
return agingPeriods.reduce((acc, aging, index) => {
|
||||
acc[`aging-${index}`] = aging.total.formatted_amount;
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
sheet.vendors.forEach((vendor) => {
|
||||
const agingRow = mapAging(vendor.aging);
|
||||
|
||||
rows.push({
|
||||
rowType: 'vendor',
|
||||
name: vendor.vendor_name,
|
||||
...agingRow,
|
||||
current: vendor.current.formatted_amount,
|
||||
total: vendor.total.formatted_amount,
|
||||
});
|
||||
});
|
||||
if (rows.length <= 0) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
...rows,
|
||||
{
|
||||
name: '',
|
||||
rowType: 'total',
|
||||
current: sheet.total.current.formatted_amount,
|
||||
...mapAging(sheet.total.aging),
|
||||
total: sheet.total.total.formatted_amount,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
export const mapTrialBalanceSheetToRows = (sheet) => {
|
||||
const results = [];
|
||||
|
||||
if (sheet.accounts) {
|
||||
sheet.accounts.forEach((account) => {
|
||||
results.push(account);
|
||||
});
|
||||
}
|
||||
if (sheet.total) {
|
||||
results.push({
|
||||
rowType: 'total',
|
||||
...sheet.total,
|
||||
});
|
||||
}
|
||||
return results;
|
||||
};
|
||||
@@ -0,0 +1,127 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import t from '@/store/types';
|
||||
|
||||
// Initial state.
|
||||
const initialState = {
|
||||
balanceSheet: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
trialBalance: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
generalLedger: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
journal: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
profitLoss: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
ARAgingSummary: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
APAgingSummary: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
purchasesByItems: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
salesByItems: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
inventoryValuation: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
customersBalanceSummary: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
vendorsBalanceSummary: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
customersTransactions: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
vendorsTransactions: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
cashFlowStatement: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
inventoryItemDetails: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
realizedGainOrLoss: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
unrealizedGainOrLoss: {
|
||||
displayFilterDrawer: false,
|
||||
},
|
||||
projectProfitabilitySummary: {
|
||||
dispalyFilterDrawer: false,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Financial statement filter toggle.
|
||||
*/
|
||||
const financialStatementFilterToggle = (financialName, statePath) => {
|
||||
return {
|
||||
[`${financialName}/${t.DISPLAY_FILTER_DRAWER_TOGGLE}`]: (state, action) => {
|
||||
state[statePath].displayFilterDrawer =
|
||||
typeof action?.payload?.toggle !== 'undefined'
|
||||
? action.payload.toggle
|
||||
: !state[statePath].displayFilterDrawer;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
...financialStatementFilterToggle(t.BALANCE_SHEET, 'balanceSheet'),
|
||||
...financialStatementFilterToggle(t.TRIAL_BALANCE_SHEET, 'trialBalance'),
|
||||
...financialStatementFilterToggle(t.JOURNAL, 'journal'),
|
||||
...financialStatementFilterToggle(t.GENERAL_LEDGER, 'generalLedger'),
|
||||
...financialStatementFilterToggle(t.PROFIT_LOSS, 'profitLoss'),
|
||||
...financialStatementFilterToggle(t.AR_AGING_SUMMARY, 'ARAgingSummary'),
|
||||
...financialStatementFilterToggle(t.AP_AGING_SUMMARY, 'APAgingSummary'),
|
||||
...financialStatementFilterToggle(t.PURCHASES_BY_ITEMS, 'purchasesByItems'),
|
||||
...financialStatementFilterToggle(t.SALES_BY_ITEMS, 'salesByItems'),
|
||||
...financialStatementFilterToggle(
|
||||
t.INVENTORY_VALUATION,
|
||||
'inventoryValuation',
|
||||
),
|
||||
...financialStatementFilterToggle(
|
||||
t.CUSTOMERS_BALANCE_SUMMARY,
|
||||
'customersBalanceSummary',
|
||||
),
|
||||
...financialStatementFilterToggle(
|
||||
t.VENDORS_BALANCE_SUMMARY,
|
||||
'vendorsBalanceSummary',
|
||||
),
|
||||
...financialStatementFilterToggle(
|
||||
t.CUSTOMERS_TRANSACTIONS,
|
||||
'customersTransactions',
|
||||
),
|
||||
...financialStatementFilterToggle(
|
||||
t.VENDORS_TRANSACTIONS,
|
||||
'vendorsTransactions',
|
||||
),
|
||||
...financialStatementFilterToggle(t.CASH_FLOW_STATEMENT, 'cashFlowStatement'),
|
||||
...financialStatementFilterToggle(
|
||||
t.INVENTORY_ITEM_DETAILS,
|
||||
'inventoryItemDetails',
|
||||
),
|
||||
...financialStatementFilterToggle(
|
||||
t.REALIZED_GAIN_OR_LOSS,
|
||||
'realizedGainOrLoss',
|
||||
),
|
||||
...financialStatementFilterToggle(
|
||||
t.UNREALIZED_GAIN_OR_LOSS,
|
||||
'unrealizedGainOrLoss',
|
||||
),
|
||||
...financialStatementFilterToggle(
|
||||
t.PROJECT_PROFITABILITY_SUMMARY,
|
||||
'projectProfitabilitySummary',
|
||||
),
|
||||
});
|
||||
@@ -0,0 +1,280 @@
|
||||
// @ts-nocheck
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
// Financial Statements selectors.
|
||||
export const sheetByTypeSelector = (sheetType) => (state, props) => {
|
||||
return state.financialStatements[sheetType];
|
||||
};
|
||||
|
||||
export const filterDrawerByTypeSelector = (sheetType) => (state) => {
|
||||
return sheetByTypeSelector(sheetType)(state)?.displayFilterDrawer;
|
||||
};
|
||||
|
||||
export const balanceSheetFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('balanceSheet')(state);
|
||||
};
|
||||
|
||||
export const profitLossSheetFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('profitLoss')(state);
|
||||
};
|
||||
|
||||
export const generalLedgerFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('generalLedger')(state);
|
||||
};
|
||||
|
||||
// Trial balance filter drawer selector.
|
||||
export const trialBalanceFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('trialBalance')(state);
|
||||
};
|
||||
|
||||
export const journalFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('journal')(state);
|
||||
};
|
||||
|
||||
export const ARAgingSummaryFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('ARAgingSummary')(state);
|
||||
};
|
||||
|
||||
export const APAgingSummaryFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('APAgingSummary')(state);
|
||||
};
|
||||
|
||||
export const purchasesByItemsFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('purchasesByItems')(state);
|
||||
};
|
||||
|
||||
export const salesByItemsFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('salesByItems')(state);
|
||||
};
|
||||
export const inventoryValuationFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('inventoryValuation')(state);
|
||||
};
|
||||
|
||||
export const customerBalanceSummaryFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('customersBalanceSummary')(state);
|
||||
};
|
||||
|
||||
export const vendorsBalanceSummaryFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('vendorsBalanceSummary')(state);
|
||||
};
|
||||
|
||||
export const customersTransactionsFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('customersTransactions')(state);
|
||||
};
|
||||
|
||||
export const vendorsTransactionsFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('vendorsTransactions')(state);
|
||||
};
|
||||
|
||||
export const cashFlowStatementFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('cashFlowStatement')(state);
|
||||
};
|
||||
|
||||
export const inventoryItemDetailsDrawerFilter = (state) => {
|
||||
return filterDrawerByTypeSelector('inventoryItemDetails')(state);
|
||||
};
|
||||
|
||||
export const realizedGainOrLossFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('realizedGainOrLoss')(state);
|
||||
};
|
||||
|
||||
export const unrealizedGainOrLossFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('unrealizedGainOrLoss')(state);
|
||||
};
|
||||
|
||||
export const projectProfitabilitySummaryFilterDrawerSelector = (state) => {
|
||||
return filterDrawerByTypeSelector('projectProfitabilitySummary')(state);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve balance sheet filter drawer.
|
||||
*/
|
||||
export const getBalanceSheetFilterDrawer = createSelector(
|
||||
balanceSheetFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve whether trial balance sheet display filter drawer.
|
||||
*/
|
||||
export const getTrialBalanceSheetFilterDrawer = createSelector(
|
||||
trialBalanceFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve profit/loss filter drawer.
|
||||
*/
|
||||
export const getProfitLossFilterDrawer = createSelector(
|
||||
profitLossSheetFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve whether display general ledger (GL) filter drawer.
|
||||
*/
|
||||
export const getGeneralLedgerFilterDrawer = createSelector(
|
||||
generalLedgerFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve whether display journal sheet filter drawer.
|
||||
*/
|
||||
export const getJournalFilterDrawer = createSelector(
|
||||
journalFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve whether display AR aging summary drawer filter.
|
||||
*/
|
||||
export const getARAgingSummaryFilterDrawer = createSelector(
|
||||
ARAgingSummaryFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve whether display AR aging summary drawer filter.
|
||||
*/
|
||||
export const getAPAgingSummaryFilterDrawer = createSelector(
|
||||
APAgingSummaryFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve financial statement query by the given sheet index.
|
||||
*/
|
||||
export const getFinancialSheetQueryFactory = (sheetType) =>
|
||||
createSelector(sheetByTypeSelector(sheetType), (sheet) => {
|
||||
return sheet && sheet.query ? sheet.query : {};
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieve whether purchases by items display filter drawer.
|
||||
*/
|
||||
export const getPurchasesByItemsFilterDrawer = createSelector(
|
||||
purchasesByItemsFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve whether sales by items display filter drawer.
|
||||
*/
|
||||
export const getSalesByItemsFilterDrawer = createSelector(
|
||||
salesByItemsFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve whether sells by items display filter drawer.
|
||||
*/
|
||||
export const getInventoryValuationFilterDrawer = createSelector(
|
||||
inventoryValuationFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve customers balance summary filter drawer.
|
||||
*/
|
||||
export const getCustomersBalanceSummaryFilterDrawer = createSelector(
|
||||
customerBalanceSummaryFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
/**
|
||||
* Retrieve vendors balance summary filter drawer.
|
||||
*/
|
||||
export const getVendorsBalanceSummaryFilterDrawer = createSelector(
|
||||
vendorsBalanceSummaryFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve customers transactions filter drawer.
|
||||
*/
|
||||
export const getCustomersTransactionsFilterDrawer = createSelector(
|
||||
customersTransactionsFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve vendors transactions filter drawer.
|
||||
*/
|
||||
export const getVendorsTransactionsFilterDrawer = createSelector(
|
||||
vendorsTransactionsFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve cash flow statement filter drawer.
|
||||
*/
|
||||
export const getCashFlowStatementFilterDrawer = createSelector(
|
||||
cashFlowStatementFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve inventory item details filter drawer.
|
||||
*/
|
||||
export const getInventoryItemDetailsFilterDrawer = createSelector(
|
||||
inventoryItemDetailsDrawerFilter,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve Realized Gain or Loss filter drawer.
|
||||
*/
|
||||
export const getRealizedGainOrLossFilterDrawer = createSelector(
|
||||
realizedGainOrLossFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
/**
|
||||
* Retrieve Unrealized Gain or Loss filter drawer.
|
||||
*/
|
||||
export const getUnrealizedGainOrLossFilterDrawer = createSelector(
|
||||
unrealizedGainOrLossFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
|
||||
export const getProjectProfitabilitySummaryFilterDrawer = createSelector(
|
||||
projectProfitabilitySummaryFilterDrawerSelector,
|
||||
(isOpen) => {
|
||||
return isOpen;
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,23 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
BALANCE_SHEET: 'BALANCE_SHEET',
|
||||
TRIAL_BALANCE_SHEET: 'TRIAL_BALANCE_SHEET',
|
||||
JOURNAL: 'JOURNAL',
|
||||
GENERAL_LEDGER: 'GENERAL_LEDGER',
|
||||
PROFIT_LOSS: 'PROFIT_LOSS',
|
||||
AR_AGING_SUMMARY: 'AR_AGING_SUMMARY',
|
||||
AP_AGING_SUMMARY: 'AP_AGING_SUMMARY',
|
||||
DISPLAY_FILTER_DRAWER_TOGGLE: 'DISPLAY_FILTER_DRAWER_TOGGLE',
|
||||
PURCHASES_BY_ITEMS: 'PURCHASES_BY_ITEMS',
|
||||
SALES_BY_ITEMS: 'SALES_BY_ITEMS',
|
||||
INVENTORY_VALUATION: 'INVENTORY_VALUATION',
|
||||
CUSTOMERS_BALANCE_SUMMARY: 'CUSTOMERS BALANCE SUMMARY',
|
||||
VENDORS_BALANCE_SUMMARY: 'VENDORS BALANCE SUMMARY',
|
||||
CUSTOMERS_TRANSACTIONS: 'CUSTOMERS TRANSACTIONS',
|
||||
VENDORS_TRANSACTIONS: 'VENDORS TRANSACTIONS',
|
||||
CASH_FLOW_STATEMENT: 'CASH FLOW STATEMENT',
|
||||
INVENTORY_ITEM_DETAILS: 'INVENTORY ITEM DETAILS',
|
||||
PROJECT_PROFITABILITY_SUMMARY: 'PROJECT PROFITABILITY SUMMARY',
|
||||
REALIZED_GAIN_OR_LOSS: 'REALIZED GAIN OR LOSS',
|
||||
UNREALIZED_GAIN_OR_LOSS: 'UNREALIZED GAIN OR LOSS',
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
// @ts-nocheck
|
||||
|
||||
|
||||
export const setGlobalErrors = (errors) => {
|
||||
return {
|
||||
type: 'GLOBAL_ERRORS_SET',
|
||||
payload: {
|
||||
errors,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import t from '@/store/types';
|
||||
|
||||
const initialState = {
|
||||
data: {},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
['GLOBAL_ERRORS_SET']: (state, action) => {
|
||||
const { errors } = action.payload;
|
||||
|
||||
state.data = {
|
||||
...state.data,
|
||||
...errors,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
/**
|
||||
* Sets the inventory adjustments table state.
|
||||
*/
|
||||
export const setInventoryAdjustmentsTableState = (queries) => {
|
||||
return {
|
||||
type: t.INVENTORY_ADJUSTMENTS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
const initialState = {
|
||||
tableState: {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
sortBy: [],
|
||||
},
|
||||
selectedRows: [],
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:inventoryAdjustments';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: ['tableState'],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('INVENTORY_ADJUSTMENTS'),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
@@ -0,0 +1,23 @@
|
||||
// @ts-nocheck
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import {
|
||||
paginationLocationQuery,
|
||||
} from '@/store/selectors';
|
||||
|
||||
const inventoryAdjustmentTableState = (state) =>
|
||||
state.inventoryAdjustments.tableState;
|
||||
|
||||
/**
|
||||
* Retrieve the inventory adjustments table state.
|
||||
*/
|
||||
export const getInventroyAdjsTableStateFactory = () =>
|
||||
createSelector(
|
||||
paginationLocationQuery,
|
||||
inventoryAdjustmentTableState,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,5 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export default {
|
||||
INVENTORY_ADJUSTMENTS_TABLE_STATE_SET: 'INVENTORY_ADJUSTMENTS/TABLE_STATE_SET',
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
// @ts-nocheck
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
|
||||
// Items categories table state.
|
||||
const itemsCategoriesTableStateSelector = (state) =>
|
||||
state.itemsCategories.tableState;
|
||||
|
||||
// Get items categories table state marged with location query.
|
||||
export const getItemsCategoriesTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
itemsCategoriesTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,12 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
/**
|
||||
* Sets the items categories table state.
|
||||
*/
|
||||
export const setItemsCategoriesTableState = (queries) => {
|
||||
return {
|
||||
type: t.ITEMS_CATEGORIES_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import {
|
||||
createTableStateReducers,
|
||||
} from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
// Initial state.
|
||||
const initialState = {
|
||||
tableState: {
|
||||
filterRoles: []
|
||||
},
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:itemCategories';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('ITEMS_CATEGORIES'),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(
|
||||
CONFIG,
|
||||
reducerInstance,
|
||||
);
|
||||
@@ -0,0 +1,4 @@
|
||||
// @ts-nocheck
|
||||
export default {
|
||||
ITEMS_CATEGORIES_TABLE_STATE_SET: 'ITEMS_CATEGORIES/TABLE_STATE_SET',
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
|
||||
const initialState = {
|
||||
tableState: {
|
||||
filterRoles: [],
|
||||
},
|
||||
categories: {},
|
||||
loading: false,
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.ITEMS_CATEGORY_LIST_SET]: (state, action) => {
|
||||
const _categories = {};
|
||||
|
||||
action.categories.forEach(category => {
|
||||
_categories[category.id] = category;
|
||||
});
|
||||
state.categories = {
|
||||
...state.categories,
|
||||
..._categories
|
||||
};
|
||||
},
|
||||
|
||||
[t.CATEGORY_DELETE]: (state, action) => {
|
||||
const { id } = action.payload;
|
||||
const categories = { ...state.categories };
|
||||
|
||||
if (typeof categories[id] !== 'undefined') {
|
||||
delete categories[id];
|
||||
state.categories = categories;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const getCategoryId = (state, id) => {
|
||||
return state.itemCategories.categories[id] || {};
|
||||
};
|
||||
18
packages/webapp/src/store/items/items.actions.tsx
Normal file
18
packages/webapp/src/store/items/items.actions.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
// @ts-nocheck
|
||||
import t from '@/store/types';
|
||||
|
||||
export const setItemsTableState = (queries) => {
|
||||
return {
|
||||
type: t.ITEMS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
export const resetItemsTableState = () => {
|
||||
return {
|
||||
type: t.ITEMS_TABLE_STATE_RESET,
|
||||
};
|
||||
}
|
||||
|
||||
export const setSelectedRowsItems = () => {};
|
||||
40
packages/webapp/src/store/items/items.reducer.tsx
Normal file
40
packages/webapp/src/store/items/items.reducer.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
// @ts-nocheck
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from '@/store/tableState.reducer';
|
||||
import t from '@/store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
inactiveMode: false,
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
selectedRows: [],
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:items';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('ITEMS', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(
|
||||
CONFIG,
|
||||
reducerInstance,
|
||||
);
|
||||
26
packages/webapp/src/store/items/items.selectors.tsx
Normal file
26
packages/webapp/src/store/items/items.selectors.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
// @ts-nocheck
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import { paginationLocationQuery } from '@/store/selectors';
|
||||
import { createDeepEqualSelector } from '@/utils';
|
||||
import { defaultTableQuery } from './items.reducer';
|
||||
|
||||
const itemsTableStateSelector = (state) => state.items.tableState;
|
||||
|
||||
// Get items table state marged with location query.
|
||||
export const getItemsTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
itemsTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const isItemsTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(itemsTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
4
packages/webapp/src/store/items/items.types.tsx
Normal file
4
packages/webapp/src/store/items/items.types.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
export default {
|
||||
ITEMS_TABLE_STATE_SET: 'ITEMS/TABLE_STATE_SET',
|
||||
ITEMS_TABLE_STATE_RESET: 'ITEMS/TABLE_STATE_RESET',
|
||||
};
|
||||
48
packages/webapp/src/store/journalNumber.reducer.tsx
Normal file
48
packages/webapp/src/store/journalNumber.reducer.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export const journalNumberChangedReducer = (type) => ({
|
||||
[type]: (state, action) => {
|
||||
const { isChanged } = action.payload;
|
||||
state.journalNumberChanged = isChanged;
|
||||
},
|
||||
});
|
||||
|
||||
export const viewPaginationSetReducer = (type) => ({
|
||||
[type]: (state, action) => {
|
||||
const { pagination, customViewId } = action.payload;
|
||||
|
||||
const mapped = {
|
||||
pageSize: parseInt(pagination.page_size, 10),
|
||||
page: parseInt(pagination.page, 10),
|
||||
total: parseInt(pagination.total, 10),
|
||||
};
|
||||
const paginationMeta = {
|
||||
...mapped,
|
||||
pagesCount: Math.ceil(mapped.total / mapped.pageSize),
|
||||
pageIndex: Math.max(mapped.page - 1, 0),
|
||||
};
|
||||
state.views = {
|
||||
...state.views,
|
||||
[customViewId]: {
|
||||
...(state.views?.[customViewId] || {}),
|
||||
paginationMeta,
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export const createTableQueryReducers = (RESOURCE_NAME) => ({
|
||||
[`${RESOURCE_NAME}/TABLE_QUERY_SET`]: (state, action) => {
|
||||
state.tableQuery = {
|
||||
...state.tableQuery,
|
||||
[state.key]: action.payload.value,
|
||||
};
|
||||
},
|
||||
|
||||
[`${RESOURCE_NAME}/TABLE_QUERIES_ADD`]: (state, action) => {
|
||||
state.tableQuery = {
|
||||
...state.tableQuery,
|
||||
...action.payload.queries,
|
||||
};
|
||||
},
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user