IO-2703 Resolve incorrect Feature wrapper use.

This commit is contained in:
Patrick Fic
2024-03-19 10:16:42 -07:00
parent 01a9e7dc34
commit cdd5b26443
5 changed files with 25 additions and 23 deletions

View File

@@ -1,23 +1,17 @@
import dayjs from "../../utils/day";
import React from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import AlertComponent from "../alert/alert.component";
import dayjs from '../../utils/day';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import { selectBodyshop } from '../../redux/user/user.selectors';
import AlertComponent from '../alert/alert.component';
import InstanceRenderManager from '../../utils/instanceRenderMgr';
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
});
function FeatureWrapper({
bodyshop,
featureName,
noauth,
children,
...restProps
}) {
function FeatureWrapper({ bodyshop, featureName, noauth, children, ...restProps }) {
const { t } = useTranslation();
if (HasFeatureAccess({ featureName, bodyshop })) return children;
@@ -25,7 +19,13 @@ function FeatureWrapper({
return (
noauth || (
<AlertComponent
message={t("general.messages.nofeatureaccess", {app: InstanceRenderManager({imex:'$t(titles.imexonline)', rome: '$t(titles.romeonline)', promanager: '$t(titles.promanager)'})})}
message={t('general.messages.nofeatureaccess', {
app: InstanceRenderManager({
imex: '$t(titles.imexonline)',
rome: '$t(titles.romeonline)',
promanager: '$t(titles.promanager)',
}),
})}
type="warning"
/>
)
@@ -33,10 +33,12 @@ function FeatureWrapper({
}
export function HasFeatureAccess({ featureName, bodyshop }) {
return (
bodyshop?.features.allAccess ||
console.log(
'Feature Name', featureName,
bodyshop?.features.allAccess,
dayjs(bodyshop?.features[featureName]).isAfter(dayjs())
);
return bodyshop?.features.allAccess || dayjs(bodyshop?.features[featureName]).isAfter(dayjs());
}
export default connect(mapStateToProps, null)(FeatureWrapper);

View File

@@ -290,7 +290,7 @@ export function JobLinesComponent({
key: 'location',
render: (text, record) => <JobLineLocationPopup jobline={record} disabled={jobRO} />,
},
...(HasFeatureAccess({ featureName: 'bills' })
...(HasFeatureAccess({ featureName: 'bills', bodyshop })
? [
{
title: t('joblines.labels.billref'),

View File

@@ -141,9 +141,10 @@ export function ReportCenterModalComponent({reportCenterModal, bodyshop}) {
const grouped = _.groupBy(FilteredReportsList, "group");
const groupExcludeKeyFilter = [...!HasFeatureAccess({featureName: 'bills'})? ["purchases"]:[],
...!HasFeatureAccess({featureName: 'timetickets'})? ["payroll"]:[],
]
const groupExcludeKeyFilter = [
...(!HasFeatureAccess({ featureName: 'bills', bodyshop }) ? ['purchases'] : []),
...(!HasFeatureAccess({ featureName: 'timetickets', bodyshop }) ? ['payroll'] : []),
];
return (
<div>

View File

@@ -18,7 +18,6 @@ import ShopInfoSpeedPrint from "./shop-info.speedprint.component";
import {useLocation, useNavigate} from "react-router-dom";
import ShopInfoTaskPresets from "./shop-info.task-presets.component";
import queryString from "query-string";
import { HasFeatureAccess } from "../feature-wrapper/feature-wrapper.component";
import InstanceRenderManager from "../../utils/instanceRenderMgr";
const mapStateToProps = createStructuredSelector({

View File

@@ -72,7 +72,7 @@ export function ShopPage({bodyshop, setSelectedHeader, setBreadcrumbs}) {
},
);
if(HasFeatureAccess("csi")){
if(HasFeatureAccess({featureName:"csi", bodyshop})){
items.push({
key: "csiq",
label: t("bodyshop.labels.csiq"),