IO-3020 IO-3036 Update ESLint. Add LockWrapper for Header. Add Blur Wrapper.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import Dinero from "dinero.js";
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { HasFeatureAccess } from "./feature-wrapper.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
const blurringProps = {
|
||||
filter: "blur(6px)"
|
||||
};
|
||||
|
||||
export function BlurWrapper({
|
||||
bodyshop,
|
||||
featureName,
|
||||
styleProp = "style",
|
||||
valueProp = "value",
|
||||
overrideValue = true,
|
||||
overrideValueFunction,
|
||||
children
|
||||
}) {
|
||||
if (!HasFeatureAccess({ featureName, bodyshop })) {
|
||||
const childrenWithBlurProps = React.Children.map(children, (child) => {
|
||||
if (React.isValidElement(child)) {
|
||||
//Clone the child, and spread in our props to overwrite it.
|
||||
let newValueProp;
|
||||
if (!overrideValue) {
|
||||
newValueProp = child.props[valueProp];
|
||||
} else {
|
||||
if (typeof overrideValueFunction === "function") {
|
||||
newValueProp = overrideValueFunction();
|
||||
} else if (overrideValueFunction === "RandomDinero") {
|
||||
newValueProp = RandomDinero();
|
||||
} else {
|
||||
newValueProp = "This is some random text. Nothing interesting here.";
|
||||
}
|
||||
}
|
||||
|
||||
return React.cloneElement(child, {
|
||||
[valueProp]: newValueProp,
|
||||
[styleProp]: { ...child.props[styleProp], ...blurringProps }
|
||||
});
|
||||
}
|
||||
return child;
|
||||
});
|
||||
|
||||
return childrenWithBlurProps;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
export default connect(mapStateToProps, null)(BlurWrapper);
|
||||
|
||||
function RandomDinero() {
|
||||
return Dinero({ amount: Math.round(Math.exp(Math.random() * 100, 2)) }).toFormat();
|
||||
}
|
||||
@@ -11,24 +11,36 @@ const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
|
||||
function FeatureWrapper({ bodyshop, featureName, noauth, children, ...restProps }) {
|
||||
function FeatureWrapper({ bodyshop, featureName, noauth, blurContent = false, children, ...restProps }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (HasFeatureAccess({ featureName, bodyshop })) return children;
|
||||
|
||||
return (
|
||||
noauth || (
|
||||
<AlertComponent
|
||||
message={t("general.messages.nofeatureaccess", {
|
||||
app: InstanceRenderManager({
|
||||
imex: "$t(titles.imexonline)",
|
||||
rome: "$t(titles.romeonline)"
|
||||
})
|
||||
})}
|
||||
type="warning"
|
||||
/>
|
||||
)
|
||||
);
|
||||
if (blurContent) {
|
||||
const childrenWithBlurProps = React.Children.map(children, (child) => {
|
||||
// Checking isValidElement is the safe way and avoids a
|
||||
// typescript error too.
|
||||
if (React.isValidElement(child)) {
|
||||
return React.cloneElement(child, { blur: true });
|
||||
}
|
||||
return child;
|
||||
});
|
||||
return childrenWithBlurProps;
|
||||
} else {
|
||||
return (
|
||||
noauth || (
|
||||
<AlertComponent
|
||||
message={t("general.messages.nofeatureaccess", {
|
||||
app: InstanceRenderManager({
|
||||
imex: "$t(titles.imexonline)",
|
||||
rome: "$t(titles.romeonline)"
|
||||
})
|
||||
})}
|
||||
type="warning"
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function HasFeatureAccess({ featureName, bodyshop }) {
|
||||
|
||||
Reference in New Issue
Block a user