Skip to content

Commit

Permalink
fix: disabled wip of new features in production (Greenstand#276)
Browse files Browse the repository at this point in the history
* fix: disabled wip of new features in production

* fix: tweak feature flags

* fix: undo moved code and tidy comments

Co-authored-by: Nick Charlton <[email protected]>
  • Loading branch information
tranquanghuy0801 and nmcharlton authored Jan 10, 2022
1 parent a05a92e commit cf5501a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 55 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ REACT_APP_REPORTING_API_ROOT=https://dev-k8s.treetracker.org/reporting
REACT_APP_REPORTING_ENABLED=true
REACT_APP_ENABLE_EARNINGS=true
REACT_APP_ENABLE_PAYMENTS=true
REACT_APP_ENABLE_MESSAGING=true
REACT_APP_API_URL=https://dev-k8s.treetracker.org
REACT_APP_EARNINGS_API_MAPPING=/earnings
25 changes: 13 additions & 12 deletions src/components/GrowerDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,19 @@ const GrowerDetail = ({ open, growerId, onClose }) => {
ID: <LinkToWebmap value={grower.id} type="user" />
</Typography>
</Grid>
{hasPermission(appContext.user, [POLICIES.SUPER_PERMISSION]) && (
<Grid item>
<Button
className={classes.messageButton}
onClick={() => sendMessageFromGrower(grower)}
component={Link}
to={'/messaging'}
>
Send Message
</Button>
</Grid>
)}
{process.env.REACT_APP_ENABLE_MESSAGING === 'true' &&
hasPermission(appContext.user, [POLICIES.SUPER_PERMISSION]) && (
<Grid item>
<Button
className={classes.messageButton}
onClick={() => sendMessageFromGrower(grower)}
component={Link}
to={'/messaging'}
>
Send Message
</Button>
</Grid>
)}
<Divider />
<Grid container direction="column" className={classes.box}>
<Typography variant="subtitle1">Captures</Typography>
Expand Down
63 changes: 27 additions & 36 deletions src/components/common/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ const useStyles = makeStyles((theme) => ({
textDecoration: 'none',
color: theme.palette.primary.main,
},
disabledLinkItem: {
pointerEvents: 'none',
},
}));

export default function GSMenu(props) {
Expand All @@ -89,49 +86,43 @@ export default function GSMenu(props) {
<Typography className={classes.menuTitle}>
{item.name}
</Typography>
{item.children.map((child, i) => (
<Link
key={`menu_${i}`}
className={
classes.linkItemText +
(child.disabled ? ' ' + classes.disabledLinkItem : '')
}
to={`${child.disabled ? '/' : child.linkTo}`}
>
<MenuItem
className={classes.menuItem}
selected={props.active === item.name}
disabled={child.disabled}
{item.children
.filter(({ disabled }) => !disabled)
.map((child, i) => (
<Link
key={`menu_${i}`}
className={classes.linkItemText}
to={child.linkTo}
>
<Grid container>
<Grid item>
<ListItemIcon className={classes.listItemIcon}>
{child.icon && <child.icon />}
</ListItemIcon>
</Grid>
<Grid item>
<ListItemText className={classes.listItemText}>
{child.name}
</ListItemText>
<MenuItem
className={classes.menuItem}
selected={props.active === item.name}
>
<Grid container>
<Grid item>
<ListItemIcon className={classes.listItemIcon}>
{child.icon && <child.icon />}
</ListItemIcon>
</Grid>
<Grid item>
<ListItemText className={classes.listItemText}>
{child.name}
</ListItemText>
</Grid>
</Grid>
</Grid>
</MenuItem>
</Link>
))}
</MenuItem>
</Link>
))}
</div>
) : (
<Link
key={`menu_${i}`}
className={
classes.linkItemText +
(item.disabled ? ' ' + classes.disabledLinkItem : '')
}
to={`${item.disabled ? '/' : item.linkTo}`}
className={classes.linkItemText}
to={item.linkTo}
>
<MenuItem
className={classes.menuItem}
selected={props.active === item.name}
disabled={item.disabled}
>
<Grid container>
<Grid item>
Expand Down
18 changes: 11 additions & 7 deletions src/context/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import InboxRounded from '@material-ui/icons/InboxRounded';
import { session, hasPermission, POLICIES } from '../models/auth';
import api from '../api/treeTrackerApi';

export const AppContext = createContext({}); // no initial context here because we want login values to be 'undefined' until they are confirmed
// no initial context here because we want login values to be 'undefined' until they are confirmed
export const AppContext = createContext({});

function getRoutes(user) {
return [
Expand Down Expand Up @@ -101,6 +102,9 @@ function getRoutes(user) {
disabled: process.env.REACT_APP_ENABLE_PAYMENTS !== 'true',
},
],
disabled:
process.env.REACT_APP_ENABLE_EARNINGS !== 'true' &&
process.env.REACT_APP_ENABLE_PAYMENTS !== 'true',
},
{
name: 'Growers',
Expand Down Expand Up @@ -149,10 +153,12 @@ function getRoutes(user) {
linkTo: '/messaging',
component: MessagingView,
icon: InboxRounded,
disabled: !hasPermission(user, [
POLICIES.SUPER_PERMISSION,
POLICIES.SEND_MESSAGES,
]),
disabled:
process.env.REACT_APP_ENABLE_MESSAGING !== 'true' ||
!hasPermission(user, [
POLICIES.SUPER_PERMISSION,
POLICIES.SEND_MESSAGES,
]),
},
];
}
Expand All @@ -167,7 +173,6 @@ export const AppProvider = (props) => {

// check if the user has an org load organizations when the user changes
useEffect(() => {
// if (user && token && !user?.policy?.organization?.id) {
if (user && token) {
loadOrganizations();
}
Expand All @@ -192,7 +197,6 @@ export const AppProvider = (props) => {
}
)
.then((response) => {
// console.log('CONTEXT CHECK SESSION', response.data, 'USER', localUser, 'TOKEN', localToken);
if (response.status === 200) {
if (response.data.token === undefined) {
//the role has not changed
Expand Down

0 comments on commit cf5501a

Please sign in to comment.