mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
37
src/components/Guards/EnsureOrganizationIsNotReady.js
Normal file
37
src/components/Guards/EnsureOrganizationIsNotReady.js
Normal file
@@ -0,0 +1,37 @@
|
||||
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';
|
||||
|
||||
/**
|
||||
* Ensures organization is not ready.
|
||||
*/
|
||||
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
src/components/Guards/EnsureOrganizationIsReady.js
Normal file
31
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
|
||||
isOrganizationReady,
|
||||
}) {
|
||||
return (isOrganizationReady) ? children : (
|
||||
<Redirect
|
||||
to={{ pathname: redirectTo }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAuthentication(),
|
||||
connect((state, props) => ({
|
||||
organizationId: props.currentOrganizationId,
|
||||
})),
|
||||
withOrganization(({ isOrganizationReady }) => ({ isOrganizationReady })),
|
||||
)(EnsureOrganizationIsReady);
|
||||
31
src/components/Guards/EnsureSubscriptionIsActive.js
Normal file
31
src/components/Guards/EnsureSubscriptionIsActive.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import { includes } from 'lodash';
|
||||
|
||||
import { compose } from 'utils';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import withSubscriptions from '../../containers/Subscriptions/withSubscriptions';
|
||||
|
||||
/**
|
||||
* Ensures the given subscription type is active or redirect to the given route.
|
||||
*/
|
||||
function EnsureSubscriptionIsActive({
|
||||
children,
|
||||
subscriptionType = 'main',
|
||||
redirectTo = '/billing',
|
||||
routePath,
|
||||
exclude,
|
||||
isSubscriptionActive,
|
||||
}) {
|
||||
return isSubscriptionActive || includes(exclude, routePath) ? (
|
||||
children
|
||||
) : (
|
||||
<Redirect to={{ pathname: redirectTo }} />
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSubscriptions(
|
||||
({ isSubscriptionActive }) => ({ isSubscriptionActive }),
|
||||
'main',
|
||||
),
|
||||
)(EnsureSubscriptionIsActive);
|
||||
31
src/components/Guards/EnsureSubscriptionsIsActive.js
Normal file
31
src/components/Guards/EnsureSubscriptionsIsActive.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import { includes } from 'lodash';
|
||||
|
||||
import { compose } from 'utils';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import withSubscriptions from '../../containers/Subscriptions/withSubscriptionss';
|
||||
|
||||
/**
|
||||
* Ensures the given subscription type is active or redirect to the given route.
|
||||
*/
|
||||
function EnsureSubscriptionsIsActive({
|
||||
children,
|
||||
subscriptionType = 'main',
|
||||
redirectTo = '/billing',
|
||||
routePath,
|
||||
exclude,
|
||||
isSubscriptionsActive,
|
||||
}) {
|
||||
return !isSubscriptionsActive || includes(exclude, routePath) ? (
|
||||
children
|
||||
) : (
|
||||
<Redirect to={{ pathname: redirectTo }} />
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSubscriptions(
|
||||
({ isSubscriptionsActive }) => ({ isSubscriptionsActive }),
|
||||
'main',
|
||||
),
|
||||
)(EnsureSubscriptionsIsActive);
|
||||
31
src/components/Guards/EnsureSubscriptionsIsInactive.js
Normal file
31
src/components/Guards/EnsureSubscriptionsIsInactive.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import { includes } from 'lodash';
|
||||
|
||||
import { compose } from 'utils';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import withSubscriptions from '../../containers/Subscriptions/withSubscriptionss';
|
||||
|
||||
/**
|
||||
* Ensures the given subscription type is active or redirect to the given route.
|
||||
*/
|
||||
function EnsureSubscriptionsIsInactive({
|
||||
children,
|
||||
subscriptionType = 'main',
|
||||
redirectTo = '/billing',
|
||||
routePath,
|
||||
exclude,
|
||||
isSubscriptionsInactive,
|
||||
}) {
|
||||
return !isSubscriptionsInactive || includes(exclude, routePath) ? (
|
||||
children
|
||||
) : (
|
||||
<Redirect to={{ pathname: redirectTo }} />
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSubscriptions(
|
||||
({ isSubscriptionsInactive }) => ({ isSubscriptionsInactive }),
|
||||
'main',
|
||||
),
|
||||
)(EnsureSubscriptionsIsInactive);
|
||||
18
src/components/Guards/PrivateRoute.js
Normal file
18
src/components/Guards/PrivateRoute.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import React from 'react';
|
||||
import BodyClassName from 'react-body-classname';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import { useIsAuthenticated } from 'hooks/state';
|
||||
|
||||
export default function PrivateRoute({ component: Component, ...rest }) {
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
|
||||
return (
|
||||
<BodyClassName className={''}>
|
||||
{isAuthenticated ? (
|
||||
<Component />
|
||||
) : (
|
||||
<Redirect to={{ pathname: '/auth/login' }} />
|
||||
)}
|
||||
</BodyClassName>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user