feat: add feature guard as hook and component.

This commit is contained in:
a.bouhuolia
2022-02-13 16:29:50 +02:00
parent fdd52f1ecf
commit 9b7befc544
12 changed files with 134 additions and 39 deletions

View File

@@ -0,0 +1,13 @@
import React from 'react';
import * as R from 'ramda';
import withFeatureCan from './withFeatureCan';
function FeatureCanJSX({ feature, children, isFeatureCan }) {
return isFeatureCan && children;
}
export const FeatureCan = R.compose(
withFeatureCan(({ isFeatureCan }) => ({
isFeatureCan,
})),
)(FeatureCanJSX);

View File

@@ -0,0 +1 @@
export * from './FeatureCan';

View File

@@ -0,0 +1,17 @@
import { connect } from 'react-redux';
import { getDashboardFeaturesSelector } from '../../store/dashboard/dashboard.selectors';
export default (mapState) => {
const featuresSelector = getDashboardFeaturesSelector();
const mapStateToProps = (state, props) => {
const features = featuresSelector(state);
const mapped = {
isFeatureCan: !!features[props.feature],
features,
};
return mapState ? mapState(mapped, state, props) : mapped;
};
return connect(mapStateToProps);
};

View File

@@ -96,6 +96,7 @@ export * from './Skeleton';
export * from './FinancialStatement';
export * from './FinancialReport';
export * from './FinancialSheet';
export * from './FeatureGuard';
const Hint = FieldHint;