Skip to content

Commit

Permalink
Merge pull request #3763 from Expensify/marcaaron-navToWorkspace
Browse files Browse the repository at this point in the history
Fix up workspace routes
  • Loading branch information
MariaHCD authored Jun 29, 2021
2 parents 1bfa5d2 + 52b9cbe commit 5cde3ca
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export default {
VALIDATE_LOGIN: 'v',
VALIDATE_LOGIN_WITH_VALIDATE_CODE: 'v/:accountID/:validateCode',
ENABLE_PAYMENTS: 'enable-payments',
WORKSPACE: 'workspace',
WORKSPACE_NEW: 'workspace/new',
WORKSPACE_CARD: 'workspace/card',
getWorkspaceRoute: policyID => `workspace/${policyID}`,
WORKSPACE_CARD: ':policyID/card',
WORKSPACE: 'workspace',
getWorkspaceCardRoute: policyID => `workspace/${policyID}/card`,
WORKSPACE_INVITE: 'workspace/:policyID/invite',
getWorkspaceInviteRoute: policyID => `workspace/${policyID}/invite`,
REQUEST_CALL: 'request-call',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import WorkspaceSidebar from '../../../pages/workspace/WorkspaceSidebar';

const WorkspaceSettingsDrawerNavigator = () => (
<BaseDrawerNavigator
drawerContent={() => <WorkspaceSidebar />}
// eslint-disable-next-line react/jsx-props-no-spreading
drawerContent={props => <WorkspaceSidebar {...props} />}
screens={[
{
name: 'WorkspaceCard',
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function goBack() {
* @param {String} route
*/
function navigate(route = ROUTES.HOME) {
if (route === ROUTES.HOME || route === ROUTES.WORKSPACE) {
if (route === ROUTES.HOME) {
if (isLoggedIn) {
openDrawer();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export default {
},

WorkspaceSettings: {
path: ROUTES.WORKSPACE,
screens: {
Workspace_Root: ROUTES.WORKSPACE,
WorkspaceCard: ROUTES.WORKSPACE_CARD,
},
},
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ function create(name) {
id: response.policyID,
type: response.policy.type,
name: response.policy.name,
role: CONST.POLICY.ROLE.ADMIN,
});
Navigation.navigate(ROUTES.getWorkspaceRoute(response.policyID));
Navigation.dismissModal();
Navigation.navigate(ROUTES.getWorkspaceCardRoute(response.policyID));
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/InitialPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const InitialSettingsPage = ({
.map(policy => ({
title: policy.name,
icon: Building,
action: () => Navigation.navigate(ROUTES.getWorkspaceRoute(policy.ID)),
action: () => Navigation.navigate(ROUTES.getWorkspaceCardRoute(policy.id)),
iconStyles: [styles.createMenuIconEmphasized],
iconFill: themeColors.iconReversed,
}))
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceCardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const WorkspaceCardPage = ({
<HeaderWithCloseButton
title={translate('workspace.common.card')}
onCloseButtonPress={() => Navigation.dismissModal()}
onBackButtonPress={() => Navigation.navigate(ROUTES.WORKSPACE)}
onBackButtonPress={() => Navigation.goBack()}
shouldShowBackButton={isSmallScreenWidth}
/>
<ScrollView style={[styles.settingsPageBackground]} bounces={false}>
Expand Down
40 changes: 36 additions & 4 deletions src/pages/workspace/WorkspaceSidebar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import _ from 'underscore';
import React from 'react';
import {View, ScrollView} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import styles from '../../styles/styles';
Expand All @@ -18,21 +22,35 @@ import Icon from '../../components/Icon';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';

const propTypes = {
/** Policy for the current route */
policy: PropTypes.shape({
/** ID of the policy */
id: PropTypes.string,

/** Name of the policy */
name: PropTypes.string,
}),

...withLocalizePropTypes,
...windowDimensionsPropTypes,
};

const WorkspaceSidebar = ({translate, isSmallScreenWidth}) => {
const defaultProps = {
policy: {},
};

const WorkspaceSidebar = ({translate, isSmallScreenWidth, policy}) => {
const menuItems = [
{
translationKey: 'workspace.common.card',
icon: ExpensifyCard,
action: () => {
Navigation.navigate(ROUTES.WORKSPACE_CARD);
Navigation.navigate(ROUTES.getWorkspaceCardRoute(policy.id));
},
isActive: Navigation.isActive(ROUTES.WORKSPACE_CARD),
isActive: Navigation.isActive(ROUTES.getWorkspaceCardRoute(policy.id)),
},
{
translationKey: 'common.people',
Expand All @@ -42,6 +60,10 @@ const WorkspaceSidebar = ({translate, isSmallScreenWidth}) => {
},
];

if (_.isEmpty(policy)) {
return null;
}

return (
<ScreenWrapper style={[!isSmallScreenWidth ? styles.borderRight : {}]}>
<ScrollView
Expand Down Expand Up @@ -86,7 +108,7 @@ const WorkspaceSidebar = ({translate, isSmallScreenWidth}) => {
styles.mb6,
]}
>
Borton Enterprises
{policy.name}
</Text>
</View>
</View>
Expand All @@ -109,9 +131,19 @@ const WorkspaceSidebar = ({translate, isSmallScreenWidth}) => {
};

WorkspaceSidebar.propTypes = propTypes;
WorkspaceSidebar.defaultProps = defaultProps;
WorkspaceSidebar.displayName = 'WorkspaceSidebar';

export default compose(
withLocalize,
withWindowDimensions,
withOnyx({
policy: {
key: (props) => {
const state = props.navigation.getState();
const policyID = lodashGet(state, ['routes', 0, 'params', 'policyID']);
return `${ONYXKEYS.COLLECTION.POLICY}${policyID}`;
},
},
}),
)(WorkspaceSidebar);

0 comments on commit 5cde3ca

Please sign in to comment.