mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
fix: hotbug in dashboard lazy loading resources.
This commit is contained in:
34
client/src/components/Guards/EnsureOrganizationIsNotReady.js
Normal file
34
client/src/components/Guards/EnsureOrganizationIsNotReady.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import { compose } from 'utils';
|
||||
import withAuthentication from 'containers/Authentication/withAuthentication';
|
||||
import withOrganization from 'containers/Organization/withOrganization';
|
||||
|
||||
function EnsureOrganizationIsNotReady({
|
||||
children,
|
||||
|
||||
// #withOrganization
|
||||
isOrganizationReady,
|
||||
isOrganizationSetupCompleted
|
||||
}) {
|
||||
return (isOrganizationReady && !isOrganizationSetupCompleted) ? (
|
||||
<Redirect to={{ pathname: '/' }} />
|
||||
) : children;
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAuthentication(({ currentOrganizationId }) => ({
|
||||
currentOrganizationId,
|
||||
})),
|
||||
connect((state, props) => ({
|
||||
organizationId: props.currentOrganizationId,
|
||||
})),
|
||||
withOrganization(({
|
||||
isOrganizationReady,
|
||||
isOrganizationSetupCompleted
|
||||
}) => ({
|
||||
isOrganizationReady,
|
||||
isOrganizationSetupCompleted
|
||||
})),
|
||||
)(EnsureOrganizationIsNotReady);
|
||||
31
client/src/components/Guards/EnsureOrganizationIsReady.js
Normal file
31
client/src/components/Guards/EnsureOrganizationIsReady.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import { compose } from 'utils';
|
||||
|
||||
import withAuthentication from 'containers/Authentication/withAuthentication';
|
||||
import withOrganization from 'containers/Organization/withOrganization';
|
||||
|
||||
|
||||
function EnsureOrganizationIsReady({
|
||||
// #ownProps
|
||||
children,
|
||||
redirectTo = '/setup',
|
||||
|
||||
// #withOrganizationByOrgId
|
||||
isOrganizationInitialized,
|
||||
}) {
|
||||
return (isOrganizationInitialized) ? children : (
|
||||
<Redirect
|
||||
to={{ pathname: redirectTo }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAuthentication(),
|
||||
connect((state, props) => ({
|
||||
organizationId: props.currentOrganizationId,
|
||||
})),
|
||||
withOrganization(({ isOrganizationInitialized }) => ({ isOrganizationInitialized })),
|
||||
)(EnsureOrganizationIsReady);
|
||||
26
client/src/components/Guards/PrivateRoute.js
Normal file
26
client/src/components/Guards/PrivateRoute.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import BodyClassName from 'react-body-classname';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import withAuthentication from 'containers/Authentication/withAuthentication';
|
||||
import { compose } from 'utils';
|
||||
|
||||
function PrivateRoute({ component: Component, isAuthorized = false, ...rest }) {
|
||||
return (
|
||||
<BodyClassName className={''}>
|
||||
{isAuthorized ? (
|
||||
<Component />
|
||||
) : (
|
||||
<Redirect
|
||||
to={{
|
||||
pathname: '/auth/login',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</BodyClassName>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAuthentication(({ isAuthorized }) => ({ isAuthorized })),
|
||||
)(PrivateRoute);
|
||||
Reference in New Issue
Block a user