Skip to content

Commit

Permalink
custom pages now hidden under featuer flag
Browse files Browse the repository at this point in the history
  • Loading branch information
frimpongopoku committed Dec 5, 2024
1 parent dd67b02 commit d4029f2
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 120 deletions.
95 changes: 60 additions & 35 deletions app/api/ui/communityAdminMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,7 @@ const CADMIN_MENU = [
}
]
},
{
key: "custom-pages",
name: "Pages(Beta)",
icon: "ios-paper",
child: [
// {
// key: "create-custom-page",
// name: "Create Page",
// link: APP_LINKS.PAGE_BUILDER_CREATE_OR_EDIT,
// target: "_blank"
// },
{
key: "all-custom-pages",
name: "All My Custom Pages",
link: APP_LINKS.PAGE_BUILDER_VIEW_PAGES
}
]
},

{
key: "settings",
name: "Settings",
Expand All @@ -235,31 +218,73 @@ const CADMIN_MENU = [
}
];

let menuAttachmentsObj = {};

menuAttachmentsObj[FLAGS.BROADCAST_MESSAGING_FF] = {
appendTo: "messages",
value: [
{
key: "send-message",
name: "Send Message",
link: "/admin/send/message"
},
{
key: "scheduled-messages",
name: "Scheduled Messages",
link: "/admin/scheduled/messages"
}
],
index: 1
let menuAttachmentsObj = {
[FLAGS.BROADCAST_MESSAGING_FF]: {
appendTo: "messages",
value: [
{
key: "send-message",
name: "Send Message",
link: "/admin/send/message"
},
{
key: "scheduled-messages",
name: "Scheduled Messages",
link: "/admin/scheduled/messages"
}
],
index: 1
},
[FLAGS.CUSTOM_PAGES]: {
index: 10,
value: [
{
key: "custom-pages",
name: "Pages(Beta)",
icon: "ios-paper",
child: [
// {
// key: "create-custom-page",
// name: "Create Page",
// link: APP_LINKS.PAGE_BUILDER_CREATE_OR_EDIT,
// target: "_blank"
// },
{
key: "all-custom-pages",
name: "All My Custom Pages",
link: APP_LINKS.PAGE_BUILDER_VIEW_PAGES
}
]
}
]
}
};

// menuAttachmentsObj[FLAGS.BROADCAST_MESSAGING_FF] = {
// appendTo: "messages",
// value: [
// {
// key: "send-message",
// name: "Send Message",
// link: "/admin/send/message"
// },
// {
// key: "scheduled-messages",
// name: "Scheduled Messages",
// link: "/admin/scheduled/messages"
// }
// ],
// index: 1
// };

const hasAlreadyBeenAppended = (mainArray, bigObjArray) => {
const idsA = bigObjArray.map((objA) => objA.key);
return idsA.every((id) => mainArray.some((objB) => objB.key === id));
};

// TODO: Rewrite this so that it is more readable, and it also handles the case where the item to be appended to is a child item (make it recurse?)
const communityAdminMenu = ({ flags }) => {
console.log("LET SEE FLAGS", flags);
if (!flags || flags?.length === 0) return CADMIN_MENU;

flags.forEach((flag) => {
Expand Down
2 changes: 1 addition & 1 deletion app/api/ui/superAdminMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ module.exports = [
{
key: "custom-pages",
name: "Pages(Beta)",
icon: "ios-people",
icon: "ios-paper",
child: [
// {
// key: "create-custom-page",
Expand Down
1 change: 1 addition & 0 deletions app/components/FeatureFlags/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export const FLAGS = {
EVENT_NUDGE_FEATURE_FLAG_KEY : "user-event-nudge-feature-flag",
CUSTOMIZE_NAVIGATION_MENU: "customize-navigation-menu-feature-flag",
CUSTOMIZE_AUTO_SHARE_SETTINGS: "shared-testimonials-nudge-feature-flag",
CUSTOM_PAGES: "custom-pages-feature-flag",
...USER_PORTAL_FLAGS
};
79 changes: 38 additions & 41 deletions app/components/Sidebar/Sidebar.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import React, { Fragment } from "react";
import PropTypes from "prop-types";
import { withStyles } from "@mui/styles";
import { connect } from 'react-redux';
import classNames from 'classnames';
import Hidden from '@mui/material/Hidden';
import Drawer from '@mui/material/Drawer';
import SwipeableDrawer from '@mui/material/SwipeableDrawer';
import dummy from 'dan-api/dummy/dummyContents';
import { bindActionCreators } from 'redux';
import styles from './sidebar-jss';
import SidebarContent from './SidebarContent';
import communityAdminMenu from '../../api/ui/communityAdminMenu';
import superAdminMenu from '../../api/ui/superAdminMenu';

import { connect } from "react-redux";
import classNames from "classnames";
import Hidden from "@mui/material/Hidden";
import Drawer from "@mui/material/Drawer";
import SwipeableDrawer from "@mui/material/SwipeableDrawer";
import dummy from "dan-api/dummy/dummyContents";
import { bindActionCreators } from "redux";
import styles from "./sidebar-jss";
import SidebarContent from "./SidebarContent";
import communityAdminMenu from "../../api/ui/communityAdminMenu";
import superAdminMenu from "../../api/ui/superAdminMenu";
import { mergeTwoArrOfObjs } from "../../utils/helpers";

class Sidebar extends React.Component {
state = {
Expand All @@ -25,51 +25,49 @@ class Sidebar extends React.Component {
flagDarker = false;

componentDidMount = () => {
window.addEventListener('scroll', this.handleScroll);
}
window.addEventListener("scroll", this.handleScroll);
};

componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll);
window.removeEventListener("scroll", this.handleScroll);
}

handleScroll = () => {
const doc = document.documentElement;
const scroll = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
const newFlagDarker = (scroll > 30);
const newFlagDarker = scroll > 30;
if (this.flagDarker !== newFlagDarker) {
this.setState({ turnDarker: newFlagDarker });
this.flagDarker = newFlagDarker;
}
}
};

handleOpen = event => {
handleOpen = (event) => {
this.setState({ anchorEl: event.currentTarget });
};

handleClose = () => {
this.setState({ anchorEl: null });
};

handleChangeStatus = status => {
handleChangeStatus = (status) => {
this.setState({ status });
this.handleClose();
}

};

render() {
const {
classes,
open,
toggleDrawerOpen,
loadTransition,
leftSidebar,
auth,
featureFlags,
} = this.props;
const { classes, open, toggleDrawerOpen, loadTransition, leftSidebar, auth, featureFlags } = this.props;
const drawerWidth = 240;

const { status, anchorEl, turnDarker } = this.state;
const dataMenu = auth && auth.is_super_admin ? superAdminMenu : communityAdminMenu({flags:auth?.feature_flags});
let flagsTogether = auth?.feature_flags || [];

// Merge the user specific flags and the community specific flags together
flagsTogether = auth?.admin_at?.reduce(
(acc, curr) => mergeTwoArrOfObjs(acc, curr?.feature_flags, "key"),
flagsTogether
);
const dataMenu = auth && auth.is_super_admin ? superAdminMenu : communityAdminMenu({ flags: flagsTogether });
return (
<Fragment>
<Hidden lgUp>
Expand Down Expand Up @@ -100,11 +98,7 @@ class Sidebar extends React.Component {
variant="permanent"
onClose={toggleDrawerOpen}
classes={{
paper: classNames(
classes.drawer,
classes.drawerPaper,
!open ? classes.drawerPaperClose : ""
),
paper: classNames(classes.drawer, classes.drawerPaper, !open ? classes.drawerPaperClose : "")
}}
open={open}
anchor={leftSidebar ? "left" : "right"}
Expand Down Expand Up @@ -135,7 +129,7 @@ Sidebar.propTypes = {
loadTransition: PropTypes.func.isRequired,
open: PropTypes.bool.isRequired,
leftSidebar: PropTypes.bool,
dataMenu: PropTypes.array.isRequired,
dataMenu: PropTypes.array.isRequired
};

Sidebar.defaultProps = {
Expand All @@ -145,8 +139,11 @@ Sidebar.defaultProps = {
function mapStateToProps(state) {
return {
auth: state.getIn(["auth"]),
featureFlags: state.getIn(["featureFlags"]),
featureFlags: state.getIn(["featureFlags"])
};
}
const SidebarMapped = connect(mapStateToProps, null)(Sidebar);
const SidebarMapped = connect(
mapStateToProps,
null
)(Sidebar);
export default withStyles(styles)(SidebarMapped);
2 changes: 1 addition & 1 deletion app/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"IS_LOCAL": false,
"IS_PROD": false,
"IS_CANARY": false,
"BUILD_VERSION": "4.16.17"
"BUILD_VERSION": "4.16.18"
}
Loading

0 comments on commit d4029f2

Please sign in to comment.