Files
bigcapital/client/src/store/authentication/authentication.reducer.js
a.bouhuolia 42230fe64b feat(FinancialReports): add loading progress bar.
fix(preformance): Optimize preformance of virtualized list.
fix(preformance): Optimize financial reports preformance.
2021-03-16 17:27:35 +02:00

50 lines
1.3 KiB
JavaScript

import { createReducer } from '@reduxjs/toolkit';
import t from 'store/types';
const initialState = {
token: '',
organization: '',
organizationId: null,
user: '',
tenant: {},
locale: '',
errors: [],
};
export default createReducer(initialState, {
[t.LOGIN_SUCCESS]: (state, action) => {
const { token, user, tenant } = action.payload;
state.token = token;
state.user = user;
state.organization = tenant.organization_id;
state.organizationId = tenant.id;
state.tenant = tenant;
},
[t.LOGIN_FAILURE]: (state, action) => {
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 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;