Skip to content

Commit

Permalink
props validation added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay-aot committed Nov 14, 2024
1 parent 5a9c581 commit 3a53ac9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
31 changes: 27 additions & 4 deletions forms-flow-nav/src/sidenav/MenuComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ import { ChevronIcon } from "@formsflow/components";
import { MULTITENANCY_ENABLED } from "../constants/constants";
import { useTranslation } from "react-i18next";
import { StorageService } from "@formsflow/service";
import PropTypes from "prop-types";

const MenuComponent = ({ eventKey, mainMenu, subMenu, optionsCount, subscribe }) => {
const MenuComponent = ({
eventKey,
mainMenu,
subMenu,
optionsCount,
subscribe,
}) => {
const [tenant, setTenant] = React.useState({});
const location = useLocation();
const history = useHistory();
Expand All @@ -16,7 +23,7 @@ const MenuComponent = ({ eventKey, mainMenu, subMenu, optionsCount, subscribe })
const { t } = useTranslation();
const noOptionsMenu = optionsCount === "0";

React.useEffect(() => {
React.useEffect(() => {
subscribe("ES_TENANT", (msg, data) => {
if (data) {
setTenant(data);
Expand All @@ -35,8 +42,10 @@ const MenuComponent = ({ eventKey, mainMenu, subMenu, optionsCount, subscribe })
}
};

const isActive = subMenu.some((menu) =>
menu.matchExps && menu.matchExps.some((exp) => exp.test(location.pathname))
const isActive = subMenu.some(
(menu) =>
menu.matchExps &&
menu.matchExps.some((exp) => exp.test(location.pathname))
);

return (
Expand Down Expand Up @@ -85,4 +94,18 @@ const MenuComponent = ({ eventKey, mainMenu, subMenu, optionsCount, subscribe })
);
};

MenuComponent.propTypes = {
eventKey: PropTypes.string.isRequired,
mainMenu: PropTypes.string.isRequired,
subMenu: PropTypes.arrayOf(
PropTypes.shape({
path: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
matchExps: PropTypes.arrayOf(PropTypes.instanceOf(RegExp)),
})
).isRequired,
optionsCount: PropTypes.string.isRequired,
subscribe: PropTypes.func.isRequired,
};

export default MenuComponent;
8 changes: 8 additions & 0 deletions forms-flow-nav/src/sidenav/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { checkIntegrationEnabled } from "../services/integration";
import MenuComponent from "./MenuComponent";
// import Appname from "./formsflow.svg";
import { ApplicationLogo } from "@formsflow/components";
import PropTypes from 'prop-types';

const Sidebar = React.memo(({ props }) => {
const [tenantLogo, setTenantLogo] = React.useState("");
Expand Down Expand Up @@ -336,4 +337,11 @@ const Sidebar = React.memo(({ props }) => {
);
});

Sidebar.propTypes = {
props: PropTypes.shape({
subscribe: PropTypes.func.isRequired,
getKcInstance: PropTypes.func.isRequired,
}).isRequired,
};

export default Sidebar;

0 comments on commit 3a53ac9

Please sign in to comment.