feat(ManualJournals): Auto-increment.

fix(BillPayment): Validate the opened payment bills.
fix(redux): presist redux state.
fix(useRequestQuery): hook.
This commit is contained in:
a.bouhuolia
2021-03-18 14:23:37 +02:00
parent 4e8bdee97a
commit 9ff8e3159d
79 changed files with 1326 additions and 889 deletions

View File

@@ -2,13 +2,8 @@ import t from 'store/types';
export const setLogin = ({ user, token, tenant }) => ({
type: t.LOGIN_SUCCESS,
payload: {
user,
token,
tenant,
},
payload: { user, token, tenant, },
});
export const setLogout = () => ({
type: t.LOGOUT,
});
export const setLogout = () => ({ type: t.LOGOUT });
export const setStoreReset = () => ({ type: t.RESET });

View File

@@ -1,4 +1,6 @@
import { createReducer } from '@reduxjs/toolkit';
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import t from 'store/types';
const initialState = {
@@ -11,7 +13,9 @@ const initialState = {
errors: [],
};
export default createReducer(initialState, {
const STORAGE_KEY = 'bigcapital:authentication';
const reducerInstance = createReducer(initialState, {
[t.LOGIN_SUCCESS]: (state, action) => {
const { token, user, tenant } = action.payload;
state.token = token;
@@ -25,19 +29,20 @@ export default createReducer(initialState, {
state.errors = action.errors;
},
[t.LOGOUT]: (state) => {
state.token = '';
state.user = {};
state.organization = '';
state.organizationId = null;
state.tenant = {};
},
[t.LOGIN_CLEAR_ERRORS]: (state) => {
state.errors = [];
},
});
export default persistReducer(
{
key: STORAGE_KEY,
blacklist: ['errors'],
storage,
},
reducerInstance,
);
export const isAuthenticated = (state) => !!state.authentication.token;
export const hasErrorType = (state, errorType) => {
return state.authentication.errors.find((e) => e.type === errorType);

View File

@@ -5,4 +5,5 @@ export default {
LOGIN_FAILURE: 'LOGIN_FAILURE',
LOGOUT: 'LOGOUT',
LOGIN_CLEAR_ERRORS: 'LOGIN_CLEAR_ERRORS',
RESET: 'RESET',
};