fix: hotbug in dashboard lazy loading resources.

This commit is contained in:
Ahmed Bouhuolia
2020-10-14 18:06:37 +02:00
parent 59e00701d3
commit 8713c77289
8 changed files with 17 additions and 20 deletions

View 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);

View 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);

View 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);